Class: PufferPages::Liquid::FileSystem

Inherits:
Liquid::BlankFileSystem
  • Object
show all
Defined in:
lib/puffer_pages/liquid/file_system.rb

Instance Method Summary collapse

Instance Method Details

#layout(name) ⇒ Object



49
50
51
52
# File 'lib/puffer_pages/liquid/file_system.rb', line 49

def layout name
  @layouts_cache ||= {}
  @layouts_cache[name] ||= PufferPages::Layout.find_layout(name)
end

#read_template_file(template_path, context) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/puffer_pages/liquid/file_system.rb', line 5

def read_template_file template_path, context
  source = case template_type(template_path)
  when :snippet then
    template_path = template_path.gsub(/^snippets\//, '')
    snippet = snippet(template_path)
    raise ::Liquid::FileSystemError,
      "No such snippet '#{template_path}' found" unless snippet
    snippet
  when :layout then
    template_path = template_path.gsub(/^layouts\//, '')
    layout = layout(template_path)
    raise ::Liquid::FileSystemError,
      "No such layout '#{template_path}' found" unless layout
    layout
  when :super then
    page_part = context[:processed]
    raise ::Liquid::FileSystemError,
      "Can not render super page_part outside the page_part context" unless page_part.is_a?(PufferPages::PagePart)
    parent_part = page_part.parent
    raise ::Liquid::FileSystemError,
      "No super page_part found for #{page_part.name}" unless parent_part
    parent_part
  when :page_part then
    page_part = context.registers[:page].inherited_page_part(template_path)
    raise ::Liquid::FileSystemError,
      "No such page_part '#{template_path}' found for current page" unless page_part
    page_part
  end

  source.respond_to?(:render) ? source : ::Liquid::Template.parse(source)
end

#snippet(name) ⇒ Object



44
45
46
47
# File 'lib/puffer_pages/liquid/file_system.rb', line 44

def snippet name
  @snippets_cache ||= {}
  @snippets_cache[name] ||= PufferPages::Snippet.find_snippet(name)
end

#template_type(template_path) ⇒ Object



37
38
39
40
41
42
# File 'lib/puffer_pages/liquid/file_system.rb', line 37

def template_type template_path
  return :super if template_path == :super
  return :layout if template_path.start_with? 'layouts/'
  return :snippet if template_path.start_with? 'snippets/'
  return :page_part
end