tilt 2.0.11 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tilt/bluecloth.rb +2 -0
- data/lib/tilt/csv.rb +2 -15
- data/lib/tilt/erb.rb +18 -8
- data/lib/tilt/erubi.rb +22 -0
- data/lib/tilt/erubis.rb +8 -5
- data/lib/tilt/haml.rb +69 -64
- data/lib/tilt/less.rb +2 -0
- data/lib/tilt/mapping.rb +59 -16
- data/lib/tilt/pipeline.rb +18 -0
- data/lib/tilt/rst-pandoc.rb +1 -1
- data/lib/tilt/sigil.rb +2 -0
- data/lib/tilt/template.rb +84 -27
- data/lib/tilt.rb +12 -8
- metadata +14 -8
- data/lib/tilt/dummy.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 837e8836cd6aacedb861823faead2fd72549f1c750e2f0350471303c1ca5cab3
|
4
|
+
data.tar.gz: 578c1873d63eb0e2426e2c86199f414f516952562c85ee9e91e0907a936603b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a63e7b55aacbe374f70317cddd821c065ae512622be8f20bc25aeb2aabd5455d91cb7d97894de420f3bfb4f7c571c5f832047db182bb35107fd6d566879c04d7
|
7
|
+
data.tar.gz: 2c2785a08edb15f9e593a1b717682212f5a50f1f6694c02256179ee15c9a1e73429a5c6ae804e83611cc645209330c36ea117c6d38698f0021e2a7d748c59919
|
data/lib/tilt/bluecloth.rb
CHANGED
data/lib/tilt/csv.rb
CHANGED
@@ -1,10 +1,5 @@
|
|
1
1
|
require 'tilt/template'
|
2
|
-
|
3
|
-
if RUBY_VERSION >= '1.9.0'
|
4
|
-
require 'csv'
|
5
|
-
else
|
6
|
-
require 'fastercsv'
|
7
|
-
end
|
2
|
+
require 'csv'
|
8
3
|
|
9
4
|
module Tilt
|
10
5
|
|
@@ -36,21 +31,13 @@ module Tilt
|
|
36
31
|
class CSVTemplate < Template
|
37
32
|
self.default_mime_type = 'text/csv'
|
38
33
|
|
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
34
|
def prepare
|
48
35
|
@outvar = options.delete(:outvar) || '_csvout'
|
49
36
|
end
|
50
37
|
|
51
38
|
def precompiled_template(locals)
|
52
39
|
<<-RUBY
|
53
|
-
#{@outvar} =
|
40
|
+
#{@outvar} = CSV.generate(**#{options}) do |csv|
|
54
41
|
#{data}
|
55
42
|
end
|
56
43
|
RUBY
|
data/lib/tilt/erb.rb
CHANGED
@@ -19,12 +19,20 @@ module Tilt
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def prepare
|
22
|
+
@freeze_string_literals = !!@options[:freeze]
|
22
23
|
@outvar = options[:outvar] || self.class.default_output_variable
|
23
|
-
|
24
|
+
trim = case options[:trim]
|
25
|
+
when false
|
26
|
+
nil
|
27
|
+
when nil, true
|
28
|
+
'<>'
|
29
|
+
else
|
30
|
+
options[:trim]
|
31
|
+
end
|
24
32
|
@engine = if SUPPORTS_KVARGS
|
25
|
-
::ERB.new(data, trim_mode:
|
33
|
+
::ERB.new(data, trim_mode: trim, eoutvar: @outvar)
|
26
34
|
else
|
27
|
-
::ERB.new(data, options[:safe],
|
35
|
+
::ERB.new(data, options[:safe], trim, @outvar)
|
28
36
|
end
|
29
37
|
end
|
30
38
|
|
@@ -52,11 +60,13 @@ module Tilt
|
|
52
60
|
|
53
61
|
# ERB generates a line to specify the character coding of the generated
|
54
62
|
# source in 1.9. Account for this in the line offset.
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
63
|
+
def precompiled(locals)
|
64
|
+
source, offset = super
|
65
|
+
[source, offset + 1]
|
66
|
+
end
|
67
|
+
|
68
|
+
def freeze_string_literals?
|
69
|
+
@freeze_string_literals
|
60
70
|
end
|
61
71
|
end
|
62
72
|
end
|
data/lib/tilt/erubi.rb
CHANGED
@@ -16,6 +16,24 @@ module Tilt
|
|
16
16
|
|
17
17
|
engine_class = @options[:engine_class] || Erubi::Engine
|
18
18
|
|
19
|
+
# If :freeze option is given, the intent is to setup frozen string
|
20
|
+
# literals in the template. So enable frozen string literals in the
|
21
|
+
# code Tilt generates if the :freeze option is given.
|
22
|
+
if @freeze_string_literals = !!@options[:freeze]
|
23
|
+
# Passing the :freeze option to Erubi sets the
|
24
|
+
# frozen-string-literal magic comment, which doesn't have an effect
|
25
|
+
# with Tilt as Tilt wraps the resulting code. Worse, the magic
|
26
|
+
# comment appearing not at the top of the file can cause a warning.
|
27
|
+
# So remove the :freeze option before passing to Erubi.
|
28
|
+
@options.delete(:freeze)
|
29
|
+
|
30
|
+
# Erubi by default appends .freeze to template literals on Ruby 2.1+,
|
31
|
+
# but that is not necessary and slows down code when Tilt is using
|
32
|
+
# frozen string literals, so pass the :freeze_template_literals
|
33
|
+
# option to not append .freeze.
|
34
|
+
@options[:freeze_template_literals] = false
|
35
|
+
end
|
36
|
+
|
19
37
|
@engine = engine_class.new(data, @options)
|
20
38
|
@outvar = @engine.bufvar
|
21
39
|
|
@@ -28,5 +46,9 @@ module Tilt
|
|
28
46
|
def precompiled_template(locals)
|
29
47
|
@src
|
30
48
|
end
|
49
|
+
|
50
|
+
def freeze_string_literals?
|
51
|
+
@freeze_string_literals
|
52
|
+
end
|
31
53
|
end
|
32
54
|
end
|
data/lib/tilt/erubis.rb
CHANGED
@@ -16,6 +16,7 @@ module Tilt
|
|
16
16
|
# within <%= %> blocks will be automatically html escaped.
|
17
17
|
class ErubisTemplate < ERBTemplate
|
18
18
|
def prepare
|
19
|
+
@freeze_string_literals = !!@options.delete(:freeze)
|
19
20
|
@outvar = options.delete(:outvar) || self.class.default_output_variable
|
20
21
|
@options.merge!(:preamble => false, :postamble => false, :bufvar => @outvar)
|
21
22
|
engine_class = options.delete(:engine_class)
|
@@ -33,11 +34,13 @@ module Tilt
|
|
33
34
|
|
34
35
|
# Erubis doesn't have ERB's line-off-by-one under 1.9 problem.
|
35
36
|
# Override and adjust back.
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
def precompiled(locals)
|
38
|
+
source, offset = super
|
39
|
+
[source, offset - 1]
|
40
|
+
end
|
41
|
+
|
42
|
+
def freeze_string_literals?
|
43
|
+
@freeze_string_literals
|
41
44
|
end
|
42
45
|
end
|
43
46
|
end
|
data/lib/tilt/haml.rb
CHANGED
@@ -4,81 +4,86 @@ require 'haml'
|
|
4
4
|
module Tilt
|
5
5
|
# Haml template implementation. See:
|
6
6
|
# http://haml.hamptoncatlin.com/
|
7
|
-
|
8
|
-
|
7
|
+
if defined?(Haml::Template) && Haml::Template < Tilt::Template
|
8
|
+
# Haml >= 6 ships its own template, prefer it when available.
|
9
|
+
HamlTemplate = Haml::Template
|
10
|
+
else
|
11
|
+
class HamlTemplate < Template
|
12
|
+
self.default_mime_type = 'text/html'
|
9
13
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
# `Gem::Version.correct?` may return false because of Haml::VERSION #=> "3.1.8 (Separated Sally)". After Haml 4, it's always correct.
|
15
|
+
if Gem::Version.correct?(Haml::VERSION) && Gem::Version.new(Haml::VERSION) >= Gem::Version.new('5.0.0.beta.2')
|
16
|
+
def prepare
|
17
|
+
options = {}.update(@options).update(filename: eval_file, line: line)
|
18
|
+
if options.include?(:outvar)
|
19
|
+
options[:buffer] = options.delete(:outvar)
|
20
|
+
options[:save_buffer] = true
|
21
|
+
end
|
22
|
+
@engine = ::Haml::TempleEngine.new(options)
|
23
|
+
@engine.compile(data)
|
17
24
|
end
|
18
|
-
@engine = ::Haml::TempleEngine.new(options)
|
19
|
-
@engine.compile(data)
|
20
|
-
end
|
21
25
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
+
def evaluate(scope, locals, &block)
|
27
|
+
raise ArgumentError, 'invalid scope: must not be frozen' if scope.frozen?
|
28
|
+
super
|
29
|
+
end
|
26
30
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
31
|
+
def precompiled_template(locals)
|
32
|
+
@engine.precompiled_with_ambles(
|
33
|
+
[],
|
34
|
+
after_preamble: <<-RUBY
|
35
|
+
__in_erb_template = true
|
36
|
+
_haml_locals = locals
|
37
|
+
RUBY
|
38
|
+
)
|
39
|
+
end
|
40
|
+
else # Following definitions are for Haml <= 4 and deprecated.
|
41
|
+
def prepare
|
42
|
+
options = @options.merge(:filename => eval_file, :line => line)
|
43
|
+
@engine = ::Haml::Engine.new(data, options)
|
44
|
+
end
|
41
45
|
|
42
|
-
|
43
|
-
|
46
|
+
def evaluate(scope, locals, &block)
|
47
|
+
raise ArgumentError, 'invalid scope: must not be frozen' if scope.frozen?
|
44
48
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
+
if @engine.respond_to?(:precompiled_method_return_value, true)
|
50
|
+
super
|
51
|
+
else
|
52
|
+
@engine.render(scope, locals, &block)
|
53
|
+
end
|
49
54
|
end
|
50
|
-
end
|
51
55
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
56
|
+
# Precompiled Haml source. Taken from the precompiled_with_ambles
|
57
|
+
# method in Haml::Precompiler:
|
58
|
+
# http://github.com/nex3/haml/blob/master/lib/haml/precompiler.rb#L111-126
|
59
|
+
def precompiled_template(locals)
|
60
|
+
@engine.precompiled
|
61
|
+
end
|
58
62
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
63
|
+
def precompiled_preamble(locals)
|
64
|
+
local_assigns = super
|
65
|
+
@engine.instance_eval do
|
66
|
+
<<-RUBY
|
67
|
+
begin
|
68
|
+
extend Haml::Helpers
|
69
|
+
_hamlout = @haml_buffer = Haml::Buffer.new(haml_buffer, #{options_for_buffer.inspect})
|
70
|
+
_erbout = _hamlout.buffer
|
71
|
+
__in_erb_template = true
|
72
|
+
_haml_locals = locals
|
73
|
+
#{local_assigns}
|
74
|
+
RUBY
|
75
|
+
end
|
71
76
|
end
|
72
|
-
end
|
73
77
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
78
|
+
def precompiled_postamble(locals)
|
79
|
+
@engine.instance_eval do
|
80
|
+
<<-RUBY
|
81
|
+
#{precompiled_method_return_value}
|
82
|
+
ensure
|
83
|
+
@haml_buffer = @haml_buffer.upper if haml_buffer
|
84
|
+
end
|
85
|
+
RUBY
|
86
|
+
end
|
82
87
|
end
|
83
88
|
end
|
84
89
|
end
|
data/lib/tilt/less.rb
CHANGED
data/lib/tilt/mapping.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'monitor'
|
2
|
+
require_relative 'pipeline'
|
2
3
|
|
3
4
|
module Tilt
|
4
5
|
# Tilt::Mapping associates file extensions with template implementations.
|
@@ -112,6 +113,62 @@ module Tilt
|
|
112
113
|
end
|
113
114
|
end
|
114
115
|
|
116
|
+
# Register a new template class using the given extension that
|
117
|
+
# represents a pipeline of multiple existing template, where the
|
118
|
+
# output from the previous template is used as input to the next
|
119
|
+
# template.
|
120
|
+
#
|
121
|
+
# This will register a template class that processes the input
|
122
|
+
# with the *erb* template processor, and takes the output of
|
123
|
+
# that and feeds it to the *scss* template processor, returning
|
124
|
+
# the output of the *scss* template processor as the result of
|
125
|
+
# the pipeline.
|
126
|
+
#
|
127
|
+
# @param ext [String] Primary extension to register
|
128
|
+
# @option :templates [Array<String>] Extensions of templates
|
129
|
+
# to execute in order (defaults to the ext.split('.').reverse)
|
130
|
+
# @option :extra_exts [Array<String>] Additional extensions to register
|
131
|
+
# @option String [Hash] Options hash for individual template in the
|
132
|
+
# pipeline (key is extension).
|
133
|
+
# @return [void]
|
134
|
+
#
|
135
|
+
# @example
|
136
|
+
# mapping.register_pipeline('scss.erb')
|
137
|
+
# mapping.register_pipeline('scss.erb', 'erb'=>{:outvar=>'@foo'})
|
138
|
+
# mapping.register_pipeline('scsserb', :extra_exts => 'scss.erb',
|
139
|
+
# :templates=>['erb', 'scss'])
|
140
|
+
def register_pipeline(ext, options={})
|
141
|
+
templates = options[:templates] || ext.split('.').reverse
|
142
|
+
templates = templates.map{|t| [self[t], options[t] || {}]}
|
143
|
+
|
144
|
+
klass = Class.new(Pipeline)
|
145
|
+
klass.send(:const_set, :TEMPLATES, templates)
|
146
|
+
|
147
|
+
register(klass, ext, *Array(options[:extra_exts]))
|
148
|
+
klass
|
149
|
+
end
|
150
|
+
|
151
|
+
# Unregisters an extension. This removes the both normal registrations
|
152
|
+
# and lazy registrations.
|
153
|
+
#
|
154
|
+
# @param extensions [Array<String>] List of extensions.
|
155
|
+
# @return nil
|
156
|
+
#
|
157
|
+
# @example
|
158
|
+
# mapping.register MyEngine::Template, 'mt'
|
159
|
+
# mapping['index.mt'] # => MyEngine::Template
|
160
|
+
# mapping.unregister('mt')
|
161
|
+
# mapping['index.mt'] # => nil
|
162
|
+
def unregister(*extensions)
|
163
|
+
extensions.each do |ext|
|
164
|
+
ext = ext.to_s
|
165
|
+
@template_map.delete(ext)
|
166
|
+
@lazy_map.delete(ext)
|
167
|
+
end
|
168
|
+
|
169
|
+
nil
|
170
|
+
end
|
171
|
+
|
115
172
|
# Checks if a file extension is registered (either eagerly or
|
116
173
|
# lazily) in this mapping.
|
117
174
|
#
|
@@ -188,7 +245,7 @@ module Tilt
|
|
188
245
|
lazy_map.each do |ext, choices|
|
189
246
|
res << ext if choices.any? { |klass, file| template_class.to_s == klass }
|
190
247
|
end
|
191
|
-
res
|
248
|
+
res.uniq
|
192
249
|
end
|
193
250
|
|
194
251
|
private
|
@@ -257,11 +314,6 @@ module Tilt
|
|
257
314
|
LOCK.exit if entered
|
258
315
|
end
|
259
316
|
|
260
|
-
# This is due to a bug in JRuby (see GH issue jruby/jruby#3585)
|
261
|
-
Tilt.autoload :Dummy, "tilt/dummy"
|
262
|
-
require "tilt/dummy"
|
263
|
-
AUTOLOAD_IS_BROKEN = Tilt.autoload?(:Dummy)
|
264
|
-
|
265
317
|
# The proper behavior (in MRI) for autoload? is to
|
266
318
|
# return `false` when the constant/file has been
|
267
319
|
# explicitly required.
|
@@ -276,16 +328,7 @@ module Tilt
|
|
276
328
|
|
277
329
|
def constant_defined?(name)
|
278
330
|
name.split('::').inject(Object) do |scope, n|
|
279
|
-
if scope.autoload?(n)
|
280
|
-
if !AUTOLOAD_IS_BROKEN
|
281
|
-
return false
|
282
|
-
end
|
283
|
-
|
284
|
-
if eval("!defined?(scope::#{n})")
|
285
|
-
return false
|
286
|
-
end
|
287
|
-
end
|
288
|
-
return false if !scope.const_defined?(n)
|
331
|
+
return false if scope.autoload?(n) || !scope.const_defined?(n)
|
289
332
|
scope.const_get(n)
|
290
333
|
end
|
291
334
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative 'template'
|
2
|
+
|
3
|
+
module Tilt
|
4
|
+
# Superclass used for pipeline templates. Should not be used directly.
|
5
|
+
class Pipeline < Template
|
6
|
+
def prepare
|
7
|
+
@pipeline = self.class::TEMPLATES.inject(proc{|*| data}) do |data, (klass, options)|
|
8
|
+
proc do |s,l,&sb|
|
9
|
+
klass.new(file, line, options, &proc{|*| data.call(s, l, &sb)}).render(s, l, &sb)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def evaluate(scope, locals, &block)
|
15
|
+
@pipeline.call(scope, locals, &block)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/tilt/rst-pandoc.rb
CHANGED
data/lib/tilt/sigil.rb
CHANGED
data/lib/tilt/template.rb
CHANGED
@@ -1,17 +1,11 @@
|
|
1
|
-
require 'thread'
|
2
|
-
|
3
1
|
module Tilt
|
4
2
|
# @private
|
5
|
-
|
6
|
-
# @private
|
7
|
-
module CompiledTemplates
|
8
|
-
self
|
9
|
-
end
|
10
|
-
elsif RUBY_VERSION >= '1.9'
|
11
|
-
BasicObject
|
12
|
-
else
|
13
|
-
Object
|
3
|
+
module CompiledTemplates
|
14
4
|
end
|
5
|
+
|
6
|
+
# @private
|
7
|
+
TOPOBJECT = CompiledTemplates
|
8
|
+
|
15
9
|
# @private
|
16
10
|
LOCK = Mutex.new
|
17
11
|
|
@@ -33,6 +27,12 @@ module Tilt
|
|
33
27
|
# interface.
|
34
28
|
attr_reader :options
|
35
29
|
|
30
|
+
# A path ending in .rb that the template code will be written to, then
|
31
|
+
# required, instead of being evaled. This is useful for determining
|
32
|
+
# coverage of compiled template code, or to use static analysis tools
|
33
|
+
# on the compiled template code.
|
34
|
+
attr_reader :compiled_path
|
35
|
+
|
36
36
|
class << self
|
37
37
|
# An empty Hash that the template engine can populate with various
|
38
38
|
# metadata.
|
@@ -136,6 +136,17 @@ module Tilt
|
|
136
136
|
end
|
137
137
|
end
|
138
138
|
|
139
|
+
# Set the prefix to use for compiled paths.
|
140
|
+
def compiled_path=(path)
|
141
|
+
if path
|
142
|
+
# Use expanded paths when loading, since that is helpful
|
143
|
+
# for coverage. Remove any .rb suffix, since that will
|
144
|
+
# be added back later.
|
145
|
+
path = File.expand_path(path.sub(/\.rb\z/i, ''))
|
146
|
+
end
|
147
|
+
@compiled_path = path
|
148
|
+
end
|
149
|
+
|
139
150
|
protected
|
140
151
|
|
141
152
|
# @!group For template implementations
|
@@ -144,9 +155,7 @@ module Tilt
|
|
144
155
|
# default_encoding-option if present. You may override this method
|
145
156
|
# in your template class if you have a better hint of the data's
|
146
157
|
# encoding.
|
147
|
-
|
148
|
-
@default_encoding
|
149
|
-
end
|
158
|
+
attr_reader :default_encoding
|
150
159
|
|
151
160
|
# Do whatever preparation is necessary to setup the underlying template
|
152
161
|
# engine. Called immediately after template data is loaded. Instance
|
@@ -158,6 +167,7 @@ module Tilt
|
|
158
167
|
end
|
159
168
|
|
160
169
|
CLASS_METHOD = Kernel.instance_method(:class)
|
170
|
+
USE_BIND_CALL = RUBY_VERSION >= '2.7'
|
161
171
|
|
162
172
|
# Execute the compiled template and return the result string. Template
|
163
173
|
# evaluation is guaranteed to be performed in the scope object with the
|
@@ -168,17 +178,20 @@ module Tilt
|
|
168
178
|
def evaluate(scope, locals, &block)
|
169
179
|
locals_keys = locals.keys
|
170
180
|
locals_keys.sort!{|x, y| x.to_s <=> y.to_s}
|
181
|
+
|
171
182
|
case scope
|
172
183
|
when Object
|
173
|
-
|
184
|
+
scope_class = Module === scope ? scope : scope.class
|
174
185
|
else
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
186
|
+
scope_class = USE_BIND_CALL ? CLASS_METHOD.bind_call(scope) : CLASS_METHOD.bind(scope).call
|
187
|
+
end
|
188
|
+
method = compiled_method(locals_keys, scope_class)
|
189
|
+
|
190
|
+
if USE_BIND_CALL
|
191
|
+
method.bind_call(scope, locals, &block)
|
192
|
+
else
|
193
|
+
method.bind(scope).call(locals, &block)
|
180
194
|
end
|
181
|
-
method.bind(scope).call(locals, &block)
|
182
195
|
end
|
183
196
|
|
184
197
|
# Generates all template source by combining the preamble, template, and
|
@@ -269,18 +282,58 @@ module Tilt
|
|
269
282
|
method_source.force_encoding(source.encoding)
|
270
283
|
end
|
271
284
|
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
285
|
+
if freeze_string_literals?
|
286
|
+
method_source << "# frozen-string-literal: true\n"
|
287
|
+
end
|
288
|
+
|
289
|
+
# Don't indent method source, to avoid indentation warnings when using compiled paths
|
290
|
+
method_source << "::Tilt::TOPOBJECT.class_eval do\ndef #{method_name}(locals)\n#{local_code}\n"
|
291
|
+
|
277
292
|
offset += method_source.count("\n")
|
278
293
|
method_source << source
|
279
294
|
method_source << "\nend;end;"
|
280
|
-
|
295
|
+
|
296
|
+
bind_compiled_method(method_source, offset, scope_class, local_keys)
|
281
297
|
unbind_compiled_method(method_name)
|
282
298
|
end
|
283
299
|
|
300
|
+
def bind_compiled_method(method_source, offset, scope_class, local_keys)
|
301
|
+
path = compiled_path
|
302
|
+
if path && scope_class.name
|
303
|
+
path = path.dup
|
304
|
+
|
305
|
+
if defined?(@compiled_path_counter)
|
306
|
+
path << '-' << @compiled_path_counter.succ!
|
307
|
+
else
|
308
|
+
@compiled_path_counter = "0".dup
|
309
|
+
end
|
310
|
+
path << ".rb"
|
311
|
+
|
312
|
+
# Wrap method source in a class block for the scope, so constant lookup works
|
313
|
+
method_source = "class #{scope_class.name}\n#{method_source}\nend"
|
314
|
+
|
315
|
+
load_compiled_method(path, method_source)
|
316
|
+
else
|
317
|
+
if path
|
318
|
+
warn "compiled_path (#{compiled_path.inspect}) ignored on template with anonymous scope_class (#{scope_class.inspect})"
|
319
|
+
end
|
320
|
+
|
321
|
+
eval_compiled_method(method_source, offset, scope_class)
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
325
|
+
def eval_compiled_method(method_source, offset, scope_class)
|
326
|
+
(scope_class || Object).class_eval(method_source, eval_file, line - offset)
|
327
|
+
end
|
328
|
+
|
329
|
+
def load_compiled_method(path, method_source)
|
330
|
+
File.binwrite(path, method_source)
|
331
|
+
|
332
|
+
# Use load and not require, so unbind_compiled_method does not
|
333
|
+
# break if the same path is used more than once.
|
334
|
+
load path
|
335
|
+
end
|
336
|
+
|
284
337
|
def unbind_compiled_method(method_name)
|
285
338
|
method = TOPOBJECT.instance_method(method_name)
|
286
339
|
TOPOBJECT.class_eval { remove_method(method_name) }
|
@@ -297,6 +350,10 @@ module Tilt
|
|
297
350
|
end
|
298
351
|
end
|
299
352
|
|
353
|
+
def freeze_string_literals?
|
354
|
+
false
|
355
|
+
end
|
356
|
+
|
300
357
|
def binary(string)
|
301
358
|
original_encoding = string.encoding
|
302
359
|
string.force_encoding(Encoding::BINARY)
|
data/lib/tilt.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require_relative 'tilt/mapping'
|
2
|
+
require_relative 'tilt/template'
|
3
3
|
|
4
4
|
# Namespace for Tilt. This module is not intended to be included anywhere.
|
5
5
|
module Tilt
|
6
6
|
# Current version.
|
7
|
-
VERSION = '2.0
|
7
|
+
VERSION = '2.1.0'
|
8
8
|
|
9
9
|
@default_mapping = Mapping.new
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
class << self
|
12
|
+
# @return [Tilt::Mapping] the main mapping object
|
13
|
+
attr_reader :default_mapping
|
14
14
|
end
|
15
15
|
|
16
16
|
# @private
|
@@ -28,6 +28,11 @@ module Tilt
|
|
28
28
|
default_mapping.register_lazy(class_name, file, *extensions)
|
29
29
|
end
|
30
30
|
|
31
|
+
# @see Tilt::Mapping#register_pipeline
|
32
|
+
def self.register_pipeline(ext, options={})
|
33
|
+
default_mapping.register_pipeline(ext, options)
|
34
|
+
end
|
35
|
+
|
31
36
|
# @deprecated Use {register} instead.
|
32
37
|
def self.prefer(template_class, *extensions)
|
33
38
|
register(template_class, *extensions)
|
@@ -140,7 +145,7 @@ module Tilt
|
|
140
145
|
register_lazy :HamlTemplate, 'tilt/haml', 'haml'
|
141
146
|
register_lazy :LessTemplate, 'tilt/less', 'less'
|
142
147
|
register_lazy :LiquidTemplate, 'tilt/liquid', 'liquid'
|
143
|
-
register_lazy :LiveScriptTemplate, 'tilt/livescript','ls'
|
148
|
+
register_lazy :LiveScriptTemplate, 'tilt/livescript','ls', 'livescript'
|
144
149
|
register_lazy :MarkabyTemplate, 'tilt/markaby', 'mab'
|
145
150
|
register_lazy :NokogiriTemplate, 'tilt/nokogiri', 'nokogiri'
|
146
151
|
register_lazy :PlainTemplate, 'tilt/plain', 'html'
|
@@ -162,6 +167,5 @@ module Tilt
|
|
162
167
|
register_lazy 'Tilt::HandlebarsTemplate', 'tilt/handlebars', 'handlebars', 'hbs'
|
163
168
|
register_lazy 'Tilt::OrgTemplate', 'org-ruby', 'org'
|
164
169
|
register_lazy 'Tilt::EmacsOrgTemplate', 'tilt/emacs_org', 'org'
|
165
|
-
register_lazy 'Opal::Processor', 'opal', 'opal', 'rb'
|
166
170
|
register_lazy 'Tilt::JbuilderTemplate', 'tilt/jbuilder', 'jbuilder'
|
167
171
|
end
|
metadata
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tilt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Tomayko
|
8
|
+
- Magnus Holm
|
9
|
+
- Jeremy Evans
|
8
10
|
autorequire:
|
9
11
|
bindir: bin
|
10
12
|
cert_chain: []
|
11
|
-
date:
|
13
|
+
date: 2023-02-17 00:00:00.000000000 Z
|
12
14
|
dependencies: []
|
13
15
|
description: Generic interface to multiple Ruby template engines
|
14
16
|
email: r@tomayko.com
|
@@ -28,7 +30,6 @@ files:
|
|
28
30
|
- lib/tilt/commonmarker.rb
|
29
31
|
- lib/tilt/creole.rb
|
30
32
|
- lib/tilt/csv.rb
|
31
|
-
- lib/tilt/dummy.rb
|
32
33
|
- lib/tilt/erb.rb
|
33
34
|
- lib/tilt/erubi.rb
|
34
35
|
- lib/tilt/erubis.rb
|
@@ -43,6 +44,7 @@ files:
|
|
43
44
|
- lib/tilt/maruku.rb
|
44
45
|
- lib/tilt/nokogiri.rb
|
45
46
|
- lib/tilt/pandoc.rb
|
47
|
+
- lib/tilt/pipeline.rb
|
46
48
|
- lib/tilt/plain.rb
|
47
49
|
- lib/tilt/prawn.rb
|
48
50
|
- lib/tilt/radius.rb
|
@@ -58,10 +60,14 @@ files:
|
|
58
60
|
- lib/tilt/typescript.rb
|
59
61
|
- lib/tilt/wikicloth.rb
|
60
62
|
- lib/tilt/yajl.rb
|
61
|
-
homepage: https://github.com/
|
63
|
+
homepage: https://github.com/jeremyevans/tilt
|
62
64
|
licenses:
|
63
65
|
- MIT
|
64
|
-
metadata:
|
66
|
+
metadata:
|
67
|
+
bug_tracker_uri: https://github.com/jeremyevans/tilt/issues
|
68
|
+
changelog_uri: https://github.com/jeremyevans/tilt/blob/master/CHANGELOG.md
|
69
|
+
mailing_list_uri: https://github.com/jeremyevans/tilt/discussions
|
70
|
+
source_code_uri: https://github.com/jeremyevans/tilt
|
65
71
|
post_install_message:
|
66
72
|
rdoc_options:
|
67
73
|
- "--line-numbers"
|
@@ -76,15 +82,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
76
82
|
requirements:
|
77
83
|
- - ">="
|
78
84
|
- !ruby/object:Gem::Version
|
79
|
-
version: '0'
|
85
|
+
version: '2.0'
|
80
86
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
87
|
requirements:
|
82
88
|
- - ">="
|
83
89
|
- !ruby/object:Gem::Version
|
84
90
|
version: '0'
|
85
91
|
requirements: []
|
86
|
-
rubygems_version: 3.
|
92
|
+
rubygems_version: 3.4.6
|
87
93
|
signing_key:
|
88
|
-
specification_version:
|
94
|
+
specification_version: 4
|
89
95
|
summary: Generic interface to multiple Ruby template engines
|
90
96
|
test_files: []
|
data/lib/tilt/dummy.rb
DELETED