Class: Jenner::TemplateFileSystem
- Inherits:
-
Object
- Object
- Jenner::TemplateFileSystem
- Defined in:
- lib/jenner/template_file_system.rb
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
- #full_path(template_path) ⇒ Object
-
#initialize(root) ⇒ TemplateFileSystem
constructor
A new instance of TemplateFileSystem.
- #read_template_file(template_path, context) ⇒ Object
Constructor Details
#initialize(root) ⇒ TemplateFileSystem
Returns a new instance of TemplateFileSystem.
5 6 7 8 |
# File 'lib/jenner/template_file_system.rb', line 5 def initialize(root) @root = root @pattern = "%s" end |
Instance Attribute Details
#root ⇒ Object (readonly)
Returns the value of attribute root.
4 5 6 |
# File 'lib/jenner/template_file_system.rb', line 4 def root @root end |
Instance Method Details
#full_path(template_path) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/jenner/template_file_system.rb', line 21 def full_path(template_path) #raise Liquid::FileSystemError, "Illegal template name '#{template_path}'" unless template_path =~ /^[^.\/][a-zA-Z0-9_\/]+$/ 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 Liquid::FileSystemError, "Illegal template path '#{File.(full_path)}'" unless File.(full_path) =~ /^#{File.(root)}/ full_path end |
#read_template_file(template_path, context) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/jenner/template_file_system.rb', line 10 def read_template_file(template_path, context) full_path = full_path(template_path) raise FileSystemError, "No such template '#{template_path}'" unless File.exists?(full_path) if File.extname(template_path) == ".haml" Haml::Engine.new(File.read(full_path)).render(Jenner.deep_struct(context.environments.first)) else File.read(full_path) end end |