Class: Middleman::Renderers::Liquid
- Defined in:
- lib/middleman-core/renderers/liquid.rb
Overview
Liquid Renderer
Constant Summary
Constants included from Contracts
Instance Attribute Summary
Attributes inherited from Extension
Instance Method Summary collapse
-
#after_configuration ⇒ Object
After config, setup liquid partial paths.
- #manipulate_resource_list(resources) ⇒ Object
- #map_value(thing) ⇒ Object
-
#read_template_file(template_path, _) ⇒ Object
Called by Liquid to retrieve a template file.
- #stringify_recursive(hash) ⇒ Object
Methods inherited from Extension
activated_extension, #add_exposed_to_context, #after_build, after_extension_activated, #after_extension_activated, #before_build, #before_configuration, clear_after_extension_callbacks, config, define_setting, expose_to_application, expose_to_config, expose_to_template, global_config, helpers, #initialize, option, #ready, resources
Methods included from Contracts
Constructor Details
This class inherits a constructor from Middleman::Extension
Instance Method Details
#after_configuration ⇒ Object
After config, setup liquid partial paths
9 10 11 |
# File 'lib/middleman-core/renderers/liquid.rb', line 9 def after_configuration ::Liquid::Template.file_system = self end |
#manipulate_resource_list(resources) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/middleman-core/renderers/liquid.rb', line 22 def manipulate_resource_list(resources) return resources unless app.extensions[:data] resources.each do |resource| next if resource.file_descriptor.nil? next unless resource.file_descriptor[:full_path].to_s =~ %r{\.liquid$} # Convert data object into a hash for liquid resource. locals: { data: stringify_recursive(app.extensions[:data].data_store.to_h) } end end |
#map_value(thing) ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/middleman-core/renderers/liquid.rb', line 42 def map_value(thing) case thing when Hash stringify_recursive(thing) when Array thing.map { |v| map_value(v) } else thing end end |
#read_template_file(template_path, _) ⇒ Object
Called by Liquid to retrieve a template file
14 15 16 17 18 |
# File 'lib/middleman-core/renderers/liquid.rb', line 14 def read_template_file(template_path, _) file = app.files.find(:source, "_#{template_path}.liquid") raise ::Liquid::FileSystemError, "No such template '#{template_path}'" unless file file.read end |
#stringify_recursive(hash) ⇒ Object
36 37 38 39 40 |
# File 'lib/middleman-core/renderers/liquid.rb', line 36 def stringify_recursive(hash) {}.tap do |h| hash.each { |key, value| h[key.to_s] = map_value(value) } end end |