module Tilt
def self.[](file)
Lookup a template class for the given filename or file
def self.[](file) if @template_mappings.key?(pattern = file.to_s.downcase) @template_mappings[pattern] elsif @template_mappings.key?(pattern = File.basename(pattern)) @template_mappings[pattern] else while !pattern.empty? if @template_mappings.key?(pattern) return @template_mappings[pattern] else pattern = pattern.sub(/^[^.]*\.?/, '') end end nil end end
def self.mappings
def self.mappings @template_mappings end
def self.new(file, line=nil, options={}, &block)
Create a new template for the given file using the file's extension
def self.new(file, line=nil, options={}, &block) if template_class = self[file] template_class.new(file, line, options, &block) else fail "No template engine registered for #{File.basename(file)}" end end
def self.register(ext, template_class)
def self.register(ext, template_class) ext = ext.to_s.sub(/^\./, '') mappings[ext.downcase] = template_class end