Class: Locomotive::Steam::Liquid::FileSystem
- Inherits:
-
Object
- Object
- Locomotive::Steam::Liquid::FileSystem
- Defined in:
- lib/locomotive/steam/liquid/file_system.rb
Overview
A Liquid file system is a way to let your templates retrieve other templates for use with the include and sections tags.
Example:
Liquid::Template.file_system = Liquid::LocalFileSystem.new(template_path)
liquid = Liquid::Template.parse(template)
This will parse the template from both the DB or the Filesystem.
Instance Attribute Summary collapse
-
#section_finder ⇒ Object
readonly
Returns the value of attribute section_finder.
-
#snippet_finder ⇒ Object
readonly
Returns the value of attribute snippet_finder.
Instance Method Summary collapse
-
#initialize(section_finder: nil, snippet_finder: nil) ⇒ FileSystem
constructor
A new instance of FileSystem.
-
#read_template_file(template_path) ⇒ Object
Called by Liquid to retrieve a template file.
Constructor Details
#initialize(section_finder: nil, snippet_finder: nil) ⇒ FileSystem
Returns a new instance of FileSystem.
18 19 20 |
# File 'lib/locomotive/steam/liquid/file_system.rb', line 18 def initialize(section_finder: nil, snippet_finder: nil) @section_finder, @snippet_finder = section_finder, snippet_finder end |
Instance Attribute Details
#section_finder ⇒ Object (readonly)
Returns the value of attribute section_finder.
16 17 18 |
# File 'lib/locomotive/steam/liquid/file_system.rb', line 16 def section_finder @section_finder end |
#snippet_finder ⇒ Object (readonly)
Returns the value of attribute snippet_finder.
16 17 18 |
# File 'lib/locomotive/steam/liquid/file_system.rb', line 16 def snippet_finder @snippet_finder end |
Instance Method Details
#read_template_file(template_path) ⇒ Object
Called by Liquid to retrieve a template file
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/locomotive/steam/liquid/file_system.rb', line 23 def read_template_file(template_path) type, name = template_path.split('--') entity = ( case type when 'sections' section_finder.find(name) when 'snippets' snippet_finder.find(name) else raise ::Liquid::FileSystemError, "This liquid context does not allow #{type}." end ) raise ::Liquid::FileSystemError, "Unable to find #{name} in the #{type} folder" if entity.nil? entity.liquid_source end |