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