Dynamic HTML template
=====================

For this demonstration, an example template has been prepared.

  >>> filename = os.path.join(path, 'layouts', 'example.html')

We instantiate the dynamic HTML template like a normal Chameleon
template, passing the filename as an argument.

  >>> from chameleon.html.template import DynamicHTMLFile
  >>> template = DynamicHTMLFile(filename)

Dynamic content and attributes are passed in as keyword arguments to
the template.

The ``content`` parameter should be passed a dict with keys
corresponding to dynamic content names and values being unicode
strings.

  >>> content = {'title': u"Document title",
  ...            'content': u"Document content"}

The ``attributes`` parameters is a double dictionary where the first
level of values are element attribute dictionaries, e.g. the second
dictionary is a mapping of element attribute names and values.
  
  >>> attributes={'meta-generator': {'content': u"Document generator"},
  ...             'meta-description': {'content': u"Document description"},
  ...             'meta-keywords': {'content': u"Document keywords"}}

Passing these arguments by keyword, we can verify the rendered output.
  
  >>> print template(content=content, attributes=attributes)
  <html>
    <head>
      <title>Document title</title>
      <!-- meta -->
      <meta content="Document generator" name="generator" />
      <meta content="Document description" name="description" />
      <meta content="Document keywords" name="keywords" />
      <style type="text/css"><!-- @import url(example.css); --></style>
      <link href="example.kss" rel="kukit" type="text/kss" />
      <script src="example.js" type="text/javascript">
      </script>
    </head>
    <body>
      <div id="content">Document content</div>
      <img src="example.png" />
    </body>
  </html>

If we pass in ``context`` and ``request`` arguments, resources
referenced in the template are rebased if a resource location
component is available.

  >>> def resource_location(context, request, path):
  ...     return 'http://host/%s' % path

  >>> from chameleon.html.interfaces import IResourceLocation  
  >>> component.provideAdapter(
  ...     resource_location,
  ...     (interface.Interface, interface.Interface, interface.Interface),
  ...     IResourceLocation)

Notice in the following that URLs of resource is rebased as defined in
the adapter.
  
  >>> print template(context=object(), request=object())
  <html>
    <head>
      <title>Example layout</title>
      <!-- meta -->
      <meta content="Emacs" name="generator" />
      <meta content="This is an example layout." name="description" />
      <meta content="example, layout, xss." name="keywords" />
      <style type="text/css"><!-- @import url(http://host/example.css); --></style>
      <link href="http://host/example.kss" rel="kukit" type="text/kss" />
      <script src="http://host/example.js" type="text/javascript">      
      </script>
    </head>
    <body>
      <div id="content">
        This is the content area.
      </div>
      <img src="http://host/example.png" />
    </body>
  </html>
