Skip to content

Commit

Permalink
Ensure front matter defaults are dot access hashes (#944)
Browse files Browse the repository at this point in the history
Fixes #704
  • Loading branch information
jaredcwhite authored Nov 23, 2024
1 parent a478184 commit d8af3c6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
12 changes: 6 additions & 6 deletions bridgetown-core/lib/bridgetown-core/front_matter/defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ module FrontMatter
# This class handles custom defaults for front matter settings.
# It is exposed via the frontmatter_defaults method on the site class.
class Defaults
using Bridgetown::Refinements

# @return [Bridgetown::Site]
attr_reader :site

Expand All @@ -16,6 +18,7 @@ def initialize(site)
def reset
@glob_cache = {}
@defaults_cache = {}
@sets = nil
end

def ensure_time!(set)
Expand Down Expand Up @@ -175,15 +178,12 @@ def matching_sets(path, collection)

# Returns a list of valid sets
#
# This is not cached to allow plugins to modify the configuration
# and have their changes take effect
#
# @return [Array<Hash>]
def valid_sets
sets = site.config["defaults"]
return [] unless sets.is_a?(Array)
@sets ||= site.config["defaults"].map(&:as_dots)
return [] unless @sets.is_a?(Array)

sets.filter_map do |set|
@sets.filter_map do |set|
if valid?(set)
massage_scope!(set)
# TODO: is this trip really necessary?
Expand Down
22 changes: 11 additions & 11 deletions bridgetown-core/test/test_front_matter_defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,22 +137,22 @@ class TestFrontMatterDefaults < BridgetownUnitTest

context "A site with front matter defaults with no path" do
setup do
@site = fixture_site(
"defaults" => [{
"scope" => {
"type" => "pages",
},
"values" => {
"key" => "val",
},
}]
)
@site.process
@site = fixture_site
@site.config.defaults << {
scope: {
type: "pages",
},
values: {
key: "val",
},
}
@site.read
@affected = @site.collections.pages.resources
@not_affected = @site.collections.posts.resources
end

should "affect only the specified type and all paths" do
assert @affected.length > 1
assert_equal @affected.reject { |page| page.data["key"] == "val" }, []
assert_equal @not_affected.reject { |page| page.data["key"] == "val" },
@not_affected
Expand Down

0 comments on commit d8af3c6

Please sign in to comment.