Class: Middleman::DataSource::Extension
- Inherits:
-
Extension
- Object
- Extension
- Middleman::DataSource::Extension
- Defined in:
- lib/middleman/data_source/extension.rb
Defined Under Namespace
Classes: UnsupportedDataExtension
Instance Attribute Summary collapse
-
#decoders ⇒ Object
readonly
Returns the value of attribute decoders.
-
#sources ⇒ Object
readonly
Returns the value of attribute sources.
Instance Method Summary collapse
-
#initialize(app, options_hash = {}, &block) ⇒ Extension
constructor
A new instance of Extension.
- #rack_app ⇒ Object
Constructor Details
#initialize(app, options_hash = {}, &block) ⇒ Extension
Returns a new instance of Extension.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/middleman/data_source/extension.rb', line 19 def initialize app, ={}, &block super app, , &block app_inst = app.respond_to?(:inst) ? app.inst : app @sources = .sources.dup @decoders = default_decoders.merge(.decoders) .files.flat_map do |remote_path, local| @sources.push({ :alias => (local || remote_path), :path => remote_path }) end @sources.each do |source| raw_extension = File.extname(source[:path]) extension = raw_extension.split('?').first parts = source[:alias].split(File::SEPARATOR) basename = File.basename(parts.pop, raw_extension) if parts.empty? original_callback = app_inst.data.callbacks[basename] app_inst.data.callbacks[basename] = Proc.new do attempt_merge_then_enhance decode_data(source, extension), original_callback end else original_callback = app_inst.data.callbacks[parts.first] app_inst.data.callbacks[parts.first] = Proc.new do built_data = { basename => decode_data(source, extension) } parts[1..-1].reverse.each do |part| built_data = { part => built_data } end attempt_merge_then_enhance built_data, original_callback end end end end |
Instance Attribute Details
#decoders ⇒ Object (readonly)
Returns the value of attribute decoders.
13 14 15 |
# File 'lib/middleman/data_source/extension.rb', line 13 def decoders @decoders end |
#sources ⇒ Object (readonly)
Returns the value of attribute sources.
13 14 15 |
# File 'lib/middleman/data_source/extension.rb', line 13 def sources @sources end |
Instance Method Details
#rack_app ⇒ Object
15 16 17 |
# File 'lib/middleman/data_source/extension.rb', line 15 def rack_app @_rack_app ||= ::Rack::Test::Session.new( ::Rack::MockSession.new( .rack_app ) ) end |