Class: Lifer::Builder::HTML::FromLiquid
- Defined in:
- lib/lifer/builder/html/from_liquid.rb,
lib/lifer/builder/html/from_liquid/drops.rb,
lib/lifer/builder/html/from_liquid/liquid_env.rb
Overview
If the HTML builder is given a Liquid template, it uses this class to parse the Liquid into HTML. Lifer project metadata is provided as context. For example:
<html>
<head>
<title>{{ collections.my_collection.name }}</title>
</head>
<body>
<h1>{{ collections.my_collection.name }}</h1>
{% for entry in collections.my_collection.entries %}
<section>
<h2>{{ entry.title }}</h2>
<p>{{ entry.summary }}</p>
<a href="{{ entry.permalink }}">Read more</a>
</section>
{% endfor %}
</body>
</html>
Defined Under Namespace
Modules: Drops, Filters Classes: LiquidEnv
Instance Method Summary collapse
-
#build ⇒ String
Reads the Liquid entry, given our document context, and builds an HTML document.
Methods inherited from FromAny
Instance Method Details
#build ⇒ String
Reads the Liquid entry, given our document context, and builds an HTML document.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/lifer/builder/html/from_liquid.rb', line 35 def build document_context = context.merge!( "content" => Liquid::Template .parse(entry.to_html, **) .render(context, **) ) document = Liquid::Template .parse(layout_file_contents, **) .render(document_context, **) return document unless (relative_layout_path = frontmatter[:layout]) layout_path = "%s/%s" % [Lifer.root, relative_layout_path] document_context = context.merge! "content" => document Liquid::Template .parse(File.read layout_path, **) .render(document_context, **) end |