[Petal] Petal 1.10_07 Released

Jean-Michel Hiver jhiver at mkdoc.com
Mon Oct 13 13:55:04 BST 2003


Hurray!

I managed to hack out a minimalistic, incomplete, strange implementation
of METAL, but it works!

Basically I have built Petal's METAL on top of the existing include
mechanism. Only define-macro and use-macro are supported. Basically it
works as follows:


metal:define-macro
==================

Say you have a file called foo.xml as follows:

  <html>
    <body>
      <p define-macro="myMacro">
        I am a macro! I can contain all kinds of TAL instructions,
        just like a regular Petal included file would.
      </p>
      <p define-macro="myOtherMacro">
        I am another macro!
      </p>
    </body>
  </html>

  
Conceptually, this file defines three distinctly includable files:

foo.xml
-------
  <html>
    <body>
      <p>
        I am a macro! I can contain all kinds of TAL instructions,
        just like a regular Petal included file would.
      </p>
    </body>
  </html>


foo.xml#myMacro
---------------
  <p>
    I am a macro! I can contain all kinds of TAL instructions,
    just like a regular Petal included file would.
  </p>


foo.xml#myOtherMacro
--------------------
  <p define-macro="myOtherMacro">
    I am another macro!
  </p>


  <tag metal:use-macro="foo.xml#myMacro">
    some dummy / explanatory content...
  </tag>


So if you so wished yo could do:

  my $template = new Petal ('foo.xml#myMacro')


This means that within Petal you could use:

  <?include file="foo.xml#myMacro"?>
  <xi:xinclude href="./foo.xml#myMacro" />
  etc.

Or you can use...


metal:use-macro
===============

And that's *VERY* simple:

  <p metal:use-macro="./foo.xml#myMacro">
    This is some dummy content...
  </p>


Will be replaced by something like that:

  <?include file="foo.xml#myMacro"?>


That's all there is to it. Please note that Petal's METAL implementation
requires some cooperation from the parser, which is only implemented at the
moment with the newly Petal::Parser. Neither Petal::Parser::XP nor
Petal::Parser::HTB support this at the moment - sorry.

Also note that because Petal's METAL implementation is just a fancy way of
doing includes, they are expanded at RUN TIME, not beforehand. I also have
updated the documentation, and there is a 'METAL' section after the section on
Petal includes.


Enjoy,
-- 
Building a better web - http://www.mkdoc.com/
---------------------------------------------
Jean-Michel Hiver
jhiver at mkdoc.com  - +44 (0)114 255 8097
Homepage: http://www.webmatrix.net/


More information about the Petal mailing list