https://bugs.underdark.nl/https://bugs.underdark.nl/favicon.ico2012-06-26T11:00:33ZBugtrackerµWeb - Feature #884: Arguments on template functionshttps://bugs.underdark.nl/issues/884?journal_id=29082012-06-26T11:00:33ZElmer de Looffelmer@underdark.nl
<ul><li><strong>Subject</strong> changed from <i>Template tag arguments.</i> to <i>Arguments on template functions</i></li><li><strong>Category</strong> set to <i>TemplateParser</i></li></ul><p>What this would require is a way of providing arguments to template tag functions. This is possible, but introduces some problems with optional <em>named</em> arguments, which need to be parsed, as well as all sorts of characters that might occur in the argument. Simple numerics are easy, but strings are significantly trickier to handle in the regex and processing code.</p>
<p>Basic template tag extension could be something like this: <code>'[tag|limit(80)]'</code> for a limit function with an argument of <code>80</code>. Functions that accept arguments should return closures, though this means that using the above limit function with the default values will still need an invocation <code>limit()</code> because the function itself is not directly usable.</p>
<p>The basic mode of operation for this could be something like this (inside a PageMaker method):</p>
<pre><code class="python syntaxhl"><span class="CodeRay"><span class="keyword">def</span> <span class="function">LengthLimitedReponse</span>(<span class="predefined-constant">self</span>):
<span class="keyword">def</span> <span class="function">LengthLimiter</span>(maxlen=<span class="integer">80</span>):
<span class="keyword">def</span> <span class="function">_Limited</span>(string, maxlen=maxlen):
<span class="keyword">return</span> string[:maxlen]
<span class="keyword">return</span> _Limited
<span class="predefined-constant">self</span>.parser.RegisterFunction(<span class="string"><span class="delimiter">'</span><span class="content">limit</span><span class="delimiter">'</span></span>, LengthLimiter)
<span class="keyword">return</span> <span class="predefined-constant">self</span>.parser.ParseString(<span class="string"><span class="delimiter">'</span><span class="content">[string|limit(80)]</span><span class="delimiter">'</span></span>, string=<span class="string"><span class="delimiter">'</span><span class="content">hello world, </span><span class="delimiter">'</span></span> * <span class="integer">20</span>)
</span></code></pre>
<p>The result for this function would be <code>'hello world, hello world, hello world, hello world, hello world, hello world, he'</code></p> µWeb - Feature #884: Arguments on template functionshttps://bugs.underdark.nl/issues/884?journal_id=29092012-06-26T11:02:19ZJan Klopperjan@underdark.nl
<ul></ul><p>Seems ok to me, is it easily added? including unittests?</p> µWeb - Feature #884: Arguments on template functionshttps://bugs.underdark.nl/issues/884?journal_id=29482012-07-05T16:22:30ZElmer de Looffelmer@underdark.nl
<ul><li><strong>Status</strong> changed from <i>New</i> to <i>Resolved</i></li><li><strong>% Done</strong> changed from <i>0</i> to <i>70</i></li></ul><p>Applied in changeset <a class="changeset" title="Added capabilities and tests for function closures on tags. Restructured the regular expression t..." href="https://bugs.underdark.nl/projects/uweb/repository/revisions/ba7abb242ae6">ba7abb242ae6</a>.</p> µWeb - Feature #884: Arguments on template functionshttps://bugs.underdark.nl/issues/884?journal_id=29492012-07-05T16:27:54ZElmer de Looffelmer@underdark.nl
<ul><li><strong>Status</strong> changed from <i>Resolved</i> to <i>Closed</i></li><li><strong>Assignee</strong> changed from <i>Elmer de Looff</i> to <i>Niek Bergman</i></li><li><strong>Target version</strong> set to <i>µWeb alpha release</i></li><li><strong>% Done</strong> changed from <i>70</i> to <i>100</i></li></ul><p>Done and done, with some limitations:</p>
<ul>
<li>Arguments are passed as strings, meaning the closure functions need to do some argument-mangling to get them to the expected type;</li>
<li>Multiple arguments are possible, but every comma counts as an argument separator, even those inside quoted or parenthesized strings;</li>
<li>Leading whitespace is restricted as the splitting is done on commas and any following whitespace.</li>
</ul>