Module: Tilt

### Home Classes Methods

### In Files

- lib/tilt.rb
- lib/tilt/asciidoc.rb
- lib/tilt/builder.rb
- lib/tilt/coffee.rb
- lib/tilt/css.rb
- lib/tilt/csv.rb
- lib/tilt/erb.rb
- lib/tilt/etanni.rb
- lib/tilt/haml.rb
- lib/tilt/liquid.rb
- lib/tilt/markaby.rb
- lib/tilt/markdown.rb
- lib/tilt/nokogiri.rb
- lib/tilt/plain.rb
- lib/tilt/radius.rb
- lib/tilt/rdoc.rb
- lib/tilt/string.rb
- lib/tilt/template.rb
- lib/tilt/textile.rb
- lib/tilt/wiki.rb
- lib/tilt/yajl.rb

### Namespace

- MODULE Tilt::CompileSite
- CLASS Tilt::AsciidoctorTemplate
- CLASS Tilt::BlueClothTemplate
- CLASS Tilt::BuilderTemplate
- CLASS Tilt::CSVTemplate
- CLASS Tilt::Cache
- CLASS Tilt::CoffeeScriptTemplate
- CLASS Tilt::CreoleTemplate
- CLASS Tilt::ERBTemplate
- CLASS Tilt::ErubisTemplate
- CLASS Tilt::EtanniTemplate
- CLASS Tilt::HamlTemplate
- CLASS Tilt::KramdownTemplate
- CLASS Tilt::LessTemplate
- CLASS Tilt::LiquidTemplate
- CLASS Tilt::MarkabyTemplate
- CLASS Tilt::MarukuTemplate
- CLASS Tilt::NokogiriTemplate
- CLASS Tilt::PlainTemplate
- CLASS Tilt::RDiscountTemplate
- CLASS Tilt::RDocTemplate
- CLASS Tilt::RadiusTemplate
- CLASS Tilt::RedClothTemplate
- CLASS Tilt::RedcarpetTemplate
- CLASS Tilt::SassTemplate
- CLASS Tilt::ScssTemplate
- CLASS Tilt::StringTemplate
- CLASS Tilt::Template
- CLASS Tilt::WikiClothTemplate
- CLASS Tilt::YajlTemplate

### Methods

- ::[]
- ::mappings
- ::new
- ::normalize
- ::prefer
- ::register
- ::registered?

### Class/Module Index

Quicksearch

- Tilt
- Tilt::AsciidoctorTemplate
- Tilt::BlueClothTemplate
- Tilt::BuilderTemplate
- Tilt::CSVTemplate
- Tilt::Cache
- Tilt::CoffeeScriptTemplate
- Tilt::CompileSite
- Tilt::CreoleTemplate
- Tilt::ERBTemplate
- Tilt::ErubisTemplate
- Tilt::EtanniTemplate
- Tilt::HamlTemplate
- Tilt::KramdownTemplate
- Tilt::LessTemplate
- Tilt::LiquidTemplate
- Tilt::MarkabyTemplate
- Tilt::MarukuTemplate
- Tilt::NokogiriTemplate
- Tilt::PlainTemplate
- Tilt::RDiscountTemplate
- Tilt::RDocTemplate
- Tilt::RadiusTemplate
- Tilt::RedClothTemplate
- Tilt::RedcarpetTemplate
- Tilt::RedcarpetTemplate::Redcarpet1
- Tilt::RedcarpetTemplate::Redcarpet2
- Tilt::SassTemplate
- Tilt::ScssTemplate
- Tilt::StringTemplate
- Tilt::Template
- Tilt::WikiClothTemplate
- Tilt::YajlTemplate

No matching classes.

# Tilt

AsciiDoc see: asciidoc.org/

### Constants

TOPOBJECT
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 69
    def self.[](file)
      pattern = file.to_s.downcase
      until pattern.empty? || registered?(pattern)
        pattern = File.basename(pattern)
        pattern.sub!(/^[^.]*\.?/, '')
      end

      # Try to find a preferred engine.
      preferred_klass = @preferred_mappings[pattern]
      return preferred_klass if preferred_klass

      # Fall back to the general list of mappings.
      klasses = @template_mappings[pattern]

      # Try to find an engine which is already loaded.
      template = klasses.detect do |klass|
        if klass.respond_to?(:engine_initialized?)
          klass.engine_initialized?
        end
      end

      return template if template

      # Try each of the classes until one succeeds. If all of them fails,
      # we'll raise the error of the first class.
      first_failure = nil

      klasses.each do |klass|
        begin
          klass.new { '' }
        rescue Exception => ex
          first_failure ||= ex
          next
        else
          return klass
        end
      end

      raise first_failure if first_failure
    end

mappings() click to toggle source

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

    # File lib/tilt.rb, line 8
    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 59
    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

normalize(ext) click to toggle source

    # File lib/tilt.rb, line 12
    def self.normalize(ext)
      ext.to_s.downcase.sub(/^\./, '')
    end

prefer(template_class, *extensions) click to toggle source

Makes a template class preferred for the given file extensions. If you don't provide any extensions, it will be preferred for all its already registered extensions:

    # Prefer RDiscount for its registered file extensions:
    Tilt.prefer(Tilt::RDiscountTemplate)

    # Prefer RDiscount only for the .md extensions:
    Tilt.prefer(Tilt::RDiscountTemplate, '.md')

    # File lib/tilt.rb, line 38
    def self.prefer(template_class, *extensions)
      if extensions.empty?
        mappings.each do |ext, klasses|
          @preferred_mappings[ext] = template_class if klasses.include? template_class
        end
      else
        extensions.each do |ext|
          ext = normalize(ext)
          register(template_class, ext)
          @preferred_mappings[ext] = template_class
        end
      end
    end

register(template_class, *extensions) click to toggle source

Register a template implementation by file extension.

    # File lib/tilt.rb, line 17
    def self.register(template_class, *extensions)
      if template_class.respond_to?(:to_str)
        # Support register(ext, template_class) too
        extensions, template_class = [template_class], extensions[0]
      end

      extensions.each do |ext|
        ext = normalize(ext)
        mappings[ext].unshift(template_class).uniq!
      end
    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 53
    def self.registered?(ext)
      mappings.key?(ext.downcase) && !mappings[ext.downcase].empty?
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.