| Module | Tilt |
| In: |
lib/tilt.rb
|
| TOPOBJECT | = | defined?(BasicObject) ? BasicObject : Object |
| VERSION | = | '1.2.2' |
Lookup a template class for the given filename or file extension. Return nil when no implementation is found.
# File lib/tilt.rb, line 35
35: def self.[](file)
36: pattern = file.to_s.downcase
37: unless registered?(pattern)
38: pattern = File.basename(pattern)
39: pattern.sub!(/^[^.]*\.?/, '') until (pattern.empty? || registered?(pattern))
40: end
41: @template_mappings[pattern]
42: end
Create a new template for the given file using the file‘s extension to determine the the template mapping.
# File lib/tilt.rb, line 25
25: def self.new(file, line=nil, options={}, &block)
26: if template_class = self[file]
27: template_class.new(file, line, options, &block)
28: else
29: fail "No template engine registered for #{File.basename(file)}"
30: end
31: end
Register a template implementation by file extension.
# File lib/tilt.rb, line 13
13: def self.register(ext, template_class)
14: ext = ext.to_s.sub(/^\./, '')
15: mappings[ext.downcase] = template_class
16: end