add StaticFileDrop
This commit is contained in:
		
							parent
							
								
									20d2eb2709
								
							
						
					
					
						commit
						229769e249
					
				|  | @ -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 | ||||
|  | @ -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 | ||||
|  |  | |||
|  | @ -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 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue