Sha256: b1f4f5d745a5a3029e735c82b0c6d11c3f5b05d4660f5f60ab27bb55aa1638e5
Contents?: true
Size: 1.4 KB
Versions: 2
Compression:
Stored size: 1.4 KB
Contents
== Builder Lets say we have a Builder document called 'test.builder' containing: html do |h| h.h1 "Example #{@title}" h.p "This is an example of a Maraby template." end Notice the use of the instance variable. Builder templates must use instance variables for data rendering in order to avoid ambiguity with the markup syntax itself. We can render Builder documents via the +render+ method, as we can any format. Since Builder 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 Builder document. data = { :title=>"Document" } html = Malt.render(:file=>'tmp/test.builder', :data=>data) html.assert.include?('<h1>Example Document</h1>') We can get a hold of the Builder document via the Malt.file function. builder = Malt.file('tmp/test.builder') builder.class.assert == Malt::Format::Builder We can convert Builder documents to html very easily. data = {:title => "Document"} html = builder.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 Builder document directly to HTML via the #html method. out = builder.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/18_builder.rb |
malt-0.2.0 | qed/03_formats/18_builder.rb |