I propose that Helma NG's macro filters make the legacy
default/prefix/suffix macro parameters redundant.
Helma 1 (as well as current Helma NG) allows a macro to take
default/prefix/suffix parameters (see [1] for more information):
<% foo default="bar" %>
<% baz prefix="qux" suffix="xuq" %>
We can easily achieve the same effect with macro filters [2] as follows:
<% foo | default "bar" %>
<% baz | prefix "qux" | suffix "xuq" %>
One effect resulting from the sequential application of filters is worth
noting: in Helma 1 it does not matter in which order the default,
prefix and suffix parameters are provided. So, assuming that `foo_macro`
returns an empty string:
<% foo prefix="-" default="0" suffix="+" %>
==> -0+
Whereas the naive translation to filters will expand as:
<% foo | prefix "-" | default "0" | suffix "+" %>
==> 0+
`prefix_filter` and `suffix_filter` prepend/append their parameter only
if the input string is not empty (or null, or undefined). So in the
latter filter chain, `prefix_filter` gets an empty input and does
therefore not prepend the "-". Then `default_filter` gets passed the
still empty string and returns its default string. This is finally
passed to `suffix_filter` as input, and as it is not empty, the
suffix is appended.
To achieve the same effect as in Helma 1, properly ordering the filters
is necessary:
<% foo | default "0" | prefix "-" | suffix "+" %> is
==> -0+
However, I think this is a somewhat degenerate case, as once you have a
default you can directly write the prefix/suffix strings as in:
-<% foo | default "0" %>+
The only case where this would not work, is when the default string is
itself the result of macro expansion (e.g. <% foo | default <%bar%> %>)
-- then you simply have to know that filters are applied sequentially (a
rather intuitive concept, in my opinion).
To conclude, I suggest dropping the special-case default/prefix/suffix
macro parameters in Helma NG and providing corresponding filters
instead. Opinions?
I've pushed a commit to implement this to the "skins" branch in my
helma-ng github repos [3], and also attached a patch for your
convenience.
[1] http://helma.org/docs/guide/framework/#macroattributes
[2] http://dev.helma.org/wiki/New+Skin+Features+in+Helma+1.6/#Macrofilters
[3] http://github.com/earl/helma-ng/commit/ef1116
--
Regards,
Andreas
Hmm, I'm not so sure about this. I tried the following and it rendered
to "-0+":
function foo_macro(params) {
return '';
}
function foobar_action() {
this.renderSkin(
createSkin('<% this.foo prefix="-" suffix="+" default="0" %>'));
}
I tried this because I wanted the filter behaviour to mimic the old
behaviour as closely as possible.
> I generally agree, as the additional pipe characters are not really a
> problem, and it makes sense to use the filter/pipe feature whenever we
> can.
Fine!
> What about an additional filter names "wrap" that combines prefix and
> suffix?
>
> <% code | wrap "<pre>" "</pre>" %>
Good idea, added it to my skins branch [1].
[1] http://github.com/earl/helma-ng/commit/c195f2
--
Andreas