Class: Bridgetown::FrontmatterDefaults
- Inherits:
-
Object
- Object
- Bridgetown::FrontmatterDefaults
- Defined in:
- lib/bridgetown-core/frontmatter_defaults.rb
Overview
This class handles custom defaults for front matter settings. It is exposed via the frontmatter_defaults method on the site class.
Instance Attribute Summary collapse
- #site ⇒ Bridgetown::Site readonly
Instance Method Summary collapse
-
#all(path, collection_name) ⇒ Hash
Collects a hash with all default values for a resource.
- #ensure_time!(set) ⇒ Object
-
#initialize(site) ⇒ FrontmatterDefaults
constructor
A new instance of FrontmatterDefaults.
- #reset ⇒ Object
Constructor Details
#initialize(site) ⇒ FrontmatterDefaults
Returns a new instance of FrontmatterDefaults.
10 11 12 13 |
# File 'lib/bridgetown-core/frontmatter_defaults.rb', line 10 def initialize(site) @site = site @defaults_cache = {} end |
Instance Attribute Details
#site ⇒ Bridgetown::Site (readonly)
8 9 10 |
# File 'lib/bridgetown-core/frontmatter_defaults.rb', line 8 def site @site end |
Instance Method Details
#all(path, collection_name) ⇒ Hash
Collects a hash with all default values for a resource
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/bridgetown-core/frontmatter_defaults.rb', line 37 def all(path, collection_name) if @defaults_cache.key?([path, collection_name]) return @defaults_cache[[path, collection_name]] end defaults = {} merge_data_cascade_for_path(path, defaults) old_scope = nil matching_sets(path, collection_name).each do |set| if has_precedence?(old_scope, set["scope"]) defaults = Utils.deep_merge_hashes(defaults, set["values"]) old_scope = set["scope"] else defaults = Utils.deep_merge_hashes(set["values"], defaults) end end @defaults_cache[[path, collection_name]] = defaults end |
#ensure_time!(set) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/bridgetown-core/frontmatter_defaults.rb', line 20 def ensure_time!(set) return set unless set.key?("values") && set["values"].key?("date") return set if set["values"]["date"].is_a?(Time) set["values"]["date"] = Utils.parse_date( set["values"]["date"], "An invalid date format was found in a front-matter default set: #{set}" ) set end |
#reset ⇒ Object
15 16 17 18 |
# File 'lib/bridgetown-core/frontmatter_defaults.rb', line 15 def reset @glob_cache = {} @defaults_cache = {} end |