Module | RubyTals
In: | lib/facets/more/rtals.rb

# Tag Attribute Language for Ruby

RubyTals is a Ruby variation on Zope Page Templates and it‘s TAL specification. It differs from TAL in that it is specifically geared for use by Ruby.

## Usage

      s = %q{
        <html>
        <body>
          <h1 rtal:content="x">[X]</h1>
          <div rtal:each="animal" rtal:do="a">
            <b rtal:content="a">[ANIMAL]</b>
          </div>
          <div rtal:if="animal.size > 1">
            There are <b rtal:body="animal.size">[ANIMAL SIZE]</b> animals.
          </div>
        </body>
        </html>
      }

      x = 'Our Little Zoo'
      animal = ['Zebra', 'Monkey', 'Tiger' ]
      out = ''

      prg = RubyTals.compile( s )
      puts eval(prg)

## Note

WARNING! This library is only minimally functional at this point. If you would like to use it please consider improving upon it!

Presently rTAL clauses can run arbitraty Ruby code. Although upping the safety level before executing a compiled template should be sufficiently protective in most cases, perhaps it would be better to limit valid expressions to single object references, ie. ‘this.that’, and then use a substitution of ’.’ for ’/’. Not only would this be highly protective, it would also be more compatible with the original TAL spec; albiet this isn‘t exacty how TALs interprets the ’/’ divider.

On the other hand perhaps it is too much restraint. For instance it would require the if-clause in the above exmaple to be something like:

          <div rtal:if="animal/plenty">

and have a definition in the evaluateing code:

      def animal.plenty
        size > 1
      end

It‘s a classic Saftey vs. Usability trade-off. Something to consider for the future.

### Methods

add_tag compile execute loop_structure parse

### Public Class methods

add_tag( name, body, attributes={} )
compile( xmlstr )
execute( script, data )
loop_structure()
parse( xml )

[Validate]