tilt 2.0.11 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- 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 +12 -31
- data/lib/tilt/commonmarker.rb +47 -81
- data/lib/tilt/creole.rb +9 -20
- data/lib/tilt/csv.rb +6 -18
- data/lib/tilt/erb.rb +23 -21
- data/lib/tilt/erubi.rb +29 -6
- data/lib/tilt/erubis.rb +17 -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 -51
- data/lib/tilt/pipeline.rb +19 -0
- data/lib/tilt/plain.rb +4 -15
- data/lib/tilt/prawn.rb +10 -25
- 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 +20 -75
- data/lib/tilt/redcloth.rb +9 -19
- data/lib/tilt/rst-pandoc.rb +7 -20
- data/lib/tilt/sass.rb +34 -43
- data/lib/tilt/slim.rb +5 -0
- data/lib/tilt/string.rb +9 -3
- data/lib/tilt/template.rb +229 -82
- 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 +60 -40
- metadata +21 -12
- 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/csv.rb
CHANGED
@@ -1,10 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
require 'csv'
|
5
|
-
else
|
6
|
-
require 'fastercsv'
|
7
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'template'
|
3
|
+
require 'csv'
|
8
4
|
|
9
5
|
module Tilt
|
10
6
|
|
@@ -36,22 +32,14 @@ module Tilt
|
|
36
32
|
class CSVTemplate < Template
|
37
33
|
self.default_mime_type = 'text/csv'
|
38
34
|
|
39
|
-
def self.engine
|
40
|
-
if RUBY_VERSION >= '1.9.0' && defined? ::CSV
|
41
|
-
::CSV
|
42
|
-
elsif defined? ::FasterCSV
|
43
|
-
::FasterCSV
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
35
|
def prepare
|
48
|
-
@outvar = options.delete(:outvar) || '_csvout'
|
36
|
+
@outvar = @options.delete(:outvar) || '_csvout'
|
49
37
|
end
|
50
38
|
|
51
39
|
def precompiled_template(locals)
|
52
40
|
<<-RUBY
|
53
|
-
#{@outvar} =
|
54
|
-
#{data}
|
41
|
+
#{@outvar} = CSV.generate(**#{@options}) do |csv|
|
42
|
+
#{@data}
|
55
43
|
end
|
56
44
|
RUBY
|
57
45
|
end
|
data/lib/tilt/erb.rb
CHANGED
@@ -1,30 +1,30 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'template'
|
2
3
|
require 'erb'
|
3
4
|
|
4
5
|
module Tilt
|
5
6
|
# ERB template implementation. See:
|
6
7
|
# http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB.html
|
7
8
|
class ERBTemplate < Template
|
8
|
-
@@default_output_variable = '_erbout'
|
9
|
-
|
10
9
|
SUPPORTS_KVARGS = ::ERB.instance_method(:initialize).parameters.assoc(:key) rescue false
|
11
10
|
|
12
|
-
def self.default_output_variable
|
13
|
-
@@default_output_variable
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.default_output_variable=(name)
|
17
|
-
warn "#{self}.default_output_variable= has been replaced with the :outvar-option"
|
18
|
-
@@default_output_variable = name
|
19
|
-
end
|
20
|
-
|
21
11
|
def prepare
|
22
|
-
@
|
23
|
-
|
12
|
+
@freeze_string_literals = !!@options[:freeze]
|
13
|
+
@outvar = @options[:outvar] || '_erbout'
|
14
|
+
trim = case @options[:trim]
|
15
|
+
when false
|
16
|
+
nil
|
17
|
+
when nil, true
|
18
|
+
'<>'
|
19
|
+
else
|
20
|
+
@options[:trim]
|
21
|
+
end
|
24
22
|
@engine = if SUPPORTS_KVARGS
|
25
|
-
::ERB.new(data, trim_mode:
|
23
|
+
::ERB.new(@data, trim_mode: trim, eoutvar: @outvar)
|
24
|
+
# :nocov:
|
26
25
|
else
|
27
|
-
::ERB.new(data, options[:safe],
|
26
|
+
::ERB.new(@data, options[:safe], trim, @outvar)
|
27
|
+
# :nocov:
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -52,11 +52,13 @@ module Tilt
|
|
52
52
|
|
53
53
|
# ERB generates a line to specify the character coding of the generated
|
54
54
|
# source in 1.9. Account for this in the line offset.
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
55
|
+
def precompiled(locals)
|
56
|
+
source, offset = super
|
57
|
+
[source, offset + 1]
|
58
|
+
end
|
59
|
+
|
60
|
+
def freeze_string_literals?
|
61
|
+
@freeze_string_literals
|
60
62
|
end
|
61
63
|
end
|
62
64
|
end
|
data/lib/tilt/erubi.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'template'
|
2
3
|
require 'erubi'
|
3
4
|
|
4
5
|
module Tilt
|
@@ -12,15 +13,33 @@ module Tilt
|
|
12
13
|
# instead of the default (which is ::Erubi::Engine).
|
13
14
|
class ErubiTemplate < Template
|
14
15
|
def prepare
|
15
|
-
@options
|
16
|
+
@options[:preamble] = false
|
17
|
+
@options[:postamble] = false
|
18
|
+
@options[:ensure] = true
|
16
19
|
|
17
20
|
engine_class = @options[:engine_class] || Erubi::Engine
|
18
21
|
|
19
|
-
|
20
|
-
|
22
|
+
# If :freeze option is given, the intent is to setup frozen string
|
23
|
+
# literals in the template. So enable frozen string literals in the
|
24
|
+
# code Tilt generates if the :freeze option is given.
|
25
|
+
if @freeze_string_literals = !!@options[:freeze]
|
26
|
+
# Passing the :freeze option to Erubi sets the
|
27
|
+
# frozen-string-literal magic comment, which doesn't have an effect
|
28
|
+
# with Tilt as Tilt wraps the resulting code. Worse, the magic
|
29
|
+
# comment appearing not at the top of the file can cause a warning.
|
30
|
+
# So remove the :freeze option before passing to Erubi.
|
31
|
+
@options.delete(:freeze)
|
32
|
+
|
33
|
+
# Erubi by default appends .freeze to template literals on Ruby 2.1+,
|
34
|
+
# but that is not necessary and slows down code when Tilt is using
|
35
|
+
# frozen string literals, so pass the :freeze_template_literals
|
36
|
+
# option to not append .freeze.
|
37
|
+
@options[:freeze_template_literals] = false
|
38
|
+
end
|
21
39
|
|
22
|
-
|
23
|
-
@
|
40
|
+
@engine = engine_class.new(@data, @options)
|
41
|
+
@outvar = @engine.bufvar
|
42
|
+
@src = @engine.src
|
24
43
|
|
25
44
|
@engine
|
26
45
|
end
|
@@ -28,5 +47,9 @@ module Tilt
|
|
28
47
|
def precompiled_template(locals)
|
29
48
|
@src
|
30
49
|
end
|
50
|
+
|
51
|
+
def freeze_string_literals?
|
52
|
+
@freeze_string_literals
|
53
|
+
end
|
31
54
|
end
|
32
55
|
end
|
data/lib/tilt/erubis.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'erb'
|
2
3
|
require 'erubis'
|
3
4
|
|
4
5
|
module Tilt
|
@@ -16,11 +17,14 @@ module Tilt
|
|
16
17
|
# within <%= %> blocks will be automatically html escaped.
|
17
18
|
class ErubisTemplate < ERBTemplate
|
18
19
|
def prepare
|
19
|
-
@
|
20
|
-
@options.
|
21
|
-
|
22
|
-
|
23
|
-
@
|
20
|
+
@freeze_string_literals = !!@options.delete(:freeze)
|
21
|
+
@outvar = @options.delete(:outvar) || '_erbout'
|
22
|
+
@options[:preamble] = false
|
23
|
+
@options[:postamble] = false
|
24
|
+
@options[:bufvar] = @outvar
|
25
|
+
engine_class = @options.delete(:engine_class)
|
26
|
+
engine_class = ::Erubis::EscapedEruby if @options.delete(:escape_html)
|
27
|
+
@engine = (engine_class || ::Erubis::Eruby).new(@data, @options)
|
24
28
|
end
|
25
29
|
|
26
30
|
def precompiled_preamble(locals)
|
@@ -33,11 +37,13 @@ module Tilt
|
|
33
37
|
|
34
38
|
# Erubis doesn't have ERB's line-off-by-one under 1.9 problem.
|
35
39
|
# Override and adjust back.
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
40
|
+
def precompiled(locals)
|
41
|
+
source, offset = super
|
42
|
+
[source, offset - 1]
|
43
|
+
end
|
44
|
+
|
45
|
+
def freeze_string_literals?
|
46
|
+
@freeze_string_literals
|
41
47
|
end
|
42
48
|
end
|
43
49
|
end
|
data/lib/tilt/etanni.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'template'
|
2
3
|
|
3
4
|
module Tilt
|
4
5
|
class EtanniTemplate < Template
|
@@ -9,7 +10,7 @@ module Tilt
|
|
9
10
|
stop = "\n#{separator}\n"
|
10
11
|
replacement = "#{stop}\\1#{start}"
|
11
12
|
|
12
|
-
temp = data.strip
|
13
|
+
temp = @data.strip
|
13
14
|
temp.gsub!(/<\?r\s+(.*?)\s+\?>/m, replacement)
|
14
15
|
|
15
16
|
@code = "_out_ = [<<#{separator}.chomp!]\n#{temp}#{stop}_out_.join"
|
data/lib/tilt/haml.rb
CHANGED
@@ -1,84 +1,92 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'template'
|
2
3
|
require 'haml'
|
3
4
|
|
4
5
|
module Tilt
|
5
6
|
# Haml template implementation. See:
|
6
7
|
# http://haml.hamptoncatlin.com/
|
7
|
-
|
8
|
-
|
8
|
+
if defined?(Haml::Template) && Haml::Template < Tilt::Template
|
9
|
+
# Haml >= 6 ships its own template, prefer it when available.
|
10
|
+
HamlTemplate = Haml::Template
|
11
|
+
else
|
12
|
+
class HamlTemplate < Template
|
13
|
+
self.default_mime_type = 'text/html'
|
9
14
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
# `Gem::Version.correct?` may return false because of Haml::VERSION #=> "3.1.8 (Separated Sally)". After Haml 4, it's always correct.
|
16
|
+
if Gem::Version.correct?(Haml::VERSION) && Gem::Version.new(Haml::VERSION) >= Gem::Version.new('5.0.0.beta.2')
|
17
|
+
def prepare
|
18
|
+
@options[:filename] = eval_file
|
19
|
+
@options[:line] = @line
|
20
|
+
if @options.include?(:outvar)
|
21
|
+
@options[:buffer] = @options.delete(:outvar)
|
22
|
+
@options[:save_buffer] = true
|
23
|
+
end
|
24
|
+
@engine = ::Haml::TempleEngine.new(@options)
|
25
|
+
@engine.compile(@data)
|
17
26
|
end
|
18
|
-
@engine = ::Haml::TempleEngine.new(options)
|
19
|
-
@engine.compile(data)
|
20
|
-
end
|
21
27
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
28
|
+
def evaluate(scope, locals, &block)
|
29
|
+
raise ArgumentError, 'invalid scope: must not be frozen' if scope.frozen?
|
30
|
+
super
|
31
|
+
end
|
26
32
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
33
|
+
def precompiled_template(locals)
|
34
|
+
@engine.precompiled_with_ambles(
|
35
|
+
[],
|
36
|
+
after_preamble: <<-RUBY
|
37
|
+
__in_erb_template = true
|
38
|
+
_haml_locals = locals
|
39
|
+
RUBY
|
40
|
+
)
|
41
|
+
end
|
42
|
+
else # Following definitions are for Haml <= 4 and deprecated.
|
43
|
+
def prepare
|
44
|
+
@options[:filename] = eval_file
|
45
|
+
@options[:line] = @line
|
46
|
+
@engine = ::Haml::Engine.new(@data, @options)
|
47
|
+
end
|
41
48
|
|
42
|
-
|
43
|
-
|
49
|
+
def evaluate(scope, locals, &block)
|
50
|
+
raise ArgumentError, 'invalid scope: must not be frozen' if scope.frozen?
|
44
51
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
52
|
+
if @engine.respond_to?(:precompiled_method_return_value, true)
|
53
|
+
super
|
54
|
+
else
|
55
|
+
@engine.render(scope, locals, &block)
|
56
|
+
end
|
49
57
|
end
|
50
|
-
end
|
51
58
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
59
|
+
# Precompiled Haml source. Taken from the precompiled_with_ambles
|
60
|
+
# method in Haml::Precompiler:
|
61
|
+
# http://github.com/nex3/haml/blob/master/lib/haml/precompiler.rb#L111-126
|
62
|
+
def precompiled_template(locals)
|
63
|
+
@engine.precompiled
|
64
|
+
end
|
58
65
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
66
|
+
def precompiled_preamble(locals)
|
67
|
+
local_assigns = super
|
68
|
+
@engine.instance_eval do
|
69
|
+
<<-RUBY
|
70
|
+
begin
|
71
|
+
extend Haml::Helpers
|
72
|
+
_hamlout = @haml_buffer = Haml::Buffer.new(haml_buffer, #{options_for_buffer.inspect})
|
73
|
+
_erbout = _hamlout.buffer
|
74
|
+
__in_erb_template = true
|
75
|
+
_haml_locals = locals
|
76
|
+
#{local_assigns}
|
77
|
+
RUBY
|
78
|
+
end
|
71
79
|
end
|
72
|
-
end
|
73
80
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
81
|
+
def precompiled_postamble(locals)
|
82
|
+
@engine.instance_eval do
|
83
|
+
<<-RUBY
|
84
|
+
#{precompiled_method_return_value}
|
85
|
+
ensure
|
86
|
+
@haml_buffer = @haml_buffer.upper if haml_buffer
|
87
|
+
end
|
88
|
+
RUBY
|
89
|
+
end
|
82
90
|
end
|
83
91
|
end
|
84
92
|
end
|
data/lib/tilt/kramdown.rb
CHANGED
@@ -1,25 +1,13 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'template'
|
2
3
|
require 'kramdown'
|
3
4
|
|
4
|
-
|
5
|
-
# Kramdown Markdown implementation. See:
|
6
|
-
# http://kramdown.rubyforge.org/
|
7
|
-
class KramdownTemplate < Template
|
8
|
-
DUMB_QUOTES = [39, 39, 34, 34]
|
5
|
+
dumb_quotes = [39, 39, 34, 34].freeze
|
9
6
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
7
|
+
# Kramdown Markdown implementation. See: https://kramdown.gettalong.org/
|
8
|
+
Tilt::KramdownTemplate = Tilt::StaticTemplate.subclass do
|
9
|
+
# dup as Krawmdown modifies the passed option with map!
|
10
|
+
@options[:smart_quotes] = dumb_quotes.dup unless @options[:smartypants]
|
15
11
|
|
16
|
-
|
17
|
-
@output ||= @engine.to_html
|
18
|
-
end
|
19
|
-
|
20
|
-
def allows_script?
|
21
|
-
false
|
22
|
-
end
|
23
|
-
end
|
12
|
+
Kramdown::Document.new(@data, @options).to_html
|
24
13
|
end
|
25
|
-
|
data/lib/tilt/liquid.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'template'
|
2
3
|
require 'liquid'
|
3
4
|
|
4
5
|
module Tilt
|
5
6
|
# Liquid template implementation. See:
|
6
7
|
# http://liquidmarkup.org/
|
7
8
|
#
|
8
|
-
# Liquid is designed to be a *safe* template system and
|
9
|
+
# Liquid is designed to be a *safe* template system and therefore
|
9
10
|
# does not provide direct access to execuatable scopes. In order to
|
10
11
|
# support a +scope+, the +scope+ must be able to represent itself
|
11
12
|
# as a hash by responding to #to_h. If the +scope+ does not respond
|
@@ -17,16 +18,17 @@ module Tilt
|
|
17
18
|
# time when using this template engine.
|
18
19
|
class LiquidTemplate < Template
|
19
20
|
def prepare
|
20
|
-
@
|
21
|
+
@options[:line_numbers] = true unless @options.has_key?(:line_numbers)
|
22
|
+
@engine = ::Liquid::Template.parse(@data, @options)
|
21
23
|
end
|
22
24
|
|
23
|
-
def evaluate(scope,
|
24
|
-
locals =
|
25
|
+
def evaluate(scope, locs)
|
26
|
+
locals = {}
|
25
27
|
if scope.respond_to?(:to_h)
|
26
|
-
scope
|
27
|
-
locals = scope.merge(locals)
|
28
|
+
scope.to_h.each{|k, v| locals[k.to_s] = v}
|
28
29
|
end
|
29
|
-
locals[
|
30
|
+
locs.each{|k, v| locals[k.to_s] = v}
|
31
|
+
locals['yield'] = block_given? ? yield : ''
|
30
32
|
locals['content'] = locals['yield']
|
31
33
|
@engine.render(locals)
|
32
34
|
end
|
@@ -34,11 +36,5 @@ module Tilt
|
|
34
36
|
def allows_script?
|
35
37
|
false
|
36
38
|
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def liquid_options
|
41
|
-
{ line_numbers: true }.merge options
|
42
|
-
end
|
43
39
|
end
|
44
40
|
end
|
data/lib/tilt/livescript.rb
CHANGED
@@ -1,23 +1,11 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'template'
|
2
3
|
require 'livescript'
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
self.default_mime_type = 'application/javascript'
|
11
|
-
|
12
|
-
def prepare
|
13
|
-
end
|
14
|
-
|
15
|
-
def evaluate(scope, locals, &block)
|
16
|
-
@output ||= LiveScript.compile(data, options)
|
17
|
-
end
|
18
|
-
|
19
|
-
def allows_script?
|
20
|
-
false
|
21
|
-
end
|
22
|
-
end
|
5
|
+
# LiveScript template implementation. See:
|
6
|
+
# http://livescript.net/
|
7
|
+
#
|
8
|
+
# LiveScript templates do not support object scopes, locals, or yield.
|
9
|
+
Tilt::LiveScriptTemplate = Tilt::StaticTemplate.subclass(mime_type: 'application/javascript') do
|
10
|
+
LiveScript.compile(@data, @options)
|
23
11
|
end
|