diff --git a/lib/jekyll/static_file.rb b/lib/jekyll/static_file.rb index beea9ddf..29d71cbe 100644 --- a/lib/jekyll/static_file.rb +++ b/lib/jekyll/static_file.rb @@ -1,6 +1,6 @@ module Jekyll class StaticFile - attr_reader :relative_path, :extname, :name + attr_reader :relative_path, :extname, :name, :data class << self # The cache of last modification times [path] -> mtime. @@ -28,10 +28,7 @@ module Jekyll @collection = collection @relative_path = File.join(*[@dir, @name].compact) @extname = File.extname(@name) - - data.default_proc = proc do |_, key| - site.frontmatter_defaults.find(relative_path, type, key) - end + @data = @site.frontmatter_defaults.all(relative_path, type) end # rubocop: enable ParameterLists @@ -103,10 +100,6 @@ module Jekyll @to_liquid ||= Drops::StaticFileDrop.new(self) end - def data - @data ||= {} - end - def basename File.basename(name, extname) end diff --git a/test/test_document.rb b/test/test_document.rb index 0c880a6b..8726c83c 100644 --- a/test/test_document.rb +++ b/test/test_document.rb @@ -132,6 +132,12 @@ class TestDocument < JekyllUnitTest assert_equal "slide", @document.data["layout"] assert_equal({ "key"=>"myval" }, @document.data["nested"]) end + + should "return front matter defaults via to_liquid" do + hash = @document.to_liquid + assert hash.key? "nested" + assert_equal({ "key"=>"myval" }, hash["nested"]) + end end context "a document as part of a collection with overridden default values" do diff --git a/test/test_static_file.rb b/test/test_static_file.rb index 1603420a..49adc96b 100644 --- a/test/test_static_file.rb +++ b/test/test_static_file.rb @@ -109,6 +109,28 @@ class TestStaticFile < JekyllUnitTest "`published: false`") end + should "respect front matter defaults" do + defaults = [{ + "scope" => { "path" => "" }, + "values" => { "front-matter" => "default" }, + },] + + static_file = setup_static_file_with_defaults "", "", "file.pdf", defaults + assert_equal "default", static_file.data["front-matter"] + end + + should "include front matter defaults in to_liquid" do + defaults = [{ + "scope" => { "path" => "" }, + "values" => { "front-matter" => "default" }, + },] + + static_file = setup_static_file_with_defaults "", "", "file.pdf", defaults + hash = static_file.to_liquid + assert hash.key? "front-matter" + assert_equal "default", hash["front-matter"] + end + should "know its last modification time" do assert_equal Time.new.to_i, @static_file.mtime end