Class: Liquid::LocalFileSystem
- Inherits:
-
Object
- Object
- Liquid::LocalFileSystem
- Defined in:
- lib/liquid-rails/liquid_monkey_patch.rb
Overview
This implements an abstract file system which retrieves template files named in a manner similar to Rails partials, ie. with the template name prefixed with an underscore. The extension “.liquid” is also added.
For security reasons, template paths are only allowed to contain letters, numbers, and underscore.
Example:
file_system = Liquid::LocalFileSystem.new("/some/path")
file_system.full_path("mypartial") # => "/some/path/_mypartial.liquid"
file_system.full_path("dir/mypartial") # => "/some/path/dir/_mypartial.liquid"
Optionally in the second argument you can specify a custom pattern for template filenames. The Kernel::sprintf format specification is used. Default pattern is “_%s.liquid”.
Example:
file_system = Liquid::LocalFileSystem.new("/some/path", "%s.html")
file_system.full_path("index") # => "/some/path/index.html"
Direct Known Subclasses
Instance Method Summary collapse
Instance Method Details
#read_template_file(template_path, _context) ⇒ Object
99 100 101 102 103 104 |
# File 'lib/liquid-rails/liquid_monkey_patch.rb', line 99 def read_template_file(template_path, _context) full_path = full_path(template_path) raise FileSystemError, "No such template '#{template_path}'" unless File.exist?(full_path) File.read(full_path) end |