Template for mail
*****************

The package provide some template facility::

  >>> from iw.email import *


We have a basic template::

  >>> template = BasicMailTemplate(u"i'm working at %(name)s")
  >>> template.cook(name=u'ingeniweb')
  >>> print template
  i'm working at ingeniweb

Template can be restructuredtext::

  >>> source = '''==========
  ... %(title)s
  ... ==========
  ... 
  ... %(paragraph)s
  ... '''
  >>> template = BasicMailTemplate(source, format='rst')
  >>> template.cook(title='nice title', paragraph= 'nice paragraph')
  >>> print template
  <?xml version="1.0" encoding="iso-8859-1" ?>
  ...
  <body>
  <div class="document" id="nice-title">
  <h1 class="title">nice title</h1>
  <p>nice paragraph</p>
  </div>
  </body>
  </html>
  <BLANKLINE>

We can also use some Cheetah based template::

  >>> path = os.path.join(testdir, 'mail.tmpl')
  >>> print open(path).read()
  ==========
  $title
  ==========
  <BLANKLINE>
  $paragraph
  <BLANKLINE>

  >>> template = CheetahMailTemplate(path, format='plain')
  >>> template.cook(title='nice title', paragraph= 'nice paragraph')
  >>> print template
  ==========
  nice title
  ==========
  <BLANKLINE>
  nice paragraph
  <BLANKLINE>

Also support unicode::

  >>> paragraph = u'''<html><body>
  ... corps du maiil avec caractère unicode:
  ... utf-8: \xc3\xa9
  ... cp552: \u2013 \u2019
  ... </body></html>'''
  >>> template = CheetahMailTemplate(path, format='plain')
  >>> template.cook(title='nice title', paragraph=paragraph)
  >>> cooked = template()
  >>> unicode(cooked, 'utf-8')
  u"==========\nnice title\n==========\n\n<html><body>\ncorps du maiil avec caract\xc3\xa8re unicode:\nutf-8: \xc3\xa9\ncp552: - '\n</body></html>\n"



Of course, Cheetah template can be render as restructuredtext::

  >>> template = CheetahMailTemplate(path, format='rst')
  >>> template.cook(title='nice title', paragraph= 'nice paragraph')
  >>> print template
  <?xml version="1.0" encoding="iso-8859-1" ?>
  ...
  <body>
  <div class="document" id="nice-title">
  <h1 class="title">nice title</h1>
  <p>nice paragraph</p>
  </div>
  </body>
  </html>
  <BLANKLINE>

And you get the same api with mako::

  >>> path = os.path.join(testdir, 'mail.mak')
  >>> template = MakoMailTemplate(path, format='rst')
  >>> template.cook(title='nice title', paragraph= 'nice paragraph')
  >>> print template
  <?xml version="1.0" encoding="iso-8859-1" ?>
  ...
  <body>
  <div class="document" id="nice-title">
  <h1 class="title">nice title</h1>
  <p>nice paragraph</p>
  </div>
  </body>
  </html>
  <BLANKLINE>

