Class: Zwite::Liquid::FileSystem

Inherits:
Object
  • Object
show all
Defined in:
lib/zwite/liquid/filesystem.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ FileSystem

Returns a new instance of FileSystem.



9
10
11
# File 'lib/zwite/liquid/filesystem.rb', line 9

def initialize(root)
  @root = root
end

Instance Attribute Details

#rootObject

Returns the value of attribute root.



7
8
9
# File 'lib/zwite/liquid/filesystem.rb', line 7

def root
  @root
end

Instance Method Details

#full_path(template_path) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/zwite/liquid/filesystem.rb', line 19

def full_path(template_path)
  full_path = if template_path.include?('/')
    File.join(root, File.dirname(template_path), "#{File.basename(template_path)}")
  else
    File.join(root, "#{template_path}")
  end

  raise Exception::exception("Illegal template path '#{File.expand_path(full_path)}'") unless File.expand_path(full_path) =~ /^#{File.expand_path(root)}/

  full_path
end

#read_template_file(template_path) ⇒ Object



13
14
15
16
17
# File 'lib/zwite/liquid/filesystem.rb', line 13

def read_template_file(template_path)
  full_path = full_path(template_path)
  raise Exception::exception("No such template '#{template_path}'") unless File.exists?(full_path)
  File.read(full_path)
end