tilt 1.2 → 1.3
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.
- data/README.md +54 -24
- data/TEMPLATES.md +250 -175
- data/lib/tilt/builder.rb +40 -0
- data/lib/tilt/coffee.rb +50 -0
- data/lib/tilt/creole.rb +28 -0
- data/lib/tilt/css.rb +67 -0
- data/lib/tilt/erb.rb +110 -0
- data/lib/tilt/haml.rb +64 -0
- data/lib/tilt/liquid.rb +41 -0
- data/lib/tilt/markaby.rb +52 -0
- data/lib/tilt/markdown.rb +131 -0
- data/lib/tilt/nokogiri.rb +43 -0
- data/lib/tilt/radius.rb +51 -0
- data/lib/tilt/rdoc.rb +32 -0
- data/lib/tilt/string.rb +21 -0
- data/lib/tilt/template.rb +285 -0
- data/lib/tilt/textile.rb +25 -0
- data/lib/tilt.rb +104 -805
- data/test/tilt_blueclothtemplate_test.rb +11 -25
- data/test/tilt_buildertemplate_test.rb +16 -1
- data/test/tilt_coffeescripttemplate_test.rb +36 -1
- data/test/tilt_creoletemplate_test.rb +24 -0
- data/test/tilt_erbtemplate_test.rb +23 -19
- data/test/tilt_erubistemplate_test.rb +17 -2
- data/test/tilt_fallback_test.rb +122 -0
- data/test/tilt_hamltemplate_test.rb +9 -4
- data/test/tilt_kramdown_test.rb +42 -0
- data/test/tilt_lesstemplate_test.rb +5 -0
- data/test/tilt_liquidtemplate_test.rb +5 -0
- data/test/tilt_markaby_test.rb +5 -0
- data/test/tilt_markdown_test.rb +149 -0
- data/test/tilt_marukutemplate_test.rb +48 -0
- data/test/tilt_nokogiritemplate_test.rb +20 -7
- data/test/tilt_radiustemplate_test.rb +5 -0
- data/test/tilt_rdiscounttemplate_test.rb +21 -6
- data/test/tilt_rdoctemplate_test.rb +6 -1
- data/test/tilt_redcarpettemplate_test.rb +55 -0
- data/test/tilt_redclothtemplate_test.rb +4 -0
- data/test/tilt_sasstemplate_test.rb +10 -0
- data/test/tilt_stringtemplate_test.rb +15 -3
- data/test/tilt_template_test.rb +6 -0
- data/tilt.gemspec +28 -2
- metadata +86 -49
|
@@ -5,35 +5,16 @@ begin
|
|
|
5
5
|
require 'bluecloth'
|
|
6
6
|
|
|
7
7
|
class BlueClothTemplateTest < Test::Unit::TestCase
|
|
8
|
-
|
|
9
|
-
Tilt.
|
|
10
|
-
Tilt.register('md', Tilt::BlueClothTemplate)
|
|
11
|
-
Tilt.register('mkd', Tilt::BlueClothTemplate)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
teardown do
|
|
15
|
-
# Need to revert to RDiscount, otherwise the RDiscount test will fail
|
|
16
|
-
Tilt.register('markdown', Tilt::RDiscountTemplate)
|
|
17
|
-
Tilt.register('md', Tilt::RDiscountTemplate)
|
|
18
|
-
Tilt.register('mkd', Tilt::RDiscountTemplate)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
test "registered for '.markdown' files unless RDiscount is loaded" do
|
|
22
|
-
unless defined?(RDiscount)
|
|
23
|
-
assert_equal Tilt::BlueClothTemplate, Tilt['test.markdown']
|
|
24
|
-
end
|
|
8
|
+
test "registered for '.md' files" do
|
|
9
|
+
assert Tilt.mappings['md'].include?(Tilt::BlueClothTemplate)
|
|
25
10
|
end
|
|
26
11
|
|
|
27
|
-
test "registered for '.
|
|
28
|
-
|
|
29
|
-
assert_equal Tilt::BlueClothTemplate, Tilt['test.md']
|
|
30
|
-
end
|
|
12
|
+
test "registered for '.mkd' files" do
|
|
13
|
+
assert Tilt.mappings['mkd'].include?(Tilt::BlueClothTemplate)
|
|
31
14
|
end
|
|
32
15
|
|
|
33
|
-
test "registered for '.
|
|
34
|
-
|
|
35
|
-
assert_equal Tilt::BlueClothTemplate, Tilt['test.mkd']
|
|
36
|
-
end
|
|
16
|
+
test "registered for '.markdown' files" do
|
|
17
|
+
assert Tilt.mappings['markdown'].include?(Tilt::BlueClothTemplate)
|
|
37
18
|
end
|
|
38
19
|
|
|
39
20
|
test "preparing and evaluating templates on #render" do
|
|
@@ -41,6 +22,11 @@ begin
|
|
|
41
22
|
assert_equal "<h1>Hello World!</h1>", template.render
|
|
42
23
|
end
|
|
43
24
|
|
|
25
|
+
test "can be rendered more than once" do
|
|
26
|
+
template = Tilt::BlueClothTemplate.new { |t| "# Hello World!" }
|
|
27
|
+
3.times { assert_equal "<h1>Hello World!</h1>", template.render }
|
|
28
|
+
end
|
|
29
|
+
|
|
44
30
|
test "smartypants when :smart is set" do
|
|
45
31
|
template = Tilt::BlueClothTemplate.new(:smartypants => true) { |t|
|
|
46
32
|
"OKAY -- 'Smarty Pants'" }
|
|
@@ -14,6 +14,11 @@ begin
|
|
|
14
14
|
assert_equal "<em>Hello World!</em>\n", template.render
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
+
test "can be rendered more than once" do
|
|
18
|
+
template = Tilt::BuilderTemplate.new { |t| "xml.em 'Hello World!'" }
|
|
19
|
+
3.times { assert_equal "<em>Hello World!</em>\n", template.render }
|
|
20
|
+
end
|
|
21
|
+
|
|
17
22
|
test "passing locals" do
|
|
18
23
|
template = Tilt::BuilderTemplate.new { "xml.em('Hey ' + name + '!')" }
|
|
19
24
|
assert_equal "<em>Hey Joe!</em>\n", template.render(Object.new, :name => 'Joe')
|
|
@@ -28,7 +33,7 @@ begin
|
|
|
28
33
|
|
|
29
34
|
test "passing a block for yield" do
|
|
30
35
|
template = Tilt::BuilderTemplate.new { "xml.em('Hey ' + yield + '!')" }
|
|
31
|
-
assert_equal "<em>Hey Joe!</em>\n", template.render { 'Joe' }
|
|
36
|
+
3.times { assert_equal "<em>Hey Joe!</em>\n", template.render { 'Joe' }}
|
|
32
37
|
end
|
|
33
38
|
|
|
34
39
|
test "block style templates" do
|
|
@@ -38,6 +43,16 @@ begin
|
|
|
38
43
|
end
|
|
39
44
|
assert_equal "<em>Hey Joe!</em>\n", template.render
|
|
40
45
|
end
|
|
46
|
+
|
|
47
|
+
test "allows nesting raw XML" do
|
|
48
|
+
subtemplate = Tilt::BuilderTemplate.new { "xml.em 'Hello World!'" }
|
|
49
|
+
template = Tilt::BuilderTemplate.new { "xml.strong { xml << yield }" }
|
|
50
|
+
3.times do
|
|
51
|
+
options = { :xml => Builder::XmlMarkup.new }
|
|
52
|
+
assert_equal "<strong>\n<em>Hello World!</em>\n</strong>\n",
|
|
53
|
+
template.render(options) { subtemplate.render(options) }
|
|
54
|
+
end
|
|
55
|
+
end
|
|
41
56
|
end
|
|
42
57
|
rescue LoadError
|
|
43
58
|
warn "Tilt::BuilderTemplate (disabled)"
|
|
@@ -14,10 +14,45 @@ begin
|
|
|
14
14
|
assert_match "puts('Hello, World!');", template.render
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
+
test "can be rendered more than once" do
|
|
18
|
+
template = Tilt::CoffeeScriptTemplate.new { |t| "puts 'Hello, World!'\n" }
|
|
19
|
+
3.times { assert_match "puts('Hello, World!');", template.render }
|
|
20
|
+
end
|
|
21
|
+
|
|
17
22
|
test "disabling coffee-script wrapper" do
|
|
18
|
-
|
|
23
|
+
str = "puts 'Hello, World!'\n"
|
|
24
|
+
|
|
25
|
+
template = Tilt::CoffeeScriptTemplate.new(:bare => true) { str }
|
|
26
|
+
assert_equal "puts('Hello, World!');", template.render
|
|
27
|
+
|
|
28
|
+
template2 = Tilt::CoffeeScriptTemplate.new(:no_wrap => true) { str}
|
|
19
29
|
assert_equal "puts('Hello, World!');", template.render
|
|
20
30
|
end
|
|
31
|
+
|
|
32
|
+
context "disabling coffee-script wrapper globally" do
|
|
33
|
+
setup do
|
|
34
|
+
@bare = Tilt::CoffeeScriptTemplate.default_bare
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
teardown do
|
|
38
|
+
Tilt::CoffeeScriptTemplate.default_bare = @bare
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
test "no options" do
|
|
42
|
+
template = Tilt::CoffeeScriptTemplate.new { |t| "puts 'Hello, World!'\n" }
|
|
43
|
+
assert_equal "puts('Hello, World!');", template.render
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
test "overridden by :bare" do
|
|
47
|
+
template = Tilt::CoffeeScriptTemplate.new(:bare => false) { "puts 'Hello, World!'\n" }
|
|
48
|
+
assert_not_equal "puts('Hello, World!');", template.render
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
test "overridden by :no_wrap" do
|
|
52
|
+
template = Tilt::CoffeeScriptTemplate.new(:no_wrap => false) { "puts 'Hello, World!'\n" }
|
|
53
|
+
assert_not_equal "puts('Hello, World!');", template.render
|
|
54
|
+
end
|
|
55
|
+
end
|
|
21
56
|
end
|
|
22
57
|
|
|
23
58
|
rescue LoadError => boom
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'contest'
|
|
2
|
+
require 'tilt'
|
|
3
|
+
|
|
4
|
+
begin
|
|
5
|
+
require 'creole'
|
|
6
|
+
|
|
7
|
+
class CreoleTemplateTest < Test::Unit::TestCase
|
|
8
|
+
test "is registered for '.creole' files" do
|
|
9
|
+
assert_equal Tilt::CreoleTemplate, Tilt['test.creole']
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
test "compiles and evaluates the template on #render" do
|
|
13
|
+
template = Tilt::CreoleTemplate.new { |t| "= Hello World!" }
|
|
14
|
+
assert_equal "<h1>Hello World!</h1>", template.render
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
test "can be rendered more than once" do
|
|
18
|
+
template = Tilt::CreoleTemplate.new { |t| "= Hello World!" }
|
|
19
|
+
3.times { assert_equal "<h1>Hello World!</h1>", template.render }
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
rescue LoadError => boom
|
|
23
|
+
warn "Tilt::CreoleTemplate (disabled)\n"
|
|
24
|
+
end
|
|
@@ -6,12 +6,11 @@ require 'tempfile'
|
|
|
6
6
|
|
|
7
7
|
class ERBTemplateTest < Test::Unit::TestCase
|
|
8
8
|
test "registered for '.erb' files" do
|
|
9
|
-
|
|
10
|
-
assert_equal Tilt::ERBTemplate, Tilt['test.html.erb']
|
|
9
|
+
assert Tilt.mappings['erb'].include?(Tilt::ERBTemplate)
|
|
11
10
|
end
|
|
12
11
|
|
|
13
12
|
test "registered for '.rhtml' files" do
|
|
14
|
-
|
|
13
|
+
assert Tilt.mappings['rhtml'].include?(Tilt::ERBTemplate)
|
|
15
14
|
end
|
|
16
15
|
|
|
17
16
|
test "loading and evaluating templates on #render" do
|
|
@@ -19,6 +18,11 @@ class ERBTemplateTest < Test::Unit::TestCase
|
|
|
19
18
|
assert_equal "Hello World!", template.render
|
|
20
19
|
end
|
|
21
20
|
|
|
21
|
+
test "can be rendered more than once" do
|
|
22
|
+
template = Tilt::ERBTemplate.new { |t| "Hello World!" }
|
|
23
|
+
3.times { assert_equal "Hello World!", template.render }
|
|
24
|
+
end
|
|
25
|
+
|
|
22
26
|
test "passing locals" do
|
|
23
27
|
template = Tilt::ERBTemplate.new { 'Hey <%= name %>!' }
|
|
24
28
|
assert_equal "Hey Joe!", template.render(Object.new, :name => 'Joe')
|
|
@@ -62,9 +66,9 @@ class ERBTemplateTest < Test::Unit::TestCase
|
|
|
62
66
|
fail 'should have raised an exception'
|
|
63
67
|
rescue => boom
|
|
64
68
|
assert_kind_of NameError, boom
|
|
65
|
-
line = boom.backtrace.first
|
|
69
|
+
line = boom.backtrace.grep(/^test\.erb:/).first
|
|
70
|
+
assert line, "Backtrace didn't contain test.erb"
|
|
66
71
|
file, line, meth = line.split(":")
|
|
67
|
-
assert_equal 'test.erb', file
|
|
68
72
|
assert_equal '13', line
|
|
69
73
|
end
|
|
70
74
|
end
|
|
@@ -85,18 +89,18 @@ class ERBTemplateTest < Test::Unit::TestCase
|
|
|
85
89
|
end
|
|
86
90
|
end
|
|
87
91
|
|
|
88
|
-
test "default
|
|
89
|
-
template = Tilt.new('test.erb', 1) { "\n<%= 1 + 1 %>\n" }
|
|
90
|
-
assert_equal "\n2
|
|
92
|
+
test "default stripping trim mode" do
|
|
93
|
+
template = Tilt::ERBTemplate.new('test.erb', 1) { "\n<%= 1 + 1 %>\n" }
|
|
94
|
+
assert_equal "\n2", template.render
|
|
91
95
|
end
|
|
92
96
|
|
|
93
97
|
test "stripping trim mode" do
|
|
94
|
-
template = Tilt.new('test.erb', 1, :trim => '-') { "\n<%= 1 + 1 -%>\n" }
|
|
98
|
+
template = Tilt::ERBTemplate.new('test.erb', 1, :trim => '-') { "\n<%= 1 + 1 -%>\n" }
|
|
95
99
|
assert_equal "\n2", template.render
|
|
96
100
|
end
|
|
97
101
|
|
|
98
102
|
test "shorthand whole line syntax trim mode" do
|
|
99
|
-
template = Tilt.new('test.erb', :trim => '%') { "\n% if true\nhello\n%end\n" }
|
|
103
|
+
template = Tilt::ERBTemplate.new('test.erb', :trim => '%') { "\n% if true\nhello\n%end\n" }
|
|
100
104
|
assert_equal "\nhello\n", template.render
|
|
101
105
|
end
|
|
102
106
|
|
|
@@ -159,9 +163,9 @@ class CompiledERBTemplateTest < Test::Unit::TestCase
|
|
|
159
163
|
fail 'should have raised an exception'
|
|
160
164
|
rescue => boom
|
|
161
165
|
assert_kind_of NameError, boom
|
|
162
|
-
line = boom.backtrace.first
|
|
166
|
+
line = boom.backtrace.grep(/^test\.erb:/).first
|
|
167
|
+
assert line, "Backtrace didn't contain test.erb"
|
|
163
168
|
file, line, meth = line.split(":")
|
|
164
|
-
assert_equal 'test.erb', file
|
|
165
169
|
assert_equal '13', line
|
|
166
170
|
end
|
|
167
171
|
end
|
|
@@ -182,18 +186,18 @@ class CompiledERBTemplateTest < Test::Unit::TestCase
|
|
|
182
186
|
end
|
|
183
187
|
end
|
|
184
188
|
|
|
185
|
-
test "default
|
|
186
|
-
template = Tilt.new('test.erb') { "\n<%= 1 + 1 %>\n" }
|
|
187
|
-
assert_equal "\n2
|
|
189
|
+
test "default stripping trim mode" do
|
|
190
|
+
template = Tilt::ERBTemplate.new('test.erb') { "\n<%= 1 + 1 %>\n" }
|
|
191
|
+
assert_equal "\n2", template.render(Scope.new)
|
|
188
192
|
end
|
|
189
193
|
|
|
190
194
|
test "stripping trim mode" do
|
|
191
|
-
template = Tilt.new('test.erb', :trim => '-') { "\n<%= 1 + 1 -%>\n" }
|
|
195
|
+
template = Tilt::ERBTemplate.new('test.erb', :trim => '-') { "\n<%= 1 + 1 -%>\n" }
|
|
192
196
|
assert_equal "\n2", template.render(Scope.new)
|
|
193
197
|
end
|
|
194
198
|
|
|
195
199
|
test "shorthand whole line syntax trim mode" do
|
|
196
|
-
template = Tilt.new('test.erb', :trim => '%') { "\n% if true\nhello\n%end\n" }
|
|
200
|
+
template = Tilt::ERBTemplate.new('test.erb', :trim => '%') { "\n% if true\nhello\n%end\n" }
|
|
197
201
|
assert_equal "\nhello\n", template.render(Scope.new)
|
|
198
202
|
end
|
|
199
203
|
|
|
@@ -203,7 +207,7 @@ class CompiledERBTemplateTest < Test::Unit::TestCase
|
|
|
203
207
|
f.puts('ふが <%= @hoge %>')
|
|
204
208
|
f.close()
|
|
205
209
|
@hoge = "ほげ"
|
|
206
|
-
erb = Tilt
|
|
210
|
+
erb = Tilt::ERBTemplate.new(f.path)
|
|
207
211
|
3.times { erb.render(self) }
|
|
208
212
|
f.delete
|
|
209
213
|
end
|
|
@@ -213,7 +217,7 @@ class CompiledERBTemplateTest < Test::Unit::TestCase
|
|
|
213
217
|
f.puts('ふが <%= @hoge %>')
|
|
214
218
|
f.close()
|
|
215
219
|
@hoge = "ほげ"
|
|
216
|
-
erb = Tilt
|
|
220
|
+
erb = Tilt::ERBTemplate.new(f.path, :default_encoding => 'UTF-8')
|
|
217
221
|
3.times { erb.render(self) }
|
|
218
222
|
f.delete
|
|
219
223
|
end
|
|
@@ -9,11 +9,26 @@ begin
|
|
|
9
9
|
assert_equal Tilt::ErubisTemplate, Tilt['test.html.erubis']
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
+
test "registered above ERB" do
|
|
13
|
+
%w[erb rhtml].each do |ext|
|
|
14
|
+
mappings = Tilt.mappings[ext]
|
|
15
|
+
erubis_idx = mappings.index(Tilt::ErubisTemplate)
|
|
16
|
+
erb_idx = mappings.index(Tilt::ERBTemplate)
|
|
17
|
+
assert erubis_idx < erb_idx,
|
|
18
|
+
"#{erubis_idx} should be lower than #{erb_idx}"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
12
22
|
test "preparing and evaluating templates on #render" do
|
|
13
23
|
template = Tilt::ErubisTemplate.new { |t| "Hello World!" }
|
|
14
24
|
assert_equal "Hello World!", template.render
|
|
15
25
|
end
|
|
16
26
|
|
|
27
|
+
test "can be rendered more than once" do
|
|
28
|
+
template = Tilt::ErubisTemplate.new { |t| "Hello World!" }
|
|
29
|
+
3.times { assert_equal "Hello World!", template.render }
|
|
30
|
+
end
|
|
31
|
+
|
|
17
32
|
test "passing locals" do
|
|
18
33
|
template = Tilt::ErubisTemplate.new { 'Hey <%= name %>!' }
|
|
19
34
|
assert_equal "Hey Joe!", template.render(Object.new, :name => 'Joe')
|
|
@@ -57,9 +72,9 @@ begin
|
|
|
57
72
|
fail 'should have raised an exception'
|
|
58
73
|
rescue => boom
|
|
59
74
|
assert_kind_of NameError, boom
|
|
60
|
-
line = boom.backtrace.first
|
|
75
|
+
line = boom.backtrace.grep(/^test\.erubis:/).first
|
|
76
|
+
assert line, "Backtrace didn't contain test.erubis"
|
|
61
77
|
file, line, meth = line.split(":")
|
|
62
|
-
assert_equal 'test.erubis', file
|
|
63
78
|
assert_equal '13', line
|
|
64
79
|
end
|
|
65
80
|
end
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
require 'contest'
|
|
2
|
+
require 'tilt'
|
|
3
|
+
|
|
4
|
+
class TiltFallbackTest < Test::Unit::TestCase
|
|
5
|
+
class FailTemplate < Tilt::Template
|
|
6
|
+
def self.engine_initialized?; false end
|
|
7
|
+
def prepare; end
|
|
8
|
+
|
|
9
|
+
def initialize_engine
|
|
10
|
+
raise LoadError, "can't load #{self.class}"
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
class WinTemplate < Tilt::Template
|
|
15
|
+
def self.engine_initialized?; true end
|
|
16
|
+
def prepare; end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
FailTemplate2 = Class.new(FailTemplate)
|
|
20
|
+
WinTemplate2 = Class.new(WinTemplate)
|
|
21
|
+
|
|
22
|
+
def set_ivar(obj, name, value)
|
|
23
|
+
obj.instance_variable_set("@#{name}", value)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def clear_ivar(obj, name)
|
|
27
|
+
ivar = "@#{name}"
|
|
28
|
+
value = obj.instance_variable_get(ivar)
|
|
29
|
+
ensure
|
|
30
|
+
obj.instance_variable_set(ivar, value.dup.clear)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
setup do
|
|
34
|
+
# Make sure every test have no mappings.
|
|
35
|
+
@p = clear_ivar(Tilt, :preferred_mappings)
|
|
36
|
+
@t = clear_ivar(Tilt, :template_mappings)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
teardown do
|
|
40
|
+
set_ivar(Tilt, :preferred_mappings, @p)
|
|
41
|
+
set_ivar(Tilt, :template_mappings, @t)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
test "returns nil on unregistered extensions" do
|
|
45
|
+
template = Tilt["md"]
|
|
46
|
+
assert_equal nil, template
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
test "returns the last registered template" do
|
|
50
|
+
Tilt.register("md", WinTemplate)
|
|
51
|
+
Tilt.register("md", WinTemplate2)
|
|
52
|
+
|
|
53
|
+
template = Tilt["md"]
|
|
54
|
+
assert_equal WinTemplate2, template
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
test "returns the last registered working template" do
|
|
58
|
+
Tilt.register("md", WinTemplate)
|
|
59
|
+
Tilt.register("md", FailTemplate)
|
|
60
|
+
|
|
61
|
+
template = Tilt["md"]
|
|
62
|
+
assert_equal WinTemplate, template
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
test "if every template fails, raise the exception from the first template" do
|
|
66
|
+
Tilt.register("md", FailTemplate)
|
|
67
|
+
Tilt.register("md", FailTemplate2)
|
|
68
|
+
|
|
69
|
+
exc = assert_raise(LoadError) { Tilt["md"] }
|
|
70
|
+
assert_match /FailTemplate2/, exc.message
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
test ".prefer should also register the template" do
|
|
74
|
+
Tilt.prefer(WinTemplate, "md")
|
|
75
|
+
assert Tilt.registered?("md")
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
test ".prefer always win" do
|
|
79
|
+
Tilt.register("md", FailTemplate)
|
|
80
|
+
Tilt.register("md", WinTemplate)
|
|
81
|
+
Tilt.prefer(FailTemplate, "md")
|
|
82
|
+
|
|
83
|
+
template = Tilt["md"]
|
|
84
|
+
assert_equal FailTemplate, template
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
test ".prefer accepts multiple extensions" do
|
|
88
|
+
extensions = %w[md mkd markdown]
|
|
89
|
+
Tilt.prefer(FailTemplate, *extensions)
|
|
90
|
+
|
|
91
|
+
extensions.each do |ext|
|
|
92
|
+
template = Tilt[ext]
|
|
93
|
+
assert_equal FailTemplate, template
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
test ".prefer with no extension should use already registered extensions" do
|
|
98
|
+
extensions = %w[md mkd markdown]
|
|
99
|
+
|
|
100
|
+
extensions.each do |ext|
|
|
101
|
+
Tilt.register(ext, FailTemplate)
|
|
102
|
+
Tilt.register(ext, WinTemplate)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
Tilt.prefer(FailTemplate)
|
|
106
|
+
|
|
107
|
+
extensions.each do |ext|
|
|
108
|
+
template = Tilt[ext]
|
|
109
|
+
assert_equal FailTemplate, template
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
test ".prefer should only override extensions the preferred library is registered for" do
|
|
114
|
+
Tilt.register("md", WinTemplate)
|
|
115
|
+
Tilt.register("mkd", FailTemplate)
|
|
116
|
+
Tilt.register("mkd", WinTemplate)
|
|
117
|
+
Tilt.prefer(FailTemplate)
|
|
118
|
+
assert_equal FailTemplate, Tilt["mkd"]
|
|
119
|
+
assert_equal WinTemplate, Tilt["md"]
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
@@ -17,6 +17,11 @@ begin
|
|
|
17
17
|
assert_equal "<p>Hello World!</p>\n", template.render
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
+
test "can be rendered more than once" do
|
|
21
|
+
template = Tilt::HamlTemplate.new { |t| "%p Hello World!" }
|
|
22
|
+
3.times { assert_equal "<p>Hello World!</p>\n", template.render }
|
|
23
|
+
end
|
|
24
|
+
|
|
20
25
|
test "passing locals" do
|
|
21
26
|
template = Tilt::HamlTemplate.new { "%p= 'Hey ' + name + '!'" }
|
|
22
27
|
assert_equal "<p>Hey Joe!</p>\n", template.render(Object.new, :name => 'Joe')
|
|
@@ -43,9 +48,9 @@ begin
|
|
|
43
48
|
fail 'should have raised an exception'
|
|
44
49
|
rescue => boom
|
|
45
50
|
assert_kind_of NameError, boom
|
|
46
|
-
line = boom.backtrace.first
|
|
51
|
+
line = boom.backtrace.grep(/^test\.haml:/).first
|
|
52
|
+
assert line, "Backtrace didn't contain test.haml"
|
|
47
53
|
file, line, meth = line.split(":")
|
|
48
|
-
assert_equal 'test.haml', file
|
|
49
54
|
assert_equal '12', line
|
|
50
55
|
end
|
|
51
56
|
end
|
|
@@ -103,9 +108,9 @@ begin
|
|
|
103
108
|
fail 'should have raised an exception'
|
|
104
109
|
rescue => boom
|
|
105
110
|
assert_kind_of NameError, boom
|
|
106
|
-
line = boom.backtrace.first
|
|
111
|
+
line = boom.backtrace.grep(/^test\.haml:/).first
|
|
112
|
+
assert line, "Backtrace didn't contain test.haml"
|
|
107
113
|
file, line, meth = line.split(":")
|
|
108
|
-
assert_equal 'test.haml', file
|
|
109
114
|
assert_equal '12', line
|
|
110
115
|
end
|
|
111
116
|
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
require 'contest'
|
|
2
|
+
require 'tilt'
|
|
3
|
+
|
|
4
|
+
begin
|
|
5
|
+
require 'kramdown'
|
|
6
|
+
|
|
7
|
+
class MarukuTemplateTest < Test::Unit::TestCase
|
|
8
|
+
test "registered for '.md' files" do
|
|
9
|
+
assert Tilt.mappings['md'].include?(Tilt::KramdownTemplate)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
test "registered for '.mkd' files" do
|
|
13
|
+
assert Tilt.mappings['mkd'].include?(Tilt::KramdownTemplate)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
test "registered for '.markdown' files" do
|
|
17
|
+
assert Tilt.mappings['markdown'].include?(Tilt::KramdownTemplate)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
test "registered above MarukuTemplate" do
|
|
21
|
+
%w[md mkd markdown].each do |ext|
|
|
22
|
+
mappings = Tilt.mappings[ext]
|
|
23
|
+
kram_idx = mappings.index(Tilt::KramdownTemplate)
|
|
24
|
+
maru_idx = mappings.index(Tilt::MarukuTemplate)
|
|
25
|
+
assert kram_idx < maru_idx,
|
|
26
|
+
"#{kram_idx} should be lower than #{maru_idx}"
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
test "preparing and evaluating templates on #render" do
|
|
31
|
+
template = Tilt::KramdownTemplate.new { |t| "# Hello World!" }
|
|
32
|
+
assert_equal "<h1 id='hello_world'>Hello World!</h1>", template.render
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
test "can be rendered more than once" do
|
|
36
|
+
template = Tilt::KramdownTemplate.new { |t| "# Hello World!" }
|
|
37
|
+
3.times { assert_equal "<h1 id='hello_world'>Hello World!</h1>", template.render }
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
rescue LoadError => boom
|
|
41
|
+
warn "Tilt::KramdownTemplate (disabled)\n"
|
|
42
|
+
end
|
|
@@ -13,6 +13,11 @@ begin
|
|
|
13
13
|
template = Tilt::LessTemplate.new { |t| ".bg { background-color: #0000ff; } \n#main\n { .bg; }\n" }
|
|
14
14
|
assert_equal ".bg, #main { background-color: #0000ff; }\n", template.render
|
|
15
15
|
end
|
|
16
|
+
|
|
17
|
+
test "can be rendered more than once" do
|
|
18
|
+
template = Tilt::LessTemplate.new { |t| ".bg { background-color: #0000ff; } \n#main\n { .bg; }\n" }
|
|
19
|
+
3.times { assert_equal ".bg, #main { background-color: #0000ff; }\n", template.render }
|
|
20
|
+
end
|
|
16
21
|
end
|
|
17
22
|
|
|
18
23
|
rescue LoadError => boom
|
|
@@ -14,6 +14,11 @@ begin
|
|
|
14
14
|
assert_equal "Hello World!", template.render
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
+
test "can be rendered more than once" do
|
|
18
|
+
template = Tilt::LiquidTemplate.new { |t| "Hello World!" }
|
|
19
|
+
3.times { assert_equal "Hello World!", template.render }
|
|
20
|
+
end
|
|
21
|
+
|
|
17
22
|
test "passing locals" do
|
|
18
23
|
template = Tilt::LiquidTemplate.new { "Hey {{ name }}!" }
|
|
19
24
|
assert_equal "Hey Joe!", template.render(nil, :name => 'Joe')
|
data/test/tilt_markaby_test.rb
CHANGED
|
@@ -26,6 +26,11 @@ begin
|
|
|
26
26
|
assert_equal "<html></html>", tilt.render
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
+
test "can be rendered more than once" do
|
|
30
|
+
tilt = ::Tilt::MarkabyTemplate.new { "html do; end" }
|
|
31
|
+
3.times { assert_equal "<html></html>", tilt.render }
|
|
32
|
+
end
|
|
33
|
+
|
|
29
34
|
test "should evaluate a template file in the scope given" do
|
|
30
35
|
scope = Object.new
|
|
31
36
|
def scope.foo
|