Module: Tilt
- Defined in:
- lib/frank/tilt.rb
Defined Under Namespace
Modules: CompileSite Classes: BuilderTemplate, Cache, CoffeeTemplate, ERBTemplate, ErubisTemplate, HamlTemplate, LessTemplate, LiquidTemplate, MustacheTemplate, RDiscountTemplate, RDocTemplate, RadiusTemplate, RedClothTemplate, SassTemplate, StringTemplate, Template
Constant Summary collapse
- VERSION =
'0.9'
Class Method Summary collapse
-
.[](file) ⇒ Object
Lookup a template class for the given filename or file extension.
-
.mappings ⇒ Object
Hash of template path pattern => template implementation class mappings.
-
.new(file, line = nil, options = {}, &block) ⇒ Object
Create a new template for the given file using the file’s extension to determine the the template mapping.
-
.register(ext, template_class) ⇒ Object
Register a template implementation by file extension.
-
.registered?(ext) ⇒ Boolean
Returns true when a template exists on an exact match of the provided file extension.
Class Method Details
.[](file) ⇒ Object
Lookup a template class for the given filename or file extension. Return nil when no implementation is found.
36 37 38 39 40 41 42 43 |
# File 'lib/frank/tilt.rb', line 36 def self.[](file) pattern = file.to_s.downcase unless registered?(pattern) pattern = File.basename(pattern) pattern.sub!(/^[^.]*\.?/, '') until (pattern.empty? || registered?(pattern)) end @template_mappings[pattern] end |
.mappings ⇒ Object
Hash of template path pattern => template implementation class mappings.
9 10 11 |
# File 'lib/frank/tilt.rb', line 9 def self.mappings @template_mappings end |
.new(file, line = nil, options = {}, &block) ⇒ Object
Create a new template for the given file using the file’s extension to determine the the template mapping.
26 27 28 29 30 31 32 |
# File 'lib/frank/tilt.rb', line 26 def self.new(file, line=nil, ={}, &block) if template_class = self[file] template_class.new(file, line, , &block) else fail "No template engine registered for #{File.basename(file)}" end end |
.register(ext, template_class) ⇒ Object
Register a template implementation by file extension.
14 15 16 17 |
# File 'lib/frank/tilt.rb', line 14 def self.register(ext, template_class) ext = ext.to_s.sub(/^\./, '') mappings[ext.downcase] = template_class end |
.registered?(ext) ⇒ Boolean
Returns true when a template exists on an exact match of the provided file extension
20 21 22 |
# File 'lib/frank/tilt.rb', line 20 def self.registered?(ext) mappings.key?(ext.downcase) end |