Skip to content.

Personal tools
You are here: Home » Plope Software » z3meld » z3meld
 
 

z3meld

Download

z3meld-0.5.tgz (CHANGES)

z3meld-0.4.tgz

View CVS Repository

http://svn.supervisord.org/z3meld

See Also

meld3

Overview

z3meld is a set of Zope 3 bindings for the meld3 XML/HTML templating system. It allows you to use meld3 templates within your Zope 3 application.

Requirements

Zope 3.1+

meld3 (http://www.plope.com/software/meld3)

Installation

Run python setup.py install.

Copy the files named meld3-meta.zcml and meld3-configure.zcml into your Zope3 instance's etc/package-includes directory.

(You can use the --home argument to install in order to place the z3meld package into your Zope's instancehome/lib/python directory, e.g. python setup.py install --home=/path/to/z3instance).

Usage

You can declare meld3 pages in ZCML. Doing so is reminiscent of declaring ZPT pages in ZCML, with a few differences. The main difference is that the equivalents to "define-macro" and "use-macro" are declared outside the templates themselves (in ZCML, typically). For example, here's a definition of a meld3 page which registers a page named foo.html. foo.html renders a "main template" with its "content well" and "head slots" filled in by dynamic transformations:

    <configure
        xmlns="http://namespaces.zope.org/zope"
        xmlns:browser="http://namespaces.zope.org/browser">

      <browser:meld3page
          for="*"
          name="foo.html"
          template="input/main_template.html"
          class=".sampletransform.Transform"
          attribute="head_transform"
          permission="zope.Public"
          layer="zope.app.rotterdam.rotterdam"
          >

         <browser:fill
               name="content_well"
               template="input/table.html"
               class=".sampletransform.Transform"
               attribute="table_transform"
               source="content"
               />

      </browser:meld3page>

    </configure>

Here are the various templates and Python modules referred to by the above ZCML:

    main_template.html
    ------------------

    <html xmlns:meld="http://www.plope.com/software/meld3">
      <head>
        <title meld:id="title">This is the title</title>
        <div meld:id="headslot">This is the head slot</div>
        <meta http-equiv="Content-Type" content="text/html; charset=latin-1">
      </head>
      <body>
       <div meld:id="slot1"/>
       <div meld:id="content_well">
         This should get replaced.
        </div>
      </body>
    </html>

    table.html
    ----------

    <html>
    <body>
    <div meld:id="content">
      <form meld:id="form1" action="#" method="POST">
        <table border="0" meld:id="table1">
          <tbody meld:id="tbody">
            <tr meld:id="tr" class="foo">
              <td meld:id="td1">Name</td>
              <td meld:id="td2">Description</td>
            </tr>
          </tbody>
        </table>
      </form>
    </div>
    </body>
    </html>

    sampletransform.py
    ------------------

    data = ( ('name1', 'desc1'), ('name2', 'desc2') )

    class Transform:
        def table_transform(self, element):
            tr = element.findmeld('tr')
            iterator = tr.repeat(data)
            for el, thing in iterator:
                el.findmeld('td1').content(thing[0])
                el.findmeld('td2').content(thing[1])

        def head_transform(self, element):
            head = element.findmeld('headslot')
            head.text = self.request['QUERY_STRING'] or 'The slot is filled'

When this view is called, it renders into:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html xmlns:meld="http://www.plope.com/software/meld3">
      <head>
        <title>This is the title</title>
        <div>The slot is filled</div></head>
      <body>
       <div></div>
       <div><form action="#" method="POST">
        <table border="0">
          <tbody>
            <tr class="foo">
              <td>name1</td>
              <td>desc1</td>
            </tr>
          <tr class="foo">
              <td>name2</td>
              <td>desc2</td>
            </tr>
          </tbody>
        </table>
      </form>
    </div>
      </body>
    </html>

The class, attribute, and layer arguments to browser:meld3page are optional. The fill directive is optional. If the fill directive is used, the class, attribute, and source to that directive are optional. For more information, see metadirectives.py in the package.

To Do

See TODO.txt for to-do items.

Reporting Bugs and Requesting Features

Please visit http://www.plope.com/software/collector to report bugs and request features.

Have fun!

  • Chris McDonough (chrism@plope.com)
Created by chrism
Last modified 2008-01-18 02:07 AM