Sha256: 7f1a6a78eb71a7214ae9ff8f529c36e3a9a4c2ed659125dabeb9acb2498458f4

Contents?: true

Size: 1.39 KB

Versions: 2

Compression:

Stored size: 1.39 KB

Contents

== Markaby

Lets say we have a Markaby document called 'test.markaby' containing:

  html do
    h1 "Example #{@title}"
    p "This is an example of a Maraby template."
  end

Notice the use of the instance variable. Markaby templates must use instance
variables for data rendering in order to avoid ambiguity with the markup
syntax itself.

We can render Markaby documents via the +render+ method, as we can any format.
Since Markaby is a template format and not just a markup syntax, so we need
to also provide the +render+ function with data for interpolation into the
Markaby document. 

  data = { :title=>"Document" }

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

  html.assert.include?('<h1>Example Document</h1>')

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

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

  markaby.class.assert == Malt::Format::Markaby

We can convert Markaby documents to html very easily.

  data = {:title => "Document"}

  html = markaby.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?('<h1>Example Document</h1>')

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

  out = markaby.html(data)

  out.assert.include?('<h1>Example Document</h1>')

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
malt-0.3.0 qed/03_formats/17_markaby.rdoc
malt-0.2.0 qed/03_formats/17_markaby.rdoc