tilt 2.0.11 → 2.7.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 (50) hide show
  1. checksums.yaml +4 -4
  2. data/COPYING +1 -0
  3. data/bin/tilt +2 -120
  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 +18 -23
  9. data/lib/tilt/babel.rb +9 -12
  10. data/lib/tilt/builder.rb +22 -13
  11. data/lib/tilt/cli.rb +134 -0
  12. data/lib/tilt/coffee.rb +26 -35
  13. data/lib/tilt/commonmarker.rb +123 -75
  14. data/lib/tilt/csv.rb +41 -43
  15. data/lib/tilt/erb.rb +90 -23
  16. data/lib/tilt/erubi.rb +70 -14
  17. data/lib/tilt/etanni.rb +12 -4
  18. data/lib/tilt/haml.rb +139 -65
  19. data/lib/tilt/kramdown.rb +54 -20
  20. data/lib/tilt/liquid.rb +75 -26
  21. data/lib/tilt/livescript.rb +14 -19
  22. data/lib/tilt/mapping.rb +233 -114
  23. data/lib/tilt/markaby.rb +16 -9
  24. data/lib/tilt/nokogiri.rb +24 -12
  25. data/lib/tilt/pandoc.rb +75 -51
  26. data/lib/tilt/pipeline.rb +24 -0
  27. data/lib/tilt/plain.rb +6 -13
  28. data/lib/tilt/prawn.rb +26 -30
  29. data/lib/tilt/radius.rb +70 -22
  30. data/lib/tilt/rdiscount.rb +75 -32
  31. data/lib/tilt/rdoc.rb +28 -35
  32. data/lib/tilt/redcarpet.rb +63 -76
  33. data/lib/tilt/redcloth.rb +35 -18
  34. data/lib/tilt/rst-pandoc.rb +28 -18
  35. data/lib/tilt/sass.rb +58 -45
  36. data/lib/tilt/slim.rb +18 -0
  37. data/lib/tilt/string.rb +19 -5
  38. data/lib/tilt/template.rb +392 -89
  39. data/lib/tilt/typescript.rb +15 -17
  40. data/lib/tilt/yajl.rb +51 -47
  41. data/lib/tilt.rb +68 -44
  42. metadata +22 -19
  43. data/lib/tilt/bluecloth.rb +0 -24
  44. data/lib/tilt/creole.rb +0 -25
  45. data/lib/tilt/dummy.rb +0 -3
  46. data/lib/tilt/erubis.rb +0 -43
  47. data/lib/tilt/less.rb +0 -30
  48. data/lib/tilt/maruku.rb +0 -22
  49. data/lib/tilt/sigil.rb +0 -34
  50. data/lib/tilt/wikicloth.rb +0 -22
data/lib/tilt/haml.rb CHANGED
@@ -1,84 +1,158 @@
1
- require 'tilt/template'
1
+ # frozen_string_literal: true
2
+
3
+ # = Haml (<tt>haml</tt>)
4
+ #
5
+ # {Haml}[https://haml.info] is a markup language that’s used to cleanly and simply describe
6
+ # the HTML of any web document without the use of inline code. Haml functions as
7
+ # a replacement for inline page templating systems such as PHP, ASP, and ERB, the
8
+ # templating language used in most Ruby on Rails applications. However, Haml
9
+ # avoids the need for explicitly coding HTML into the template, because it itself
10
+ # is a description of the HTML, with some code to generate dynamic content.
11
+ # ({more}[http://haml.info/about.html)]
12
+ #
13
+ # === Example
14
+ #
15
+ # %html
16
+ # %head
17
+ # %title= @title
18
+ # %body
19
+ # %h1
20
+ # Hello
21
+ # = world + '!'
22
+ #
23
+ # === Usage
24
+ #
25
+ # The <tt>Tilt::HamlTemplate</tt> class is registered for all files ending in <tt>.haml</tt>
26
+ # by default. Haml templates support custom evaluation scopes and locals:
27
+ #
28
+ # >> require 'haml'
29
+ # >> template = Tilt.new('hello.haml')
30
+ # => #<Tilt::HamlTemplate @file='hello.haml'>
31
+ # >> @title = "Hello Haml!"
32
+ # >> template.render(self, :world => 'Haml!')
33
+ # => "
34
+ # <html>
35
+ # <head>
36
+ # <title>Hello Haml!</title>
37
+ # </head>
38
+ # <body>
39
+ # <h1>Hello Haml!</h1>
40
+ # </body>
41
+ # </html>"
42
+ #
43
+ # Or, use the <tt>Tilt::HamlTemplate</tt> class directly to process strings:
44
+ #
45
+ # >> require 'haml'
46
+ # >> template = Tilt::HamlTemplate.new { "%h1= 'Hello Haml!'" }
47
+ # => #<Tilt::HamlTemplate @file=nil ...>
48
+ # >> template.render
49
+ # => "<h1>Hello Haml!</h1>"
50
+ #
51
+ # __NOTE:__ It's suggested that your program <tt>require 'haml'</tt> at load time when
52
+ # using this template engine within a threaded environment.
53
+ #
54
+ # === Options
55
+ #
56
+ # Please see the {Haml Reference}[http://haml.info/docs/yardoc/file.HAML_REFERENCE.html#options] for all available options.
57
+ #
58
+ # === See also
59
+ #
60
+ # * {#haml.docs}[http://haml.info/docs.html]
61
+ # * {Haml Tutorial}[http://haml.info/tutorial.html]
62
+ # * {Haml Reference}[http://haml.info/docs/yardoc/file.HAML_REFERENCE.html]
63
+ #
64
+ # === Related module
65
+ #
66
+ # * Tilt::HamlTemplate
67
+
68
+ require_relative 'template'
2
69
  require 'haml'
3
70
 
4
71
  module Tilt
5
72
  # Haml template implementation. See:
6
73
  # http://haml.hamptoncatlin.com/
7
- class HamlTemplate < Template
8
- self.default_mime_type = 'text/html'
74
+ if defined?(Haml::Template) && Haml::Template < Tilt::Template
75
+ # Haml >= 6 ships its own template, prefer it when available.
76
+ HamlTemplate = Haml::Template
77
+ else
78
+ class HamlTemplate < Template
79
+ self.default_mime_type = 'text/html'
9
80
 
10
- # `Gem::Version.correct?` may return false because of Haml::VERSION #=> "3.1.8 (Separated Sally)". After Haml 4, it's always correct.
11
- if Gem::Version.correct?(Haml::VERSION) && Gem::Version.new(Haml::VERSION) >= Gem::Version.new('5.0.0.beta.2')
12
- def prepare
13
- options = {}.update(@options).update(filename: eval_file, line: line)
14
- if options.include?(:outvar)
15
- options[:buffer] = options.delete(:outvar)
16
- options[:save_buffer] = true
81
+ # <tt>Gem::Version.correct?</tt> may return false because of Haml::VERSION #=> "3.1.8 (Separated Sally)". After Haml 4, it's always correct.
82
+ if Gem::Version.correct?(Haml::VERSION) && Gem::Version.new(Haml::VERSION) >= Gem::Version.new('5.0.0.beta.2')
83
+ def prepare
84
+ @options[:filename] = eval_file
85
+ @options[:line] = @line
86
+ if @options.include?(:outvar)
87
+ @options[:buffer] = @options.delete(:outvar)
88
+ @options[:save_buffer] = true
89
+ end
90
+ @engine = ::Haml::TempleEngine.new(@options)
91
+ @engine.compile(@data)
17
92
  end
18
- @engine = ::Haml::TempleEngine.new(options)
19
- @engine.compile(data)
20
- end
21
93
 
22
- def evaluate(scope, locals, &block)
23
- raise ArgumentError, 'invalid scope: must not be frozen' if scope.frozen?
24
- super
25
- end
94
+ def evaluate(scope, locals, &block)
95
+ raise ArgumentError, 'invalid scope: must not be frozen' if scope.frozen?
96
+ super
97
+ end
26
98
 
27
- def precompiled_template(locals)
28
- @engine.precompiled_with_ambles(
29
- [],
30
- after_preamble: <<-RUBY
31
- __in_erb_template = true
32
- _haml_locals = locals
33
- RUBY
34
- )
35
- end
36
- else # Following definitions are for Haml <= 4 and deprecated.
37
- def prepare
38
- options = @options.merge(:filename => eval_file, :line => line)
39
- @engine = ::Haml::Engine.new(data, options)
40
- end
99
+ def precompiled_template(locals)
100
+ @engine.precompiled_with_ambles(
101
+ [],
102
+ after_preamble: <<-RUBY
103
+ __in_erb_template = true
104
+ _haml_locals = locals
105
+ RUBY
106
+ )
107
+ end
108
+ else # Following definitions are for Haml <= 4 and deprecated.
109
+ def prepare
110
+ @options[:filename] = eval_file
111
+ @options[:line] = @line
112
+ @engine = ::Haml::Engine.new(@data, @options)
113
+ end
41
114
 
42
- def evaluate(scope, locals, &block)
43
- raise ArgumentError, 'invalid scope: must not be frozen' if scope.frozen?
115
+ def evaluate(scope, locals, &block)
116
+ raise ArgumentError, 'invalid scope: must not be frozen' if scope.frozen?
44
117
 
45
- if @engine.respond_to?(:precompiled_method_return_value, true)
46
- super
47
- else
48
- @engine.render(scope, locals, &block)
118
+ if @engine.respond_to?(:precompiled_method_return_value, true)
119
+ super
120
+ else
121
+ @engine.render(scope, locals, &block)
122
+ end
49
123
  end
50
- end
51
124
 
52
- # Precompiled Haml source. Taken from the precompiled_with_ambles
53
- # method in Haml::Precompiler:
54
- # http://github.com/nex3/haml/blob/master/lib/haml/precompiler.rb#L111-126
55
- def precompiled_template(locals)
56
- @engine.precompiled
57
- end
125
+ # Precompiled Haml source. Taken from the precompiled_with_ambles
126
+ # method in Haml::Precompiler:
127
+ # http://github.com/nex3/haml/blob/master/lib/haml/precompiler.rb#L111-126
128
+ def precompiled_template(locals)
129
+ @engine.precompiled
130
+ end
58
131
 
59
- def precompiled_preamble(locals)
60
- local_assigns = super
61
- @engine.instance_eval do
62
- <<-RUBY
63
- begin
64
- extend Haml::Helpers
65
- _hamlout = @haml_buffer = Haml::Buffer.new(haml_buffer, #{options_for_buffer.inspect})
66
- _erbout = _hamlout.buffer
67
- __in_erb_template = true
68
- _haml_locals = locals
69
- #{local_assigns}
70
- RUBY
132
+ def precompiled_preamble(locals)
133
+ local_assigns = super
134
+ @engine.instance_eval do
135
+ <<-RUBY
136
+ begin
137
+ extend Haml::Helpers
138
+ _hamlout = @haml_buffer = Haml::Buffer.new(haml_buffer, #{options_for_buffer.inspect})
139
+ _erbout = _hamlout.buffer
140
+ __in_erb_template = true
141
+ _haml_locals = locals
142
+ #{local_assigns}
143
+ RUBY
144
+ end
71
145
  end
72
- end
73
146
 
74
- def precompiled_postamble(locals)
75
- @engine.instance_eval do
76
- <<-RUBY
77
- #{precompiled_method_return_value}
78
- ensure
79
- @haml_buffer = @haml_buffer.upper if haml_buffer
80
- end
81
- RUBY
147
+ def precompiled_postamble(locals)
148
+ @engine.instance_eval do
149
+ <<-RUBY
150
+ #{precompiled_method_return_value}
151
+ ensure
152
+ @haml_buffer = @haml_buffer.upper if haml_buffer
153
+ end
154
+ RUBY
155
+ end
82
156
  end
83
157
  end
84
158
  end
data/lib/tilt/kramdown.rb CHANGED
@@ -1,25 +1,59 @@
1
- require 'tilt/template'
2
- require 'kramdown'
1
+ # frozen_string_literal: true
2
+
3
+ # = Markdown (<tt>markdown</tt>, <tt>md</tt>, <tt>mkd</tt>)
4
+ #
5
+ # Markdown is a lightweight markup language, created by John Gruber
6
+ # and Aaron Swartz. For any markup that is not covered by Markdown’s syntax, HTML
7
+ # is used. Marking up plain text with Markdown markup is easy and Markdown
8
+ # formatted texts are readable.
9
+ #
10
+ # === Example
11
+ #
12
+ # Hello Markdown Templates
13
+ # ========================
14
+ #
15
+ # Hello World. This is a paragraph.
16
+ #
17
+ # === Usage
18
+ #
19
+ # To wrap a Markdown formatted document with a layout:
20
+ #
21
+ # layout = Tilt['erb'].new do
22
+ # "<!doctype html><title></title><%= yield %>"
23
+ # end
24
+ # data = Tilt['md'].new { "# hello tilt" }
25
+ # layout.render { data.render }
26
+ # # => "<!doctype html><title></title><h1>hello tilt</h1>\n"
27
+ #
28
+ # === Options
29
+ #
30
+ # Every implementation of Markdown *should* support these options, but there are
31
+ # some known problems with the Kramdown engine.
32
+ #
33
+ # ==== <tt>:smartypants => true|false</tt>
34
+ #
35
+ # Set <tt>true</tt> to enable [Smarty Pants][smartypants] style punctuation replacement.
36
+ #
37
+ # In Kramdown this option only applies to smart quotes. It will apply a
38
+ # subset of Smarty Pants (e.g. <tt>...</tt> to <tt>…</tt>) regardless of any option.
39
+ #
40
+ # ==== <tt>:escape_html => true|false</tt>
41
+ #
42
+ # Kramdown doesn't support this option.
43
+ #
44
+ # === See also
45
+ #
46
+ # * {Markdown Syntax Documentation}[http://daringfireball.net/projects/markdown/syntax]
47
+ # * {Kramdown Markdown implementation}[https://kramdown.gettalong.org]
3
48
 
4
- module Tilt
5
- # Kramdown Markdown implementation. See:
6
- # http://kramdown.rubyforge.org/
7
- class KramdownTemplate < Template
8
- DUMB_QUOTES = [39, 39, 34, 34]
49
+ require_relative 'template'
50
+ require 'kramdown'
9
51
 
10
- def prepare
11
- options[:smart_quotes] = DUMB_QUOTES unless options[:smartypants]
12
- @engine = Kramdown::Document.new(data, options)
13
- @output = nil
14
- end
52
+ dumb_quotes = [39, 39, 34, 34].freeze
15
53
 
16
- def evaluate(scope, locals, &block)
17
- @output ||= @engine.to_html
18
- end
54
+ Tilt::KramdownTemplate = Tilt::StaticTemplate.subclass do
55
+ # dup as Krawmdown modifies the passed option with map!
56
+ @options[:smart_quotes] = dumb_quotes.dup unless @options[:smartypants]
19
57
 
20
- def allows_script?
21
- false
22
- end
23
- end
58
+ Kramdown::Document.new(@data, @options).to_html
24
59
  end
25
-
data/lib/tilt/liquid.rb CHANGED
@@ -1,32 +1,87 @@
1
- require 'tilt/template'
1
+ # frozen_string_literal: true
2
+
3
+ # = Liquid (<tt>liquid</tt>)
4
+ #
5
+ # Liquid is designed to be a *safe* template system and therefore
6
+ # does not provide direct access to execuatable scopes. In order to
7
+ # support a +scope+, the +scope+ must be able to represent itself
8
+ # as a hash by responding to #to_h. If the +scope+ does not respond
9
+ # to #to_h it will be ignored.
10
+ #
11
+ # LiquidTemplate does not support yield blocks.
12
+ #
13
+ # === Example
14
+ #
15
+ # <html>
16
+ # <head>
17
+ # <title>{{ title }}</title>
18
+ # </head>
19
+ # <body>
20
+ # <h1>Hello {{ world }}!</h1>
21
+ # </body>
22
+ # </html>
23
+ #
24
+ # === Usage
25
+ #
26
+ # <tt>Tilt::LiquidTemplate</tt> is registered for all files ending in <tt>.liquid</tt> by
27
+ # default. Liquid templates support locals and objects that respond to
28
+ # <tt>#to_h</tt> as scopes:
29
+ #
30
+ # >> require 'liquid'
31
+ # >> require 'tilt'
32
+ # >> template = Tilt.new('hello.liquid')
33
+ # => #<Tilt::LiquidTemplate @file='hello.liquid'>
34
+ # >> scope = { :title => "Hello Liquid Templates" }
35
+ # >> template.render(nil, :world => "Liquid")
36
+ # => "
37
+ # <html>
38
+ # <head>
39
+ # <title>Hello Liquid Templates</title>
40
+ # </head>
41
+ # <body>
42
+ # <h1>Hello Liquid!</h1>
43
+ # </body>
44
+ # </html>"
45
+ #
46
+ # Or, use <tt>Tilt::LiquidTemplate</tt> directly to process strings:
47
+ #
48
+ # >> require 'liquid'
49
+ # >> template = Tilt::LiquidTemplate.new { "<h1>Hello Liquid!</h1>" }
50
+ # => #<Tilt::LiquidTemplate @file=nil ...>
51
+ # >> template.render
52
+ # => "<h1>Hello Liquid!</h1>"
53
+ #
54
+ # __NOTE:__ It's suggested that your program <tt>require 'liquid'</tt> at load
55
+ # time when using this template engine within a threaded environment.
56
+ #
57
+ # === See also
58
+ #
59
+ # * {Liquid}[http://liquidmarkup.org]
60
+ # * {Liquid for Programmers}[https://wiki.github.com/Shopify/liquid/liquid-for-programmers]
61
+ # * {Liquid Docs}[http://liquid.rubyforge.org/]
62
+ # * GitHub: {Shopify/liquid}[https://github.com/Shopify/liquid/]
63
+ #
64
+ # === Related module
65
+ #
66
+ # * Tilt::LiquidTemplate
67
+
68
+ require_relative 'template'
2
69
  require 'liquid'
3
70
 
4
71
  module Tilt
5
- # Liquid template implementation. See:
6
- # http://liquidmarkup.org/
7
- #
8
- # Liquid is designed to be a *safe* template system and threfore
9
- # does not provide direct access to execuatable scopes. In order to
10
- # support a +scope+, the +scope+ must be able to represent itself
11
- # as a hash by responding to #to_h. If the +scope+ does not respond
12
- # to #to_h it will be ignored.
13
- #
14
- # LiquidTemplate does not support yield blocks.
15
- #
16
- # It's suggested that your program require 'liquid' at load
17
- # time when using this template engine.
18
72
  class LiquidTemplate < Template
19
73
  def prepare
20
- @engine = ::Liquid::Template.parse(data, liquid_options)
74
+ @options[:line_numbers] = true unless @options.has_key?(:line_numbers)
75
+ @engine = ::Liquid::Template.parse(@data, @options)
21
76
  end
22
77
 
23
- def evaluate(scope, locals, &block)
24
- locals = locals.inject({}){ |h,(k,v)| h[k.to_s] = v ; h }
78
+ def evaluate(scope, locs)
79
+ locals = {}
25
80
  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)
81
+ scope.to_h.each{|k, v| locals[k.to_s] = v}
28
82
  end
29
- locals['yield'] = block.nil? ? '' : yield
83
+ locs.each{|k, v| locals[k.to_s] = v}
84
+ locals['yield'] = block_given? ? yield : ''
30
85
  locals['content'] = locals['yield']
31
86
  @engine.render(locals)
32
87
  end
@@ -34,11 +89,5 @@ module Tilt
34
89
  def allows_script?
35
90
  false
36
91
  end
37
-
38
- private
39
-
40
- def liquid_options
41
- { line_numbers: true }.merge options
42
- end
43
92
  end
44
93
  end
@@ -1,23 +1,18 @@
1
- require 'tilt/template'
2
- require 'livescript'
3
-
4
- module Tilt
5
- # LiveScript template implementation. See:
6
- # http://livescript.net/
7
- #
8
- # LiveScript templates do not support object scopes, locals, or yield.
9
- class LiveScriptTemplate < Template
10
- self.default_mime_type = 'application/javascript'
1
+ # frozen_string_literal: true
11
2
 
12
- def prepare
13
- end
3
+ # = LiveScript
4
+ #
5
+ # LiveScript template implementation.
6
+ #
7
+ # LiveScript templates do not support object scopes, locals, or yield.
8
+ #
9
+ # === See also
10
+ #
11
+ # * http://livescript.net
14
12
 
15
- def evaluate(scope, locals, &block)
16
- @output ||= LiveScript.compile(data, options)
17
- end
13
+ require_relative 'template'
14
+ require 'livescript'
18
15
 
19
- def allows_script?
20
- false
21
- end
22
- end
16
+ Tilt::LiveScriptTemplate = Tilt::StaticTemplate.subclass(mime_type: 'application/javascript') do
17
+ LiveScript.compile(@data, @options)
23
18
  end