Helma Logo
main list history
previous version  overview  next version

Version 38 by hannes on 30. October 2006, 22:45

== 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.
# The following types are supported as parameter values:
## strings: "foo"
## numbers: 13
## boolean false|true
## object literals: {foo: bar, x: y}
## array literals: [1, 2, "drei"]
# For string values, single or double quotes are optional unless the value contains whitespace characters.
# Round brackets ( ) can be used to group multiple macro parameters into one. (syntactic sugar for arrays?)
# <strike>Macro parameter values wrappedn in {{ }} are interpreted as nested skins.</strike>
# Helma provides native skin scanning/parsing features, but skins and macros are implemented in JavaScript.
# <strike>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.</strike>
# Todo: provide a feature for marking subtemplates within a skin file.

Macro parameters are passed in a way that allows sequential access for unnamed parameters and keyed access for named parameters:

    var param = {
      next: function() {
          /\* provide iterator style access to unnamed parameters */
      byName: {
          /\* provide access to named parameters */

== Implementation ==

Native template scanning support is implemented in class *org.helma.template.TemplateScanner|Source/file/helma/trunk/src/org/helma/template/TemplateScanner.java*, which can be conveniently accessed using the global parseSkinResource(path) function. You It parses skins to a java.util.List filled with Strings for the static parts and Macro tags, which are again java.util.List objects with a special param property that contains the tag's named parameters. All this is wrapped in *helma 2 core reference/scriptableLists* and *helma 2 core reference/scriptablemaps* so you can currently test sweep through it using something like:like it were native JavaScript arrays and objects.

I started a simple JavaScript renderer for skins parsed this way.   var t = new PackagesIt currently implements very simplistic if/foreach constructs.
    t.parse("foo <% image 'dancer.gif' {class: 'storyImage'} %> bar");
<% this.attachments %>

The following code shows how to use this:

  function handle_get() {
    var t = new Templatex("skins/main.skin");
    t.render({topics: ["Berge", "Täler", "Seen", "Flüsse"]});

== Examples ==

I removed the old examples since they didn't match the renewed spec anymore. Generally speaking, all kinds of macro syntax can be implemented based on the features discribed in this proposals, as long as they use <% %> as macro delimiters.

== Comments ==

I removed Jürg's comments as well, for the same reason.