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
@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
end
# rubocop: enable ParameterLists
@ -96,13 +100,15 @@ module Jekyll
end
def to_liquid
{
"basename" => File.basename(name, extname),
"name" => name,
"extname" => extname,
"modified_time" => modified_time,
"path" => File.join("", relative_path),
}
@to_liquid ||= Drops::StaticFileDrop.new(self)
end
def data
@data ||= {}
end
def basename
File.basename(name, extname)
end
def placeholders

View File

@ -148,8 +148,9 @@ class TestStaticFile < JekyllUnitTest
"extname" => ".txt",
"modified_time" => @static_file.modified_time,
"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