Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template fragment #109

Merged
merged 7 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,13 @@ tests/basic/theModule/theModule
tests/bugs/test_nwt_bug4_debug
examples/prologue/serverPrologue
examples/prologue/serverJester
examples/dynlib/libtemplates.so
examples/dynlib/runner
examples/hcr/hcrex
examples/hcr/libtmpls.so
examples/hcr/tmpls
src/nimja/hcrutils
examples/fromReadme/server
tests/basic/test_variable_escape
tests/basic/test_fragments
tests/basic/test_procmodule
4 changes: 2 additions & 2 deletions docs/nimja.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ <h1><a class="toc-backref" href="#6">Imports</a></h1>
<div class="section" id="19">
<h1><a class="toc-backref" href="#19">Exports</a></h1>
<dl class="item">
<a href="nimja/parser.html#compileTemplateStr.m,typed,staticstring,staticbool,staticstring,untyped"><span class="Identifier">compileTemplateStr</span></a>, <a href="nimja/parser.html#compileTemplateFile.m,staticstring,staticstring,staticbool,staticstring,untyped"><span class="Identifier">compileTemplateFile</span></a>, <a href="nimja/sharedhelper.html#getScriptDir.t"><span class="Identifier">getScriptDir</span></a>, <a href="nimja/parser.html#tmpls.m,staticstring,staticstring,untyped"><span class="Identifier">tmpls</span></a>, <a href="nimja/parser.html#tmplf.m,staticstring,staticstring,untyped"><span class="Identifier">tmplf</span></a>, <a href="nimja/nimjautils.html#Loop"><span class="Identifier">Loop</span></a>, <a href="nimja/nimjautils.html#includeRaw,string"><span class="Identifier">includeRaw</span></a>, <a href="nimja/nimjautils.html#slugify,string,string"><span class="Identifier">slugify</span></a>, <a href="nimja/nimjautils.html#|.m,untyped,untyped"><span class="Identifier">|</span></a>, <a href="nimja/nimjautils.html#Loopable"><span class="Identifier">Loopable</span></a>, <a href="nimja/nimjautils.html#allowedCharsInSlug"><span class="Identifier">allowedCharsInSlug</span></a>, <a href="nimja/nimjautils.html#loop.i,openArray[T]"><span class="Identifier">loop</span></a>, <a href="nimja/nimjautils.html#nl2br,string"><span class="Identifier">nl2br</span></a>, <a href="nimja/nimjautils.html#includeStaticAsDataurl,staticstring,staticstring"><span class="Identifier">includeStaticAsDataurl</span></a>, <a href="nimja/nimjautils.html#includeRawStatic,staticstring"><span class="Identifier">includeRawStatic</span></a>, <a href="nimja/nimjautils.html#~.t,untyped,untyped"><span class="Identifier">~</span></a>, <a href="nimja/nimjautils.html#?.t,untyped,untyped"><span class="Identifier">?</span></a>, <a href="nimja/nimjautils.html#cycle,Loop,openArray[T]"><span class="Identifier">cycle</span></a>, <a href="nimja/nimjautils.html#truncate,string,Natural,string"><span class="Identifier">truncate</span></a>, <a href="nimja/nimjautils.html#spaceless,string"><span class="Identifier">spaceless</span></a>
<a href="nimja/parser.html#compileTemplateStr.m,typed,staticstring,staticbool,staticstring,staticstring,untyped"><span class="Identifier">compileTemplateStr</span></a>, <a href="nimja/parser.html#compileTemplateFile.m,staticstring,staticstring,staticbool,staticstring,staticstring,untyped"><span class="Identifier">compileTemplateFile</span></a>, <a href="nimja/sharedhelper.html#getScriptDir.t"><span class="Identifier">getScriptDir</span></a>, <a href="nimja/parser.html#tmpls.m,staticstring,staticstring,staticstring,untyped"><span class="Identifier">tmpls</span></a>, <a href="nimja/parser.html#tmplf.m,staticstring,staticstring,untyped"><span class="Identifier">tmplf</span></a>, <a href="nimja/nimjautils.html#Loop"><span class="Identifier">Loop</span></a>, <a href="nimja/nimjautils.html#includeRaw,string"><span class="Identifier">includeRaw</span></a>, <a href="nimja/nimjautils.html#slugify,string,string"><span class="Identifier">slugify</span></a>, <a href="nimja/nimjautils.html#|.m,untyped,untyped"><span class="Identifier">|</span></a>, <a href="nimja/nimjautils.html#Loopable"><span class="Identifier">Loopable</span></a>, <a href="nimja/nimjautils.html#allowedCharsInSlug"><span class="Identifier">allowedCharsInSlug</span></a>, <a href="nimja/nimjautils.html#loop.i,openArray[T]"><span class="Identifier">loop</span></a>, <a href="nimja/nimjautils.html#nl2br,string"><span class="Identifier">nl2br</span></a>, <a href="nimja/nimjautils.html#includeStaticAsDataurl,staticstring,staticstring"><span class="Identifier">includeStaticAsDataurl</span></a>, <a href="nimja/nimjautils.html#includeRawStatic,staticstring"><span class="Identifier">includeRawStatic</span></a>, <a href="nimja/nimjautils.html#~.t,untyped,untyped"><span class="Identifier">~</span></a>, <a href="nimja/nimjautils.html#?.t,untyped,untyped"><span class="Identifier">?</span></a>, <a href="nimja/nimjautils.html#cycle,Loop,openArray[T]"><span class="Identifier">cycle</span></a>, <a href="nimja/nimjautils.html#truncate,string,Natural,string"><span class="Identifier">truncate</span></a>, <a href="nimja/nimjautils.html#spaceless,string"><span class="Identifier">spaceless</span></a>
</dl>
</div>

Expand All @@ -81,7 +81,7 @@ <h1><a class="toc-backref" href="#19">Exports</a></h1>
<div class="twelve-columns footer">
<span class="nim-sprite"></span>
<br>
<small style="color: var(--hint);">Made with Nim. Generated: 2024-08-12 07:43:26 UTC</small>
<small style="color: var(--hint);">Made with Nim. Generated: 2024-09-16 11:01:55 UTC</small>
</div>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions docs/nimja/lexer.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ <h1><a class="toc-backref" href="#15">Iterators</a></h1>
<dt><pre><span class="Keyword">iterator</span> <a href="#lex.i%2Cstring"><span class="Identifier">lex</span></a><span class="Other">(</span><span class="Identifier">buf</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">)</span><span class="Other">:</span> <a href="lexer.html#Token"><span class="Identifier">Token</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>


Lexes the string in <tt class="docutils literal"><span class="pre"><span class="Identifier">buf</span></span></tt> yields <tt class="docutils literal"><span class="pre"><span class="Identifier">Token</span></span></tt>

</dd>
</div>
Expand All @@ -134,7 +134,7 @@ <h1><a class="toc-backref" href="#15">Iterators</a></h1>
<div class="twelve-columns footer">
<span class="nim-sprite"></span>
<br>
<small style="color: var(--hint);">Made with Nim. Generated: 2024-08-12 07:43:26 UTC</small>
<small style="color: var(--hint);">Made with Nim. Generated: 2024-09-16 11:01:55 UTC</small>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion docs/nimja/nimjautils.html
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ <h1><a class="toc-backref" href="#18">Templates</a></h1>
<div class="twelve-columns footer">
<span class="nim-sprite"></span>
<br>
<small style="color: var(--hint);">Made with Nim. Generated: 2024-08-12 07:43:26 UTC</small>
<small style="color: var(--hint);">Made with Nim. Generated: 2024-09-16 11:01:55 UTC</small>
</div>
</div>
</div>
Expand Down
36 changes: 21 additions & 15 deletions docs/nimja/parser.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,31 @@ <h1 class="title">nimja/parser</h1>
<summary><a class="reference reference-toplevel" href="#17" id="67">Macros</a></summary>
<ul class="simple simple-toc-section">
<ul class="simple nested-toc-section">compileTemplateFile
<li><a class="reference" href="#compileTemplateFile.m%2Cstaticstring%2Cstaticstring%2Cstaticbool%2Cstaticstring%2Cuntyped" title="compileTemplateFile(path: static string; baseDir: static string = &quot;&quot;;
<li><a class="reference" href="#compileTemplateFile.m%2Cstaticstring%2Cstaticstring%2Cstaticbool%2Cstaticstring%2Cstaticstring%2Cuntyped" title="compileTemplateFile(path: static string; baseDir: static string = &quot;&quot;;
iter: static bool = false;
varname: static string = &quot;result&quot;; context: untyped = nil): untyped">compileTemplateFile(path: static string; baseDir: static string = &quot;&quot;;
varname: static string = &quot;result&quot;;
blockToRender: static string = &quot;&quot;; context: untyped = nil): untyped">compileTemplateFile(path: static string; baseDir: static string = &quot;&quot;;
iter: static bool = false;
varname: static string = &quot;result&quot;; context: untyped = nil): untyped</a></li>
varname: static string = &quot;result&quot;;
blockToRender: static string = &quot;&quot;; context: untyped = nil): untyped</a></li>

</ul>
<ul class="simple nested-toc-section">compileTemplateStr
<li><a class="reference" href="#compileTemplateStr.m%2Ctyped%2Cstaticstring%2Cstaticbool%2Cstaticstring%2Cuntyped" title="compileTemplateStr(str: typed; baseDir: static string = &quot;&quot;;
<li><a class="reference" href="#compileTemplateStr.m%2Ctyped%2Cstaticstring%2Cstaticbool%2Cstaticstring%2Cstaticstring%2Cuntyped" title="compileTemplateStr(str: typed; baseDir: static string = &quot;&quot;;
iter: static bool = false; varname: static string = &quot;result&quot;;
context: untyped = nil): untyped">compileTemplateStr(str: typed; baseDir: static string = &quot;&quot;;
blockToRender: static string = &quot;&quot;; context: untyped = nil): untyped">compileTemplateStr(str: typed; baseDir: static string = &quot;&quot;;
iter: static bool = false; varname: static string = &quot;result&quot;;
context: untyped = nil): untyped</a></li>
blockToRender: static string = &quot;&quot;; context: untyped = nil): untyped</a></li>

</ul>
<ul class="simple nested-toc-section">tmplf
<li><a class="reference" href="#tmplf.m%2Cstaticstring%2Cstaticstring%2Cuntyped" title="tmplf(str: static string; baseDir: static string = &quot;&quot;; context: untyped = nil): string">tmplf(str: static string; baseDir: static string = &quot;&quot;; context: untyped = nil): string</a></li>

</ul>
<ul class="simple nested-toc-section">tmpls
<li><a class="reference" href="#tmpls.m%2Cstaticstring%2Cstaticstring%2Cuntyped" title="tmpls(str: static string; baseDir: static string = &quot;&quot;; context: untyped = nil): string">tmpls(str: static string; baseDir: static string = &quot;&quot;; context: untyped = nil): string</a></li>
<li><a class="reference" href="#tmpls.m%2Cstaticstring%2Cstaticstring%2Cstaticstring%2Cuntyped" title="tmpls(str: static string; baseDir: static string = &quot;&quot;;
blockToRender: static string = &quot;&quot;; context: untyped = nil): string">tmpls(str: static string; baseDir: static string = &quot;&quot;;
blockToRender: static string = &quot;&quot;; context: untyped = nil): string</a></li>

</ul>

Expand Down Expand Up @@ -104,10 +108,11 @@ <h1><a class="toc-backref" href="#6">Imports</a></h1>
<h1><a class="toc-backref" href="#17">Macros</a></h1>
<dl class="item">
<div id="compileTemplateFile-macros-all">
<div id="compileTemplateFile.m,staticstring,staticstring,staticbool,staticstring,untyped">
<dt><pre><span class="Keyword">macro</span> <a href="#compileTemplateFile.m%2Cstaticstring%2Cstaticstring%2Cstaticbool%2Cstaticstring%2Cuntyped"><span class="Identifier">compileTemplateFile</span></a><span class="Other">(</span><span class="Identifier">path</span><span class="Other">:</span> <span class="Identifier">static</span> <span class="Identifier">string</span><span class="Other">;</span> <span class="Identifier">baseDir</span><span class="Other">:</span> <span class="Identifier">static</span> <span class="Identifier">string</span> <span class="Other">=</span> <span class="StringLit">&quot;&quot;</span><span class="Other">;</span>
<div id="compileTemplateFile.m,staticstring,staticstring,staticbool,staticstring,staticstring,untyped">
<dt><pre><span class="Keyword">macro</span> <a href="#compileTemplateFile.m%2Cstaticstring%2Cstaticstring%2Cstaticbool%2Cstaticstring%2Cstaticstring%2Cuntyped"><span class="Identifier">compileTemplateFile</span></a><span class="Other">(</span><span class="Identifier">path</span><span class="Other">:</span> <span class="Identifier">static</span> <span class="Identifier">string</span><span class="Other">;</span> <span class="Identifier">baseDir</span><span class="Other">:</span> <span class="Identifier">static</span> <span class="Identifier">string</span> <span class="Other">=</span> <span class="StringLit">&quot;&quot;</span><span class="Other">;</span>
<span class="Identifier">iter</span><span class="Other">:</span> <span class="Identifier">static</span> <span class="Identifier">bool</span> <span class="Other">=</span> <span class="Identifier">false</span><span class="Other">;</span>
<span class="Identifier">varname</span><span class="Other">:</span> <span class="Identifier">static</span> <span class="Identifier">string</span> <span class="Other">=</span> <span class="StringLit">&quot;result&quot;</span><span class="Other">;</span>
<span class="Identifier">blockToRender</span><span class="Other">:</span> <span class="Identifier">static</span> <span class="Identifier">string</span> <span class="Other">=</span> <span class="StringLit">&quot;&quot;</span><span class="Other">;</span>
<span class="Identifier">context</span><span class="Other">:</span> <span class="Identifier">untyped</span> <span class="Other">=</span> <span class="Keyword">nil</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">untyped</span></pre></dt>
<dd>

Expand Down Expand Up @@ -136,10 +141,11 @@ <h1><a class="toc-backref" href="#17">Macros</a></h1>

</div>
<div id="compileTemplateStr-macros-all">
<div id="compileTemplateStr.m,typed,staticstring,staticbool,staticstring,untyped">
<dt><pre><span class="Keyword">macro</span> <a href="#compileTemplateStr.m%2Ctyped%2Cstaticstring%2Cstaticbool%2Cstaticstring%2Cuntyped"><span class="Identifier">compileTemplateStr</span></a><span class="Other">(</span><span class="Identifier">str</span><span class="Other">:</span> <span class="Identifier">typed</span><span class="Other">;</span> <span class="Identifier">baseDir</span><span class="Other">:</span> <span class="Identifier">static</span> <span class="Identifier">string</span> <span class="Other">=</span> <span class="StringLit">&quot;&quot;</span><span class="Other">;</span>
<div id="compileTemplateStr.m,typed,staticstring,staticbool,staticstring,staticstring,untyped">
<dt><pre><span class="Keyword">macro</span> <a href="#compileTemplateStr.m%2Ctyped%2Cstaticstring%2Cstaticbool%2Cstaticstring%2Cstaticstring%2Cuntyped"><span class="Identifier">compileTemplateStr</span></a><span class="Other">(</span><span class="Identifier">str</span><span class="Other">:</span> <span class="Identifier">typed</span><span class="Other">;</span> <span class="Identifier">baseDir</span><span class="Other">:</span> <span class="Identifier">static</span> <span class="Identifier">string</span> <span class="Other">=</span> <span class="StringLit">&quot;&quot;</span><span class="Other">;</span>
<span class="Identifier">iter</span><span class="Other">:</span> <span class="Identifier">static</span> <span class="Identifier">bool</span> <span class="Other">=</span> <span class="Identifier">false</span><span class="Other">;</span>
<span class="Identifier">varname</span><span class="Other">:</span> <span class="Identifier">static</span> <span class="Identifier">string</span> <span class="Other">=</span> <span class="StringLit">&quot;result&quot;</span><span class="Other">;</span>
<span class="Identifier">blockToRender</span><span class="Other">:</span> <span class="Identifier">static</span> <span class="Identifier">string</span> <span class="Other">=</span> <span class="StringLit">&quot;&quot;</span><span class="Other">;</span>
<span class="Identifier">context</span><span class="Other">:</span> <span class="Identifier">untyped</span> <span class="Other">=</span> <span class="Keyword">nil</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">untyped</span></pre></dt>
<dd>

Expand Down Expand Up @@ -186,9 +192,9 @@ <h1><a class="toc-backref" href="#17">Macros</a></h1>

</div>
<div id="tmpls-macros-all">
<div id="tmpls.m,staticstring,staticstring,untyped">
<dt><pre><span class="Keyword">macro</span> <a href="#tmpls.m%2Cstaticstring%2Cstaticstring%2Cuntyped"><span class="Identifier">tmpls</span></a><span class="Other">(</span><span class="Identifier">str</span><span class="Other">:</span> <span class="Identifier">static</span> <span class="Identifier">string</span><span class="Other">;</span> <span class="Identifier">baseDir</span><span class="Other">:</span> <span class="Identifier">static</span> <span class="Identifier">string</span> <span class="Other">=</span> <span class="StringLit">&quot;&quot;</span><span class="Other">;</span>
<span class="Identifier">context</span><span class="Other">:</span> <span class="Identifier">untyped</span> <span class="Other">=</span> <span class="Keyword">nil</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">string</span></pre></dt>
<div id="tmpls.m,staticstring,staticstring,staticstring,untyped">
<dt><pre><span class="Keyword">macro</span> <a href="#tmpls.m%2Cstaticstring%2Cstaticstring%2Cstaticstring%2Cuntyped"><span class="Identifier">tmpls</span></a><span class="Other">(</span><span class="Identifier">str</span><span class="Other">:</span> <span class="Identifier">static</span> <span class="Identifier">string</span><span class="Other">;</span> <span class="Identifier">baseDir</span><span class="Other">:</span> <span class="Identifier">static</span> <span class="Identifier">string</span> <span class="Other">=</span> <span class="StringLit">&quot;&quot;</span><span class="Other">;</span>
<span class="Identifier">blockToRender</span><span class="Other">:</span> <span class="Identifier">static</span> <span class="Identifier">string</span> <span class="Other">=</span> <span class="StringLit">&quot;&quot;</span><span class="Other">;</span> <span class="Identifier">context</span><span class="Other">:</span> <span class="Identifier">untyped</span> <span class="Other">=</span> <span class="Keyword">nil</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">string</span></pre></dt>
<dd>

Compiles a Nimja template string and returns directly. Can be used inline, without a wrapper proc.<pre class="listing"><span class="Identifier">echo</span> <span class="Identifier">tmpls</span><span class="Punctuation">(</span><span class="LongStringLit">&quot;&quot;&quot;{% if true %}Is true!{% endif %}&quot;&quot;&quot;</span><span class="Punctuation">)</span></pre><p>A context can be supplied to the template, to override the variable names:</p>
Expand Down Expand Up @@ -220,7 +226,7 @@ <h1><a class="toc-backref" href="#19">Exports</a></h1>
<div class="twelve-columns footer">
<span class="nim-sprite"></span>
<br>
<small style="color: var(--hint);">Made with Nim. Generated: 2024-08-12 07:43:26 UTC</small>
<small style="color: var(--hint);">Made with Nim. Generated: 2024-09-16 11:01:55 UTC</small>
</div>
</div>
</div>
Expand Down
Loading
Loading