Sha256: d8aa848488e6aa53a7e78355642b63034b3525e76e575226be1046d980ef9ad1

Contents?: true

Size: 1.35 KB

Versions: 3

Compression:

Stored size: 1.35 KB

Contents

== RBHTML

Tenjin is a general purpose template language with support for multiple
languages including Ruby. The variation of Tenjin for Ruby, called rbTenjin,
defines a document format with an extension of `.rbhtml`.

Lets say we have a Tenjin document called 'test.rbhtml' containing:

  Hello #{@name}!
  <ul>
  <?rb for item in @items ?>
   <li>${item}</li>
  <?rb end ?>
  </ul>

We can render the document via #render.

  data = { :name=>'World', :items=>['<AAA>', 'B&B', '"CCC"'] }

  @html = Malt.render(:file=>'tmp/test.rbhtml', :data=>data)

And we can verify that @html is:

  Hello World!
  <ul>
   <li>&lt;AAA&gt;</li>
   <li>B&amp;B</li>
   <li>&quot;CCC&quot;</li>
  </ul>

We can get a hold of the RBHTML document via the Malt.file function.

  rbhtml = Malt.file('tmp/test.rbhtml')

  rbhtml.class.assert == Malt::Format::RBHTML

We can convert RBHTML documents to HTML documents via #to_html.

  data = { :name=>'World', :items=>['<AAA>', 'B&B', '"CCC"'] }

  html = rbhtml.to_html(data)

First we will notice that the output is an instance of Malt::Format::HTML.

  html.class.assert == Malt::Format::HTML

And that by calling #to_s we can get the rendered HTML document.

  html.to_s.assert.include?('Hello World!')

Or we can convert the RBHTML document directly to HTML via the #html method.

  out = rbhtml.html(data)

  out.assert.include?('Hello World!')

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
malt-0.3.0 qed/03_formats/12_rbhtml.rdoc
malt-0.2.0 qed/03_formats/12_rbhtml.rdoc
malt-0.1.1 qed/03_formats/12_rbhtml.rdoc