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
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'template'
4
+
5
+ module Tilt
6
+ # Superclass used for pipeline templates. Should not be used directly.
7
+ class Pipeline < Template
8
+ def prepare
9
+ @pipeline = self.class::TEMPLATES.inject(proc{|*| data}) do |data, (klass, ext, options)|
10
+ proc do |s,l,&sb|
11
+ options = options
12
+ if ext_opts = @options[ext]
13
+ options = options.merge(ext_opts)
14
+ end
15
+ klass.new(file, line, options, &proc{|*| data.call(s, l, &sb)}).render(s, l, &sb)
16
+ end
17
+ end
18
+ end
19
+
20
+ def evaluate(scope, locals, &block)
21
+ @pipeline.call(scope, locals, &block)
22
+ end
23
+ end
24
+ end
data/lib/tilt/plain.rb CHANGED
@@ -1,16 +1,9 @@
1
- require 'tilt/template'
1
+ # frozen_string_literal: true
2
2
 
3
+ # = Plain
4
+ #
5
+ # Raw text (no template functionality).
3
6
 
4
- module Tilt
5
- # Raw text (no template functionality).
6
- class PlainTemplate < Template
7
- self.default_mime_type = 'text/html'
7
+ require_relative 'template'
8
8
 
9
- def prepare
10
- end
11
-
12
- def evaluate(scope, locals, &block)
13
- @output ||= data
14
- end
15
- end
16
- end
9
+ Tilt::PlainTemplate = Tilt::StaticTemplate.subclass{@data}
data/lib/tilt/prawn.rb CHANGED
@@ -1,43 +1,39 @@
1
- require 'tilt/template'
1
+ # frozen_string_literal: true
2
+
3
+ # = Prawn
4
+ #
5
+ # Prawn template implementation.
6
+ #
7
+ # === See also
8
+ #
9
+ # * http://prawnpdf.org
10
+ #
11
+ # === Related module
12
+ #
13
+ # * Tilt::PrawnTemplate
14
+
15
+ require_relative 'template'
2
16
  require 'prawn'
3
17
 
4
18
  module Tilt
5
- # Prawn template implementation. See: http://prawnpdf.org
6
- #
7
19
  class PrawnTemplate < Template
8
20
  self.default_mime_type = 'application/pdf'
9
-
21
+
10
22
  def prepare
11
- @engine = ::Prawn::Document.new(prawn_options)
23
+ @options[:page_size] = 'A4' unless @options.has_key?(:page_size)
24
+ @options[:page_layout] = :portrait unless @options.has_key?(:page_layout)
12
25
  end
13
-
26
+
14
27
  def evaluate(scope, locals, &block)
15
- pdf = @engine
16
- if data.respond_to?(:to_str)
17
- locals[:pdf] = pdf
18
- super(scope, locals, &block)
19
- elsif data.kind_of?(Proc)
20
- data.call(pdf)
21
- end
22
- @output ||= pdf.render
23
- end
24
-
25
- def allows_script?
26
- false
28
+ pdf = ::Prawn::Document.new(@options)
29
+ locals = locals.dup
30
+ locals[:pdf] = pdf
31
+ super
32
+ pdf.render
27
33
  end
28
-
34
+
29
35
  def precompiled_template(locals)
30
- data.to_str
36
+ @data.to_str
31
37
  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
38
  end
42
-
43
39
  end
data/lib/tilt/radius.rb CHANGED
@@ -1,44 +1,92 @@
1
- require 'tilt/template'
1
+ # frozen_string_literal: true
2
+
3
+ # = Radius (<tt>radius</tt>)
4
+ #
5
+ # {Radius}[http://radius.rubyforge.org] is the template language used by {Radiant CMS}[http://radiantcms.org]. It is
6
+ # a tag language designed to be valid XML/HTML.
7
+ #
8
+ # === Example
9
+ #
10
+ # <html>
11
+ # <body>
12
+ # <h1><r:title /></h1>
13
+ # <ul class="<r:type />">
14
+ # <r:repeat times="3">
15
+ # <li><r:hello />!</li>
16
+ # </r:repeat>
17
+ # </ul>
18
+ # <r:yield />
19
+ # </body>
20
+ # </html>
21
+ #
22
+ # === Usage
23
+ #
24
+ # To render a template such as the one above.
25
+ #
26
+ # scope = OpenStruct.new
27
+ # scope.title = "Radius Example"
28
+ # scope.hello = "Hello, World!"
29
+ #
30
+ # require 'radius'
31
+ # template = Tilt::RadiusTemplate.new('example.radius', :tag_prefix=>'r')
32
+ # template.render(scope, :type=>'hlist'){ "Jackpot!" }
33
+ #
34
+ # The result will be:
35
+ #
36
+ # <html>
37
+ # <body>
38
+ # <h1>Radius Example</h1>
39
+ # <ul class="hlist">
40
+ # <li>Hello, World!</li>
41
+ # <li>Hello, World!</li>
42
+ # <li>Hello, World!</li>
43
+ # </ul>
44
+ # Jackpot!
45
+ # </body>
46
+ # </html>
47
+ #
48
+ # === See also
49
+ #
50
+ # * {Radius}[http://radius.rubyforge.org]
51
+ # * {Radiant CMS}[http://radiantcms.org]
52
+ #
53
+ # === Related module
54
+ #
55
+ # * Tilt::RadiusTemplate
56
+
57
+ require_relative 'template'
2
58
  require 'radius'
3
59
 
4
60
  module Tilt
5
61
  # Radius Template
6
62
  # http://github.com/jlong/radius/
7
63
  class RadiusTemplate < Template
8
- def self.context_class
9
- @context_class ||= Class.new(Radius::Context) do
10
- attr_accessor :tilt_scope
11
-
12
- def tag_missing(name, attributes)
13
- tilt_scope.__send__(name)
14
- end
64
+ class ContextClass < Radius::Context
65
+ attr_accessor :tilt_scope
15
66
 
16
- def dup
17
- i = super
18
- i.tilt_scope = tilt_scope
19
- i
20
- end
67
+ def tag_missing(name, attributes)
68
+ tilt_scope.__send__(name)
21
69
  end
22
- end
23
70
 
24
- def prepare
71
+ def dup
72
+ i = super
73
+ i.tilt_scope = tilt_scope
74
+ i
75
+ end
25
76
  end
26
77
 
27
78
  def evaluate(scope, locals, &block)
28
- context = self.class.context_class.new
79
+ context = ContextClass.new
29
80
  context.tilt_scope = scope
30
- context.define_tag("yield") do
31
- block.call
32
- end
81
+ context.define_tag("yield", &block) if block
33
82
  locals.each do |tag, value|
34
83
  context.define_tag(tag) do
35
84
  value
36
85
  end
37
86
  end
38
87
 
39
- options = {:tag_prefix => 'r'}.merge(@options)
40
- parser = Radius::Parser.new(context, options)
41
- parser.parse(data)
88
+ @options[:tag_prefix] = 'r' unless @options.has_key?(:tag_prefix)
89
+ Radius::Parser.new(context, @options).parse(@data)
42
90
  end
43
91
 
44
92
  def allows_script?
@@ -1,39 +1,82 @@
1
- require 'tilt/template'
2
- require 'rdiscount'
3
-
4
- module Tilt
5
- # Discount Markdown implementation. See:
6
- # http://github.com/rtomayko/rdiscount
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'
1
+ # frozen_string_literal: true
13
2
 
14
- ALIAS = {
15
- :escape_html => :filter_html,
16
- :smartypants => :smart
17
- }
3
+ # = RDiscount (<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
+ # RDiscount is a simple text filter. It does not support +scope+ or
11
+ # +locals+. The +:smart+ and +:filter_html+ options may be set true
12
+ # to enable those flags on the underlying RDiscount object.
13
+ #
14
+ # === Example
15
+ #
16
+ # Hello Markdown Templates
17
+ # ========================
18
+ #
19
+ # Hello World. This is a paragraph.
20
+ #
21
+ # === Usage
22
+ #
23
+ # To wrap a Markdown formatted document with a layout:
24
+ #
25
+ # layout = Tilt['erb'].new do
26
+ # "<!doctype html><title></title><%= yield %>"
27
+ # end
28
+ # data = Tilt['md'].new { "# hello tilt" }
29
+ # layout.render { data.render }
30
+ # # => "<!doctype html><title></title><h1>hello tilt</h1>\n"
31
+ #
32
+ # === Options
33
+ #
34
+ # ==== <tt>:smartypants => true|false</tt>
35
+ #
36
+ # Set <tt>true</tt> to enable [Smarty Pants][smartypants] style punctuation replacement.
37
+ #
38
+ # ==== <tt>:escape_html => true|false</tt>
39
+ #
40
+ # Set <tt>true</tt> disallow raw HTML in Markdown contents. HTML is converted to
41
+ # literal text by escaping <tt><</tt> characters.
42
+ #
43
+ # === See also
44
+ #
45
+ # * {Markdown Syntax Documentation}[http://daringfireball.net/projects/markdown/syntax]
46
+ # * [Discount][discount]
47
+ # * {RDiscount}[http://github.com/rtomayko/rdiscount]
48
+ #
49
+ # -----------------------------------
50
+ #
51
+ # [Discount][discount] is an implementation of the Markdown markup language in C.
52
+ # [RDiscount][rdiscount] is a Ruby wrapper around Discount.
53
+ #
54
+ # All the documentation of {Markdown}[#markdown] applies in addition to the following:
55
+ #
56
+ # === Usage
57
+ #
58
+ # The <tt>Tilt::RDiscountTemplate</tt> class is registered for all files ending in
59
+ # <tt>.markdown</tt>, <tt>.md</tt> or <tt>.mkd</tt> by default with the highest priority. If you
60
+ # specifically want to use RDiscount, it's recommended to use <tt>#prefer</tt>:
61
+ #
62
+ # Tilt.prefer Tilt::RDiscountTemplate
63
+ #
64
+ # __NOTE:__ It's suggested that your program <tt>require 'rdiscount'</tt> at load time when
65
+ # using this template engine within a threaded environment.
18
66
 
19
- FLAGS = [:smart, :filter_html, :smartypants, :escape_html]
67
+ require_relative 'template'
68
+ require 'rdiscount'
20
69
 
21
- def flags
22
- FLAGS.select { |flag| options[flag] }.map { |flag| ALIAS[flag] || flag }
23
- end
70
+ aliases = {
71
+ :escape_html => :filter_html,
72
+ :smartypants => :smart
73
+ }.freeze
24
74
 
25
- def prepare
26
- @engine = RDiscount.new(data, *flags)
27
- @output = nil
28
- end
75
+ _flags = [:smart, :filter_html, :smartypants, :escape_html].freeze
29
76
 
30
- def evaluate(scope, locals, &block)
31
- @output ||= @engine.to_html
32
- end
77
+ Tilt::RDiscountTemplate = Tilt::StaticTemplate.subclass do
78
+ flags = _flags.select { |flag| @options[flag] }.
79
+ map! { |flag| aliases[flag] || flag }
33
80
 
34
- def allows_script?
35
- false
36
- end
37
- end
81
+ RDiscount.new(@data, *flags).to_html
38
82
  end
39
-
data/lib/tilt/rdoc.rb CHANGED
@@ -1,40 +1,33 @@
1
- require 'tilt/template'
1
+ # frozen_string_literal: true
2
+
3
+ # = RDoc (<tt>rdoc</tt>)
4
+ #
5
+ # {RDoc}[http://rdoc.rubyforge.org] is the simple text markup system that comes with Ruby's standard
6
+ # library.
7
+ #
8
+ # === Example
9
+ #
10
+ # = Hello RDoc Templates
11
+ #
12
+ # Hello World. This is a paragraph.
13
+ #
14
+ # === Usage
15
+ #
16
+ # __NOTE:__ It's suggested that your program <tt>require 'rdoc'</tt>,
17
+ # <tt>require 'rdoc/markup'</tt>, and <tt>require 'rdoc/markup/to_html'</tt> at load time
18
+ # when using this template engine in a threaded environment.
19
+ #
20
+ # === See also
21
+ #
22
+ # * {RDoc}[http://rdoc.rubyforge.org]
23
+ # * {RDoc Github}[https://github.com/ruby/rdoc]
24
+
25
+ require_relative 'template'
2
26
  require 'rdoc'
3
27
  require 'rdoc/markup'
4
28
  require 'rdoc/markup/to_html'
29
+ require 'rdoc/options'
5
30
 
6
- module Tilt
7
- # RDoc template. See:
8
- # http://rdoc.rubyforge.org/
9
- #
10
- # It's suggested that your program `require 'rdoc/markup'` and
11
- # `require 'rdoc/markup/to_html'` at load time when using this template
12
- # engine in a threaded environment.
13
- class RDocTemplate < Template
14
- self.default_mime_type = 'text/html'
15
-
16
- def markup
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
31
+ Tilt::RDocTemplate = Tilt::StaticTemplate.subclass do
32
+ RDoc::Markup::ToHtml.new(RDoc::Options.new, nil).convert(@data).to_s
40
33
  end
@@ -1,86 +1,73 @@
1
- require 'tilt/template'
1
+ # frozen_string_literal: true
2
+
3
+ # = Markdown (<tt>markdown</tt>, <tt>md</tt>, <tt>mkd</tt>)
4
+ #
5
+ # {Markdown}[http://daringfireball.net/projects/markdown/syntax] is a
6
+ # lightweight markup language, created by John Gruber and Aaron Swartz.
7
+ # For any markup that is not covered by Markdown’s syntax, HTML is used.
8
+ # Marking up plain text with Markdown markup is easy and Markdown
9
+ # formatted texts are readable.
10
+ #
11
+ # === Example
12
+ #
13
+ # Hello Markdown Templates
14
+ # ========================
15
+ #
16
+ # Hello World. This is a paragraph.
17
+ #
18
+ # === Usage
19
+ #
20
+ # To wrap a Markdown formatted document with a layout:
21
+ #
22
+ # layout = Tilt['erb'].new do
23
+ # "<!doctype html><title></title><%= yield %>"
24
+ # end
25
+ # data = Tilt['md'].new { "# hello tilt" }
26
+ # layout.render { data.render }
27
+ # # => "<!doctype html><title></title><h1>hello tilt</h1>\n"
28
+ #
29
+ # === Options
30
+ #
31
+ # ==== <tt>:smartypants => true|false</tt>
32
+ #
33
+ # Set <tt>true</tt> to enable [Smarty Pants][smartypants] style punctuation replacement.
34
+ #
35
+ # ==== <tt>:escape_html => true|false</tt>
36
+ #
37
+ # Set <tt>true</tt> disallow raw HTML in Markdown contents. HTML is converted to
38
+ # literal text by escaping <tt><</tt> characters.
39
+ #
40
+ # === See also
41
+ #
42
+ # * {Markdown Syntax Documentation}[http://daringfireball.net/projects/markdown/syntax]
43
+
44
+ require_relative 'template'
2
45
  require 'redcarpet'
3
46
 
4
- module Tilt
5
- # Compatibility mode for Redcarpet 1.x
6
- class Redcarpet1Template < Template
7
- self.default_mime_type = 'text/html'
47
+ aliases = {:escape_html => :filter_html, :smartypants => :smart}.freeze
8
48
 
9
- ALIAS = {
10
- :escape_html => :filter_html,
11
- :smartypants => :smart
12
- }
13
-
14
- FLAGS = [:smart, :filter_html, :smartypants, :escape_html]
15
-
16
- def flags
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
49
+ Tilt::RedcarpetTemplate = Tilt::StaticTemplate.subclass do
50
+ aliases.each do |opt, aka|
51
+ if options.key?(aka) || !@options.key?(opt)
52
+ @options[opt] = @options.delete(aka)
31
53
  end
32
54
  end
33
55
 
34
- # Future proof mode for Redcarpet 2.x (not yet released)
35
- class Redcarpet2Template < Template
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
42
-
43
- if renderer == ::Redcarpet::Render::XHTML
44
- ::Redcarpet::Render::SmartyHTML.new(:xhtml => true)
45
- elsif renderer == ::Redcarpet::Render::HTML
46
- ::Redcarpet::Render::SmartyHTML
47
- elsif renderer.is_a? Class
48
- Class.new(renderer) { include ::Redcarpet::Render::SmartyPants }
49
- else
50
- renderer.extend ::Redcarpet::Render::SmartyPants
51
- end
52
- end
53
-
54
- def prepare
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
56
+ # only raise an exception if someone is trying to enable :escape_html
57
+ @options.delete(:escape_html) unless @options[:escape_html]
58
+
59
+ renderer = @options.delete(:renderer) || ::Redcarpet::Render::HTML.new(@options)
60
+ if options.delete(:smartypants) && !(renderer.is_a?(Class) && renderer <= ::Redcarpet::Render::SmartyPants)
61
+ renderer = if renderer == ::Redcarpet::Render::XHTML
62
+ ::Redcarpet::Render::SmartyHTML.new(:xhtml => true)
63
+ elsif renderer == ::Redcarpet::Render::HTML
64
+ ::Redcarpet::Render::SmartyHTML
65
+ elsif renderer.is_a? Class
66
+ Class.new(renderer) { include ::Redcarpet::Render::SmartyPants }
67
+ else
68
+ renderer.extend ::Redcarpet::Render::SmartyPants
66
69
  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
- superclass = Redcarpet2Template
79
- else
80
- superclass = Redcarpet1Template
81
70
  end
82
71
 
83
- class RedcarpetTemplate < superclass
84
- end
72
+ Redcarpet::Markdown.new(renderer, @options).render(@data)
85
73
  end
86
-
data/lib/tilt/redcloth.rb CHANGED
@@ -1,23 +1,40 @@
1
- require 'tilt/template'
2
- require 'redcloth'
1
+ # frozen_string_literal: true
3
2
 
4
- module Tilt
5
- # RedCloth implementation. See:
6
- # http://redcloth.org/
7
- class RedClothTemplate < Template
8
- def prepare
9
- @engine = RedCloth.new(data)
10
- options.each {|k, v| @engine.send("#{k}=", v) if @engine.respond_to? "#{k}="}
11
- @output = nil
12
- end
3
+ # = Textile (<tt>textile</tt>)
4
+ #
5
+ # Textile is a lightweight markup language originally developed by Dean Allen and
6
+ # billed as a "humane Web text generator". Textile converts its marked-up text
7
+ # input to valid, well-formed XHTML and also inserts character entity references
8
+ # for apostrophes, opening and closing single and double quotation marks,
9
+ # ellipses and em dashes.
10
+ #
11
+ # Textile formatted texts are converted to HTML with the {RedCloth}[http://redcloth.org]
12
+ # engine, which is a Ruby extension written in C.
13
+ #
14
+ # === Example
15
+ #
16
+ # h1. Hello Textile Templates
17
+ #
18
+ # Hello World. This is a paragraph.
19
+ #
20
+ # === Usage
21
+ #
22
+ # __NOTE:__ It's suggested that your program <tt>require 'redcloth'</tt> at load time
23
+ # when using this template engine in a threaded environment.
24
+ #
25
+ # === See Also
26
+ #
27
+ # * {RedCloth}[http://redcloth.org]
28
+ # * https://github.com/jgarber/redcloth
13
29
 
14
- def evaluate(scope, locals, &block)
15
- @output ||= @engine.to_html
16
- end
30
+ require_relative 'template'
31
+ require 'redcloth'
17
32
 
18
- def allows_script?
19
- false
20
- end
33
+ Tilt::RedClothTemplate = Tilt::StaticTemplate.subclass do
34
+ engine = RedCloth.new(@data)
35
+ @options.each do |k, v|
36
+ m = :"#{k}="
37
+ engine.send(m, v) if engine.respond_to? m
21
38
  end
39
+ engine.to_html
22
40
  end
23
-
@@ -1,23 +1,33 @@
1
- require 'tilt/template'
2
- require 'pandoc'
1
+ # frozen_string_literal: true
3
2
 
4
- module Tilt
5
- # Pandoc reStructuredText implementation. See:
6
- # http://pandoc.org/
7
- class RstPandocTemplate < PandocTemplate
8
- self.default_mime_type = 'text/html'
3
+ # = reStructuredText (<tt>rst</tt>)
4
+ #
5
+ # reStructuredText is a lightweight markup language originally developed by David Goodger,
6
+ # based on StructuredText and Setext. reStructuredText is primarily used for technical
7
+ # documentation in the Python programming language community, e.g. by the
8
+ # {Sphinx}[http://www.sphinx-doc.org/en/stable/rest.html] Python documentation generator.
9
+ #
10
+ # reStructuredText formatted texts are converted to HTML with {Pandoc}[http://pandoc.org/], which
11
+ # is an application written in Haskell, with a Ruby wrapper provided by the
12
+ # {pandoc-ruby}[https://github.com/alphabetum/pandoc-ruby] gem.
13
+ #
14
+ # === Example
15
+ #
16
+ # Hello Rst Templates
17
+ # ===================
18
+ #
19
+ # Hello World. This is a paragraph.
20
+ #
21
+ # === See Also
22
+ #
23
+ # * {Pandoc}[http://pandoc.org/]
24
+ # * {pandoc-ruby}[https://github.com/alphabetum/pandoc-ruby]
9
25
 
10
- def prepare
11
- @engine = PandocRuby.new(data, :f => "rst")
12
- @output = nil
13
- end
26
+ require_relative 'template'
27
+ require_relative 'pandoc'
14
28
 
15
- def evaluate(scope, locals, &block)
16
- @output ||= @engine.to_html.strip
17
- end
29
+ rst = {:f => "rst"}.freeze
18
30
 
19
- def allows_script?
20
- false
21
- end
22
- end
31
+ Tilt::RstPandocTemplate = Tilt::StaticTemplate.subclass do
32
+ PandocRuby.new(@data, rst).to_html.strip
23
33
  end