Class: Lifer::Builder::HTML::FromERB
- Defined in:
- lib/lifer/builder/html/from_erb.rb
Overview
If the HTML builder is given an ERB template, it uses this class to parse the ERB into HTML. Lifer project metadata is provided as context. For example:
<html>
<head>
<title><%= my_collection.name %></title>
</head>
<body>
<h1><%= my_collection.name %></h1>
<% my_collection.entries.each do |entry| %>
<section>
<h2><%= entry.title %></h2>
<p><%= entry.summary %></p>
<a href="<%= entry.permalink %>">Read more</a>
</section>
<% end %>
</body>
</html>
Instance Method Summary collapse
-
#render ⇒ String
Reads the entry as ERB, given our renderer context (see the documentation for ‘#build_binding_context`) and renders the production-ready entry.
Methods inherited from FromAny
Instance Method Details
#render ⇒ String
Reads the entry as ERB, given our renderer context (see the documentation for ‘#build_binding_context`) and renders the production-ready entry.
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/lifer/builder/html/from_erb.rb', line 31 def render document = ERB.new(layout_file_contents).result context return document unless (relative_layout_path = frontmatter[:layout]) document_binding = binding.tap { |binding| binding.local_variable_set :content, document } layout_path = "%s/%s" % [Lifer.root, relative_layout_path] ERB.new(File.read layout_path).result(document_binding) end |