tilt 2.0.0 → 2.4.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.
Files changed (96) hide show
  1. checksums.yaml +5 -5
  2. data/COPYING +2 -1
  3. data/bin/tilt +2 -110
  4. data/lib/tilt/_emacs_org.rb +2 -0
  5. data/lib/tilt/_handlebars.rb +2 -0
  6. data/lib/tilt/_jbuilder.rb +2 -0
  7. data/lib/tilt/_org.rb +2 -0
  8. data/lib/tilt/asciidoc.rb +11 -23
  9. data/lib/tilt/babel.rb +8 -0
  10. data/lib/tilt/builder.rb +23 -14
  11. data/lib/tilt/cli.rb +134 -0
  12. data/lib/tilt/coffee.rb +17 -25
  13. data/lib/tilt/commonmarker.rb +95 -0
  14. data/lib/tilt/creole.rb +9 -20
  15. data/lib/tilt/csv.rb +9 -21
  16. data/lib/tilt/erb.rb +27 -19
  17. data/lib/tilt/erubi.rb +55 -0
  18. data/lib/tilt/erubis.rb +20 -12
  19. data/lib/tilt/etanni.rb +5 -4
  20. data/lib/tilt/haml.rb +79 -42
  21. data/lib/tilt/kramdown.rb +8 -28
  22. data/lib/tilt/liquid.rb +11 -9
  23. data/lib/tilt/livescript.rb +11 -0
  24. data/lib/tilt/mapping.rb +242 -95
  25. data/lib/tilt/markaby.rb +5 -7
  26. data/lib/tilt/maruku.rb +6 -18
  27. data/lib/tilt/nokogiri.rb +11 -10
  28. data/lib/tilt/pandoc.rb +39 -0
  29. data/lib/tilt/pipeline.rb +19 -0
  30. data/lib/tilt/plain.rb +4 -19
  31. data/lib/tilt/prawn.rb +28 -0
  32. data/lib/tilt/radius.rb +15 -22
  33. data/lib/tilt/rdiscount.rb +17 -33
  34. data/lib/tilt/rdoc.rb +14 -35
  35. data/lib/tilt/redcarpet.rb +20 -93
  36. data/lib/tilt/redcloth.rb +9 -19
  37. data/lib/tilt/rst-pandoc.rb +10 -0
  38. data/lib/tilt/sass.rb +59 -22
  39. data/lib/tilt/slim.rb +5 -0
  40. data/lib/tilt/string.rb +9 -3
  41. data/lib/tilt/template.rb +246 -78
  42. data/lib/tilt/typescript.rb +19 -0
  43. data/lib/tilt/wikicloth.rb +8 -18
  44. data/lib/tilt/yajl.rb +5 -11
  45. data/lib/tilt.rb +91 -41
  46. metadata +39 -102
  47. data/CHANGELOG.md +0 -61
  48. data/Gemfile +0 -39
  49. data/HACKING +0 -16
  50. data/README.md +0 -206
  51. data/Rakefile +0 -95
  52. data/docs/TEMPLATES.md +0 -523
  53. data/docs/common.css +0 -14
  54. data/lib/tilt/bluecloth.rb +0 -24
  55. data/lib/tilt/less.rb +0 -38
  56. data/test/markaby/locals.mab +0 -1
  57. data/test/markaby/markaby.mab +0 -1
  58. data/test/markaby/markaby_other_static.mab +0 -1
  59. data/test/markaby/render_twice.mab +0 -1
  60. data/test/markaby/scope.mab +0 -1
  61. data/test/markaby/yielding.mab +0 -2
  62. data/test/test_helper.rb +0 -64
  63. data/test/tilt_asciidoctor_test.rb +0 -44
  64. data/test/tilt_blueclothtemplate_test.rb +0 -33
  65. data/test/tilt_buildertemplate_test.rb +0 -59
  66. data/test/tilt_cache_test.rb +0 -32
  67. data/test/tilt_coffeescripttemplate_test.rb +0 -104
  68. data/test/tilt_compilesite_test.rb +0 -51
  69. data/test/tilt_creoletemplate_test.rb +0 -24
  70. data/test/tilt_csv_test.rb +0 -65
  71. data/test/tilt_erbtemplate_test.rb +0 -239
  72. data/test/tilt_erubistemplate_test.rb +0 -151
  73. data/test/tilt_etannitemplate_test.rb +0 -174
  74. data/test/tilt_hamltemplate_test.rb +0 -144
  75. data/test/tilt_kramdown_test.rb +0 -20
  76. data/test/tilt_lesstemplate_test.less +0 -1
  77. data/test/tilt_lesstemplate_test.rb +0 -42
  78. data/test/tilt_liquidtemplate_test.rb +0 -78
  79. data/test/tilt_mapping_test.rb +0 -229
  80. data/test/tilt_markaby_test.rb +0 -88
  81. data/test/tilt_markdown_test.rb +0 -174
  82. data/test/tilt_marukutemplate_test.rb +0 -36
  83. data/test/tilt_metadata_test.rb +0 -42
  84. data/test/tilt_nokogiritemplate_test.rb +0 -87
  85. data/test/tilt_radiustemplate_test.rb +0 -75
  86. data/test/tilt_rdiscounttemplate_test.rb +0 -43
  87. data/test/tilt_rdoctemplate_test.rb +0 -29
  88. data/test/tilt_redcarpettemplate_test.rb +0 -59
  89. data/test/tilt_redclothtemplate_test.rb +0 -36
  90. data/test/tilt_sasstemplate_test.rb +0 -41
  91. data/test/tilt_stringtemplate_test.rb +0 -171
  92. data/test/tilt_template_test.rb +0 -316
  93. data/test/tilt_test.rb +0 -60
  94. data/test/tilt_wikiclothtemplate_test.rb +0 -32
  95. data/test/tilt_yajltemplate_test.rb +0 -101
  96. data/tilt.gemspec +0 -107
data/lib/tilt/erb.rb CHANGED
@@ -1,25 +1,31 @@
1
- require 'tilt/template'
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
- def self.default_output_variable
11
- @@default_output_variable
12
- end
13
-
14
- def self.default_output_variable=(name)
15
- warn "#{self}.default_output_variable= has been replaced with the :outvar-option"
16
- @@default_output_variable = name
17
- end
9
+ SUPPORTS_KVARGS = ::ERB.instance_method(:initialize).parameters.assoc(:key) rescue false
18
10
 
19
11
  def prepare
20
- @outvar = options[:outvar] || self.class.default_output_variable
21
- options[:trim] = '<>' if !(options[:trim] == false) && (options[:trim].nil? || options[:trim] == true)
22
- @engine = ::ERB.new(data, options[:safe], options[:trim], @outvar)
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
22
+ @engine = if SUPPORTS_KVARGS
23
+ ::ERB.new(@data, trim_mode: trim, eoutvar: @outvar)
24
+ # :nocov:
25
+ else
26
+ ::ERB.new(@data, options[:safe], trim, @outvar)
27
+ # :nocov:
28
+ end
23
29
  end
24
30
 
25
31
  def precompiled_template(locals)
@@ -46,11 +52,13 @@ module Tilt
46
52
 
47
53
  # ERB generates a line to specify the character coding of the generated
48
54
  # source in 1.9. Account for this in the line offset.
49
- if RUBY_VERSION >= '1.9.0'
50
- def precompiled(locals)
51
- source, offset = super
52
- [source, offset + 1]
53
- end
55
+ def precompiled(locals)
56
+ source, offset = super
57
+ [source, offset + 1]
58
+ end
59
+
60
+ def freeze_string_literals?
61
+ @freeze_string_literals
54
62
  end
55
63
  end
56
64
  end
data/lib/tilt/erubi.rb ADDED
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+ require_relative 'template'
3
+ require 'erubi'
4
+
5
+ module Tilt
6
+ # Erubi (a simplified version of Erubis) template implementation.
7
+ # See https://github.com/jeremyevans/erubi
8
+ #
9
+ # ErubiTemplate supports the following additional options, in addition
10
+ # to the options supported by the Erubi engine:
11
+ #
12
+ # :engine_class :: allows you to specify a custom engine class to use
13
+ # instead of the default (which is ::Erubi::Engine).
14
+ class ErubiTemplate < Template
15
+ def prepare
16
+ @options[:preamble] = false
17
+ @options[:postamble] = false
18
+ @options[:ensure] = true
19
+
20
+ engine_class = @options[:engine_class] || Erubi::Engine
21
+
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
39
+
40
+ @engine = engine_class.new(@data, @options)
41
+ @outvar = @engine.bufvar
42
+ @src = @engine.src
43
+
44
+ @engine
45
+ end
46
+
47
+ def precompiled_template(locals)
48
+ @src
49
+ end
50
+
51
+ def freeze_string_literals?
52
+ @freeze_string_literals
53
+ end
54
+ end
55
+ end
data/lib/tilt/erubis.rb CHANGED
@@ -1,6 +1,9 @@
1
- require 'tilt/erb'
1
+ # frozen_string_literal: true
2
+ require_relative 'erb'
2
3
  require 'erubis'
3
4
 
5
+ warn 'tilt/erubis is deprecated, as erubis requires modifying string literals', uplevel: 1
6
+
4
7
  module Tilt
5
8
  # Erubis template implementation. See:
6
9
  # http://www.kuwata-lab.com/erubis/
@@ -16,15 +19,18 @@ module Tilt
16
19
  # within <%= %> blocks will be automatically html escaped.
17
20
  class ErubisTemplate < ERBTemplate
18
21
  def prepare
19
- @outvar = options.delete(:outvar) || self.class.default_output_variable
20
- @options.merge!(:preamble => false, :postamble => false, :bufvar => @outvar)
21
- engine_class = options.delete(:engine_class)
22
- engine_class = ::Erubis::EscapedEruby if options.delete(:escape_html)
23
- @engine = (engine_class || ::Erubis::Eruby).new(data, options)
22
+ @freeze_string_literals = !!@options.delete(:freeze)
23
+ @outvar = @options.delete(:outvar) || '_erbout'
24
+ @options[:preamble] = false
25
+ @options[:postamble] = false
26
+ @options[:bufvar] = @outvar
27
+ engine_class = @options.delete(:engine_class)
28
+ engine_class = ::Erubis::EscapedEruby if @options.delete(:escape_html)
29
+ @engine = (engine_class || ::Erubis::Eruby).new(@data, @options)
24
30
  end
25
31
 
26
32
  def precompiled_preamble(locals)
27
- [super, "#{@outvar} = _buf = ''"].join("\n")
33
+ [super, "#{@outvar} = _buf = String.new"].join("\n")
28
34
  end
29
35
 
30
36
  def precompiled_postamble(locals)
@@ -33,11 +39,13 @@ module Tilt
33
39
 
34
40
  # Erubis doesn't have ERB's line-off-by-one under 1.9 problem.
35
41
  # Override and adjust back.
36
- if RUBY_VERSION >= '1.9.0'
37
- def precompiled(locals)
38
- source, offset = super
39
- [source, offset - 1]
40
- end
42
+ def precompiled(locals)
43
+ source, offset = super
44
+ [source, offset - 1]
45
+ end
46
+
47
+ def freeze_string_literals?
48
+ @freeze_string_literals
41
49
  end
42
50
  end
43
51
  end
data/lib/tilt/etanni.rb CHANGED
@@ -1,18 +1,19 @@
1
- require 'tilt/template'
1
+ # frozen_string_literal: true
2
+ require_relative 'template'
2
3
 
3
4
  module Tilt
4
5
  class EtanniTemplate < Template
5
6
  def prepare
6
7
  separator = data.hash.abs
7
- chomp = "<<#{separator}.chomp!"
8
+ chomp = "<<#{separator}.chomp"
8
9
  start = "\n_out_ << #{chomp}\n"
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
- @code = "_out_ = [<<#{separator}.chomp!]\n#{temp}#{stop}_out_.join"
16
+ @code = "_out_ = [<<#{separator}.chomp]\n#{temp}#{stop}_out_.join"
16
17
  end
17
18
 
18
19
  def precompiled_template(locals)
data/lib/tilt/haml.rb CHANGED
@@ -1,57 +1,94 @@
1
- require 'tilt/template'
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
- class HamlTemplate < Template
8
- self.default_mime_type = 'text/html'
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
- def prepare
11
- options = @options.merge(:filename => eval_file, :line => line)
12
- @engine = ::Haml::Engine.new(data, options)
13
- end
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)
26
+ end
14
27
 
15
- def evaluate(scope, locals, &block)
16
- if @engine.respond_to?(:precompiled_method_return_value, true)
17
- super
18
- else
19
- @engine.render(scope, locals, &block)
20
- end
21
- end
28
+ def evaluate(scope, locals, &block)
29
+ raise ArgumentError, 'invalid scope: must not be frozen' if scope.frozen?
30
+ super
31
+ end
22
32
 
23
- # Precompiled Haml source. Taken from the precompiled_with_ambles
24
- # method in Haml::Precompiler:
25
- # http://github.com/nex3/haml/blob/master/lib/haml/precompiler.rb#L111-126
26
- def precompiled_template(locals)
27
- @engine.precompiled
28
- end
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
29
48
 
30
- def precompiled_preamble(locals)
31
- local_assigns = super
32
- @engine.instance_eval do
33
- <<-RUBY
34
- begin
35
- extend Haml::Helpers
36
- _hamlout = @haml_buffer = Haml::Buffer.new(@haml_buffer, #{options_for_buffer.inspect})
37
- _erbout = _hamlout.buffer
38
- __in_erb_template = true
39
- _haml_locals = locals
40
- #{local_assigns}
41
- RUBY
42
- end
43
- end
49
+ def evaluate(scope, locals, &block)
50
+ raise ArgumentError, 'invalid scope: must not be frozen' if scope.frozen?
44
51
 
45
- def precompiled_postamble(locals)
46
- @engine.instance_eval do
47
- <<-RUBY
48
- #{precompiled_method_return_value}
49
- ensure
50
- @haml_buffer = @haml_buffer.upper
52
+ if @engine.respond_to?(:precompiled_method_return_value, true)
53
+ super
54
+ else
55
+ @engine.render(scope, locals, &block)
51
56
  end
52
- RUBY
57
+ end
58
+
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
65
+
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
79
+ end
80
+
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
90
+ end
53
91
  end
54
92
  end
55
93
  end
56
94
  end
57
-
data/lib/tilt/kramdown.rb CHANGED
@@ -1,33 +1,13 @@
1
- require 'tilt/template'
1
+ # frozen_string_literal: true
2
+ require_relative 'template'
2
3
  require 'kramdown'
3
4
 
4
- module Tilt
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
- def self.engine_initialized?
11
- defined? ::Kramdown
12
- 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]
13
11
 
14
- def initialize_engine
15
- require_template_library 'kramdown'
16
- end
17
-
18
- def prepare
19
- options[:smart_quotes] = DUMB_QUOTES unless options[:smartypants]
20
- @engine = Kramdown::Document.new(data, options)
21
- @output = nil
22
- end
23
-
24
- def evaluate(scope, locals, &block)
25
- @output ||= @engine.to_html
26
- end
27
-
28
- def allows_script?
29
- false
30
- end
31
- end
12
+ Kramdown::Document.new(@data, @options).to_html
32
13
  end
33
-
data/lib/tilt/liquid.rb CHANGED
@@ -1,11 +1,12 @@
1
- require 'tilt/template'
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
- # http://liquid.rubyforge.org/
7
+ # http://liquidmarkup.org/
7
8
  #
8
- # Liquid is designed to be a *safe* template system and threfore
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
- @engine = ::Liquid::Template.parse(data)
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, locals, &block)
24
- locals = locals.inject({}){ |h,(k,v)| h[k.to_s] = v ; h }
25
+ def evaluate(scope, locs)
26
+ locals = {}
25
27
  if scope.respond_to?(:to_h)
26
- scope = scope.to_h.inject({}){ |h,(k,v)| h[k.to_s] = v ; h }
27
- locals = scope.merge(locals)
28
+ scope.to_h.each{|k, v| locals[k.to_s] = v}
28
29
  end
29
- locals['yield'] = block.nil? ? '' : yield
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
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+ require_relative 'template'
3
+ require 'livescript'
4
+
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)
11
+ end