Class: Lifer::Builder::HTML::FromLiquid::Drops::SettingsDrop
- Inherits:
-
Liquid::Drop
- Object
- Liquid::Drop
- Lifer::Builder::HTML::FromLiquid::Drops::SettingsDrop
- Defined in:
- lib/lifer/builder/html/from_liquid/drops/settings_drop.rb
Overview
This drop allows users to access the current Lifer project settings from Liquid templates. Example:
Instance Method Summary collapse
-
#initialize(settings = Lifer.settings) ⇒ SettingsDrop
constructor
A new instance of SettingsDrop.
-
#liquid_method_missing(arg) ⇒ CollectionDrop, NilClass
Dynamically define Liquid accessors based on the Lifer settings object.
-
#to_s ⇒ String
Ensure the settings tree can be output to a rendered template if need be.
Constructor Details
#initialize(settings = Lifer.settings) ⇒ SettingsDrop
Returns a new instance of SettingsDrop.
9 10 11 |
# File 'lib/lifer/builder/html/from_liquid/drops/settings_drop.rb', line 9 def initialize(settings = Lifer.settings) @settings = Lifer::Utilities.stringify_keys(settings) end |
Instance Method Details
#liquid_method_missing(arg) ⇒ CollectionDrop, NilClass
Dynamically define Liquid accessors based on the Lifer settings object.
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/lifer/builder/html/from_liquid/drops/settings_drop.rb', line 25 def liquid_method_missing(arg) value = settings[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 the settings tree can be output to a rendered template if need be.
16 |
# File 'lib/lifer/builder/html/from_liquid/drops/settings_drop.rb', line 16 def to_s = settings.to_json |