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

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

# File lib/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/tilt.rb, line 26
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/tilt.rb, line 14
def self.register(ext, template_class)
  ext = ext.to_s.sub(/^\./, '')
  mappings[ext.downcase] = template_class
end
registered?(ext) click to toggle source

Returns true when a template exists on an exact match of the provided file extension

# File lib/tilt.rb, line 20
def self.registered?(ext)
  mappings.key?(ext.downcase)
end