tilt 2.0.10 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/COPYING +1 -0
- data/bin/tilt +2 -120
- data/lib/tilt/_emacs_org.rb +2 -0
- data/lib/tilt/_handlebars.rb +2 -0
- data/lib/tilt/_jbuilder.rb +2 -0
- data/lib/tilt/_org.rb +2 -0
- data/lib/tilt/asciidoc.rb +11 -23
- data/lib/tilt/babel.rb +5 -13
- data/lib/tilt/builder.rb +18 -13
- data/lib/tilt/cli.rb +134 -0
- data/lib/tilt/coffee.rb +18 -25
- data/lib/tilt/commonmarker.rb +47 -71
- data/lib/tilt/creole.rb +9 -20
- data/lib/tilt/csv.rb +6 -18
- data/lib/tilt/erb.rb +32 -16
- data/lib/tilt/erubi.rb +29 -6
- data/lib/tilt/erubis.rb +20 -11
- data/lib/tilt/etanni.rb +3 -2
- data/lib/tilt/haml.rb +73 -65
- data/lib/tilt/kramdown.rb +8 -20
- data/lib/tilt/liquid.rb +10 -14
- data/lib/tilt/livescript.rb +8 -20
- data/lib/tilt/mapping.rb +228 -109
- data/lib/tilt/markaby.rb +5 -7
- data/lib/tilt/maruku.rb +5 -19
- data/lib/tilt/nokogiri.rb +11 -10
- data/lib/tilt/pandoc.rb +33 -43
- data/lib/tilt/pipeline.rb +19 -0
- data/lib/tilt/plain.rb +4 -15
- data/lib/tilt/prawn.rb +15 -23
- data/lib/tilt/radius.rb +15 -22
- data/lib/tilt/rdiscount.rb +17 -33
- data/lib/tilt/rdoc.rb +14 -35
- data/lib/tilt/redcarpet.rb +25 -64
- data/lib/tilt/redcloth.rb +9 -19
- data/lib/tilt/rst-pandoc.rb +7 -15
- data/lib/tilt/sass.rb +45 -28
- data/lib/tilt/slim.rb +5 -0
- data/lib/tilt/string.rb +4 -3
- data/lib/tilt/template.rb +231 -73
- data/lib/tilt/typescript.rb +11 -18
- data/lib/tilt/wikicloth.rb +7 -19
- data/lib/tilt/yajl.rb +5 -11
- data/lib/tilt.rb +61 -29
- metadata +24 -16
- data/lib/tilt/bluecloth.rb +0 -24
- data/lib/tilt/dummy.rb +0 -3
- data/lib/tilt/less.rb +0 -30
- data/lib/tilt/sigil.rb +0 -34
data/lib/tilt/prawn.rb
CHANGED
@@ -1,43 +1,35 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'template'
|
2
3
|
require 'prawn'
|
3
4
|
|
4
5
|
module Tilt
|
5
6
|
# Prawn template implementation. See: http://prawnpdf.org
|
6
|
-
#
|
7
7
|
class PrawnTemplate < Template
|
8
8
|
self.default_mime_type = 'application/pdf'
|
9
9
|
|
10
10
|
def prepare
|
11
|
-
@
|
11
|
+
@options[:page_size] = 'A4' unless @options.has_key?(:page_size)
|
12
|
+
@options[:page_layout] = :portrait unless @options.has_key?(:page_layout)
|
13
|
+
@engine = ::Prawn::Document.new(@options)
|
12
14
|
end
|
13
15
|
|
14
16
|
def evaluate(scope, locals, &block)
|
15
17
|
pdf = @engine
|
16
|
-
if data.respond_to?(:to_str)
|
18
|
+
if @data.respond_to?(:to_str)
|
19
|
+
locals = locals.dup
|
17
20
|
locals[:pdf] = pdf
|
18
|
-
super
|
19
|
-
|
20
|
-
data.
|
21
|
+
super
|
22
|
+
else
|
23
|
+
warn "Non-string provided as prawn template data. This is no longer supported and support for it will be removed in Tilt 2.3", :uplevel=>2
|
24
|
+
# :nocov:
|
25
|
+
@data.call(pdf) if @data.kind_of?(Proc)
|
26
|
+
# :nocov:
|
21
27
|
end
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
def allows_script?
|
26
|
-
false
|
28
|
+
pdf.render
|
27
29
|
end
|
28
30
|
|
29
31
|
def precompiled_template(locals)
|
30
|
-
data.to_str
|
32
|
+
@data.to_str
|
31
33
|
end
|
32
|
-
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
def prawn_options
|
37
|
-
# defaults to A4 instead of crazy US Letter format.
|
38
|
-
{ :page_size => "A4", :page_layout => :portrait }.merge(options)
|
39
|
-
end
|
40
|
-
|
41
34
|
end
|
42
|
-
|
43
35
|
end
|
data/lib/tilt/radius.rb
CHANGED
@@ -1,44 +1,37 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'template'
|
2
3
|
require 'radius'
|
3
4
|
|
4
5
|
module Tilt
|
5
6
|
# Radius Template
|
6
7
|
# http://github.com/jlong/radius/
|
7
8
|
class RadiusTemplate < Template
|
8
|
-
|
9
|
-
|
10
|
-
attr_accessor :tilt_scope
|
9
|
+
class ContextClass < Radius::Context
|
10
|
+
attr_accessor :tilt_scope
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
def dup
|
17
|
-
i = super
|
18
|
-
i.tilt_scope = tilt_scope
|
19
|
-
i
|
20
|
-
end
|
12
|
+
def tag_missing(name, attributes)
|
13
|
+
tilt_scope.__send__(name)
|
21
14
|
end
|
22
|
-
end
|
23
15
|
|
24
|
-
|
16
|
+
def dup
|
17
|
+
i = super
|
18
|
+
i.tilt_scope = tilt_scope
|
19
|
+
i
|
20
|
+
end
|
25
21
|
end
|
26
22
|
|
27
23
|
def evaluate(scope, locals, &block)
|
28
|
-
context =
|
24
|
+
context = ContextClass.new
|
29
25
|
context.tilt_scope = scope
|
30
|
-
context.define_tag("yield")
|
31
|
-
block.call
|
32
|
-
end
|
26
|
+
context.define_tag("yield", &block) if block
|
33
27
|
locals.each do |tag, value|
|
34
28
|
context.define_tag(tag) do
|
35
29
|
value
|
36
30
|
end
|
37
31
|
end
|
38
32
|
|
39
|
-
options
|
40
|
-
|
41
|
-
parser.parse(data)
|
33
|
+
@options[:tag_prefix] = 'r' unless @options.has_key?(:tag_prefix)
|
34
|
+
Radius::Parser.new(context, @options).parse(@data)
|
42
35
|
end
|
43
36
|
|
44
37
|
def allows_script?
|
data/lib/tilt/rdiscount.rb
CHANGED
@@ -1,39 +1,23 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'template'
|
2
3
|
require 'rdiscount'
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
# RDiscount is a simple text filter. It does not support +scope+ or
|
9
|
-
# +locals+. The +:smart+ and +:filter_html+ options may be set true
|
10
|
-
# to enable those flags on the underlying RDiscount object.
|
11
|
-
class RDiscountTemplate < Template
|
12
|
-
self.default_mime_type = 'text/html'
|
5
|
+
aliases = {
|
6
|
+
:escape_html => :filter_html,
|
7
|
+
:smartypants => :smart
|
8
|
+
}.freeze
|
13
9
|
|
14
|
-
|
15
|
-
:escape_html => :filter_html,
|
16
|
-
:smartypants => :smart
|
17
|
-
}
|
10
|
+
_flags = [:smart, :filter_html, :smartypants, :escape_html].freeze
|
18
11
|
|
19
|
-
|
12
|
+
# Discount Markdown implementation. See:
|
13
|
+
# http://github.com/rtomayko/rdiscount
|
14
|
+
#
|
15
|
+
# RDiscount is a simple text filter. It does not support +scope+ or
|
16
|
+
# +locals+. The +:smart+ and +:filter_html+ options may be set true
|
17
|
+
# to enable those flags on the underlying RDiscount object.
|
18
|
+
Tilt::RDiscountTemplate = Tilt::StaticTemplate.subclass do
|
19
|
+
flags = _flags.select { |flag| @options[flag] }.
|
20
|
+
map! { |flag| aliases[flag] || flag }
|
20
21
|
|
21
|
-
|
22
|
-
FLAGS.select { |flag| options[flag] }.map { |flag| ALIAS[flag] || flag }
|
23
|
-
end
|
24
|
-
|
25
|
-
def prepare
|
26
|
-
@engine = RDiscount.new(data, *flags)
|
27
|
-
@output = nil
|
28
|
-
end
|
29
|
-
|
30
|
-
def evaluate(scope, locals, &block)
|
31
|
-
@output ||= @engine.to_html
|
32
|
-
end
|
33
|
-
|
34
|
-
def allows_script?
|
35
|
-
false
|
36
|
-
end
|
37
|
-
end
|
22
|
+
RDiscount.new(@data, *flags).to_html
|
38
23
|
end
|
39
|
-
|
data/lib/tilt/rdoc.rb
CHANGED
@@ -1,40 +1,19 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'template'
|
2
3
|
require 'rdoc'
|
3
4
|
require 'rdoc/markup'
|
4
5
|
require 'rdoc/markup/to_html'
|
6
|
+
require 'rdoc/options'
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
begin
|
18
|
-
# RDoc 4.0
|
19
|
-
require 'rdoc/options'
|
20
|
-
RDoc::Markup::ToHtml.new(RDoc::Options.new, nil)
|
21
|
-
rescue ArgumentError
|
22
|
-
# RDoc < 4.0
|
23
|
-
RDoc::Markup::ToHtml.new
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def prepare
|
28
|
-
@engine = markup.convert(data)
|
29
|
-
@output = nil
|
30
|
-
end
|
31
|
-
|
32
|
-
def evaluate(scope, locals, &block)
|
33
|
-
@output ||= @engine.to_s
|
34
|
-
end
|
35
|
-
|
36
|
-
def allows_script?
|
37
|
-
false
|
38
|
-
end
|
39
|
-
end
|
8
|
+
# RDoc template. See: https://github.com/ruby/rdoc
|
9
|
+
#
|
10
|
+
# It's suggested that your program run the following at load time when
|
11
|
+
# using this templae engine in a threaded environment:
|
12
|
+
#
|
13
|
+
# require 'rdoc'
|
14
|
+
# require 'rdoc/markup'
|
15
|
+
# require 'rdoc/markup/to_html'
|
16
|
+
# require 'rdoc/options'
|
17
|
+
Tilt::RDocTemplate = Tilt::StaticTemplate.subclass do
|
18
|
+
RDoc::Markup::ToHtml.new(RDoc::Options.new, nil).convert(@data).to_s
|
40
19
|
end
|
data/lib/tilt/redcarpet.rb
CHANGED
@@ -1,46 +1,34 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'template'
|
2
3
|
require 'redcarpet'
|
3
4
|
|
4
|
-
|
5
|
-
# Compatibility mode for Redcarpet 1.x
|
6
|
-
class Redcarpet1Template < Template
|
7
|
-
self.default_mime_type = 'text/html'
|
5
|
+
aliases = {:escape_html => :filter_html, :smartypants => :smart}.freeze
|
8
6
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
# :nocov:
|
8
|
+
unless defined? ::Redcarpet::Render and defined? ::Redcarpet::Markdown
|
9
|
+
# Redcarpet 1.x
|
10
|
+
warn "Tilt support for RedCarpet 1.x is deprecated and will be removed in Tilt 2.3", uplevel: 1
|
11
|
+
_flags = [:smart, :filter_html, :smartypants, :escape_html]
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
FLAGS.select { |flag| options[flag] }.map { |flag| ALIAS[flag] || flag }
|
18
|
-
end
|
19
|
-
|
20
|
-
def prepare
|
21
|
-
@engine = RedcarpetCompat.new(data, *flags)
|
22
|
-
@output = nil
|
23
|
-
end
|
24
|
-
|
25
|
-
def evaluate(scope, locals, &block)
|
26
|
-
@output ||= @engine.to_html
|
27
|
-
end
|
28
|
-
|
29
|
-
def allows_script?
|
30
|
-
false
|
31
|
-
end
|
13
|
+
Tilt::RedcarpetTemplate = Tilt::StaticTemplate.subclass do
|
14
|
+
flags = _flags.select { |flag| @options[flag] }.map! { |flag| aliases[flag] || flag }
|
15
|
+
RedcarpetCompat.new(@data, *flags).to_html
|
32
16
|
end
|
17
|
+
# :nocov:
|
18
|
+
else
|
19
|
+
Tilt::RedcarpetTemplate = Tilt::StaticTemplate.subclass do
|
20
|
+
aliases.each do |opt, aka|
|
21
|
+
if options.key?(aka) || !@options.key?(opt)
|
22
|
+
@options[opt] = @options.delete(aka)
|
23
|
+
end
|
24
|
+
end
|
33
25
|
|
34
|
-
|
35
|
-
|
36
|
-
self.default_mime_type = 'text/html'
|
37
|
-
|
38
|
-
def generate_renderer
|
39
|
-
renderer = options.delete(:renderer) || ::Redcarpet::Render::HTML.new(options)
|
40
|
-
return renderer unless options.delete(:smartypants)
|
41
|
-
return renderer if renderer.is_a?(Class) && renderer <= ::Redcarpet::Render::SmartyPants
|
26
|
+
# only raise an exception if someone is trying to enable :escape_html
|
27
|
+
@options.delete(:escape_html) unless @options[:escape_html]
|
42
28
|
|
43
|
-
|
29
|
+
renderer = @options.delete(:renderer) || ::Redcarpet::Render::HTML.new(@options)
|
30
|
+
if options.delete(:smartypants) && !(renderer.is_a?(Class) && renderer <= ::Redcarpet::Render::SmartyPants)
|
31
|
+
renderer = if renderer == ::Redcarpet::Render::XHTML
|
44
32
|
::Redcarpet::Render::SmartyHTML.new(:xhtml => true)
|
45
33
|
elsif renderer == ::Redcarpet::Render::HTML
|
46
34
|
::Redcarpet::Render::SmartyHTML
|
@@ -51,33 +39,6 @@ module Tilt
|
|
51
39
|
end
|
52
40
|
end
|
53
41
|
|
54
|
-
|
55
|
-
# try to support the same aliases
|
56
|
-
Redcarpet1Template::ALIAS.each do |opt, aka|
|
57
|
-
next if options.key? opt or not options.key? aka
|
58
|
-
options[opt] = options.delete(aka)
|
59
|
-
end
|
60
|
-
|
61
|
-
# only raise an exception if someone is trying to enable :escape_html
|
62
|
-
options.delete(:escape_html) unless options[:escape_html]
|
63
|
-
|
64
|
-
@engine = ::Redcarpet::Markdown.new(generate_renderer, options)
|
65
|
-
@output = nil
|
66
|
-
end
|
67
|
-
|
68
|
-
def evaluate(scope, locals, &block)
|
69
|
-
@output ||= @engine.render(data)
|
70
|
-
end
|
71
|
-
|
72
|
-
def allows_script?
|
73
|
-
false
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
if defined? ::Redcarpet::Render and defined? ::Redcarpet::Markdown
|
78
|
-
RedcarpetTemplate = Redcarpet2Template
|
79
|
-
else
|
80
|
-
RedcarpetTemplate = Redcarpet1Template
|
42
|
+
Redcarpet::Markdown.new(renderer, @options).render(@data)
|
81
43
|
end
|
82
44
|
end
|
83
|
-
|
data/lib/tilt/redcloth.rb
CHANGED
@@ -1,23 +1,13 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'template'
|
2
3
|
require 'redcloth'
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
options.each {|k, v| @engine.send("#{k}=", v) if @engine.respond_to? "#{k}="}
|
11
|
-
@output = nil
|
12
|
-
end
|
13
|
-
|
14
|
-
def evaluate(scope, locals, &block)
|
15
|
-
@output ||= @engine.to_html
|
16
|
-
end
|
17
|
-
|
18
|
-
def allows_script?
|
19
|
-
false
|
20
|
-
end
|
5
|
+
# RedCloth implementation. See: https://github.com/jgarber/redcloth
|
6
|
+
Tilt::RedClothTemplate = Tilt::StaticTemplate.subclass do
|
7
|
+
engine = RedCloth.new(@data)
|
8
|
+
@options.each do |k, v|
|
9
|
+
m = :"#{k}="
|
10
|
+
engine.send(m, v) if engine.respond_to? m
|
21
11
|
end
|
12
|
+
engine.to_html
|
22
13
|
end
|
23
|
-
|
data/lib/tilt/rst-pandoc.rb
CHANGED
@@ -1,18 +1,10 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'template'
|
3
|
+
require_relative 'pandoc'
|
3
4
|
|
4
|
-
|
5
|
-
# Pandoc reStructuredText implementation. See:
|
6
|
-
# http://pandoc.org/
|
7
|
-
# Use PandocTemplate and specify input format
|
8
|
-
class RstPandocTemplate < PandocTemplate
|
9
|
-
def tilt_to_pandoc_mapping
|
10
|
-
{ :smartypants => :smart }
|
11
|
-
end
|
5
|
+
rst = {:f => "rst"}.freeze
|
12
6
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
17
|
-
end
|
7
|
+
# Pandoc reStructuredText implementation. See: # http://pandoc.org/
|
8
|
+
Tilt::RstPandocTemplate = Tilt::StaticTemplate.subclass do
|
9
|
+
PandocRuby.new(@data, rst).to_html.strip
|
18
10
|
end
|
data/lib/tilt/sass.rb
CHANGED
@@ -1,52 +1,69 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'template'
|
2
3
|
|
3
4
|
module Tilt
|
4
|
-
# Sass template implementation. See:
|
5
|
-
# http://haml.hamptoncatlin.com/
|
5
|
+
# Sass template implementation for generating CSS. See: https://sass-lang.com/
|
6
6
|
#
|
7
7
|
# Sass templates do not support object scopes, locals, or yield.
|
8
|
-
class SassTemplate <
|
8
|
+
class SassTemplate < StaticTemplate
|
9
9
|
self.default_mime_type = 'text/css'
|
10
10
|
|
11
11
|
begin
|
12
|
-
require '
|
13
|
-
|
12
|
+
require 'sass-embedded'
|
13
|
+
# :nocov:
|
14
|
+
require 'uri'
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def _prepare_output
|
19
|
+
::Sass.compile_string(@data, **sass_options).css
|
20
|
+
end
|
21
|
+
|
22
|
+
def sass_options
|
23
|
+
path = File.absolute_path(eval_file)
|
24
|
+
path = '/' + path unless path.start_with?('/')
|
25
|
+
@options[:url] = ::URI::File.build([nil, ::URI::DEFAULT_PARSER.escape(path)]).to_s
|
26
|
+
@options[:syntax] = :indented
|
27
|
+
@options
|
28
|
+
end
|
14
29
|
rescue LoadError => err
|
15
30
|
begin
|
16
|
-
require '
|
17
|
-
|
31
|
+
require 'sassc'
|
32
|
+
Engine = ::SassC::Engine
|
18
33
|
rescue LoadError
|
19
|
-
|
34
|
+
begin
|
35
|
+
require 'sass'
|
36
|
+
Engine = ::Sass::Engine
|
37
|
+
rescue LoadError
|
38
|
+
raise err
|
39
|
+
end
|
20
40
|
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def prepare
|
24
|
-
@engine = Sass::Engine.new(data, sass_options)
|
25
|
-
end
|
26
41
|
|
27
|
-
|
28
|
-
@output ||= @engine.render
|
29
|
-
end
|
42
|
+
private
|
30
43
|
|
31
|
-
|
32
|
-
|
33
|
-
|
44
|
+
def _prepare_output
|
45
|
+
Engine.new(@data, sass_options).render
|
46
|
+
end
|
34
47
|
|
35
|
-
|
36
|
-
|
37
|
-
|
48
|
+
def sass_options
|
49
|
+
@options[:filename] = eval_file
|
50
|
+
@options[:line] = @line
|
51
|
+
@options[:syntax] = :sass
|
52
|
+
@options
|
53
|
+
end
|
54
|
+
# :nocov:
|
38
55
|
end
|
39
56
|
end
|
40
57
|
|
41
|
-
# Sass's new .scss type template implementation.
|
42
58
|
class ScssTemplate < SassTemplate
|
43
59
|
self.default_mime_type = 'text/css'
|
44
60
|
|
45
|
-
|
61
|
+
private
|
62
|
+
|
46
63
|
def sass_options
|
47
|
-
|
64
|
+
super
|
65
|
+
@options[:syntax] = :scss
|
66
|
+
@options
|
48
67
|
end
|
49
68
|
end
|
50
|
-
|
51
69
|
end
|
52
|
-
|
data/lib/tilt/slim.rb
ADDED
data/lib/tilt/string.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'template'
|
2
3
|
|
3
4
|
module Tilt
|
4
5
|
# The template source is evaluated as a Ruby string. The #{} interpolation
|
5
6
|
# syntax can be used to generated dynamic output.
|
6
7
|
class StringTemplate < Template
|
7
8
|
def prepare
|
8
|
-
hash = "TILT#{data.hash.abs}"
|
9
|
-
@code = String.new("<<#{hash}.chomp\n#{data}\n#{hash}")
|
9
|
+
hash = "TILT#{@data.hash.abs}"
|
10
|
+
@code = String.new("<<#{hash}.chomp\n#{@data}\n#{hash}")
|
10
11
|
end
|
11
12
|
|
12
13
|
def precompiled_template(locals)
|