Module | Tilt |
In: |
lib/sinatra/tilt.rb
|
VERSION | = | '0.8' |
Lookup a template class for the given filename or file extension. Return nil when no implementation is found.
# File lib/sinatra/tilt.rb, line 31 31: def self.[](file) 32: if @template_mappings.key?(pattern = file.to_s.downcase) 33: @template_mappings[pattern] 34: elsif @template_mappings.key?(pattern = File.basename(pattern)) 35: @template_mappings[pattern] 36: else 37: while !pattern.empty? 38: if @template_mappings.key?(pattern) 39: return @template_mappings[pattern] 40: else 41: pattern = pattern.sub(/^[^.]*\.?/, '') 42: end 43: end 44: nil 45: end 46: end
Create a new template for the given file using the file‘s extension to determine the the template mapping.
# File lib/sinatra/tilt.rb, line 21 21: def self.new(file, line=nil, options={}, &block) 22: if template_class = self[file] 23: template_class.new(file, line, options, &block) 24: else 25: fail "No template engine registered for #{File.basename(file)}" 26: end 27: end