Helma Logo
main list history
previous version  overview  next version

Version 13 by hannes on 09. December 2005, 13:53

== Spec ==

* Macros in skins are delimited by (% %).
* Macros can contain both named and unnamed parameters, in any combination (see Notes for implementation details).
* Named parameters are denoted as name=value, unnamed parameters are denoted as value.
* For string parameter values, single or double quotes are optional unless the value contains whitespace characters.
* Macro parameter values wrapped in ( ) are interpreted as nested macros.
* Macro parameter values wrappedn in {{ }} are interpreted as nested skins.
* Skins and macros are both implemented as plain JS objects.
* Nested skins and macros are passed to macros as skin and macro objects, respectively. In other words, macro evaluation and skin rendering is up to the containing macro.
* Standard macros such as if/else, foreach, equals, greaterThan are implemented as plain macros in JS.

== Notes ==

* My original intention was to use * instead of % for top level macro delimiters, but Gobi would interpret these as Wiki links. Anyway, I haven't committed myself to any choice of delimiter sequences, I just think my current proposal looks pretty sane and implementable to me. I do think this is an essential question.
* Even though it doesn't look that way, this proposal provides easy backwards compatibility with old style model domain macro syntax and conventions. I'll show how when I talk further about JS implementation.

Macro parameters are passed in a way that allows sequential value lookup, sequential name lookup and named lookup:

    var param = {
      values: [],
      names: [],
      byName: {}
    }

== Examples ==

==== Simple login info/form

(%
  if (user) {{
    <div>Logged in as (% user.name %)</div>
  }} else {{
    <form action="(% loginUrl %)">
    <table><tr>
      <td>Name</td><td><input name="name"></td>
      <td>Password</td><td><input type="password" name="password"></td>
    </tr></table>
    </form>
  }}
%)

Same thing implemented with prefix, suffix and default params:

(% user.name prefix="<div>Logged in as " suffix="</div>"
    default={{
      <form action="(% loginUrl %)">
      <table><tr>
        <td>Name</td><td><input name="name"></td>
        <td>Password</td><td><input type="password" name="password"></td>
      </tr></table>
      </form>
    }}
  %)

==== Story with comments

Variant 1, using multiple skin/macro nesting:

<h1>(% story.title %)</h1>
<div>(% story.text %)</div>
(%
  if (story.hasComments) {{
  <table>
  (% foreach comment in (story.comments)
    {{
    <tr>
      <td>(% encode(comment.title) %)</td>
      <td>(% encode(comment.text) %)</td>
    </tr>
    }}
  %)
  </table>
  }}
%)

Variant 2, using prefix and suffix parameters to avoid nesting:

<h1>(% story.title %)</h1>
<div>(% story.text %)</div>
(%
  foreach comment in (story.comments)
  {{
    <tr>
      <td>(% encode(comment.title) %)</td>
      <td>(% encode(comment.text) %)</td>
    </tr>
  }}
  prefix=<table> suffix=</table>
%)

     removed
     added