Class: Lifer::Builder::HTML

Inherits:
Lifer::Builder show all
Defined in:
lib/lifer/builder/html.rb,
lib/lifer/builder/html/from_any.rb,
lib/lifer/builder/html/from_erb.rb,
lib/lifer/builder/html/from_liquid.rb

Overview

This builder makes HTML documents out of any entry type that responds to ‘#to_html` and writes them to the configured Lifer output directory.

The HTML builder depends on the collection’s layout file. Layout files can be ERB or Liquid template files. The layout file yields entry contents via a ‘content` call that is parsed by ERB or Liquid.

Layout files can also include other contextual information about the current Lifer project to provide “normal website features” like navigation links, indexes, and so on. Context is provided via:

- `my_collection_name`: Or, any collection by name.

  For example, you can iterate over the entries of any named collection by
  accessing the collection like this:

      my_collection.entries

- `settings`: Serialized Lifer settings from the configuration file.

- `collections`: A list of collections.

- `content`: The content of the current entry.

The ‘:content` variable is especially powerful, as it also parses any given entry that’s an ERB file with the same local variables in context.

[1]: docs.ruby-lang.org/en/3.3/ERB.html [2]: shopify.github.io/liquid/

Defined Under Namespace

Classes: FromAny, FromERB, FromLiquid

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Lifer::Builder

build!, prebuild!

Class Method Details

.execute(root:) ⇒ void

This method returns an undefined value.

Traverses and renders each entry for each collection in the configured output directory for the Lifer project.

Parameters:

  • root (String)

    The Lifer root.



46
47
48
49
50
# File 'lib/lifer/builder/html.rb', line 46

def execute(root:)
  Dir.chdir Lifer.output_directory do
    new(root: root).execute
  end
end

Instance Method Details

#executevoid

This method returns an undefined value.

Traverses and renders each entry for each collection.



56
57
58
59
60
61
# File 'lib/lifer/builder/html.rb', line 56

def execute
  Lifer.collections(without_selections: true).each do |collection|
    generate_output_directories_for collection
    generate_output_entries_for collection
  end
end