tilt 2.0.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/COPYING +2 -1
- data/bin/tilt +2 -110
- 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 +11 -23
- data/lib/tilt/babel.rb +8 -0
- data/lib/tilt/builder.rb +23 -14
- data/lib/tilt/cli.rb +134 -0
- data/lib/tilt/coffee.rb +17 -25
- data/lib/tilt/commonmarker.rb +95 -0
- data/lib/tilt/creole.rb +9 -20
- data/lib/tilt/csv.rb +9 -21
- data/lib/tilt/erb.rb +27 -19
- data/lib/tilt/erubi.rb +55 -0
- data/lib/tilt/erubis.rb +20 -12
- data/lib/tilt/etanni.rb +5 -4
- data/lib/tilt/haml.rb +79 -42
- data/lib/tilt/kramdown.rb +8 -28
- data/lib/tilt/liquid.rb +11 -9
- data/lib/tilt/livescript.rb +11 -0
- data/lib/tilt/mapping.rb +242 -95
- data/lib/tilt/markaby.rb +5 -7
- data/lib/tilt/maruku.rb +6 -18
- data/lib/tilt/nokogiri.rb +11 -10
- data/lib/tilt/pandoc.rb +39 -0
- data/lib/tilt/pipeline.rb +19 -0
- data/lib/tilt/plain.rb +4 -19
- data/lib/tilt/prawn.rb +28 -0
- data/lib/tilt/radius.rb +15 -22
- data/lib/tilt/rdiscount.rb +17 -33
- data/lib/tilt/rdoc.rb +14 -35
- data/lib/tilt/redcarpet.rb +20 -93
- data/lib/tilt/redcloth.rb +9 -19
- data/lib/tilt/rst-pandoc.rb +10 -0
- data/lib/tilt/sass.rb +59 -22
- data/lib/tilt/slim.rb +5 -0
- data/lib/tilt/string.rb +9 -3
- data/lib/tilt/template.rb +246 -78
- data/lib/tilt/typescript.rb +19 -0
- data/lib/tilt/wikicloth.rb +8 -18
- data/lib/tilt/yajl.rb +5 -11
- data/lib/tilt.rb +91 -41
- metadata +39 -102
- data/CHANGELOG.md +0 -61
- data/Gemfile +0 -39
- data/HACKING +0 -16
- data/README.md +0 -206
- data/Rakefile +0 -95
- data/docs/TEMPLATES.md +0 -523
- data/docs/common.css +0 -14
- data/lib/tilt/bluecloth.rb +0 -24
- data/lib/tilt/less.rb +0 -38
- 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/test_helper.rb +0 -64
- data/test/tilt_asciidoctor_test.rb +0 -44
- data/test/tilt_blueclothtemplate_test.rb +0 -33
- data/test/tilt_buildertemplate_test.rb +0 -59
- data/test/tilt_cache_test.rb +0 -32
- data/test/tilt_coffeescripttemplate_test.rb +0 -104
- data/test/tilt_compilesite_test.rb +0 -51
- data/test/tilt_creoletemplate_test.rb +0 -24
- data/test/tilt_csv_test.rb +0 -65
- data/test/tilt_erbtemplate_test.rb +0 -239
- data/test/tilt_erubistemplate_test.rb +0 -151
- data/test/tilt_etannitemplate_test.rb +0 -174
- data/test/tilt_hamltemplate_test.rb +0 -144
- 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 -78
- data/test/tilt_mapping_test.rb +0 -229
- data/test/tilt_markaby_test.rb +0 -88
- data/test/tilt_markdown_test.rb +0 -174
- 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_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 -59
- data/test/tilt_redclothtemplate_test.rb +0 -36
- data/test/tilt_sasstemplate_test.rb +0 -41
- data/test/tilt_stringtemplate_test.rb +0 -171
- data/test/tilt_template_test.rb +0 -316
- data/test/tilt_test.rb +0 -60
- data/test/tilt_wikiclothtemplate_test.rb +0 -32
- data/test/tilt_yajltemplate_test.rb +0 -101
- data/tilt.gemspec +0 -107
data/test/tilt_template_test.rb
DELETED
@@ -1,316 +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 InitializingMockTemplate < Tilt::Template
|
79
|
-
@@initialized_count = 0
|
80
|
-
def self.initialized_count
|
81
|
-
@@initialized_count
|
82
|
-
end
|
83
|
-
|
84
|
-
def initialize_engine
|
85
|
-
@@initialized_count += 1
|
86
|
-
end
|
87
|
-
|
88
|
-
def prepare
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
class PreparingMockTemplate < Tilt::Template
|
93
|
-
def prepare
|
94
|
-
raise "data must be set" if data.nil?
|
95
|
-
@prepared = true
|
96
|
-
end
|
97
|
-
def prepared? ; @prepared ; end
|
98
|
-
end
|
99
|
-
|
100
|
-
test "raises NotImplementedError when #prepare not defined" do
|
101
|
-
assert_raises(NotImplementedError) { Tilt::Template.new { |template| "Hello World!" } }
|
102
|
-
end
|
103
|
-
|
104
|
-
test "raises NotImplementedError when #evaluate or #template_source not defined" do
|
105
|
-
inst = PreparingMockTemplate.new { |t| "Hello World!" }
|
106
|
-
assert_raises(NotImplementedError) { inst.render }
|
107
|
-
assert inst.prepared?
|
108
|
-
end
|
109
|
-
|
110
|
-
class SimpleMockTemplate < PreparingMockTemplate
|
111
|
-
def evaluate(scope, locals, &block)
|
112
|
-
raise "should be prepared" unless prepared?
|
113
|
-
raise "scope should be present" if scope.nil?
|
114
|
-
raise "locals should be present" if locals.nil?
|
115
|
-
"<em>#{@data}</em>"
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
test "prepares and evaluates the template on #render" do
|
120
|
-
inst = SimpleMockTemplate.new { |t| "Hello World!" }
|
121
|
-
assert_equal "<em>Hello World!</em>", inst.render
|
122
|
-
assert inst.prepared?
|
123
|
-
end
|
124
|
-
|
125
|
-
class SourceGeneratingMockTemplate < PreparingMockTemplate
|
126
|
-
def precompiled_template(locals)
|
127
|
-
"foo = [] ; foo << %Q{#{data}} ; foo.join"
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
test "template_source with locals" do
|
132
|
-
inst = SourceGeneratingMockTemplate.new { |t| 'Hey #{name}!' }
|
133
|
-
assert_equal "Hey Joe!", inst.render(Object.new, :name => 'Joe')
|
134
|
-
assert inst.prepared?
|
135
|
-
end
|
136
|
-
|
137
|
-
test "template_source with locals of strings" do
|
138
|
-
inst = SourceGeneratingMockTemplate.new { |t| 'Hey #{name}!' }
|
139
|
-
assert_equal "Hey Joe!", inst.render(Object.new, 'name' => 'Joe')
|
140
|
-
assert inst.prepared?
|
141
|
-
end
|
142
|
-
|
143
|
-
test "template_source with locals having non-variable keys raises error" do
|
144
|
-
inst = SourceGeneratingMockTemplate.new { |t| '1 + 2 = #{_answer}' }
|
145
|
-
err = assert_raises(RuntimeError) { inst.render(Object.new, 'ANSWER' => 3) }
|
146
|
-
assert_equal "invalid locals key: \"ANSWER\" (keys must be variable names)", err.message
|
147
|
-
assert_equal "1 + 2 = 3", inst.render(Object.new, '_answer' => 3)
|
148
|
-
end
|
149
|
-
|
150
|
-
test "template_source with nil locals" do
|
151
|
-
inst = SourceGeneratingMockTemplate.new { |t| 'Hey' }
|
152
|
-
assert_equal 'Hey', inst.render(Object.new, nil)
|
153
|
-
assert inst.prepared?
|
154
|
-
end
|
155
|
-
|
156
|
-
class CustomGeneratingMockTemplate < PreparingMockTemplate
|
157
|
-
def precompiled_template(locals)
|
158
|
-
data
|
159
|
-
end
|
160
|
-
|
161
|
-
def precompiled_preamble(locals)
|
162
|
-
options.fetch(:preamble)
|
163
|
-
end
|
164
|
-
|
165
|
-
def precompiled_postamble(locals)
|
166
|
-
options.fetch(:postamble)
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
test "supports pre/postamble" do
|
171
|
-
inst = CustomGeneratingMockTemplate.new(
|
172
|
-
:preamble => 'buf = []',
|
173
|
-
:postamble => 'buf.join'
|
174
|
-
) { 'buf << 1' }
|
175
|
-
|
176
|
-
assert_equal "1", inst.render
|
177
|
-
end
|
178
|
-
|
179
|
-
class Person
|
180
|
-
CONSTANT = "Bob"
|
181
|
-
|
182
|
-
attr_accessor :name
|
183
|
-
def initialize(name)
|
184
|
-
@name = name
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
test "template_source with an object scope" do
|
189
|
-
inst = SourceGeneratingMockTemplate.new { |t| 'Hey #{@name}!' }
|
190
|
-
scope = Person.new('Joe')
|
191
|
-
assert_equal "Hey Joe!", inst.render(scope)
|
192
|
-
end
|
193
|
-
|
194
|
-
test "template_source with a block for yield" do
|
195
|
-
inst = SourceGeneratingMockTemplate.new { |t| 'Hey #{yield}!' }
|
196
|
-
assert_equal "Hey Joe!", inst.render(Object.new){ 'Joe' }
|
197
|
-
end
|
198
|
-
|
199
|
-
test "template which accesses a constant" do
|
200
|
-
inst = SourceGeneratingMockTemplate.new { |t| 'Hey #{CONSTANT}!' }
|
201
|
-
assert_equal "Hey Bob!", inst.render(Person.new("Joe"))
|
202
|
-
end
|
203
|
-
|
204
|
-
test "populates Tilt.current_template during rendering" do
|
205
|
-
inst = SourceGeneratingMockTemplate.new { '#{$inst = Tilt.current_template}' }
|
206
|
-
inst.render
|
207
|
-
assert_equal inst, $inst
|
208
|
-
assert_nil Tilt.current_template
|
209
|
-
end
|
210
|
-
|
211
|
-
test "populates Tilt.current_template in nested rendering" do
|
212
|
-
inst1 = SourceGeneratingMockTemplate.new { '#{$inst.render; $inst1 = Tilt.current_template}' }
|
213
|
-
inst2 = SourceGeneratingMockTemplate.new { '#{$inst2 = Tilt.current_template}' }
|
214
|
-
$inst = inst2
|
215
|
-
inst1.render
|
216
|
-
assert_equal inst1, $inst1
|
217
|
-
assert_equal inst2, $inst2
|
218
|
-
assert_nil Tilt.current_template
|
219
|
-
end
|
220
|
-
|
221
|
-
##
|
222
|
-
# Encodings
|
223
|
-
|
224
|
-
class DynamicMockTemplate < MockTemplate
|
225
|
-
def precompiled_template(locals)
|
226
|
-
options[:code]
|
227
|
-
end
|
228
|
-
end
|
229
|
-
|
230
|
-
class UTF8Template < MockTemplate
|
231
|
-
def default_encoding
|
232
|
-
Encoding::UTF_8
|
233
|
-
end
|
234
|
-
end
|
235
|
-
|
236
|
-
if ''.respond_to?(:encoding)
|
237
|
-
original_encoding = Encoding.default_external
|
238
|
-
|
239
|
-
setup do
|
240
|
-
@file = Tempfile.open('template')
|
241
|
-
@file.puts "stuff"
|
242
|
-
@file.close
|
243
|
-
@template = @file.path
|
244
|
-
end
|
245
|
-
|
246
|
-
teardown do
|
247
|
-
Encoding.default_external = original_encoding
|
248
|
-
Encoding.default_internal = nil
|
249
|
-
@file.delete
|
250
|
-
end
|
251
|
-
|
252
|
-
test "reading from file assumes default external encoding" do
|
253
|
-
Encoding.default_external = 'Big5'
|
254
|
-
inst = MockTemplate.new(@template)
|
255
|
-
assert_equal 'Big5', inst.data.encoding.to_s
|
256
|
-
end
|
257
|
-
|
258
|
-
test "reading from file with a :default_encoding overrides default external" do
|
259
|
-
Encoding.default_external = 'Big5'
|
260
|
-
inst = MockTemplate.new(@template, :default_encoding => 'GBK')
|
261
|
-
assert_equal 'GBK', inst.data.encoding.to_s
|
262
|
-
end
|
263
|
-
|
264
|
-
test "reading from file with default_internal set does no transcoding" do
|
265
|
-
Encoding.default_internal = 'utf-8'
|
266
|
-
Encoding.default_external = 'Big5'
|
267
|
-
inst = MockTemplate.new(@template)
|
268
|
-
assert_equal 'Big5', inst.data.encoding.to_s
|
269
|
-
end
|
270
|
-
|
271
|
-
test "using provided template data verbatim when given as string" do
|
272
|
-
Encoding.default_internal = 'Big5'
|
273
|
-
inst = MockTemplate.new(@template) { "blah".force_encoding('GBK') }
|
274
|
-
assert_equal 'GBK', inst.data.encoding.to_s
|
275
|
-
end
|
276
|
-
|
277
|
-
test "uses the template from the generated source code" do
|
278
|
-
tmpl = "ふが"
|
279
|
-
code = tmpl.inspect.encode('Shift_JIS')
|
280
|
-
inst = DynamicMockTemplate.new(:code => code) { '' }
|
281
|
-
res = inst.render
|
282
|
-
assert_equal 'Shift_JIS', res.encoding.to_s
|
283
|
-
assert_equal tmpl, res.encode(tmpl.encoding)
|
284
|
-
end
|
285
|
-
|
286
|
-
test "uses the magic comment from the generated source code" do
|
287
|
-
tmpl = "ふが"
|
288
|
-
code = ("# coding: Shift_JIS\n" + tmpl.inspect).encode('Shift_JIS')
|
289
|
-
# Set it to an incorrect encoding
|
290
|
-
code.force_encoding('UTF-8')
|
291
|
-
|
292
|
-
inst = DynamicMockTemplate.new(:code => code) { '' }
|
293
|
-
res = inst.render
|
294
|
-
assert_equal 'Shift_JIS', res.encoding.to_s
|
295
|
-
assert_equal tmpl, res.encode(tmpl.encoding)
|
296
|
-
end
|
297
|
-
|
298
|
-
test "uses #default_encoding instead of default_external" do
|
299
|
-
Encoding.default_external = 'Big5'
|
300
|
-
inst = UTF8Template.new(@template)
|
301
|
-
assert_equal 'UTF-8', inst.data.encoding.to_s
|
302
|
-
end
|
303
|
-
|
304
|
-
test "uses #default_encoding instead of current encoding" do
|
305
|
-
tmpl = "".force_encoding('Big5')
|
306
|
-
inst = UTF8Template.new(@template) { tmpl }
|
307
|
-
assert_equal 'UTF-8', inst.data.encoding.to_s
|
308
|
-
end
|
309
|
-
|
310
|
-
test "raises error if the encoding is not valid" do
|
311
|
-
assert_raises(Encoding::InvalidByteSequenceError) do
|
312
|
-
UTF8Template.new(@template) { "\xe4" }
|
313
|
-
end
|
314
|
-
end
|
315
|
-
end
|
316
|
-
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,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>/, 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>/, template.render }
|
28
|
-
end
|
29
|
-
end
|
30
|
-
rescue LoadError => boom
|
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
|
data/tilt.gemspec
DELETED
@@ -1,107 +0,0 @@
|
|
1
|
-
Gem::Specification.new do |s|
|
2
|
-
s.specification_version = 2 if s.respond_to? :specification_version=
|
3
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
4
|
-
|
5
|
-
s.name = 'tilt'
|
6
|
-
s.version = '2.0.0'
|
7
|
-
s.date = '2013-11-30'
|
8
|
-
|
9
|
-
s.description = "Generic interface to multiple Ruby template engines"
|
10
|
-
s.summary = s.description
|
11
|
-
s.license = "MIT"
|
12
|
-
|
13
|
-
s.authors = ["Ryan Tomayko"]
|
14
|
-
s.email = "r@tomayko.com"
|
15
|
-
|
16
|
-
# = MANIFEST =
|
17
|
-
s.files = %w[
|
18
|
-
CHANGELOG.md
|
19
|
-
COPYING
|
20
|
-
Gemfile
|
21
|
-
HACKING
|
22
|
-
README.md
|
23
|
-
Rakefile
|
24
|
-
bin/tilt
|
25
|
-
docs/TEMPLATES.md
|
26
|
-
docs/common.css
|
27
|
-
lib/tilt.rb
|
28
|
-
lib/tilt/asciidoc.rb
|
29
|
-
lib/tilt/bluecloth.rb
|
30
|
-
lib/tilt/builder.rb
|
31
|
-
lib/tilt/coffee.rb
|
32
|
-
lib/tilt/creole.rb
|
33
|
-
lib/tilt/csv.rb
|
34
|
-
lib/tilt/erb.rb
|
35
|
-
lib/tilt/erubis.rb
|
36
|
-
lib/tilt/etanni.rb
|
37
|
-
lib/tilt/haml.rb
|
38
|
-
lib/tilt/kramdown.rb
|
39
|
-
lib/tilt/less.rb
|
40
|
-
lib/tilt/liquid.rb
|
41
|
-
lib/tilt/mapping.rb
|
42
|
-
lib/tilt/markaby.rb
|
43
|
-
lib/tilt/maruku.rb
|
44
|
-
lib/tilt/nokogiri.rb
|
45
|
-
lib/tilt/plain.rb
|
46
|
-
lib/tilt/radius.rb
|
47
|
-
lib/tilt/rdiscount.rb
|
48
|
-
lib/tilt/rdoc.rb
|
49
|
-
lib/tilt/redcarpet.rb
|
50
|
-
lib/tilt/redcloth.rb
|
51
|
-
lib/tilt/sass.rb
|
52
|
-
lib/tilt/string.rb
|
53
|
-
lib/tilt/template.rb
|
54
|
-
lib/tilt/wikicloth.rb
|
55
|
-
lib/tilt/yajl.rb
|
56
|
-
test/markaby/locals.mab
|
57
|
-
test/markaby/markaby.mab
|
58
|
-
test/markaby/markaby_other_static.mab
|
59
|
-
test/markaby/render_twice.mab
|
60
|
-
test/markaby/scope.mab
|
61
|
-
test/markaby/yielding.mab
|
62
|
-
test/test_helper.rb
|
63
|
-
test/tilt_asciidoctor_test.rb
|
64
|
-
test/tilt_blueclothtemplate_test.rb
|
65
|
-
test/tilt_buildertemplate_test.rb
|
66
|
-
test/tilt_cache_test.rb
|
67
|
-
test/tilt_coffeescripttemplate_test.rb
|
68
|
-
test/tilt_compilesite_test.rb
|
69
|
-
test/tilt_creoletemplate_test.rb
|
70
|
-
test/tilt_csv_test.rb
|
71
|
-
test/tilt_erbtemplate_test.rb
|
72
|
-
test/tilt_erubistemplate_test.rb
|
73
|
-
test/tilt_etannitemplate_test.rb
|
74
|
-
test/tilt_hamltemplate_test.rb
|
75
|
-
test/tilt_kramdown_test.rb
|
76
|
-
test/tilt_lesstemplate_test.less
|
77
|
-
test/tilt_lesstemplate_test.rb
|
78
|
-
test/tilt_liquidtemplate_test.rb
|
79
|
-
test/tilt_mapping_test.rb
|
80
|
-
test/tilt_markaby_test.rb
|
81
|
-
test/tilt_markdown_test.rb
|
82
|
-
test/tilt_marukutemplate_test.rb
|
83
|
-
test/tilt_metadata_test.rb
|
84
|
-
test/tilt_nokogiritemplate_test.rb
|
85
|
-
test/tilt_radiustemplate_test.rb
|
86
|
-
test/tilt_rdiscounttemplate_test.rb
|
87
|
-
test/tilt_rdoctemplate_test.rb
|
88
|
-
test/tilt_redcarpettemplate_test.rb
|
89
|
-
test/tilt_redclothtemplate_test.rb
|
90
|
-
test/tilt_sasstemplate_test.rb
|
91
|
-
test/tilt_stringtemplate_test.rb
|
92
|
-
test/tilt_template_test.rb
|
93
|
-
test/tilt_test.rb
|
94
|
-
test/tilt_wikiclothtemplate_test.rb
|
95
|
-
test/tilt_yajltemplate_test.rb
|
96
|
-
tilt.gemspec
|
97
|
-
]
|
98
|
-
# = MANIFEST =
|
99
|
-
|
100
|
-
s.executables = ['tilt']
|
101
|
-
s.test_files = s.files.select {|path| path =~ /^test\/.*_test.rb/}
|
102
|
-
|
103
|
-
s.homepage = "http://github.com/rtomayko/tilt/"
|
104
|
-
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Tilt", "--main", "Tilt"]
|
105
|
-
s.require_paths = %w[lib]
|
106
|
-
s.rubygems_version = '1.1.1'
|
107
|
-
end
|