class Locomotive::Steam::Liquid::FileSystem

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.

Attributes

section_finder[R]
snippet_finder[R]

Public Class Methods

new(section_finder: nil, snippet_finder: nil) click to toggle source
# 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

Public Instance Methods

read_template_file(template_path) click to toggle source

Called by Liquid to retrieve a template file

# 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