class Liquid::LocalFileSystem
file_system.full_path(“index”) # => “/some/path/index.html”
file_system = Liquid::LocalFileSystem.new(“/some/path”, “%s.html”)
Example:
Default pattern is “_%s.liquid”.
The Kernel::sprintf format specification is used.
Optionally in the second argument you can specify a custom pattern for template filenames.
file_system.full_path(“dir/mypartial”) # => “/some/path/dir/_mypartial.liquid”
file_system.full_path(“mypartial”) # => “/some/path/_mypartial.liquid”
file_system = Liquid::LocalFileSystem.new(“/some/path”)
Example:
For security reasons, template paths are only allowed to contain letters, numbers, and underscore.
ie. with the template name prefixed with an underscore. The extension “.liquid” is also added.
This implements an abstract file system which retrieves template files named in a manner similar to Rails partials,
def full_path(template_path)
def full_path(template_path) raise FileSystemError, "Illegal template name '#{template_path}'" unless %r{\A[^./][a-zA-Z0-9_/]+\z}.match?(template_path) full_path = if template_path.include?('/') File.join(root, File.dirname(template_path), @pattern % File.basename(template_path)) else File.join(root, @pattern % template_path) end raise FileSystemError, "Illegal template path '#{File.expand_path(full_path)}'" unless File.expand_path(full_path).start_with?(File.expand_path(root)) full_path end
def initialize(root, pattern = "_%s.liquid")
def initialize(root, pattern = "_%s.liquid") @root = root @pattern = pattern end
def read_template_file(template_path)
def read_template_file(template_path) full_path = full_path(template_path) raise FileSystemError, "No such template '#{template_path}'" unless File.exist?(full_path) File.read(full_path) end