Class: Lifer::Builder::HTML::FromLiquid

Inherits:
FromAny
  • Object
show all
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

Methods inherited from FromAny

build

Instance Method Details

#renderString

Reads the entry as Liquid, given our document context, and renders an entry.

Returns:

  • (String)

    The rendered entry.



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 render
  document_context = context.merge!(
    "content" => Liquid::Template
      .parse(entry.to_html, **parse_options)
      .render(context, **render_options)
  )
  document = Liquid::Template
    .parse(layout_file_contents, **parse_options)
    .render(document_context, **render_options)

  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, **parse_options)
    .render(document_context, **render_options)
end