module Tilt

  1. lib/tilt.rb
  2. lib/tilt/asciidoc.rb
  3. lib/tilt/babel.rb
  4. lib/tilt/builder.rb
  5. lib/tilt/cli.rb
  6. lib/tilt/coffee.rb
  7. lib/tilt/commonmarker.rb
  8. lib/tilt/csv.rb
  9. lib/tilt/erb.rb
  10. lib/tilt/erubi.rb
  11. lib/tilt/etanni.rb
  12. lib/tilt/haml.rb
  13. lib/tilt/kramdown.rb
  14. lib/tilt/liquid.rb
  15. lib/tilt/livescript.rb
  16. lib/tilt/mapping.rb
  17. lib/tilt/markaby.rb
  18. lib/tilt/nokogiri.rb
  19. lib/tilt/pandoc.rb
  20. lib/tilt/pipeline.rb
  21. lib/tilt/plain.rb
  22. lib/tilt/prawn.rb
  23. lib/tilt/radius.rb
  24. lib/tilt/rdiscount.rb
  25. lib/tilt/rdoc.rb
  26. lib/tilt/redcarpet.rb
  27. lib/tilt/redcloth.rb
  28. lib/tilt/rst-pandoc.rb
  29. lib/tilt/sass.rb
  30. lib/tilt/slim.rb
  31. lib/tilt/string.rb
  32. lib/tilt/template.rb
  33. lib/tilt/typescript.rb
  34. lib/tilt/yajl.rb
  35. show all

Namespace for Tilt. This module is not intended to be included anywhere.

Constants

AsciidoctorTemplate = Tilt::StaticTemplate.subclass do @options[:header_footer] = false if @options[:header_footer].nil? Asciidoctor.render(@data, @options) end  
BabelTemplate = Tilt::StaticTemplate.subclass(mime_type: 'application/javascript') do @options[:filename] ||= @file Babel::Transpiler.transform(@data)["code"] end  
CommonMarkerTemplate = Tilt::StaticTemplate.subclass do parse_options = @options.select { |key, _| parse_opts.include?(key.downcase) }.transform_keys(&:downcase) parse_options.merge!(@options.select { |key, _| aliases.has_key?(key) }.transform_keys { |key| aliases[key] }) render_options = @options.select { |key, _| render_opts.include?(key.downcase) }.transform_keys(&:downcase) extensions = @options.select { |key, _| exts.include?(key) }.transform_keys(&:downcase) Commonmarker.to_html(@data, options: { parse: parse_options, render: render_options, extension: extensions }) end  
HamlTemplate = Haml::Template  

Haml >= 6 ships its own template, prefer it when available.

KramdownTemplate = Tilt::StaticTemplate.subclass do # dup as Krawmdown modifies the passed option with map! @options[:smart_quotes] = dumb_quotes.dup unless @options[:smartypants] Kramdown::Document.new(@data, @options).to_html end  
LOCK = Mutex.new  

@private

LiveScriptTemplate = Tilt::StaticTemplate.subclass(mime_type: 'application/javascript') do LiveScript.compile(@data, @options) end  
PandocTemplate = Tilt::StaticTemplate.subclass do # turn options hash into an array # Map tilt options to pandoc options # Replace hash keys with value true with symbol for key # Remove hash keys with value false # Leave other hash keys untouched pandoc_options = [] from = "markdown" smart_extension = "-smart" @options.each do |k,v| case k when :smartypants smart_extension = "+smart" if v when :escape_html from = "markdown-raw_html" if v when :commonmark from = "commonmark" if v when :markdown_strict from = "markdown_strict" if v else case v when true pandoc_options << k when false # do nothing else pandoc_options << { k => v } end end end pandoc_options << { :f => from + smart_extension } PandocRuby.new(@data, *pandoc_options).to_html.strip end  
PlainTemplate = Tilt::StaticTemplate.subclass{@data}  
RDiscountTemplate = Tilt::StaticTemplate.subclass do flags = _flags.select { |flag| @options[flag] }. map! { |flag| aliases[flag] || flag } RDiscount.new(@data, *flags).to_html end  
RDocTemplate = Tilt::StaticTemplate.subclass do RDoc::Markup::ToHtml.new(RDoc::Options.new, nil).convert(@data).to_s end  
RedClothTemplate = Tilt::StaticTemplate.subclass do engine = RedCloth.new(@data) @options.each do |k, v| m = :"#{k}=" engine.send(m, v) if engine.respond_to? m end engine.to_html end  
RedcarpetTemplate = Tilt::StaticTemplate.subclass do aliases.each do |opt, aka| if options.key?(aka) || !@options.key?(opt) @options[opt] = @options.delete(aka) end end # only raise an exception if someone is trying to enable :escape_html @options.delete(:escape_html) unless @options[:escape_html] renderer = @options.delete(:renderer) || ::Redcarpet::Render::HTML.new(@options) if options.delete(:smartypants) && !(renderer.is_a?(Class) && renderer <= ::Redcarpet::Render::SmartyPants) renderer = if renderer == ::Redcarpet::Render::XHTML ::Redcarpet::Render::SmartyHTML.new(:xhtml => true) elsif renderer == ::Redcarpet::Render::HTML ::Redcarpet::Render::SmartyHTML elsif renderer.is_a? Class Class.new(renderer) { include ::Redcarpet::Render::SmartyPants } else renderer.extend ::Redcarpet::Render::SmartyPants end end Redcarpet::Markdown.new(renderer, @options).render(@data) end  
RstPandocTemplate = Tilt::StaticTemplate.subclass do PandocRuby.new(@data, rst).to_html.strip end  
SlimTemplate = Slim::Template  
TOPOBJECT = CompiledTemplates  

@private

TypeScriptTemplate = Tilt::StaticTemplate.subclass(mime_type: 'application/javascript') do option_args = [] @options.each do |key, value| next unless value option_args << "--#{key}" if value != true option_args << value.to_s end end TypeScript::Node.compile(@data, *option_args) end  
VERSION = '2.6.1'  

Current version.

Public Class Aliases

prefer -> lazy_map

Alias register as prefer for Tilt 1.x compatibility.

register -> lazy_map
register_lazy -> lazy_map
register_pipeline -> lazy_map

Attributes

default_mapping [R]

@return [Tilt::Mapping] the main mapping object

extract_fixed_locals [RW]

Whether to extract fixed locals from templates by scanning the template content.

Public Class methods

[](file)
[show source]
   # File lib/tilt.rb
75 def self.[](file)
76   @default_mapping[file]
77 end
finalize!()

Replace the default mapping with a finalized version of the default mapping. This can be done to improve performance after the template libraries you desire to use have already been loaded. Once this is is called, all attempts to modify the default mapping will fail. This also freezes Tilt itself.

[show source]
   # File lib/tilt.rb
24 def self.finalize!
25   return self if @default_mapping.is_a?(FinalizedMapping)
26 
27   class << self
28     prepend(Module.new do
29       def lazy_map(*)
30         raise "Tilt.#{__callee__} not supported after Tilt.finalize! has been called"
31       end
32       alias register lazy_map
33       alias register_lazy lazy_map
34       alias register_pipeline lazy_map
35       alias prefer lazy_map
36     end)
37   end
38 
39   @default_mapping = @default_mapping.finalized
40 
41   freeze
42 end
lazy_map(*)
[show source]
   # File lib/tilt.rb
29 def lazy_map(*)
30   raise "Tilt.#{__callee__} not supported after Tilt.finalize! has been called"
31 end
new(file, line=nil, options=nil, &block)
[show source]
   # File lib/tilt.rb
70 def self.new(file, line=nil, options=nil, &block)
71   @default_mapping.new(file, line, options, &block)
72 end
registered?(ext)
[show source]
   # File lib/tilt.rb
65 def self.registered?(ext)
66   @default_mapping.registered?(ext)
67 end
template_for(file)
[show source]
   # File lib/tilt.rb
80 def self.template_for(file)
81   @default_mapping.template_for(file)
82 end
templates_for(file)
[show source]
   # File lib/tilt.rb
85 def self.templates_for(file)
86   @default_mapping.templates_for(file)
87 end