Class: Quintype::Liquid::FileSystem

Inherits:
Liquid::LocalFileSystem
  • Object
show all
Includes:
FileSystemCacheReadFile
Defined in:
lib/quintype/liquid/file_system.rb

Instance Method Summary collapse

Instance Method Details

#full_path(template_path) ⇒ Object

Raises:

  • (Liquid::FileSystemError)


40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/quintype/liquid/file_system.rb', line 40

def full_path(template_path)
  raise Liquid::FileSystemError, "Illegal template name '#{template_path}'" unless template_path =~ /\A[^.\/][a-zA-Z0-9_\.\/]+\z/

  full_path = if template_path.include?('/'.freeze)
    File.join(root, File.dirname(template_path), @pattern % File.basename(template_path))
  else
    File.join(root, @pattern % template_path)
  end

  raise Liquid::FileSystemError, "Illegal template path '#{File.expand_path(full_path)}'" unless File.expand_path(full_path) =~ /\A#{File.expand_path(root)}/

  full_path
end

#read_file(path) ⇒ Object



12
13
14
15
# File 'lib/quintype/liquid/file_system.rb', line 12

def read_file(path)
  full_path = full_path(path)
  File.read(full_path) if File.exists?(full_path)
end

#read_template_file(template_path, context) ⇒ Object

Raises:

  • (Liquid::FileSystemError)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/quintype/liquid/file_system.rb', line 19

def read_template_file(template_path, context)
  controller = context.registers[:controller]
  controller_path = controller.controller_path
  formats = controller.formats.map { |format| '.' + format.to_s } + ['']

  file = nil

  formats.each do |format|
    path = template_path.include?('/') ? template_path : "#{controller_path}/#{template_path}"
    path = path + format

    file = read_file(path)

    break if file
  end

  raise Liquid::FileSystemError, "No such template '#{template_path}'" unless file

  file
end