Class: Locomotive::Steam::Liquid::FileSystem

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_finderObject (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_finderObject (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

Raises:

  • (::Liquid::FileSystemError)


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