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 | ||||
|   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 | ||||
|  |  | |||
|  | @ -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 | ||||
|  |  | |||
|  | @ -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 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue