Class: Lifer::Builder::HTML::FromLiquid::Drops::FrontmatterDrop
- Inherits:
-
Liquid::Drop
- Object
- Liquid::Drop
- Lifer::Builder::HTML::FromLiquid::Drops::FrontmatterDrop
- 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.
Instance Method Summary collapse
-
#initialize(entry) ⇒ FrontmatterDrop
constructor
A new instance of FrontmatterDrop.
-
#liquid_method_missing(arg) ⇒ CollectionDrop, NilClass
Dynamically define Liquid accessors based on the Lifer settings object.
-
#to_s ⇒ String
Ensure that the frontmatter can be output wholly into a rendered template if need be.
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.
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_s ⇒ String
Ensure that the frontmatter can be output wholly into a rendered template if need be.
17 |
# File 'lib/lifer/builder/html/from_liquid/drops/frontmatter_drop.rb', line 17 def to_s = frontmatter.to_json |