@@ -727,7 +727,6 @@ proc compile(str: string, blockToRender: string = ""): seq[NwtNode] =
727
727
blocks[nwtn.blockName] = nwtn.blockBody
728
728
if blockToRender == " " :
729
729
var base = templateCache[0 ]
730
- # return fillBlocks(base).condenseStrings() # ast condense after blocks are filled # TODO remove
731
730
result = fillBlocks (base).condenseStrings () # ast condense after blocks are filled
732
731
else :
733
732
if blocks.contains (blockToRender):
@@ -738,7 +737,6 @@ proc compile(str: string, blockToRender: string = ""): seq[NwtNode] =
738
737
quit ()
739
738
# echo result
740
739
741
-
742
740
proc generatePreallocatedStringDef (len: int ): NimNode =
743
741
# dumpAstGen:
744
742
# when result is string:
@@ -810,13 +808,14 @@ template tmplsMacroImpl() =
810
808
alias.add body
811
809
result .add alias
812
810
813
- macro compileTemplateStr * (str: typed , baseDir: static string = " " , iter: static bool = false ,
814
- varname: static string = " result" , blockToRender: static string = " " , context: untyped = nil ): untyped =
811
+ macro compileTemplateStr * (str: typed , baseDir: static string = " " ,
812
+ blockToRender: static string = " " , iter: static bool = false ,
813
+ varname: static string = " result" , context: untyped = nil ): untyped =
815
814
# # Compiles a Nimja template from a string.
816
815
# #
817
816
# # .. code-block:: Nim
818
817
# # proc yourFunc(yourParams: bool): string =
819
- # # compileTemplateString ("{%if yourParams%}TRUE{%endif%}")
818
+ # # compileTemplateStr ("{%if yourParams%}TRUE{%endif%}")
820
819
# #
821
820
# # echo yourFunc(true)
822
821
# #
@@ -826,15 +825,15 @@ macro compileTemplateStr*(str: typed, baseDir: static string = "", iter: static
826
825
# #
827
826
# # .. code-block:: nim
828
827
# # iterator yourIter(yourParams: bool): string =
829
- # # compileTemplateString ("{%for idx in 0 .. 100%}{{idx}}{%endfor%}", iter = true)
828
+ # # compileTemplateStr ("{%for idx in 0 .. 100%}{{idx}}{%endfor%}", iter = true)
830
829
# #
831
830
# # for elem in yourIter(true):
832
831
# # echo elem
833
832
# #
834
833
# # `varname` specifies the variable that is appended to.
835
834
# #
836
835
# #
837
- # # A context can be supplied to the `compileTemplateString ` (also `compileTemplateFile`), to override variable names:
836
+ # # A context can be supplied to the `compileTemplateStr ` (also `compileTemplateFile`), to override variable names:
838
837
# #
839
838
# # .. code-block:: nim
840
839
# # block:
@@ -845,7 +844,7 @@ macro compileTemplateStr*(str: typed, baseDir: static string = "", iter: static
845
844
# # var rax = Rax(aa: "aaaa", bb: 13.37)
846
845
# # var foo = 123
847
846
# # proc render(): string =
848
- # # compileTemplateString ("{{node.bb}}{{baa}}", {node: rax, baa: foo})
847
+ # # compileTemplateStr ("{{node.bb}}{{baa}}", {node: rax, baa: foo})
849
848
# #
850
849
851
850
# Please note, currently the context **cannot be** procs/funcs etc.
@@ -855,8 +854,9 @@ macro compileTemplateStr*(str: typed, baseDir: static string = "", iter: static
855
854
tmplsMacroImpl ()
856
855
doCompile (str.strVal, blockToRender, result )
857
856
858
- macro compileTemplateFile * (path: static string , baseDir: static string = " " , iter: static bool = false ,
859
- varname: static string = " result" , blockToRender: static string = " " , context: untyped = nil ): untyped =
857
+ macro compileTemplateFile * (path: static string , baseDir: static string = " " ,
858
+ blockToRender: static string = " " , iter: static bool = false ,
859
+ varname: static string = " result" , context: untyped = nil ): untyped =
860
860
# # Compiles a Nimja template from a file.
861
861
# #
862
862
# # .. code-block:: nim
@@ -878,7 +878,7 @@ macro compileTemplateFile*(path: static string, baseDir: static string = "", ite
878
878
# #
879
879
# # `varname` specifies the variable that is appended to.
880
880
# #
881
- # # A context can be supplied to the `compileTemplateFile` (also `compileTemplateString `), to override variable names:
881
+ # # A context can be supplied to the `compileTemplateFile` (also `compileTemplateStr `), to override variable names:
882
882
# #
883
883
# # .. code-block:: nim
884
884
# # block:
@@ -898,9 +898,9 @@ macro compileTemplateFile*(path: static string, baseDir: static string = "", ite
898
898
tmplsMacroImpl ()
899
899
doCompile (str, blockToRender, result )
900
900
901
- template tmplsImpl (str: static string , baseDir: static string , blockToRender: static string = " " ): string =
901
+ template tmplsImpl (str: static string , baseDir: static string , blockToRender: static string ): string =
902
902
var nimjaTmplsVar: string
903
- compileTemplateStr (str, baseDir, varname = astToStr nimjaTmplsVar, blockToRender = blockToRender )
903
+ compileTemplateStr (str, baseDir, blockToRender, varname = astToStr nimjaTmplsVar)
904
904
nimjaTmplsVar
905
905
906
906
macro tmpls * (str: static string , baseDir: static string = " " ,
@@ -926,12 +926,12 @@ macro tmpls*(str: static string, baseDir: static string = "",
926
926
result .add quote do :
927
927
tmplsImpl (`str`, `baseDir`, `blockToRender`)
928
928
929
- template tmplfImpl (path: static string , baseDir: static string = " " ,): string =
929
+ template tmplfImpl (path: static string , baseDir: static string = " " , blockToRender: static string = " " ): string =
930
930
var nimjaTmplfVar: string
931
- compileTemplateFile (path, baseDir, varname = astToStr nimjaTmplfVar)
931
+ compileTemplateFile (path, baseDir, blockToRender, varname = astToStr nimjaTmplfVar)
932
932
nimjaTmplfVar
933
933
934
- macro tmplf * (str: static string , baseDir: static string = " " , context: untyped = nil ): string =
934
+ macro tmplf * (str: static string , baseDir: static string = " " , blockToRender: static string = " " , context: untyped = nil ): string =
935
935
# # Compiles a Nimja template file and returns directly.
936
936
# # Can be used inline, without a wrapper proc.
937
937
# #
@@ -950,4 +950,4 @@ macro tmplf*(str: static string, baseDir: static string = "", context: untyped =
950
950
# #
951
951
tmplsMacroImpl ()
952
952
result .add quote do :
953
- tmplfImpl (`str`, `baseDir`)
953
+ tmplfImpl (`str`, `baseDir`, `blockToRender` )
0 commit comments