| Module | Tilt |
| In: |
lib/tilt.rb
|
| VERSION | = | '1.1' |
Lookup a template class for the given filename or file extension. Return nil when no implementation is found.
# File lib/tilt.rb, line 36
36: def self.[](file)
37: pattern = file.to_s.downcase
38: unless registered?(pattern)
39: pattern = File.basename(pattern)
40: pattern.sub!(/^[^.]*\.?/, '') until (pattern.empty? || registered?(pattern))
41: end
42: @template_mappings[pattern]
43: 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 26
26: def self.new(file, line=nil, options={}, &block)
27: if template_class = self[file]
28: template_class.new(file, line, options, &block)
29: else
30: fail "No template engine registered for #{File.basename(file)}"
31: end
32: end
Register a template implementation by file extension.
# File lib/tilt.rb, line 14
14: def self.register(ext, template_class)
15: ext = ext.to_s.sub(/^\./, '')
16: mappings[ext.downcase] = template_class
17: end