Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure front matter defaults are dot access hashes #944

Merged
merged 1 commit into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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