Static files contain front matter default keys when to_liquid'd (#6162)
Merge pull request 6162
This commit is contained in:
parent
4f4d42444a
commit
f91b614793
|
@ -1,6 +1,6 @@
|
||||||
module Jekyll
|
module Jekyll
|
||||||
class StaticFile
|
class StaticFile
|
||||||
attr_reader :relative_path, :extname, :name
|
attr_reader :relative_path, :extname, :name, :data
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
# The cache of last modification times [path] -> mtime.
|
# The cache of last modification times [path] -> mtime.
|
||||||
|
@ -28,10 +28,7 @@ module Jekyll
|
||||||
@collection = collection
|
@collection = collection
|
||||||
@relative_path = File.join(*[@dir, @name].compact)
|
@relative_path = File.join(*[@dir, @name].compact)
|
||||||
@extname = File.extname(@name)
|
@extname = File.extname(@name)
|
||||||
|
@data = @site.frontmatter_defaults.all(relative_path, type)
|
||||||
data.default_proc = proc do |_, key|
|
|
||||||
site.frontmatter_defaults.find(relative_path, type, key)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
# rubocop: enable ParameterLists
|
# rubocop: enable ParameterLists
|
||||||
|
|
||||||
|
@ -103,10 +100,6 @@ module Jekyll
|
||||||
@to_liquid ||= Drops::StaticFileDrop.new(self)
|
@to_liquid ||= Drops::StaticFileDrop.new(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
def data
|
|
||||||
@data ||= {}
|
|
||||||
end
|
|
||||||
|
|
||||||
def basename
|
def basename
|
||||||
File.basename(name, extname)
|
File.basename(name, extname)
|
||||||
end
|
end
|
||||||
|
|
|
@ -132,6 +132,12 @@ class TestDocument < JekyllUnitTest
|
||||||
assert_equal "slide", @document.data["layout"]
|
assert_equal "slide", @document.data["layout"]
|
||||||
assert_equal({ "key"=>"myval" }, @document.data["nested"])
|
assert_equal({ "key"=>"myval" }, @document.data["nested"])
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context "a document as part of a collection with overridden default values" do
|
context "a document as part of a collection with overridden default values" do
|
||||||
|
|
|
@ -109,6 +109,28 @@ class TestStaticFile < JekyllUnitTest
|
||||||
"`published: false`")
|
"`published: false`")
|
||||||
end
|
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
|
should "know its last modification time" do
|
||||||
assert_equal Time.new.to_i, @static_file.mtime
|
assert_equal Time.new.to_i, @static_file.mtime
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue