tilt 2.8.0 → 2.10.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/lib/tilt/commonmarker.rb +2 -2
- data/lib/tilt/erb.rb +2 -2
- data/lib/tilt/herb.rb +110 -0
- data/lib/tilt/mapping.rb +24 -13
- data/lib/tilt/pandoc.rb +30 -11
- data/lib/tilt/pipeline.rb +3 -3
- data/lib/tilt/radius.rb +19 -2
- data/lib/tilt/rdoc.rb +2 -2
- data/lib/tilt/rst-pandoc.rb +6 -1
- data/lib/tilt/sass.rb +3 -3
- data/lib/tilt/string.rb +2 -1
- data/lib/tilt/template.rb +38 -37
- data/lib/tilt.rb +6 -5
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0202adaed9df38f951dba8a08ae37c6b0e4794027e07f8f1073763503da2f21c
|
|
4
|
+
data.tar.gz: c387711421b7d97fbbddda360bf4e3ca0b336277a538922640657485ae4d1d6a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e5ccd9b03732da4200837fa39c6c02d424778d31dd8bd0aec8d467508b1b54362c2c0eddde2def26ddd989f64df4508bb8431d9c6a1e913b6d8b06b653bb96b8
|
|
7
|
+
data.tar.gz: eb7b6ea7dbb9f556efc85e5c26056bacee34dd57c0dbce24e796acb4e2023843ff5852b4b56b93c12c92bd6099d9957b15621768178259ff31e5588d2798842c
|
data/lib/tilt/commonmarker.rb
CHANGED
|
@@ -105,7 +105,7 @@ if defined?(::Commonmarker)
|
|
|
105
105
|
|
|
106
106
|
Commonmarker.to_html(@data, options: { parse: parse_options, render: render_options, extension: extensions })
|
|
107
107
|
end
|
|
108
|
-
# :
|
|
108
|
+
# simplecov:disable
|
|
109
109
|
else
|
|
110
110
|
aliases = {
|
|
111
111
|
:smartypants => :SMART
|
|
@@ -157,4 +157,4 @@ else
|
|
|
157
157
|
CommonMarker.render_doc(@data, parse_options, extensions).to_html(render_options, extensions)
|
|
158
158
|
end
|
|
159
159
|
end
|
|
160
|
-
# :
|
|
160
|
+
# simplecov:enable
|
data/lib/tilt/erb.rb
CHANGED
|
@@ -86,10 +86,10 @@ module Tilt
|
|
|
86
86
|
end
|
|
87
87
|
@engine = if SUPPORTS_KVARGS
|
|
88
88
|
::ERB.new(@data, trim_mode: trim, eoutvar: @outvar)
|
|
89
|
-
# :
|
|
89
|
+
# simplecov:disable
|
|
90
90
|
else
|
|
91
91
|
::ERB.new(@data, options[:safe], trim, @outvar)
|
|
92
|
-
# :
|
|
92
|
+
# simplecov:enable
|
|
93
93
|
end
|
|
94
94
|
end
|
|
95
95
|
|
data/lib/tilt/herb.rb
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# = Herb (<tt>herb</tt>, <tt>html.erb</tt>)
|
|
4
|
+
#
|
|
5
|
+
# {Herb}[https://herb-tools.dev] is an HTML-aware ERB implementation, which parses the
|
|
6
|
+
# HTML in the template in addition to the embedded Ruby.
|
|
7
|
+
#
|
|
8
|
+
# Herb's engine is API compatible with the Erubi engine, so all the documentation of
|
|
9
|
+
# {Erubi}[rdoc-ref:lib/tilt/erubi.rb] applies in addition to the following:
|
|
10
|
+
#
|
|
11
|
+
# === Differences from Erubi
|
|
12
|
+
#
|
|
13
|
+
# Herb parses the HTML in the template, and raises <tt>Herb::Engine::CompilationError</tt>
|
|
14
|
+
# when creating the template if the HTML is invalid (such as unclosed or mismatched tags),
|
|
15
|
+
# or if the embedded Ruby has invalid syntax. Erubi inspects neither the HTML nor the Ruby;
|
|
16
|
+
# with Erubi, invalid Ruby syntax instead raises a SyntaxError when Tilt compiles the
|
|
17
|
+
# template, which by default does not happen until the template is first rendered.
|
|
18
|
+
#
|
|
19
|
+
# Herb escapes interpolated values based on where they appear in the document, using a
|
|
20
|
+
# separate escape function for attribute values, <tt><script></tt> content, and
|
|
21
|
+
# <tt><style></tt> content. Erubi uses a single escape function everywhere.
|
|
22
|
+
#
|
|
23
|
+
# Herb accepts additional engine options. As with the Erubi engine options, these are
|
|
24
|
+
# passed through to the engine class. See
|
|
25
|
+
# {Herb::Engine}[https://herb-tools.dev/projects/engine] for the full list.
|
|
26
|
+
#
|
|
27
|
+
# === Usage
|
|
28
|
+
#
|
|
29
|
+
# The <tt>Tilt::HerbTemplate</tt> class is registered for all files ending in <tt>.herb</tt> or
|
|
30
|
+
# <tt>.html.erb</tt> by default. Unlike {Erubi}[rdoc-ref:lib/tilt/erubi.rb], it is not
|
|
31
|
+
# registered for <tt>.erb</tt> or <tt>.rhtml</tt>, since that would change which engine is
|
|
32
|
+
# used for existing templates. To use Herb for those as well, use:
|
|
33
|
+
#
|
|
34
|
+
# Tilt.register Tilt::HerbTemplate, 'erb', 'rhtml'
|
|
35
|
+
#
|
|
36
|
+
# __NOTE:__ It's suggested that your program <tt>require 'herb'</tt> at load time when
|
|
37
|
+
# using this template engine within a threaded environment.
|
|
38
|
+
#
|
|
39
|
+
# === Options
|
|
40
|
+
#
|
|
41
|
+
# ==== <tt>:engine_class => Herb::Engine</tt>
|
|
42
|
+
#
|
|
43
|
+
# Allows you to specify a custom engine class to use instead of the
|
|
44
|
+
# default which is <tt>Herb::Engine</tt>.
|
|
45
|
+
#
|
|
46
|
+
# ==== Other
|
|
47
|
+
#
|
|
48
|
+
# Other options are passed to the constructor of the engine class.
|
|
49
|
+
#
|
|
50
|
+
# === See also
|
|
51
|
+
#
|
|
52
|
+
# * {Herb Home}[https://herb-tools.dev]
|
|
53
|
+
# * {Herb::Engine}[https://herb-tools.dev/projects/engine]
|
|
54
|
+
# * {Herb Source}[https://github.com/marcoroth/herb]
|
|
55
|
+
#
|
|
56
|
+
# === Related module
|
|
57
|
+
#
|
|
58
|
+
# * Tilt::HerbTemplate
|
|
59
|
+
|
|
60
|
+
require_relative 'template'
|
|
61
|
+
require 'herb'
|
|
62
|
+
require 'herb/engine'
|
|
63
|
+
|
|
64
|
+
module Tilt
|
|
65
|
+
class HerbTemplate < Template
|
|
66
|
+
def prepare
|
|
67
|
+
@options[:preamble] = false
|
|
68
|
+
@options[:postamble] = false
|
|
69
|
+
@options[:ensure] = true
|
|
70
|
+
|
|
71
|
+
# Unlike Erubi, Herb uses the filename when reporting errors, so pass
|
|
72
|
+
# the file Tilt loaded the template from if the caller did not set one.
|
|
73
|
+
@options[:filename] ||= file
|
|
74
|
+
|
|
75
|
+
engine_class = @options[:engine_class] || Herb::Engine
|
|
76
|
+
|
|
77
|
+
# If :freeze option is given, the intent is to setup frozen string
|
|
78
|
+
# literals in the template. So enable frozen string literals in the
|
|
79
|
+
# code Tilt generates if the :freeze option is given.
|
|
80
|
+
if @freeze_string_literals = !!@options[:freeze]
|
|
81
|
+
# Passing the :freeze option to Herb sets the
|
|
82
|
+
# frozen-string-literal magic comment, which doesn't have an effect
|
|
83
|
+
# with Tilt as Tilt wraps the resulting code. Worse, the magic
|
|
84
|
+
# comment appearing not at the top of the file can cause a warning.
|
|
85
|
+
# So remove the :freeze option before passing to Herb.
|
|
86
|
+
@options.delete(:freeze)
|
|
87
|
+
|
|
88
|
+
# Herb by default appends .freeze to template literals, but that is
|
|
89
|
+
# not necessary and slows down code when Tilt is using frozen string
|
|
90
|
+
# literals, so pass the :freeze_template_literals option to not
|
|
91
|
+
# append .freeze.
|
|
92
|
+
@options[:freeze_template_literals] = false
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
@engine = engine_class.new(@data, @options)
|
|
96
|
+
@outvar = @engine.bufvar
|
|
97
|
+
@src = @engine.src
|
|
98
|
+
|
|
99
|
+
@engine
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def precompiled_template(locals)
|
|
103
|
+
@src
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def freeze_string_literals?
|
|
107
|
+
@freeze_string_literals
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
data/lib/tilt/mapping.rb
CHANGED
|
@@ -138,6 +138,7 @@ module Tilt
|
|
|
138
138
|
LOCK.synchronize do
|
|
139
139
|
@template_map = other.template_map.dup
|
|
140
140
|
@lazy_map = other.lazy_map.dup
|
|
141
|
+
@lazy_map.each {|ext, choices| @lazy_map[ext] = choices.dup}
|
|
141
142
|
end
|
|
142
143
|
end
|
|
143
144
|
|
|
@@ -149,12 +150,7 @@ module Tilt
|
|
|
149
150
|
# not attempt to load additional files (useful when restricting
|
|
150
151
|
# file system access after template libraries in use are loaded).
|
|
151
152
|
def finalized
|
|
152
|
-
|
|
153
|
-
register_defined_classes(LOCK.synchronize{classes.map(&:first)}, pattern)
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
# Check if a template class is already present
|
|
157
|
-
FinalizedMapping.new(LOCK.synchronize{@template_map.dup}.freeze)
|
|
153
|
+
dup.finalized!
|
|
158
154
|
end
|
|
159
155
|
|
|
160
156
|
# Registers a lazy template implementation by file extension. You
|
|
@@ -182,7 +178,7 @@ module Tilt
|
|
|
182
178
|
|
|
183
179
|
v = [class_name, file].freeze
|
|
184
180
|
extensions.each do |ext|
|
|
185
|
-
LOCK.synchronize{@lazy_map[ext].unshift(v)}
|
|
181
|
+
LOCK.synchronize{@lazy_map[ext.to_s.downcase].unshift(v)}
|
|
186
182
|
end
|
|
187
183
|
end
|
|
188
184
|
|
|
@@ -204,7 +200,7 @@ module Tilt
|
|
|
204
200
|
end
|
|
205
201
|
|
|
206
202
|
extensions.each do |ext|
|
|
207
|
-
ext = ext.to_s
|
|
203
|
+
ext = ext.to_s.downcase
|
|
208
204
|
LOCK.synchronize do
|
|
209
205
|
@template_map[ext] = template_class
|
|
210
206
|
end
|
|
@@ -259,7 +255,7 @@ module Tilt
|
|
|
259
255
|
# mapping['index.mt'] # => nil
|
|
260
256
|
def unregister(*extensions)
|
|
261
257
|
extensions.each do |ext|
|
|
262
|
-
ext = ext.to_s
|
|
258
|
+
ext = ext.to_s.downcase
|
|
263
259
|
LOCK.synchronize do
|
|
264
260
|
@template_map.delete(ext)
|
|
265
261
|
@lazy_map.delete(ext)
|
|
@@ -296,6 +292,19 @@ module Tilt
|
|
|
296
292
|
res
|
|
297
293
|
end
|
|
298
294
|
|
|
295
|
+
protected
|
|
296
|
+
|
|
297
|
+
# Internals of finalized
|
|
298
|
+
def finalized!
|
|
299
|
+
@lazy_map.each do |pattern, classes|
|
|
300
|
+
unless @template_map[pattern]
|
|
301
|
+
register_defined_classes(classes.map(&:first), pattern)
|
|
302
|
+
end
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
FinalizedMapping.new(@template_map.freeze)
|
|
306
|
+
end
|
|
307
|
+
|
|
299
308
|
private
|
|
300
309
|
|
|
301
310
|
def lazy?(ext)
|
|
@@ -331,9 +340,9 @@ module Tilt
|
|
|
331
340
|
choices.each do |class_name, file|
|
|
332
341
|
begin
|
|
333
342
|
require file
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
343
|
+
unless template_class = constant_defined?(class_name)
|
|
344
|
+
raise NameError, "constant not defined: #{class_name.inspect}"
|
|
345
|
+
end
|
|
337
346
|
rescue LoadError => ex
|
|
338
347
|
first_failure ||= ex
|
|
339
348
|
else
|
|
@@ -360,7 +369,9 @@ module Tilt
|
|
|
360
369
|
def constant_defined?(name)
|
|
361
370
|
name.split('::').inject(Object) do |scope, n|
|
|
362
371
|
return false if scope.autoload?(n) || !scope.const_defined?(n)
|
|
363
|
-
scope.const_get(n)
|
|
372
|
+
v = scope.const_get(n)
|
|
373
|
+
raise TypeError, "expected template constant to be a module" unless Module === v
|
|
374
|
+
v
|
|
364
375
|
end
|
|
365
376
|
end
|
|
366
377
|
end
|
data/lib/tilt/pandoc.rb
CHANGED
|
@@ -4,27 +4,27 @@
|
|
|
4
4
|
#
|
|
5
5
|
# {Markdown}[http://daringfireball.net/projects/markdown/syntax] is a
|
|
6
6
|
# lightweight markup language, created by John Gruber and Aaron Swartz.
|
|
7
|
-
# For any markup that is not covered by Markdown
|
|
7
|
+
# For any markup that is not covered by Markdown's syntax, HTML is used.
|
|
8
8
|
# Marking up plain text with Markdown markup is easy and Markdown
|
|
9
9
|
# formatted texts are readable.
|
|
10
10
|
#
|
|
11
11
|
# === Example
|
|
12
12
|
#
|
|
13
|
-
#
|
|
14
|
-
#
|
|
13
|
+
# Hello Markdown Templates
|
|
14
|
+
# ========================
|
|
15
15
|
#
|
|
16
|
-
#
|
|
16
|
+
# Hello World. This is a paragraph.
|
|
17
17
|
#
|
|
18
18
|
# === Usage
|
|
19
19
|
#
|
|
20
20
|
# To wrap a Markdown formatted document with a layout:
|
|
21
21
|
#
|
|
22
|
-
#
|
|
23
|
-
#
|
|
24
|
-
#
|
|
25
|
-
#
|
|
26
|
-
#
|
|
27
|
-
#
|
|
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
28
|
#
|
|
29
29
|
# === Options
|
|
30
30
|
#
|
|
@@ -37,6 +37,19 @@
|
|
|
37
37
|
# Set <tt>true</tt> disallow raw HTML in Markdown contents. HTML is converted to
|
|
38
38
|
# literal text by escaping <tt><</tt> characters.
|
|
39
39
|
#
|
|
40
|
+
# ==== <tt>:commonmark => true|false</tt>
|
|
41
|
+
#
|
|
42
|
+
# Set <tt>true</tt> to use commonmark as the format.
|
|
43
|
+
#
|
|
44
|
+
# ==== <tt>:markdown_strict => true|false</tt>
|
|
45
|
+
#
|
|
46
|
+
# Set <tt>true</tt> to use markdown_strict as the format.
|
|
47
|
+
#
|
|
48
|
+
# ==== Other options
|
|
49
|
+
#
|
|
50
|
+
# <tt>true</tt> values pass the key as an argument. <tt>false</tt> values are ignored.
|
|
51
|
+
# Other values pass the key as a long option, with the value as the option value.
|
|
52
|
+
#
|
|
40
53
|
# === See also
|
|
41
54
|
#
|
|
42
55
|
# * {Markdown Syntax Documentation}[http://daringfireball.net/projects/markdown/syntax]
|
|
@@ -53,13 +66,14 @@ Tilt::PandocTemplate = Tilt::StaticTemplate.subclass do
|
|
|
53
66
|
# Leave other hash keys untouched
|
|
54
67
|
pandoc_options = []
|
|
55
68
|
from = "markdown"
|
|
69
|
+
escape_html = false
|
|
56
70
|
smart_extension = "-smart"
|
|
57
71
|
@options.each do |k,v|
|
|
58
72
|
case k
|
|
59
73
|
when :smartypants
|
|
60
74
|
smart_extension = "+smart" if v
|
|
61
75
|
when :escape_html
|
|
62
|
-
|
|
76
|
+
escape_html = true if v
|
|
63
77
|
when :commonmark
|
|
64
78
|
from = "commonmark" if v
|
|
65
79
|
when :markdown_strict
|
|
@@ -75,6 +89,11 @@ Tilt::PandocTemplate = Tilt::StaticTemplate.subclass do
|
|
|
75
89
|
end
|
|
76
90
|
end
|
|
77
91
|
end
|
|
92
|
+
if escape_html
|
|
93
|
+
# pandoc's commonmark reader ignores -raw_html, so it cannot honor :escape_html
|
|
94
|
+
raise ArgumentError, ":escape_html is not supported with :commonmark" if from == "commonmark"
|
|
95
|
+
from += "-raw_html-raw_attribute"
|
|
96
|
+
end
|
|
78
97
|
pandoc_options << { :f => from + smart_extension }
|
|
79
98
|
|
|
80
99
|
PandocRuby.new(@data, *pandoc_options).to_html.strip
|
data/lib/tilt/pipeline.rb
CHANGED
|
@@ -8,11 +8,11 @@ module Tilt
|
|
|
8
8
|
def prepare
|
|
9
9
|
@pipeline = self.class::TEMPLATES.inject(proc{|*| data}) do |data, (klass, ext, options)|
|
|
10
10
|
proc do |s,l,&sb|
|
|
11
|
-
|
|
11
|
+
render_options = options
|
|
12
12
|
if ext_opts = @options[ext]
|
|
13
|
-
|
|
13
|
+
render_options = render_options.merge(ext_opts)
|
|
14
14
|
end
|
|
15
|
-
klass.new(file, line,
|
|
15
|
+
klass.new(file, line, render_options, &proc{|*| data.call(s, l, &sb)}).render(s, l, &sb)
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
18
|
end
|
data/lib/tilt/radius.rb
CHANGED
|
@@ -45,6 +45,15 @@
|
|
|
45
45
|
# </body>
|
|
46
46
|
# </html>
|
|
47
47
|
#
|
|
48
|
+
# === Options
|
|
49
|
+
#
|
|
50
|
+
# ==== <tt>:restrict_scope_methods => true|false</tt>
|
|
51
|
+
#
|
|
52
|
+
# Set <tt>true</tt> to make tags that are not defined as locals only call
|
|
53
|
+
# scope methods that are not public methods of Object (such as +inspect+,
|
|
54
|
+
# +instance_variables+, and +freeze+). Use this when template authors are
|
|
55
|
+
# not trusted. Default is false.
|
|
56
|
+
#
|
|
48
57
|
# === See also
|
|
49
58
|
#
|
|
50
59
|
# * {Radius}[http://radius.rubyforge.org]
|
|
@@ -65,7 +74,7 @@ module Tilt
|
|
|
65
74
|
attr_accessor :tilt_scope
|
|
66
75
|
|
|
67
76
|
def tag_missing(name, attributes)
|
|
68
|
-
tilt_scope.
|
|
77
|
+
tilt_scope.public_send(name)
|
|
69
78
|
end
|
|
70
79
|
|
|
71
80
|
def dup
|
|
@@ -75,8 +84,16 @@ module Tilt
|
|
|
75
84
|
end
|
|
76
85
|
end
|
|
77
86
|
|
|
87
|
+
# Context used with the :restrict_scope_methods option.
|
|
88
|
+
class RestrictedContextClass < ContextClass
|
|
89
|
+
def tag_missing(name, attributes)
|
|
90
|
+
raise Radius::UndefinedTagError, name if Object.public_method_defined?(name)
|
|
91
|
+
super
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
78
95
|
def evaluate(scope, locals, &block)
|
|
79
|
-
context = ContextClass.new
|
|
96
|
+
context = (@options[:restrict_scope_methods] ? RestrictedContextClass : ContextClass).new
|
|
80
97
|
context.tilt_scope = scope
|
|
81
98
|
context.define_tag("yield", &block) if block
|
|
82
99
|
locals.each do |tag, value|
|
data/lib/tilt/rdoc.rb
CHANGED
|
@@ -32,10 +32,10 @@ Tilt::RDocTemplate = if defined?(RDoc::VERSION) && RDoc::VERSION >= "8"
|
|
|
32
32
|
Tilt::StaticTemplate.subclass do
|
|
33
33
|
RDoc::Markup::ToHtml.new.convert(@data).to_s
|
|
34
34
|
end
|
|
35
|
-
# :
|
|
35
|
+
# simplecov:disable
|
|
36
36
|
else
|
|
37
37
|
Tilt::StaticTemplate.subclass do
|
|
38
38
|
RDoc::Markup::ToHtml.new(RDoc::Options.new, nil).convert(@data).to_s
|
|
39
39
|
end
|
|
40
40
|
end
|
|
41
|
-
# :
|
|
41
|
+
# simplecov:enable
|
data/lib/tilt/rst-pandoc.rb
CHANGED
|
@@ -11,6 +11,9 @@
|
|
|
11
11
|
# is an application written in Haskell, with a Ruby wrapper provided by the
|
|
12
12
|
# {pandoc-ruby}[https://github.com/alphabetum/pandoc-ruby] gem.
|
|
13
13
|
#
|
|
14
|
+
# If the +:sandbox+ option is given, Pandoc is run with <tt>--sandbox</tt>, so
|
|
15
|
+
# directives such as <tt>include</tt> cannot read local files. This requires Pandoc 2.15+.
|
|
16
|
+
#
|
|
14
17
|
# === Example
|
|
15
18
|
#
|
|
16
19
|
# Hello Rst Templates
|
|
@@ -29,5 +32,7 @@ require_relative 'pandoc'
|
|
|
29
32
|
rst = {:f => "rst"}.freeze
|
|
30
33
|
|
|
31
34
|
Tilt::RstPandocTemplate = Tilt::StaticTemplate.subclass do
|
|
32
|
-
|
|
35
|
+
args = [@data, rst]
|
|
36
|
+
args << :sandbox if @options[:sandbox]
|
|
37
|
+
PandocRuby.new(*args).to_html.strip
|
|
33
38
|
end
|
data/lib/tilt/sass.rb
CHANGED
|
@@ -23,7 +23,7 @@ module Tilt
|
|
|
23
23
|
|
|
24
24
|
begin
|
|
25
25
|
require 'sass-embedded'
|
|
26
|
-
# :
|
|
26
|
+
# simplecov:disable
|
|
27
27
|
require 'uri'
|
|
28
28
|
|
|
29
29
|
ALLOWED_KEYS = (defined?(::Sass::Compiler) ? ::Sass::Compiler : ::Sass::Embedded).
|
|
@@ -43,7 +43,7 @@ module Tilt
|
|
|
43
43
|
path = File.absolute_path(eval_file)
|
|
44
44
|
path = '/' + path unless path.start_with?('/')
|
|
45
45
|
opts = @options.dup
|
|
46
|
-
opts[:url] = ::URI::File.build([nil, ::URI::DEFAULT_PARSER.escape(path)]).to_s
|
|
46
|
+
opts[:url] = ::URI::File.build([nil, ::URI::DEFAULT_PARSER.escape(path, /[^a-zA-Z0-9\-._~!$&'()*+,;=:@\/]/)]).to_s
|
|
47
47
|
opts[:syntax] = :indented
|
|
48
48
|
opts.delete_if{|k| !ALLOWED_KEYS.include?(k)} if ALLOWED_KEYS
|
|
49
49
|
opts
|
|
@@ -73,7 +73,7 @@ module Tilt
|
|
|
73
73
|
@options[:syntax] = :sass
|
|
74
74
|
@options
|
|
75
75
|
end
|
|
76
|
-
# :
|
|
76
|
+
# simplecov:enable
|
|
77
77
|
end
|
|
78
78
|
end
|
|
79
79
|
|
data/lib/tilt/string.rb
CHANGED
|
@@ -16,7 +16,8 @@ module Tilt
|
|
|
16
16
|
def prepare
|
|
17
17
|
hash = "TILT#{@data.hash.abs}"
|
|
18
18
|
@freeze_string_literals = !!@options[:freeze]
|
|
19
|
-
|
|
19
|
+
# Heredoc changes \r\n to \n, chomp removes \r\n
|
|
20
|
+
@code = String.new("<<#{hash}.chomp\n#{@data}\r\r\n#{hash}")
|
|
20
21
|
end
|
|
21
22
|
|
|
22
23
|
def precompiled_template(locals)
|
data/lib/tilt/template.rb
CHANGED
|
@@ -31,7 +31,8 @@ module Tilt
|
|
|
31
31
|
# A path ending in .rb that the template code will be written to, then
|
|
32
32
|
# required, instead of being evaled. This is useful for determining
|
|
33
33
|
# coverage of compiled template code, or to use static analysis tools
|
|
34
|
-
# on the compiled template code.
|
|
34
|
+
# on the compiled template code. The directory containing the path must
|
|
35
|
+
# not be writable by untrusted users.
|
|
35
36
|
attr_reader :compiled_path
|
|
36
37
|
|
|
37
38
|
class << self
|
|
@@ -196,15 +197,26 @@ module Tilt
|
|
|
196
197
|
key = scope_class
|
|
197
198
|
end
|
|
198
199
|
elsif @scope_class
|
|
199
|
-
key = locals_keys
|
|
200
|
+
key = locals_keys
|
|
200
201
|
else
|
|
201
202
|
key = [scope_class, locals_keys].freeze
|
|
202
203
|
end
|
|
203
204
|
|
|
204
|
-
LOCK.synchronize
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
205
|
+
if meth = LOCK.synchronize{@compiled_method[key]}
|
|
206
|
+
return meth
|
|
207
|
+
end
|
|
208
|
+
unless @fixed_locals
|
|
209
|
+
keys = locals_keys.map do |k|
|
|
210
|
+
case k
|
|
211
|
+
when String
|
|
212
|
+
"#{k}".freeze
|
|
213
|
+
when Symbol
|
|
214
|
+
k
|
|
215
|
+
else
|
|
216
|
+
raise TypeError, "invalid local key given: #{k.inspect}"
|
|
217
|
+
end
|
|
218
|
+
end.freeze
|
|
219
|
+
key = @scope_class ? keys : [scope_class, keys].freeze
|
|
208
220
|
end
|
|
209
221
|
meth = compile_template_method(locals_keys, scope_class)
|
|
210
222
|
LOCK.synchronize do
|
|
@@ -257,9 +269,9 @@ module Tilt
|
|
|
257
269
|
when Object
|
|
258
270
|
Module === scope ? scope : scope.class
|
|
259
271
|
else
|
|
260
|
-
# :
|
|
272
|
+
# simplecov:disable
|
|
261
273
|
USE_BIND_CALL ? CLASS_METHOD.bind_call(scope) : CLASS_METHOD.bind(scope).call
|
|
262
|
-
# :
|
|
274
|
+
# simplecov:enable
|
|
263
275
|
end
|
|
264
276
|
end
|
|
265
277
|
|
|
@@ -325,13 +337,13 @@ module Tilt
|
|
|
325
337
|
def _dup_string_if_frozen(string)
|
|
326
338
|
+string
|
|
327
339
|
end
|
|
328
|
-
# :
|
|
340
|
+
# simplecov:disable
|
|
329
341
|
else
|
|
330
342
|
def _dup_string_if_frozen(string)
|
|
331
343
|
string.frozen? ? string.dup : string
|
|
332
344
|
end
|
|
333
345
|
end
|
|
334
|
-
# :
|
|
346
|
+
# simplecov:enable
|
|
335
347
|
|
|
336
348
|
def process_arg(arg)
|
|
337
349
|
if arg
|
|
@@ -350,9 +362,9 @@ module Tilt
|
|
|
350
362
|
def read_template_file
|
|
351
363
|
data = File.binread(file)
|
|
352
364
|
# Set it to the default external (without verifying)
|
|
353
|
-
# :
|
|
365
|
+
# simplecov:disable
|
|
354
366
|
data.force_encoding(Encoding.default_external) if Encoding.default_external
|
|
355
|
-
# :
|
|
367
|
+
# simplecov:enable
|
|
356
368
|
data
|
|
357
369
|
end
|
|
358
370
|
|
|
@@ -366,22 +378,21 @@ module Tilt
|
|
|
366
378
|
end
|
|
367
379
|
|
|
368
380
|
def local_extraction(local_keys)
|
|
369
|
-
assignments =
|
|
381
|
+
assignments = []
|
|
382
|
+
locals_assignment = nil
|
|
383
|
+
local_keys.each do |k|
|
|
370
384
|
if k.to_s =~ /\A[a-z_][a-zA-Z_0-9]*\z/
|
|
371
|
-
"#{k} = locals[#{k.inspect}]"
|
|
385
|
+
assignment = "#{k} = locals[#{k.inspect}]"
|
|
386
|
+
if k.to_s == 'locals'
|
|
387
|
+
locals_assignment = assignment
|
|
388
|
+
else
|
|
389
|
+
assignments << assignment
|
|
390
|
+
end
|
|
372
391
|
else
|
|
373
392
|
raise "invalid locals key: #{k.inspect} (keys must be variable names)"
|
|
374
393
|
end
|
|
375
394
|
end
|
|
376
|
-
|
|
377
|
-
s = "locals = locals[:locals]"
|
|
378
|
-
if assignments.delete(s)
|
|
379
|
-
# If there is a locals key itself named <tt>locals</tt>, delete it from the ordered keys so we can
|
|
380
|
-
# assign it last. This is important because the assignment of all other locals depends on the
|
|
381
|
-
# <tt>locals</tt> local variable still matching the <tt>locals</tt> method argument given to the method
|
|
382
|
-
# created in <tt>#compile_template_method</tt>.
|
|
383
|
-
assignments << s
|
|
384
|
-
end
|
|
395
|
+
assignments << locals_assignment if locals_assignment
|
|
385
396
|
|
|
386
397
|
assignments.join("\n")
|
|
387
398
|
end
|
|
@@ -394,7 +405,7 @@ module Tilt
|
|
|
394
405
|
method.bind_call(scope, locals, &block)
|
|
395
406
|
end
|
|
396
407
|
end
|
|
397
|
-
# :
|
|
408
|
+
# simplecov:disable
|
|
398
409
|
else
|
|
399
410
|
def evaluate_method(method, scope, locals, &block)
|
|
400
411
|
if @fixed_locals
|
|
@@ -409,7 +420,7 @@ module Tilt
|
|
|
409
420
|
end
|
|
410
421
|
end
|
|
411
422
|
end
|
|
412
|
-
# :
|
|
423
|
+
# simplecov:enable
|
|
413
424
|
|
|
414
425
|
def compile_template_method(local_keys, scope_class=nil)
|
|
415
426
|
source, offset = precompiled(local_keys)
|
|
@@ -456,7 +467,7 @@ module Tilt
|
|
|
456
467
|
method_source_prefix = "# frozen-string-literal: true\n"
|
|
457
468
|
method_source = method_source.sub(/\A# frozen-string-literal: true\n/, '')
|
|
458
469
|
end
|
|
459
|
-
method_source = "#{method_source_prefix}class #{scope_class.name}\n#{method_source}\nend"
|
|
470
|
+
method_source = "#{method_source_prefix}#{scope_class.is_a?(Class) ? 'class' : 'module'} #{scope_class.name}\n#{method_source}\nend"
|
|
460
471
|
|
|
461
472
|
load_compiled_method(path, method_source)
|
|
462
473
|
else
|
|
@@ -537,22 +548,12 @@ module Tilt
|
|
|
537
548
|
yield script
|
|
538
549
|
end
|
|
539
550
|
|
|
540
|
-
|
|
541
|
-
script[/\A[ \t]*\#.*coding\s*[=:]\s*([[:alnum:]\-_]+).*$/n, 1]
|
|
542
|
-
end
|
|
551
|
+
script.b[/\A[ \t]*\#.*coding\s*[=:]\s*([[:alnum:]\-_]+).*$/n, 1]
|
|
543
552
|
end
|
|
544
553
|
|
|
545
554
|
def freeze_string_literals?
|
|
546
555
|
false
|
|
547
556
|
end
|
|
548
|
-
|
|
549
|
-
def binary(string)
|
|
550
|
-
original_encoding = string.encoding
|
|
551
|
-
string.force_encoding(Encoding::BINARY)
|
|
552
|
-
yield
|
|
553
|
-
ensure
|
|
554
|
-
string.force_encoding(original_encoding)
|
|
555
|
-
end
|
|
556
557
|
end
|
|
557
558
|
|
|
558
559
|
# Static templates are templates that return the same output for every render
|
data/lib/tilt.rb
CHANGED
|
@@ -5,7 +5,7 @@ require_relative 'tilt/template'
|
|
|
5
5
|
# Namespace for Tilt. This module is not intended to be included anywhere.
|
|
6
6
|
module Tilt
|
|
7
7
|
# Current version.
|
|
8
|
-
VERSION = '2.
|
|
8
|
+
VERSION = '2.10.0'
|
|
9
9
|
|
|
10
10
|
EMPTY_ARRAY = [].freeze
|
|
11
11
|
private_constant :EMPTY_ARRAY
|
|
@@ -138,16 +138,17 @@ module Tilt
|
|
|
138
138
|
@cache = {}
|
|
139
139
|
end
|
|
140
140
|
end
|
|
141
|
-
# :
|
|
141
|
+
# simplecov:disable
|
|
142
142
|
# TILT3: Remove Tilt::Cache
|
|
143
143
|
deprecate_constant :Cache if respond_to?(:deprecate_constant, true)
|
|
144
|
-
# :
|
|
144
|
+
# simplecov:enable
|
|
145
145
|
|
|
146
146
|
# Template Implementations ================================================
|
|
147
147
|
|
|
148
148
|
# ERB
|
|
149
|
-
register_lazy :ERBTemplate, 'tilt/erb', 'erb', 'rhtml'
|
|
150
|
-
register_lazy :ErubiTemplate, 'tilt/erubi', 'erb', 'rhtml', 'erubi'
|
|
149
|
+
register_lazy :ERBTemplate, 'tilt/erb', 'erb', 'rhtml', 'html.erb'
|
|
150
|
+
register_lazy :ErubiTemplate, 'tilt/erubi', 'erb', 'rhtml', 'erubi', 'html.erb'
|
|
151
|
+
register_lazy :HerbTemplate, 'tilt/herb', 'herb', 'html.erb'
|
|
151
152
|
|
|
152
153
|
# Markdown
|
|
153
154
|
register_lazy :KramdownTemplate, 'tilt/kramdown', 'markdown', 'mkd', 'md'
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: tilt
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.10.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ryan Tomayko
|
|
@@ -36,6 +36,7 @@ files:
|
|
|
36
36
|
- lib/tilt/erubi.rb
|
|
37
37
|
- lib/tilt/etanni.rb
|
|
38
38
|
- lib/tilt/haml.rb
|
|
39
|
+
- lib/tilt/herb.rb
|
|
39
40
|
- lib/tilt/kramdown.rb
|
|
40
41
|
- lib/tilt/liquid.rb
|
|
41
42
|
- lib/tilt/livescript.rb
|
|
@@ -87,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
87
88
|
- !ruby/object:Gem::Version
|
|
88
89
|
version: '0'
|
|
89
90
|
requirements: []
|
|
90
|
-
rubygems_version: 4.0.
|
|
91
|
+
rubygems_version: 4.0.20
|
|
91
92
|
specification_version: 4
|
|
92
93
|
summary: Generic interface to multiple Ruby template engines
|
|
93
94
|
test_files: []
|