tilt 2.0.9 → 2.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tilt.rb +1 -1
- data/lib/tilt/template.rb +7 -12
- metadata +3 -104
- data/CHANGELOG.md +0 -132
- data/Gemfile +0 -70
- data/HACKING +0 -16
- data/README.md +0 -233
- data/Rakefile +0 -106
- data/docs/TEMPLATES.md +0 -555
- data/docs/common.css +0 -14
- data/man/index.txt +0 -2
- data/man/tilt.1.ronn +0 -59
- data/test/markaby/locals.mab +0 -1
- data/test/markaby/markaby.mab +0 -1
- data/test/markaby/markaby_other_static.mab +0 -1
- data/test/markaby/render_twice.mab +0 -1
- data/test/markaby/scope.mab +0 -1
- data/test/markaby/yielding.mab +0 -2
- data/test/mytemplate.rb +0 -2
- data/test/test_helper.rb +0 -64
- data/test/tilt_asciidoctor_test.rb +0 -50
- data/test/tilt_babeltemplate.rb +0 -33
- data/test/tilt_blueclothtemplate_test.rb +0 -33
- data/test/tilt_buildertemplate_test.rb +0 -72
- data/test/tilt_cache_test.rb +0 -43
- data/test/tilt_coffeescripttemplate_test.rb +0 -141
- data/test/tilt_commonmarkertemplate_test.rb +0 -28
- data/test/tilt_compilesite_test.rb +0 -51
- data/test/tilt_creoletemplate_test.rb +0 -24
- data/test/tilt_csv_test.rb +0 -77
- data/test/tilt_erbtemplate_test.rb +0 -239
- data/test/tilt_erubistemplate_test.rb +0 -151
- data/test/tilt_erubitemplate_test.rb +0 -158
- data/test/tilt_etannitemplate_test.rb +0 -174
- data/test/tilt_hamltemplate_test.rb +0 -166
- data/test/tilt_kramdown_test.rb +0 -20
- data/test/tilt_lesstemplate_test.less +0 -1
- data/test/tilt_lesstemplate_test.rb +0 -42
- data/test/tilt_liquidtemplate_test.rb +0 -87
- data/test/tilt_livescripttemplate_test.rb +0 -37
- data/test/tilt_mapping_test.rb +0 -232
- data/test/tilt_markaby_test.rb +0 -88
- data/test/tilt_markdown_test.rb +0 -186
- data/test/tilt_marukutemplate_test.rb +0 -36
- data/test/tilt_metadata_test.rb +0 -42
- data/test/tilt_nokogiritemplate_test.rb +0 -87
- data/test/tilt_pandoctemplate_test.rb +0 -67
- data/test/tilt_prawntemplate.prawn +0 -1
- data/test/tilt_prawntemplate_test.rb +0 -75
- data/test/tilt_radiustemplate_test.rb +0 -75
- data/test/tilt_rdiscounttemplate_test.rb +0 -43
- data/test/tilt_rdoctemplate_test.rb +0 -29
- data/test/tilt_redcarpettemplate_test.rb +0 -54
- data/test/tilt_redclothtemplate_test.rb +0 -36
- data/test/tilt_rstpandoctemplate_test.rb +0 -32
- data/test/tilt_sasstemplate_test.rb +0 -42
- data/test/tilt_sigil_test.rb +0 -41
- data/test/tilt_stringtemplate_test.rb +0 -171
- data/test/tilt_template_test.rb +0 -314
- data/test/tilt_test.rb +0 -60
- data/test/tilt_typescript_test.rb +0 -38
- data/test/tilt_wikiclothtemplate_test.rb +0 -32
- data/test/tilt_yajltemplate_test.rb +0 -101
- data/tilt.gemspec +0 -130
data/test/tilt_template_test.rb
DELETED
@@ -1,314 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
require 'test_helper'
|
3
|
-
require 'tilt'
|
4
|
-
require 'tilt/template'
|
5
|
-
require 'tempfile'
|
6
|
-
|
7
|
-
class TiltTemplateTest < Minitest::Test
|
8
|
-
|
9
|
-
class MockTemplate < Tilt::Template
|
10
|
-
def prepare
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
test "needs a file or block" do
|
15
|
-
assert_raises(ArgumentError) { Tilt::Template.new }
|
16
|
-
end
|
17
|
-
|
18
|
-
test "initializing with a file" do
|
19
|
-
inst = MockTemplate.new('foo.erb') {}
|
20
|
-
assert_equal 'foo.erb', inst.file
|
21
|
-
end
|
22
|
-
|
23
|
-
test "initializing with a file and line" do
|
24
|
-
inst = MockTemplate.new('foo.erb', 55) {}
|
25
|
-
assert_equal 'foo.erb', inst.file
|
26
|
-
assert_equal 55, inst.line
|
27
|
-
end
|
28
|
-
|
29
|
-
test "initializing with a tempfile" do
|
30
|
-
tempfile = Tempfile.new('tilt_template_test')
|
31
|
-
inst = MockTemplate.new(tempfile)
|
32
|
-
assert_equal File.basename(tempfile.path), inst.basename
|
33
|
-
end
|
34
|
-
|
35
|
-
test "initializing with a pathname" do
|
36
|
-
tempfile = Tempfile.new('tilt_template_test')
|
37
|
-
pathname = Pathname.new(tempfile.path)
|
38
|
-
inst = MockTemplate.new(pathname)
|
39
|
-
assert_equal File.basename(tempfile.path), inst.basename
|
40
|
-
end
|
41
|
-
|
42
|
-
class SillyHash < Hash
|
43
|
-
def path(arg)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
test "initialize with hash that implements #path" do
|
48
|
-
options = SillyHash[:key => :value]
|
49
|
-
inst = MockTemplate.new(options) {}
|
50
|
-
assert_equal :value, inst.options[:key]
|
51
|
-
end
|
52
|
-
|
53
|
-
test "uses correct eval_file" do
|
54
|
-
inst = MockTemplate.new('foo.erb', 55) {}
|
55
|
-
assert_equal 'foo.erb', inst.eval_file
|
56
|
-
end
|
57
|
-
|
58
|
-
test "uses a default filename for #eval_file when no file provided" do
|
59
|
-
inst = MockTemplate.new { 'Hi' }
|
60
|
-
refute_nil inst.eval_file
|
61
|
-
assert !inst.eval_file.include?("\n")
|
62
|
-
end
|
63
|
-
|
64
|
-
test "calculating template's #basename" do
|
65
|
-
inst = MockTemplate.new('/tmp/templates/foo.html.erb') {}
|
66
|
-
assert_equal 'foo.html.erb', inst.basename
|
67
|
-
end
|
68
|
-
|
69
|
-
test "calculating the template's #name" do
|
70
|
-
inst = MockTemplate.new('/tmp/templates/foo.html.erb') {}
|
71
|
-
assert_equal 'foo', inst.name
|
72
|
-
end
|
73
|
-
|
74
|
-
test "initializing with a data loading block" do
|
75
|
-
MockTemplate.new { |template| "Hello World!" }
|
76
|
-
end
|
77
|
-
|
78
|
-
class PreparingMockTemplate < Tilt::Template
|
79
|
-
def prepare
|
80
|
-
raise "data must be set" if data.nil?
|
81
|
-
@prepared = true
|
82
|
-
end
|
83
|
-
def prepared? ; @prepared ; end
|
84
|
-
end
|
85
|
-
|
86
|
-
test "raises NotImplementedError when #prepare not defined" do
|
87
|
-
assert_raises(NotImplementedError) { Tilt::Template.new { |template| "Hello World!" } }
|
88
|
-
end
|
89
|
-
|
90
|
-
test "raises NotImplementedError when #evaluate or #template_source not defined" do
|
91
|
-
inst = PreparingMockTemplate.new { |t| "Hello World!" }
|
92
|
-
assert_raises(NotImplementedError) { inst.render }
|
93
|
-
assert inst.prepared?
|
94
|
-
end
|
95
|
-
|
96
|
-
class SimpleMockTemplate < PreparingMockTemplate
|
97
|
-
def evaluate(scope, locals, &block)
|
98
|
-
raise "should be prepared" unless prepared?
|
99
|
-
raise "scope should be present" if scope.nil?
|
100
|
-
raise "locals should be present" if locals.nil?
|
101
|
-
"<em>#{@data}</em>"
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
test "prepares and evaluates the template on #render" do
|
106
|
-
inst = SimpleMockTemplate.new { |t| "Hello World!" }
|
107
|
-
assert_equal "<em>Hello World!</em>", inst.render
|
108
|
-
assert inst.prepared?
|
109
|
-
end
|
110
|
-
|
111
|
-
test 'prepares and evaluates the template on #render with nil arg' do
|
112
|
-
inst = SimpleMockTemplate.new { |t| "Hello World!" }
|
113
|
-
assert_equal '<em>Hello World!</em>', inst.render(nil)
|
114
|
-
assert inst.prepared?
|
115
|
-
end
|
116
|
-
|
117
|
-
class SourceGeneratingMockTemplate < PreparingMockTemplate
|
118
|
-
def precompiled_template(locals)
|
119
|
-
"foo = [] ; foo << %Q{#{data}} ; foo.join"
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
test "template_source with locals" do
|
124
|
-
inst = SourceGeneratingMockTemplate.new { |t| 'Hey #{name}!' }
|
125
|
-
assert_equal "Hey Joe!", inst.render(Object.new, :name => 'Joe')
|
126
|
-
assert inst.prepared?
|
127
|
-
end
|
128
|
-
|
129
|
-
test "template_source with locals of strings" do
|
130
|
-
inst = SourceGeneratingMockTemplate.new { |t| 'Hey #{name}!' }
|
131
|
-
assert_equal "Hey Joe!", inst.render(Object.new, 'name' => 'Joe')
|
132
|
-
assert inst.prepared?
|
133
|
-
end
|
134
|
-
|
135
|
-
test "template_source with locals of strings" do
|
136
|
-
inst = SourceGeneratingMockTemplate.new { |t| 'Hey #{name}!' }
|
137
|
-
assert_equal "Hey Joe!", inst.render(Object.new, 'name' => 'Joe', :name=>'Joe')
|
138
|
-
assert inst.prepared?
|
139
|
-
end
|
140
|
-
|
141
|
-
test "template_source with locals having non-variable keys raises error" do
|
142
|
-
inst = SourceGeneratingMockTemplate.new { |t| '1 + 2 = #{_answer}' }
|
143
|
-
err = assert_raises(RuntimeError) { inst.render(Object.new, 'ANSWER' => 3) }
|
144
|
-
assert_equal "invalid locals key: \"ANSWER\" (keys must be variable names)", err.message
|
145
|
-
assert_equal "1 + 2 = 3", inst.render(Object.new, '_answer' => 3)
|
146
|
-
end
|
147
|
-
|
148
|
-
test "template_source with nil locals" do
|
149
|
-
inst = SourceGeneratingMockTemplate.new { |t| 'Hey' }
|
150
|
-
assert_equal 'Hey', inst.render(Object.new, nil)
|
151
|
-
assert inst.prepared?
|
152
|
-
end
|
153
|
-
|
154
|
-
class CustomGeneratingMockTemplate < PreparingMockTemplate
|
155
|
-
def precompiled_template(locals)
|
156
|
-
data
|
157
|
-
end
|
158
|
-
|
159
|
-
def precompiled_preamble(locals)
|
160
|
-
options.fetch(:preamble)
|
161
|
-
end
|
162
|
-
|
163
|
-
def precompiled_postamble(locals)
|
164
|
-
options.fetch(:postamble)
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
test "supports pre/postamble" do
|
169
|
-
inst = CustomGeneratingMockTemplate.new(
|
170
|
-
:preamble => 'buf = []',
|
171
|
-
:postamble => 'buf.join'
|
172
|
-
) { 'buf << 1' }
|
173
|
-
|
174
|
-
assert_equal "1", inst.render
|
175
|
-
end
|
176
|
-
|
177
|
-
class Person
|
178
|
-
CONSTANT = "Bob"
|
179
|
-
|
180
|
-
attr_accessor :name
|
181
|
-
def initialize(name)
|
182
|
-
@name = name
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
test "template_source with an object scope" do
|
187
|
-
inst = SourceGeneratingMockTemplate.new { |t| 'Hey #{@name}!' }
|
188
|
-
scope = Person.new('Joe')
|
189
|
-
assert_equal "Hey Joe!", inst.render(scope)
|
190
|
-
end
|
191
|
-
|
192
|
-
test "template_source with a block for yield" do
|
193
|
-
inst = SourceGeneratingMockTemplate.new { |t| 'Hey #{yield}!' }
|
194
|
-
assert_equal "Hey Joe!", inst.render(Object.new){ 'Joe' }
|
195
|
-
end
|
196
|
-
|
197
|
-
test "template which accesses a constant" do
|
198
|
-
inst = SourceGeneratingMockTemplate.new { |t| 'Hey #{CONSTANT}!' }
|
199
|
-
assert_equal "Hey Bob!", inst.render(Person.new("Joe"))
|
200
|
-
end
|
201
|
-
|
202
|
-
test "populates Tilt.current_template during rendering" do
|
203
|
-
inst = SourceGeneratingMockTemplate.new { '#{$inst = Tilt.current_template}' }
|
204
|
-
inst.render
|
205
|
-
assert_equal inst, $inst
|
206
|
-
assert_nil Tilt.current_template
|
207
|
-
end
|
208
|
-
|
209
|
-
test "populates Tilt.current_template in nested rendering" do
|
210
|
-
inst1 = SourceGeneratingMockTemplate.new { '#{$inst.render; $inst1 = Tilt.current_template}' }
|
211
|
-
inst2 = SourceGeneratingMockTemplate.new { '#{$inst2 = Tilt.current_template}' }
|
212
|
-
$inst = inst2
|
213
|
-
inst1.render
|
214
|
-
assert_equal inst1, $inst1
|
215
|
-
assert_equal inst2, $inst2
|
216
|
-
assert_nil Tilt.current_template
|
217
|
-
end
|
218
|
-
|
219
|
-
##
|
220
|
-
# Encodings
|
221
|
-
|
222
|
-
class DynamicMockTemplate < MockTemplate
|
223
|
-
def precompiled_template(locals)
|
224
|
-
options[:code]
|
225
|
-
end
|
226
|
-
end
|
227
|
-
|
228
|
-
class UTF8Template < MockTemplate
|
229
|
-
def default_encoding
|
230
|
-
Encoding::UTF_8
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
if ''.respond_to?(:encoding)
|
235
|
-
original_encoding = Encoding.default_external
|
236
|
-
|
237
|
-
setup do
|
238
|
-
@file = Tempfile.open('template')
|
239
|
-
@file.puts "stuff"
|
240
|
-
@file.close
|
241
|
-
@template = @file.path
|
242
|
-
end
|
243
|
-
|
244
|
-
teardown do
|
245
|
-
Encoding.default_external = original_encoding
|
246
|
-
Encoding.default_internal = nil
|
247
|
-
@file.delete
|
248
|
-
end
|
249
|
-
|
250
|
-
test "reading from file assumes default external encoding" do
|
251
|
-
Encoding.default_external = 'Big5'
|
252
|
-
inst = MockTemplate.new(@template)
|
253
|
-
assert_equal 'Big5', inst.data.encoding.to_s
|
254
|
-
end
|
255
|
-
|
256
|
-
test "reading from file with a :default_encoding overrides default external" do
|
257
|
-
Encoding.default_external = 'Big5'
|
258
|
-
inst = MockTemplate.new(@template, :default_encoding => 'GBK')
|
259
|
-
assert_equal 'GBK', inst.data.encoding.to_s
|
260
|
-
end
|
261
|
-
|
262
|
-
test "reading from file with default_internal set does no transcoding" do
|
263
|
-
Encoding.default_internal = 'utf-8'
|
264
|
-
Encoding.default_external = 'Big5'
|
265
|
-
inst = MockTemplate.new(@template)
|
266
|
-
assert_equal 'Big5', inst.data.encoding.to_s
|
267
|
-
end
|
268
|
-
|
269
|
-
test "using provided template data verbatim when given as string" do
|
270
|
-
Encoding.default_internal = 'Big5'
|
271
|
-
inst = MockTemplate.new(@template) { "blah".force_encoding('GBK') }
|
272
|
-
assert_equal 'GBK', inst.data.encoding.to_s
|
273
|
-
end
|
274
|
-
|
275
|
-
test "uses the template from the generated source code" do
|
276
|
-
tmpl = "ふが"
|
277
|
-
code = tmpl.inspect.encode('Shift_JIS')
|
278
|
-
inst = DynamicMockTemplate.new(:code => code) { '' }
|
279
|
-
res = inst.render
|
280
|
-
assert_equal 'Shift_JIS', res.encoding.to_s
|
281
|
-
assert_equal tmpl, res.encode(tmpl.encoding)
|
282
|
-
end
|
283
|
-
|
284
|
-
test "uses the magic comment from the generated source code" do
|
285
|
-
tmpl = "ふが"
|
286
|
-
code = ("# coding: Shift_JIS\n" + tmpl.inspect).encode('Shift_JIS')
|
287
|
-
# Set it to an incorrect encoding
|
288
|
-
code.force_encoding('UTF-8')
|
289
|
-
|
290
|
-
inst = DynamicMockTemplate.new(:code => code) { '' }
|
291
|
-
res = inst.render
|
292
|
-
assert_equal 'Shift_JIS', res.encoding.to_s
|
293
|
-
assert_equal tmpl, res.encode(tmpl.encoding)
|
294
|
-
end
|
295
|
-
|
296
|
-
test "uses #default_encoding instead of default_external" do
|
297
|
-
Encoding.default_external = 'Big5'
|
298
|
-
inst = UTF8Template.new(@template)
|
299
|
-
assert_equal 'UTF-8', inst.data.encoding.to_s
|
300
|
-
end
|
301
|
-
|
302
|
-
test "uses #default_encoding instead of current encoding" do
|
303
|
-
tmpl = "".force_encoding('Big5')
|
304
|
-
inst = UTF8Template.new(@template) { tmpl }
|
305
|
-
assert_equal 'UTF-8', inst.data.encoding.to_s
|
306
|
-
end
|
307
|
-
|
308
|
-
test "raises error if the encoding is not valid" do
|
309
|
-
assert_raises(Encoding::InvalidByteSequenceError) do
|
310
|
-
UTF8Template.new(@template) { "\xe4" }
|
311
|
-
end
|
312
|
-
end
|
313
|
-
end
|
314
|
-
end
|
data/test/tilt_test.rb
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'tilt'
|
3
|
-
|
4
|
-
class TiltTest < Minitest::Test
|
5
|
-
class MockTemplate
|
6
|
-
attr_reader :args, :block
|
7
|
-
def initialize(*args, &block)
|
8
|
-
@args = args
|
9
|
-
@block = block
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
test "registering template implementation classes by file extension" do
|
14
|
-
Tilt.register(MockTemplate, 'mock')
|
15
|
-
end
|
16
|
-
|
17
|
-
test "an extension is registered if explicit handle is found" do
|
18
|
-
Tilt.register(MockTemplate, 'mock')
|
19
|
-
assert Tilt.registered?('mock')
|
20
|
-
end
|
21
|
-
|
22
|
-
test "registering template classes by symbol file extension" do
|
23
|
-
Tilt.register(MockTemplate, :mock)
|
24
|
-
end
|
25
|
-
|
26
|
-
test "looking up template classes by exact file extension" do
|
27
|
-
Tilt.register(MockTemplate, 'mock')
|
28
|
-
impl = Tilt['mock']
|
29
|
-
assert_equal MockTemplate, impl
|
30
|
-
end
|
31
|
-
|
32
|
-
test "looking up template classes by implicit file extension" do
|
33
|
-
Tilt.register(MockTemplate, 'mock')
|
34
|
-
impl = Tilt['.mock']
|
35
|
-
assert_equal MockTemplate, impl
|
36
|
-
end
|
37
|
-
|
38
|
-
test "looking up template classes with multiple file extensions" do
|
39
|
-
Tilt.register(MockTemplate, 'mock')
|
40
|
-
impl = Tilt['index.html.mock']
|
41
|
-
assert_equal MockTemplate, impl
|
42
|
-
end
|
43
|
-
|
44
|
-
test "looking up template classes by file name" do
|
45
|
-
Tilt.register(MockTemplate, 'mock')
|
46
|
-
impl = Tilt['templates/test.mock']
|
47
|
-
assert_equal MockTemplate, impl
|
48
|
-
end
|
49
|
-
|
50
|
-
test "looking up non-existant template class" do
|
51
|
-
assert_nil Tilt['none']
|
52
|
-
end
|
53
|
-
|
54
|
-
test "creating new template instance with a filename" do
|
55
|
-
Tilt.register(MockTemplate, 'mock')
|
56
|
-
template = Tilt.new('foo.mock', 1, :key => 'val') { 'Hello World!' }
|
57
|
-
assert_equal ['foo.mock', 1, {:key => 'val'}], template.args
|
58
|
-
assert_equal 'Hello World!', template.block.call
|
59
|
-
end
|
60
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'tilt'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'tilt/typescript'
|
6
|
-
|
7
|
-
class TypeScriptTemplateTest < Minitest::Test
|
8
|
-
def setup
|
9
|
-
@ts = "var x:number = 5"
|
10
|
-
@js = /var x = 5;\s*/
|
11
|
-
end
|
12
|
-
|
13
|
-
test "is registered for '.ts' files" do
|
14
|
-
assert_equal Tilt::TypeScriptTemplate, Tilt['test.ts']
|
15
|
-
end
|
16
|
-
|
17
|
-
test "is registered for '.tsx' files" do
|
18
|
-
assert_equal Tilt::TypeScriptTemplate, Tilt['test.tsx']
|
19
|
-
end
|
20
|
-
|
21
|
-
test "compiles and evaluates the template on #render" do
|
22
|
-
template = Tilt::TypeScriptTemplate.new { @ts }
|
23
|
-
assert_match @js, template.render
|
24
|
-
end
|
25
|
-
|
26
|
-
test "supports source map" do
|
27
|
-
template = Tilt::TypeScriptTemplate.new(inlineSourceMap: true) { @ts }
|
28
|
-
assert_match %r(sourceMappingURL), template.render
|
29
|
-
end
|
30
|
-
|
31
|
-
test "can be rendered more than once" do
|
32
|
-
template = Tilt::TypeScriptTemplate.new { @ts }
|
33
|
-
3.times { assert_match @js, template.render }
|
34
|
-
end
|
35
|
-
end
|
36
|
-
rescue LoadError
|
37
|
-
warn "Tilt::TypeScriptTemplate (disabled)"
|
38
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'tilt'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'tilt/wikicloth'
|
6
|
-
|
7
|
-
class WikiClothTemplateTest < Minitest::Test
|
8
|
-
test "is registered for '.mediawiki' files" do
|
9
|
-
assert_equal Tilt::WikiClothTemplate, Tilt['test.mediawiki']
|
10
|
-
end
|
11
|
-
|
12
|
-
test "is registered for '.mw' files" do
|
13
|
-
assert_equal Tilt::WikiClothTemplate, Tilt['test.mw']
|
14
|
-
end
|
15
|
-
|
16
|
-
test "is registered for '.wiki' files" do
|
17
|
-
assert_equal Tilt::WikiClothTemplate, Tilt['test.wiki']
|
18
|
-
end
|
19
|
-
|
20
|
-
test "compiles and evaluates the template on #render" do
|
21
|
-
template = Tilt::WikiClothTemplate.new { |t| "= Hello World! =" }
|
22
|
-
assert_match(/<h1>.*Hello World!.*<\/h1>/m, template.render)
|
23
|
-
end
|
24
|
-
|
25
|
-
test "can be rendered more than once" do
|
26
|
-
template = Tilt::WikiClothTemplate.new { |t| "= Hello World! =" }
|
27
|
-
3.times { assert_match(/<h1>.*Hello World!.*<\/h1>/m, template.render) }
|
28
|
-
end
|
29
|
-
end
|
30
|
-
rescue LoadError
|
31
|
-
warn "Tilt::WikiClothTemplate (disabled)"
|
32
|
-
end
|
@@ -1,101 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'tilt'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'tilt/yajl'
|
6
|
-
|
7
|
-
class YajlTemplateTest < Minitest::Test
|
8
|
-
test "is registered for '.yajl' files" do
|
9
|
-
assert_equal Tilt::YajlTemplate, Tilt['test.yajl']
|
10
|
-
end
|
11
|
-
|
12
|
-
test "compiles and evaluates the template on #render" do
|
13
|
-
template = Tilt::YajlTemplate.new { "json = { :integer => 3, :string => 'hello' }" }
|
14
|
-
output = template.render
|
15
|
-
result = Yajl::Parser.parse(output)
|
16
|
-
expect = {"integer" => 3,"string" => "hello"}
|
17
|
-
assert_equal expect, result
|
18
|
-
end
|
19
|
-
|
20
|
-
test "can be rendered more than once" do
|
21
|
-
template = Tilt::YajlTemplate.new { "json = { :integer => 3, :string => 'hello' }" }
|
22
|
-
expect = {"integer" => 3,"string" => "hello"}
|
23
|
-
3.times do
|
24
|
-
output = template.render
|
25
|
-
result = Yajl::Parser.parse(output)
|
26
|
-
assert_equal expect, result
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
test "evaluating ruby code" do
|
31
|
-
template = Tilt::YajlTemplate.new { "json = { :integer => (3 * 2) }" }
|
32
|
-
assert_equal '{"integer":6}', template.render
|
33
|
-
end
|
34
|
-
|
35
|
-
test "evaluating in an object scope" do
|
36
|
-
template = Tilt::YajlTemplate.new { "json = { :string => 'Hey ' + @name + '!' }" }
|
37
|
-
scope = Object.new
|
38
|
-
scope.instance_variable_set :@name, 'Joe'
|
39
|
-
assert_equal '{"string":"Hey Joe!"}', template.render(scope)
|
40
|
-
end
|
41
|
-
|
42
|
-
test "passing locals" do
|
43
|
-
template = Tilt::YajlTemplate.new { "json = { :string => 'Hey ' + name + '!' }" }
|
44
|
-
assert_equal '{"string":"Hey Joe!"}', template.render(Object.new, :name => 'Joe')
|
45
|
-
end
|
46
|
-
|
47
|
-
test "passing a block for yield" do
|
48
|
-
template = Tilt::YajlTemplate.new { "json = { :string => 'Hey ' + yield + '!' }" }
|
49
|
-
assert_equal '{"string":"Hey Joe!"}', template.render { 'Joe' }
|
50
|
-
assert_equal '{"string":"Hey Moe!"}', template.render { 'Moe' }
|
51
|
-
end
|
52
|
-
|
53
|
-
test "template multiline" do
|
54
|
-
template = Tilt::YajlTemplate.new { %Q{
|
55
|
-
json = {
|
56
|
-
:string => "hello"
|
57
|
-
}
|
58
|
-
} }
|
59
|
-
assert_equal '{"string":"hello"}', template.render
|
60
|
-
end
|
61
|
-
|
62
|
-
test "template can reuse existing json buffer" do
|
63
|
-
template = Tilt::YajlTemplate.new { "json.merge! :string => 'hello'" }
|
64
|
-
assert_equal '{"string":"hello"}', template.render
|
65
|
-
end
|
66
|
-
|
67
|
-
test "template can end with any statement" do
|
68
|
-
template = Tilt::YajlTemplate.new { %Q{
|
69
|
-
json = {
|
70
|
-
:string => "hello"
|
71
|
-
}
|
72
|
-
four = 2 * 2
|
73
|
-
json[:integer] = four
|
74
|
-
nil
|
75
|
-
} }
|
76
|
-
result = template.render
|
77
|
-
assert( (result == '{"string":"hello","integer":4}') || (result == '{"integer":4,"string":"hello"}') )
|
78
|
-
end
|
79
|
-
|
80
|
-
test "option callback" do
|
81
|
-
options = { :callback => 'foo' }
|
82
|
-
template = Tilt::YajlTemplate.new(nil, options) { "json = { :string => 'hello' }" }
|
83
|
-
assert_equal 'foo({"string":"hello"});', template.render
|
84
|
-
end
|
85
|
-
|
86
|
-
test "option variable" do
|
87
|
-
options = { :variable => 'output' }
|
88
|
-
template = Tilt::YajlTemplate.new(nil, options) { "json = { :string => 'hello' }" }
|
89
|
-
assert_equal 'var output = {"string":"hello"};', template.render
|
90
|
-
end
|
91
|
-
|
92
|
-
test "option callback and variable" do
|
93
|
-
options = { :callback => 'foo', :variable => 'output' }
|
94
|
-
template = Tilt::YajlTemplate.new(nil, options) { "json = { :string => 'hello' }" }
|
95
|
-
assert_equal 'var output = {"string":"hello"}; foo(output);', template.render
|
96
|
-
end
|
97
|
-
|
98
|
-
end
|
99
|
-
rescue LoadError
|
100
|
-
warn "Tilt::YajlTemplateTest (disabled)"
|
101
|
-
end
|