Sha256: 19156b62dc1d4e056a4355f59ac32b840daeb96e209e58e9d5fd64a175fa6c11
Contents?: true
Size: 1.21 KB
Versions: 3
Compression:
Stored size: 1.21 KB
Contents
== Haml Lets say we have a Haml document called 'test.haml' containing: %h1== Example #{title} %p This is an example of a Haml template. We can render Haml documents via the +render+ method, as we can any format. While it might not appear as such on first glance, Haml is actually a template format and not just a markup language, so we need to also provide the +render+ function with data for interpolation into the Haml document. data = { :title=>"Document" } html = Malt.render(:file=>'tmp/test.haml', :data=>data) html.assert.include?('<h1>Example Document</h1>') We can get a hold of the Haml document via the Malt.file function. haml = Malt.file('tmp/test.haml') haml.class.assert == Malt::Format::Haml We can convert Haml documents to html very easily. data = {:title => "Document"} html = haml.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 Haml document directly to HTML via the #html method. out = haml.html(data) out.assert.include?('<h1>Example Document</h1>')
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
malt-0.3.0 | qed/03_formats/07_haml.rdoc |
malt-0.2.0 | qed/03_formats/07_haml.rdoc |
malt-0.1.1 | qed/03_formats/07_haml.rdoc |