Tilt

Constants

VERSION

Public Class Methods

[](file) click to toggle source

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
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
mappings() click to toggle source

Hash of template path pattern => template implementation class mappings.

# File lib/sinatra/tilt.rb, line 9
def self.mappings
  @template_mappings
end
new(file, line=nil, options={}, &block) click to toggle source

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
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
register(ext, template_class) click to toggle source

Register a template implementation by file extension.

# File lib/sinatra/tilt.rb, line 14
def self.register(ext, template_class)
  ext = ext.to_s.sub(/^\./, '')
  mappings[ext.downcase] = template_class
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.