Merge pull request #5871 from jekyll/static-file-drop

Merge pull request 5871
This commit is contained in:
jekyllbot 2017-02-10 21:08:49 -05:00 committed by GitHub
commit 7ea53e0a3f
3 changed files with 26 additions and 8 deletions

View File

@ -0,0 +1,11 @@
module Jekyll
module Drops
class StaticFileDrop < Drop
extend Forwardable
def_delegators :@obj, :name, :extname, :modified_time, :basename
def_delegator :@obj, :relative_path, :path
def_delegator :@obj, :data, :fallback_data
def_delegator :@obj, :type, :collection
end
end
end

View File

@ -28,6 +28,10 @@ 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.default_proc = proc do |_, key|
site.frontmatter_defaults.find(relative_path, type, key)
end
end end
# rubocop: enable ParameterLists # rubocop: enable ParameterLists
@ -96,13 +100,15 @@ module Jekyll
end end
def to_liquid def to_liquid
{ @to_liquid ||= Drops::StaticFileDrop.new(self)
"basename" => File.basename(name, extname), end
"name" => name,
"extname" => extname, def data
"modified_time" => modified_time, @data ||= {}
"path" => File.join("", relative_path), end
}
def basename
File.basename(name, extname)
end end
def placeholders def placeholders

View File

@ -148,8 +148,9 @@ class TestStaticFile < JekyllUnitTest
"extname" => ".txt", "extname" => ".txt",
"modified_time" => @static_file.modified_time, "modified_time" => @static_file.modified_time,
"path" => "/static_file.txt", "path" => "/static_file.txt",
"collection" => nil
} }
assert_equal expected, @static_file.to_liquid assert_equal expected, @static_file.to_liquid.to_h
end end
end end
end end