Helma Macros 2.0
This is a proposal by Hannes, as a result of many discussions in the last year(s):
I AM EXCITED !!! - that's what i think :)
originally i prefered a syntax that goes like this:
We use plain HTML/XML syntax and don't introduce
any Helma-specific tags, just three attributes:
* h:macro is used to mark a tag as macro. Any tag containing a h:macro
attribute will be replaced by the output of that macro, with the
contents of the tag passed to the macro function as second argument.
* h:name is used as identifier of subskins within a skin. Any names
can be used, but "prefix", "suffix" and "default" are handled in the
way Helma currently does.
* h:msg is used for automatic translation as proposed
by Robert and Matthias. Everything within those tags
would be replaced by a localized message
(details to be determined).
Put into practice, a simple macro that loops through
stories in a site object could look like this:
<div h:macro="site.loop">
<h3 h:name="prefix" h:msg="storylistHeader">Story Listing</h3>
<ul>
<li h:name="listitem" h:macro="story.title">Story Title</li>
</ul>
<p h:name="default" h:msg="storylistEmpty">No stories</p>
</ul>
All the macro had to do here is get the "listitem"
subskin and call it on each story it wants to render.
prefix and default are handled by Helma. The only
unsolved piece here is how to render the <ul></ul>,
but I think Helma could do automatic parent element
rendering by using a "skin stack" to know when it
enters/leaves a skin fragment.
So far this looks pretty good to me, but I haven't had
coffee yet today. What do you think?
I AM EXCITED !!! - that's what i think :)
originally i prefered a syntax that goes like this:
<hop:macro name="Page.someMacro">
pass this part as the second parameter (e.g. as a skin)
</hop:macro>
but the more i think about this, sticking to (x)html, and just extend it by a view attributes is the much better way.
<input h:macro="html" name="foo" type="text" />
could result in:
function html_macro(param, tag, content) {
case (tag) {
switch "input":
if (param.type == "text") {
Html.input(param, ...)...
}
}
}
matthias - 16. Feb, 12:05
0 comments - add comment - 0 trackbacks








