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.
- 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 +18 -23
- data/lib/tilt/babel.rb +9 -12
- data/lib/tilt/builder.rb +22 -13
- data/lib/tilt/cli.rb +134 -0
- data/lib/tilt/coffee.rb +26 -35
- data/lib/tilt/commonmarker.rb +123 -75
- data/lib/tilt/csv.rb +41 -43
- data/lib/tilt/erb.rb +90 -23
- data/lib/tilt/erubi.rb +70 -14
- data/lib/tilt/etanni.rb +12 -4
- data/lib/tilt/haml.rb +139 -65
- data/lib/tilt/kramdown.rb +54 -20
- data/lib/tilt/liquid.rb +75 -26
- data/lib/tilt/livescript.rb +14 -19
- data/lib/tilt/mapping.rb +233 -114
- data/lib/tilt/markaby.rb +16 -9
- data/lib/tilt/nokogiri.rb +24 -12
- data/lib/tilt/pandoc.rb +75 -51
- data/lib/tilt/pipeline.rb +24 -0
- data/lib/tilt/plain.rb +6 -13
- data/lib/tilt/prawn.rb +26 -30
- data/lib/tilt/radius.rb +70 -22
- data/lib/tilt/rdiscount.rb +75 -32
- data/lib/tilt/rdoc.rb +28 -35
- data/lib/tilt/redcarpet.rb +63 -76
- data/lib/tilt/redcloth.rb +35 -18
- data/lib/tilt/rst-pandoc.rb +28 -18
- data/lib/tilt/sass.rb +58 -45
- data/lib/tilt/slim.rb +18 -0
- data/lib/tilt/string.rb +19 -5
- data/lib/tilt/template.rb +392 -89
- data/lib/tilt/typescript.rb +15 -17
- data/lib/tilt/yajl.rb +51 -47
- data/lib/tilt.rb +68 -44
- metadata +22 -19
- data/lib/tilt/bluecloth.rb +0 -24
- data/lib/tilt/creole.rb +0 -25
- data/lib/tilt/dummy.rb +0 -3
- data/lib/tilt/erubis.rb +0 -43
- data/lib/tilt/less.rb +0 -30
- data/lib/tilt/maruku.rb +0 -22
- data/lib/tilt/sigil.rb +0 -34
- data/lib/tilt/wikicloth.rb +0 -22
data/lib/tilt/commonmarker.rb
CHANGED
|
@@ -1,88 +1,136 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
+
# ==== <tt>:smartypants => true|false</tt>
|
|
31
|
+
#
|
|
32
|
+
# Set <tt>true</tt> to enable [Smarty Pants][smartypants] style punctuation replacement.
|
|
33
|
+
#
|
|
34
|
+
# ==== <tt>:escape_html => true|false</tt>
|
|
35
|
+
#
|
|
36
|
+
# Set <tt>true</tt> disallow raw HTML in Markdown contents. HTML is converted to
|
|
37
|
+
# literal text by escaping <tt><</tt> characters.
|
|
38
|
+
#
|
|
39
|
+
# === See also
|
|
40
|
+
#
|
|
41
|
+
# * {Markdown Syntax Documentation}[http://daringfireball.net/projects/markdown/syntax]
|
|
3
42
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
self.default_mime_type = 'text/html'
|
|
43
|
+
require_relative 'template'
|
|
44
|
+
require 'commonmarker'
|
|
7
45
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
].freeze
|
|
46
|
+
if defined?(::Commonmarker)
|
|
47
|
+
aliases = {
|
|
48
|
+
:smartypants => :smart
|
|
49
|
+
}.freeze
|
|
50
|
+
parse_opts = [
|
|
51
|
+
:smart,
|
|
52
|
+
:default_info_string,
|
|
53
|
+
].freeze
|
|
54
|
+
render_opts = [
|
|
55
|
+
:hardbreaks,
|
|
56
|
+
:github_pre_lang,
|
|
57
|
+
:width,
|
|
58
|
+
:unsafe,
|
|
59
|
+
:escape,
|
|
60
|
+
:sourcepos,
|
|
61
|
+
].freeze
|
|
62
|
+
exts = [
|
|
63
|
+
:strikethrough,
|
|
64
|
+
:tagfilter,
|
|
65
|
+
:table,
|
|
66
|
+
:autolink,
|
|
67
|
+
:tasklist,
|
|
68
|
+
:superscript,
|
|
69
|
+
:header_ids,
|
|
70
|
+
:footnotes,
|
|
71
|
+
:description_lists,
|
|
72
|
+
:front_matter_delimiter,
|
|
73
|
+
:shortcodes,
|
|
74
|
+
].freeze
|
|
38
75
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
76
|
+
Tilt::CommonMarkerTemplate = Tilt::StaticTemplate.subclass do
|
|
77
|
+
parse_options = @options.select { |key, _| parse_opts.include?(key.downcase) }.transform_keys(&:downcase)
|
|
78
|
+
parse_options.merge!(@options.select { |key, _| aliases.has_key?(key) }.transform_keys { |key| aliases[key] })
|
|
79
|
+
render_options = @options.select { |key, _| render_opts.include?(key.downcase) }.transform_keys(&:downcase)
|
|
80
|
+
extensions = @options.select { |key, _| exts.include?(key) }.transform_keys(&:downcase)
|
|
44
81
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
82
|
+
Commonmarker.to_html(@data, options: { parse: parse_options, render: render_options, extension: extensions })
|
|
83
|
+
end
|
|
84
|
+
# :nocov:
|
|
85
|
+
else
|
|
86
|
+
aliases = {
|
|
87
|
+
:smartypants => :SMART
|
|
88
|
+
}.freeze
|
|
89
|
+
parse_opts = [
|
|
90
|
+
:FOOTNOTES,
|
|
91
|
+
:LIBERAL_HTML_TAG,
|
|
92
|
+
:SMART,
|
|
93
|
+
:smartypants,
|
|
94
|
+
:STRIKETHROUGH_DOUBLE_TILDE,
|
|
95
|
+
:UNSAFE,
|
|
96
|
+
:VALIDATE_UTF8,
|
|
97
|
+
].freeze
|
|
98
|
+
render_opts = [
|
|
99
|
+
:FOOTNOTES,
|
|
100
|
+
:FULL_INFO_STRING,
|
|
101
|
+
:GITHUB_PRE_LANG,
|
|
102
|
+
:HARDBREAKS,
|
|
103
|
+
:NOBREAKS,
|
|
104
|
+
:SAFE, # Removed in v0.18.0 (2018-10-17)
|
|
105
|
+
:SOURCEPOS,
|
|
106
|
+
:TABLE_PREFER_STYLE_ATTRIBUTES,
|
|
107
|
+
:UNSAFE,
|
|
108
|
+
].freeze
|
|
109
|
+
exts = [
|
|
110
|
+
:autolink,
|
|
111
|
+
:strikethrough,
|
|
112
|
+
:table,
|
|
113
|
+
:tagfilter,
|
|
114
|
+
:tasklist,
|
|
115
|
+
].freeze
|
|
52
116
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
:DEFAULT
|
|
57
|
-
end
|
|
117
|
+
Tilt::CommonMarkerTemplate = Tilt::StaticTemplate.subclass do
|
|
118
|
+
extensions = exts.select do |extension|
|
|
119
|
+
@options[extension]
|
|
58
120
|
end
|
|
59
121
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
options[option]
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
OPTION_ALIAS[option] || option
|
|
122
|
+
parse_options, render_options = [parse_opts, render_opts].map do |opts|
|
|
123
|
+
opts = opts.select do |option|
|
|
124
|
+
@options[option]
|
|
125
|
+
end.map! do |option|
|
|
126
|
+
aliases[option] || option
|
|
66
127
|
end
|
|
67
|
-
if actual_options.any?
|
|
68
|
-
actual_options
|
|
69
|
-
else
|
|
70
|
-
:DEFAULT
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
128
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
@output = nil
|
|
129
|
+
opts = :DEFAULT unless opts.any?
|
|
130
|
+
opts
|
|
77
131
|
end
|
|
78
132
|
|
|
79
|
-
|
|
80
|
-
doc = CommonMarker.render_doc(data, parse_options, extensions)
|
|
81
|
-
doc.to_html(render_options, extensions)
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
def allows_script?
|
|
85
|
-
false
|
|
86
|
-
end
|
|
133
|
+
CommonMarker.render_doc(@data, parse_options, extensions).to_html(render_options, extensions)
|
|
87
134
|
end
|
|
88
135
|
end
|
|
136
|
+
# :nocov:
|
data/lib/tilt/csv.rb
CHANGED
|
@@ -1,57 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# = CSV
|
|
4
|
+
#
|
|
5
|
+
# CSV Template implementation.
|
|
6
|
+
#
|
|
7
|
+
# === Example
|
|
8
|
+
#
|
|
9
|
+
# # Example of csv template
|
|
10
|
+
# tpl = <<-EOS
|
|
11
|
+
# # header
|
|
12
|
+
# csv << ['NAME', 'ID']
|
|
13
|
+
#
|
|
14
|
+
# # data rows
|
|
15
|
+
# @people.each do |person|
|
|
16
|
+
# csv << [person[:name], person[:id]]
|
|
17
|
+
# end
|
|
18
|
+
# EOS
|
|
19
|
+
#
|
|
20
|
+
# @people = [
|
|
21
|
+
# {:name => "Joshua Peek", :id => 1},
|
|
22
|
+
# {:name => "Ryan Tomayko", :id => 2},
|
|
23
|
+
# {:name => "Simone Carletti", :id => 3}
|
|
24
|
+
# ]
|
|
25
|
+
#
|
|
26
|
+
# template = Tilt::CSVTemplate.new { tpl }
|
|
27
|
+
# template.render(self)
|
|
28
|
+
#
|
|
29
|
+
# === See also
|
|
30
|
+
#
|
|
31
|
+
# * http://ruby-doc.org/stdlib/libdoc/csv/rdoc/CSV.html
|
|
32
|
+
#
|
|
33
|
+
# === Related module
|
|
34
|
+
#
|
|
35
|
+
# * Tilt::CSVTemplate
|
|
36
|
+
|
|
37
|
+
require_relative 'template'
|
|
38
|
+
require 'csv'
|
|
8
39
|
|
|
9
40
|
module Tilt
|
|
10
41
|
|
|
11
|
-
# CSV Template implementation. See:
|
|
12
|
-
# http://ruby-doc.org/stdlib/libdoc/csv/rdoc/CSV.html
|
|
13
|
-
#
|
|
14
|
-
# == Example
|
|
15
|
-
#
|
|
16
|
-
# # Example of csv template
|
|
17
|
-
# tpl = <<-EOS
|
|
18
|
-
# # header
|
|
19
|
-
# csv << ['NAME', 'ID']
|
|
20
|
-
#
|
|
21
|
-
# # data rows
|
|
22
|
-
# @people.each do |person|
|
|
23
|
-
# csv << [person[:name], person[:id]]
|
|
24
|
-
# end
|
|
25
|
-
# EOS
|
|
26
|
-
#
|
|
27
|
-
# @people = [
|
|
28
|
-
# {:name => "Joshua Peek", :id => 1},
|
|
29
|
-
# {:name => "Ryan Tomayko", :id => 2},
|
|
30
|
-
# {:name => "Simone Carletti", :id => 3}
|
|
31
|
-
# ]
|
|
32
|
-
#
|
|
33
|
-
# template = Tilt::CSVTemplate.new { tpl }
|
|
34
|
-
# template.render(self)
|
|
35
|
-
#
|
|
36
42
|
class CSVTemplate < Template
|
|
37
43
|
self.default_mime_type = 'text/csv'
|
|
38
44
|
|
|
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
45
|
def prepare
|
|
48
|
-
@outvar = options.delete(:outvar) || '_csvout'
|
|
46
|
+
@outvar = @options.delete(:outvar) || '_csvout'
|
|
49
47
|
end
|
|
50
48
|
|
|
51
49
|
def precompiled_template(locals)
|
|
52
50
|
<<-RUBY
|
|
53
|
-
#{@outvar} =
|
|
54
|
-
#{data}
|
|
51
|
+
#{@outvar} = CSV.generate(**#{@options}) do |csv|
|
|
52
|
+
#{@data}
|
|
55
53
|
end
|
|
56
54
|
RUBY
|
|
57
55
|
end
|
data/lib/tilt/erb.rb
CHANGED
|
@@ -1,30 +1,95 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# = ERB (<tt>erb</tt>, <tt>rhtml</tt>)
|
|
4
|
+
#
|
|
5
|
+
# ERB is a simple but powerful template languge for Ruby. In Tilt it's
|
|
6
|
+
# backed by {Erubi}[rdoc-ref:lib/tilt/erubi.rb] (if installed on your system] or by
|
|
7
|
+
# {erb.rb}[rdoc-ref:lib/tilt/erb.rb] (which is included in Ruby's standard library]. This
|
|
8
|
+
# documentation applies to both implementations.
|
|
9
|
+
#
|
|
10
|
+
# === Example
|
|
11
|
+
#
|
|
12
|
+
# Hello <%= world %>!
|
|
13
|
+
#
|
|
14
|
+
# === Usage
|
|
15
|
+
#
|
|
16
|
+
# ERB templates support custom evaluation scopes and locals:
|
|
17
|
+
#
|
|
18
|
+
# >> require 'erb'
|
|
19
|
+
# >> template = Tilt.new('hello.html.erb')
|
|
20
|
+
# >> template.render(self, :world => 'World!')
|
|
21
|
+
# => "Hello World!"
|
|
22
|
+
#
|
|
23
|
+
# Or, use <tt>Tilt['erb']</tt> directly to process strings:
|
|
24
|
+
#
|
|
25
|
+
# template = Tilt['erb'].new { "Hello <%= world %>!" }
|
|
26
|
+
# template.render(self, :world => 'World!')
|
|
27
|
+
#
|
|
28
|
+
# The <tt>Tilt::ERBTemplate</tt> class is registered for all files ending in <tt>.erb</tt> or
|
|
29
|
+
# <tt>.rhtml</tt> by default, but with a *lower* priority than ErubiTemplate.
|
|
30
|
+
# If you specifically want to use ERB, it's recommended to use
|
|
31
|
+
# <tt>#prefer</tt>:
|
|
32
|
+
#
|
|
33
|
+
# Tilt.prefer Tilt::ERBTemplate
|
|
34
|
+
#
|
|
35
|
+
# __NOTE:__ It's suggested that your program <tt>require 'erb'</tt> at load time when
|
|
36
|
+
# using this template engine within a threaded environment.
|
|
37
|
+
#
|
|
38
|
+
# === Options
|
|
39
|
+
#
|
|
40
|
+
# ==== <tt>:trim => trim</tt>
|
|
41
|
+
#
|
|
42
|
+
# The ERB trim mode flags. This is a string consisting of any combination of the
|
|
43
|
+
# following characters:
|
|
44
|
+
#
|
|
45
|
+
# * <tt>'>'</tt> omits newlines for lines ending in <tt>></tt>
|
|
46
|
+
# * <tt>'<>'</tt> omits newlines for lines starting with <tt><%</tt> and ending in <tt>%></tt>
|
|
47
|
+
# * <tt>'%'</tt> enables processing of lines beginning with <tt>%</tt>
|
|
48
|
+
# * <tt>true</tt> is an alias of <tt><></tt>
|
|
49
|
+
#
|
|
50
|
+
# ==== <tt>:outvar => '_erbout'</tt>
|
|
51
|
+
#
|
|
52
|
+
# The name of the variable used to accumulate template output. This can be
|
|
53
|
+
# any valid Ruby expression but must be assignable. By default a local
|
|
54
|
+
# variable named <tt>_erbout</tt> is used.
|
|
55
|
+
#
|
|
56
|
+
# ==== <tt>:freeze => false</tt>
|
|
57
|
+
#
|
|
58
|
+
# If set to true, will set the <tt>frozen_string_literal</tt> flag in the compiled
|
|
59
|
+
# template code, so that string literals inside the templates will be frozen.
|
|
60
|
+
#
|
|
61
|
+
# === See also
|
|
62
|
+
#
|
|
63
|
+
# * http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB.html
|
|
64
|
+
#
|
|
65
|
+
# === Related module
|
|
66
|
+
#
|
|
67
|
+
# * Tilt::ERBTemplate
|
|
68
|
+
|
|
69
|
+
require_relative 'template'
|
|
2
70
|
require 'erb'
|
|
3
71
|
|
|
4
72
|
module Tilt
|
|
5
|
-
# ERB template implementation. See:
|
|
6
|
-
# http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB.html
|
|
7
73
|
class ERBTemplate < Template
|
|
8
|
-
@@default_output_variable = '_erbout'
|
|
9
|
-
|
|
10
74
|
SUPPORTS_KVARGS = ::ERB.instance_method(:initialize).parameters.assoc(:key) rescue false
|
|
11
75
|
|
|
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
76
|
def prepare
|
|
22
|
-
@
|
|
23
|
-
|
|
77
|
+
@freeze_string_literals = !!@options[:freeze]
|
|
78
|
+
@outvar = @options[:outvar] || '_erbout'
|
|
79
|
+
trim = case @options[:trim]
|
|
80
|
+
when false
|
|
81
|
+
nil
|
|
82
|
+
when nil, true
|
|
83
|
+
'<>'
|
|
84
|
+
else
|
|
85
|
+
@options[:trim]
|
|
86
|
+
end
|
|
24
87
|
@engine = if SUPPORTS_KVARGS
|
|
25
|
-
::ERB.new(data, trim_mode:
|
|
88
|
+
::ERB.new(@data, trim_mode: trim, eoutvar: @outvar)
|
|
89
|
+
# :nocov:
|
|
26
90
|
else
|
|
27
|
-
::ERB.new(data, options[:safe],
|
|
91
|
+
::ERB.new(@data, options[:safe], trim, @outvar)
|
|
92
|
+
# :nocov:
|
|
28
93
|
end
|
|
29
94
|
end
|
|
30
95
|
|
|
@@ -52,11 +117,13 @@ module Tilt
|
|
|
52
117
|
|
|
53
118
|
# ERB generates a line to specify the character coding of the generated
|
|
54
119
|
# source in 1.9. Account for this in the line offset.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
120
|
+
def precompiled(locals)
|
|
121
|
+
source, offset = super
|
|
122
|
+
[source, offset + 1]
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def freeze_string_literals?
|
|
126
|
+
@freeze_string_literals
|
|
60
127
|
end
|
|
61
128
|
end
|
|
62
129
|
end
|
data/lib/tilt/erubi.rb
CHANGED
|
@@ -1,26 +1,78 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# = Erubi (<tt>erb</tt>, <tt>rhtml</tt>, <tt>erubi</tt>)
|
|
4
|
+
#
|
|
5
|
+
# {Erubi}[https://github.com/jeremyevans/erubi] is an ERB implementation that uses the same algorithm as
|
|
6
|
+
# the erubis gem, but is maintained and offers numerous improvements.
|
|
7
|
+
#
|
|
8
|
+
# All the documentation of {ERB}[rdoc-ref:lib/tilt/erb.rb] applies in addition to the following:
|
|
9
|
+
#
|
|
10
|
+
# === Usage
|
|
11
|
+
#
|
|
12
|
+
# The <tt>Tilt::ErubiTemplate</tt> class is registered for all files ending in <tt>.erb</tt> or
|
|
13
|
+
# <tt>.rhtml</tt> by default, with the *highest* priority.
|
|
14
|
+
#
|
|
15
|
+
# __NOTE:__ It's suggested that your program <tt>require 'erubi'</tt> at load time when
|
|
16
|
+
# using this template engine within a threaded environment.
|
|
17
|
+
#
|
|
18
|
+
# === Options
|
|
19
|
+
#
|
|
20
|
+
# ==== <tt>:engine_class => Erubi::Engine</tt>
|
|
21
|
+
#
|
|
22
|
+
# Allows you to specify a custom engine class to use instead of the
|
|
23
|
+
# default which is <tt>Erubi::Engine</tt>.
|
|
24
|
+
#
|
|
25
|
+
# ==== Other
|
|
26
|
+
#
|
|
27
|
+
# Other options are passed to the constructor of the engine class.
|
|
28
|
+
#
|
|
29
|
+
# ErubiTemplate supports the following additional options, in addition
|
|
30
|
+
# to the options supported by the Erubi engine:
|
|
31
|
+
#
|
|
32
|
+
# :engine_class :: allows you to specify a custom engine class to use
|
|
33
|
+
# instead of the default (which is ::Erubi::Engine).
|
|
34
|
+
#
|
|
35
|
+
# === See also
|
|
36
|
+
#
|
|
37
|
+
# * {Erubi Home}[https://github.com/jeremyevans/erubi]
|
|
38
|
+
#
|
|
39
|
+
# === Related module
|
|
40
|
+
#
|
|
41
|
+
# * Tilt::ErubiTemplate
|
|
42
|
+
|
|
43
|
+
require_relative 'template'
|
|
2
44
|
require 'erubi'
|
|
3
45
|
|
|
4
46
|
module Tilt
|
|
5
|
-
# Erubi (a simplified version of Erubis) template implementation.
|
|
6
|
-
# See https://github.com/jeremyevans/erubi
|
|
7
|
-
#
|
|
8
|
-
# ErubiTemplate supports the following additional options, in addition
|
|
9
|
-
# to the options supported by the Erubi engine:
|
|
10
|
-
#
|
|
11
|
-
# :engine_class :: allows you to specify a custom engine class to use
|
|
12
|
-
# instead of the default (which is ::Erubi::Engine).
|
|
13
47
|
class ErubiTemplate < Template
|
|
14
48
|
def prepare
|
|
15
|
-
@options
|
|
49
|
+
@options[:preamble] = false
|
|
50
|
+
@options[:postamble] = false
|
|
51
|
+
@options[:ensure] = true
|
|
16
52
|
|
|
17
53
|
engine_class = @options[:engine_class] || Erubi::Engine
|
|
18
54
|
|
|
19
|
-
|
|
20
|
-
|
|
55
|
+
# If :freeze option is given, the intent is to setup frozen string
|
|
56
|
+
# literals in the template. So enable frozen string literals in the
|
|
57
|
+
# code Tilt generates if the :freeze option is given.
|
|
58
|
+
if @freeze_string_literals = !!@options[:freeze]
|
|
59
|
+
# Passing the :freeze option to Erubi sets the
|
|
60
|
+
# frozen-string-literal magic comment, which doesn't have an effect
|
|
61
|
+
# with Tilt as Tilt wraps the resulting code. Worse, the magic
|
|
62
|
+
# comment appearing not at the top of the file can cause a warning.
|
|
63
|
+
# So remove the :freeze option before passing to Erubi.
|
|
64
|
+
@options.delete(:freeze)
|
|
21
65
|
|
|
22
|
-
|
|
23
|
-
|
|
66
|
+
# Erubi by default appends .freeze to template literals on Ruby 2.1+,
|
|
67
|
+
# but that is not necessary and slows down code when Tilt is using
|
|
68
|
+
# frozen string literals, so pass the :freeze_template_literals
|
|
69
|
+
# option to not append .freeze.
|
|
70
|
+
@options[:freeze_template_literals] = false
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
@engine = engine_class.new(@data, @options)
|
|
74
|
+
@outvar = @engine.bufvar
|
|
75
|
+
@src = @engine.src
|
|
24
76
|
|
|
25
77
|
@engine
|
|
26
78
|
end
|
|
@@ -28,5 +80,9 @@ module Tilt
|
|
|
28
80
|
def precompiled_template(locals)
|
|
29
81
|
@src
|
|
30
82
|
end
|
|
83
|
+
|
|
84
|
+
def freeze_string_literals?
|
|
85
|
+
@freeze_string_literals
|
|
86
|
+
end
|
|
31
87
|
end
|
|
32
88
|
end
|
data/lib/tilt/etanni.rb
CHANGED
|
@@ -1,18 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# = Etanni
|
|
4
|
+
#
|
|
5
|
+
# === Related module
|
|
6
|
+
#
|
|
7
|
+
# * Tilt::EtanniTemplate
|
|
8
|
+
|
|
9
|
+
require_relative 'template'
|
|
2
10
|
|
|
3
11
|
module Tilt
|
|
4
12
|
class EtanniTemplate < Template
|
|
5
13
|
def prepare
|
|
6
14
|
separator = data.hash.abs
|
|
7
|
-
chomp = "<<#{separator}.chomp
|
|
15
|
+
chomp = "<<#{separator}.chomp"
|
|
8
16
|
start = "\n_out_ << #{chomp}\n"
|
|
9
17
|
stop = "\n#{separator}\n"
|
|
10
18
|
replacement = "#{stop}\\1#{start}"
|
|
11
19
|
|
|
12
|
-
temp = data.strip
|
|
20
|
+
temp = @data.strip
|
|
13
21
|
temp.gsub!(/<\?r\s+(.*?)\s+\?>/m, replacement)
|
|
14
22
|
|
|
15
|
-
@code = "_out_ = [<<#{separator}.chomp
|
|
23
|
+
@code = "_out_ = [<<#{separator}.chomp]\n#{temp}#{stop}_out_.join"
|
|
16
24
|
end
|
|
17
25
|
|
|
18
26
|
def precompiled_template(locals)
|