Class: Lifer::Builder::HTML::FromLiquid::Drops::FrontmatterDrop

Inherits:
Liquid::Drop
  • Object
show all
Defined in:
lib/lifer/builder/html/from_liquid/drops/frontmatter_drop.rb

Overview

Markdown entries may contain YAML frontmatter. And if they do, we need a way for the Liquid templates to access that data.

Examples:

Usage

{{ entry.frontmatter.any_available_frontmatter_key }}

Instance Method Summary collapse

Constructor Details

#initialize(entry) ⇒ FrontmatterDrop

Returns a new instance of FrontmatterDrop.



9
10
11
# File 'lib/lifer/builder/html/from_liquid/drops/frontmatter_drop.rb', line 9

def initialize(entry)
  @frontmatter = Lifer::Utilities.stringify_keys(entry.frontmatter)
end

Instance Method Details

#liquid_method_missing(arg) ⇒ CollectionDrop, NilClass

Dynamically define Liquid accessors based on the Lifer settings object.

Examples:

Get a collection’s URI strategy.

{{ settings.my_collection.uri_strategy }}

Parameters:

  • arg (String)

    The name of a collection.

Returns:



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/lifer/builder/html/from_liquid/drops/frontmatter_drop.rb', line 26

def liquid_method_missing(arg)
  value = frontmatter[arg]

  if value.is_a?(Hash)
    as_drop(value)
  elsif value.is_a?(Array) && value.all? { _1.is_a?(Hash) }
    value.map { as_drop(_1) }
  else
    value
  end
end

#to_sString

Ensure that the frontmatter can be output wholly into a rendered template if need be.

Returns:

  • (String)


17
# File 'lib/lifer/builder/html/from_liquid/drops/frontmatter_drop.rb', line 17

def to_s = frontmatter.to_json