Sha256: 5672f214a49623a9d6ec625e9afb45c1403b2e62c3197e5980a78350f3c3eb1d
Contents?: true
Size: 1.61 KB
Versions: 3
Compression:
Stored size: 1.61 KB
Contents
== Liquid Lets say we have a Liquid document called 'test.liquid' containing: <h1>Example {{ title }}</h1> <p>This is an example of a Liquid template.</p> We can render liquid documents via the +render+ method, as we can any format. However, becuase Liquid is a template format and not just a markup syntax, we need to also provide the +render+ function with data for interpolation into the liquid document. data = { :title=>"Document" } html = Malt.render(:file=>'tmp/test.liquid', :data=>data) html.assert.include?('<h1>Example Document</h1>') Liquid doesn't actually care what format the document is rendered as, since it is purely a template engine that can be applied to any other format. Lets say we have a Liquid document called 'test.liquid' containing ... <h1>Example {{ title }}</h1> <p>This is an example of a Liquid template.</p> We can render erb documents to any format we wish. liq = Malt.file('tmp/test.liquid') html = liq.to_html(:title=>"Document") We will notice that the output is an instance of Malt::Format::HTML. html.class.assert == Malt::Format::HTML We will notice that the output is an instance of Malt::Format::HTML. html.class.assert == Malt::Format::HTML Then 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 document directly to HTML via the #html method. out = liq.html(:title=>"Alternate") out.assert.include?('<h1>Example Alternate</h1>') Liquid doesn't actually care what format the document is rendered as, since it is purely a template engine that can be applied to any format.
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
malt-0.3.0 | qed/03_formats/06_liquid.rdoc |
malt-0.2.0 | qed/03_formats/06_liquid.rdoc |
malt-0.1.1 | qed/03_formats/06_liquid.rdoc |