add StaticFileDrop

This commit is contained in:
Ben Balter 2017-02-08 17:44:47 -05:00
parent 20d2eb2709
commit 229769e249
No known key found for this signature in database
GPG Key ID: DBB67C246AD356C4
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