tilt 1.4.1 → 2.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/COPYING +1 -1
- data/bin/tilt +18 -8
- data/lib/tilt/asciidoc.rb +1 -8
- data/lib/tilt/babel.rb +16 -0
- data/lib/tilt/bluecloth.rb +24 -0
- data/lib/tilt/builder.rb +12 -15
- data/lib/tilt/coffee.rb +10 -6
- data/lib/tilt/commonmarker.rb +88 -0
- data/lib/tilt/creole.rb +25 -0
- data/lib/tilt/csv.rb +12 -18
- data/lib/tilt/dummy.rb +3 -0
- data/lib/tilt/erb.rb +9 -56
- data/lib/tilt/erubi.rb +32 -0
- data/lib/tilt/erubis.rb +43 -0
- data/lib/tilt/haml.rb +66 -44
- data/lib/tilt/kramdown.rb +25 -0
- data/lib/tilt/less.rb +30 -0
- data/lib/tilt/liquid.rb +9 -10
- data/lib/tilt/livescript.rb +23 -0
- data/lib/tilt/mapping.rb +293 -0
- data/lib/tilt/markaby.rb +1 -8
- data/lib/tilt/maruku.rb +22 -0
- data/lib/tilt/nokogiri.rb +1 -8
- data/lib/tilt/pandoc.rb +57 -0
- data/lib/tilt/plain.rb +0 -4
- data/lib/tilt/prawn.rb +43 -0
- data/lib/tilt/radius.rb +1 -8
- data/lib/tilt/rdiscount.rb +39 -0
- data/lib/tilt/rdoc.rb +3 -10
- data/lib/tilt/redcarpet.rb +86 -0
- data/lib/tilt/{textile.rb → redcloth.rb} +1 -8
- data/lib/tilt/rst-pandoc.rb +23 -0
- data/lib/tilt/sass.rb +78 -0
- data/lib/tilt/sigil.rb +34 -0
- data/lib/tilt/string.rb +1 -1
- data/lib/tilt/template.rb +121 -105
- data/lib/tilt/typescript.rb +26 -0
- data/lib/tilt/wikicloth.rb +22 -0
- data/lib/tilt/yajl.rb +1 -8
- data/lib/tilt.rb +118 -155
- metadata +38 -469
- data/CHANGELOG.md +0 -44
- data/Gemfile +0 -32
- data/HACKING +0 -16
- data/README.md +0 -232
- data/Rakefile +0 -104
- data/TEMPLATES.md +0 -516
- data/lib/tilt/css.rb +0 -80
- data/lib/tilt/markdown.rb +0 -214
- data/lib/tilt/wiki.rb +0 -58
- data/test/contest.rb +0 -68
- 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/tilt_asciidoctor_test.rb +0 -44
- data/test/tilt_blueclothtemplate_test.rb +0 -45
- data/test/tilt_buildertemplate_test.rb +0 -59
- data/test/tilt_cache_test.rb +0 -32
- data/test/tilt_coffeescripttemplate_test.rb +0 -114
- data/test/tilt_compilesite_test.rb +0 -51
- data/test/tilt_creoletemplate_test.rb +0 -28
- data/test/tilt_csv_test.rb +0 -69
- data/test/tilt_erbtemplate_test.rb +0 -239
- data/test/tilt_erubistemplate_test.rb +0 -151
- data/test/tilt_etannitemplate_test.rb +0 -173
- data/test/tilt_fallback_test.rb +0 -122
- data/test/tilt_hamltemplate_test.rb +0 -144
- data/test/tilt_kramdown_test.rb +0 -42
- 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_markaby_test.rb +0 -88
- data/test/tilt_markdown_test.rb +0 -172
- data/test/tilt_marukutemplate_test.rb +0 -48
- data/test/tilt_nokogiritemplate_test.rb +0 -87
- data/test/tilt_radiustemplate_test.rb +0 -75
- data/test/tilt_rdiscounttemplate_test.rb +0 -55
- data/test/tilt_rdoctemplate_test.rb +0 -31
- data/test/tilt_redcarpettemplate_test.rb +0 -71
- data/test/tilt_redclothtemplate_test.rb +0 -36
- data/test/tilt_sasstemplate_test.rb +0 -41
- data/test/tilt_stringtemplate_test.rb +0 -170
- data/test/tilt_template_test.rb +0 -323
- data/test/tilt_test.rb +0 -65
- data/test/tilt_wikiclothtemplate_test.rb +0 -32
- data/test/tilt_yajltemplate_test.rb +0 -101
- data/tilt.gemspec +0 -120
@@ -1,173 +0,0 @@
|
|
1
|
-
require 'contest'
|
2
|
-
require 'tilt'
|
3
|
-
|
4
|
-
class EtanniTemplateTest < Test::Unit::TestCase
|
5
|
-
test "registered for '.etn' files" do
|
6
|
-
assert_equal Tilt::EtanniTemplate, Tilt['test.etn']
|
7
|
-
end
|
8
|
-
|
9
|
-
test "registered for '.etanni' files" do
|
10
|
-
assert_equal Tilt::EtanniTemplate, Tilt['test.etanni']
|
11
|
-
end
|
12
|
-
|
13
|
-
test "loading and evaluating templates on #render" do
|
14
|
-
template = Tilt::EtanniTemplate.new { |t| "Hello World!" }
|
15
|
-
assert_equal "Hello World!", template.render
|
16
|
-
end
|
17
|
-
|
18
|
-
test "can be rendered more than once" do
|
19
|
-
template = Tilt::EtanniTemplate.new { |t| "Hello World!" }
|
20
|
-
3.times { assert_equal "Hello World!", template.render }
|
21
|
-
end
|
22
|
-
|
23
|
-
test "passing locals" do
|
24
|
-
template = Tilt::EtanniTemplate.new { 'Hey #{name}!' }
|
25
|
-
assert_equal "Hey Joe!", template.render(Object.new, :name => 'Joe')
|
26
|
-
end
|
27
|
-
|
28
|
-
test "evaluating in an object scope" do
|
29
|
-
template = Tilt::EtanniTemplate.new { 'Hey #{@name}!' }
|
30
|
-
scope = Object.new
|
31
|
-
scope.instance_variable_set :@name, 'Joe'
|
32
|
-
assert_equal "Hey Joe!", template.render(scope)
|
33
|
-
end
|
34
|
-
|
35
|
-
test "passing a block for yield" do
|
36
|
-
template = Tilt::EtanniTemplate.new { 'Hey #{yield}!' }
|
37
|
-
assert_equal "Hey Joe!", template.render { 'Joe' }
|
38
|
-
assert_equal "Hey Moe!", template.render { 'Moe' }
|
39
|
-
end
|
40
|
-
|
41
|
-
test "multiline templates" do
|
42
|
-
template = Tilt::EtanniTemplate.new { "Hello\nWorld!\n" }
|
43
|
-
assert_equal "Hello\nWorld!", template.render
|
44
|
-
end
|
45
|
-
|
46
|
-
test "backtrace file and line reporting without locals" do
|
47
|
-
data = File.read(__FILE__).split("\n__END__\n").last
|
48
|
-
fail unless data[0] == ?<
|
49
|
-
template = Tilt::EtanniTemplate.new('test.etn', 11) { data }
|
50
|
-
begin
|
51
|
-
template.render
|
52
|
-
fail 'should have raised an exception'
|
53
|
-
rescue => boom
|
54
|
-
assert_kind_of NameError, boom
|
55
|
-
line = boom.backtrace.grep(/^test\.etn:/).first
|
56
|
-
assert line, "Backtrace didn't contain test.etn"
|
57
|
-
file, line, meth = line.split(":")
|
58
|
-
assert_equal '13', line
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
test "backtrace file and line reporting with locals" do
|
63
|
-
data = File.read(__FILE__).split("\n__END__\n").last
|
64
|
-
fail unless data[0] == ?<
|
65
|
-
template = Tilt::EtanniTemplate.new('test.etn', 1) { data }
|
66
|
-
begin
|
67
|
-
template.render(nil, :name => 'Joe', :foo => 'bar')
|
68
|
-
fail 'should have raised an exception'
|
69
|
-
rescue => boom
|
70
|
-
assert_kind_of RuntimeError, boom
|
71
|
-
line = boom.backtrace.first
|
72
|
-
file, line, meth = line.split(":")
|
73
|
-
assert_equal 'test.etn', file
|
74
|
-
assert_equal '6', line
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
|
80
|
-
class CompiledEtanniTemplateTest < Test::Unit::TestCase
|
81
|
-
def teardown
|
82
|
-
GC.start
|
83
|
-
end
|
84
|
-
|
85
|
-
class Scope
|
86
|
-
end
|
87
|
-
|
88
|
-
test "compiling template source to a method" do
|
89
|
-
template = Tilt::EtanniTemplate.new { |t| "Hello World!" }
|
90
|
-
template.render(Scope.new)
|
91
|
-
method = template.send(:compiled_method, [])
|
92
|
-
assert_kind_of UnboundMethod, method
|
93
|
-
end
|
94
|
-
|
95
|
-
test "loading and evaluating templates on #render" do
|
96
|
-
template = Tilt::EtanniTemplate.new { |t| "Hello World!" }
|
97
|
-
assert_equal "Hello World!", template.render(Scope.new)
|
98
|
-
end
|
99
|
-
|
100
|
-
test "passing locals" do
|
101
|
-
template = Tilt::EtanniTemplate.new { 'Hey #{name}!' }
|
102
|
-
assert_equal "Hey Joe!", template.render(Scope.new, :name => 'Joe')
|
103
|
-
assert_equal "Hey Moe!", template.render(Scope.new, :name => 'Moe')
|
104
|
-
end
|
105
|
-
|
106
|
-
test "evaluating in an object scope" do
|
107
|
-
template = Tilt::EtanniTemplate.new { 'Hey #{@name}!' }
|
108
|
-
scope = Scope.new
|
109
|
-
scope.instance_variable_set :@name, 'Joe'
|
110
|
-
assert_equal "Hey Joe!", template.render(scope)
|
111
|
-
scope.instance_variable_set :@name, 'Moe'
|
112
|
-
assert_equal "Hey Moe!", template.render(scope)
|
113
|
-
end
|
114
|
-
|
115
|
-
test "passing a block for yield" do
|
116
|
-
template = Tilt::EtanniTemplate.new { 'Hey #{yield}!' }
|
117
|
-
assert_equal "Hey Joe!", template.render(Scope.new) { 'Joe' }
|
118
|
-
assert_equal "Hey Moe!", template.render(Scope.new) { 'Moe' }
|
119
|
-
end
|
120
|
-
|
121
|
-
test "multiline templates" do
|
122
|
-
template = Tilt::EtanniTemplate.new { "Hello\nWorld!\n" }
|
123
|
-
assert_equal "Hello\nWorld!", template.render(Scope.new)
|
124
|
-
end
|
125
|
-
|
126
|
-
test "template with '}'" do
|
127
|
-
template = Tilt::EtanniTemplate.new { "Hello }" }
|
128
|
-
assert_equal "Hello }", template.render
|
129
|
-
end
|
130
|
-
|
131
|
-
test "backtrace file and line reporting without locals" do
|
132
|
-
data = File.read(__FILE__).split("\n__END__\n").last
|
133
|
-
fail unless data[0] == ?<
|
134
|
-
template = Tilt::EtanniTemplate.new('test.etn', 11) { data }
|
135
|
-
begin
|
136
|
-
template.render(Scope.new)
|
137
|
-
fail 'should have raised an exception'
|
138
|
-
rescue => boom
|
139
|
-
assert_kind_of NameError, boom
|
140
|
-
line = boom.backtrace.first
|
141
|
-
line = boom.backtrace.grep(/^test\.etn:/).first
|
142
|
-
assert line, "Backtrace didn't contain test.etn"
|
143
|
-
file, line, meth = line.split(":")
|
144
|
-
assert_equal '13', line
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
test "backtrace file and line reporting with locals" do
|
149
|
-
data = File.read(__FILE__).split("\n__END__\n").last
|
150
|
-
fail unless data[0] == ?<
|
151
|
-
template = Tilt::EtanniTemplate.new('test.etn') { data }
|
152
|
-
begin
|
153
|
-
template.render(Scope.new, :name => 'Joe', :foo => 'bar')
|
154
|
-
fail 'should have raised an exception'
|
155
|
-
rescue => boom
|
156
|
-
assert_kind_of RuntimeError, boom
|
157
|
-
line = boom.backtrace.first
|
158
|
-
file, line, meth = line.split(":")
|
159
|
-
assert_equal 'test.etn', file
|
160
|
-
assert_equal '6', line
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
__END__
|
166
|
-
<html>
|
167
|
-
<body>
|
168
|
-
<h1>Hey #{name}!</h1>
|
169
|
-
|
170
|
-
|
171
|
-
<p>#{fail}</p>
|
172
|
-
</body>
|
173
|
-
</html>
|
data/test/tilt_fallback_test.rb
DELETED
@@ -1,122 +0,0 @@
|
|
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
|
-
|
@@ -1,144 +0,0 @@
|
|
1
|
-
require 'contest'
|
2
|
-
require 'tilt'
|
3
|
-
|
4
|
-
begin
|
5
|
-
class ::MockError < NameError
|
6
|
-
end
|
7
|
-
|
8
|
-
require 'haml'
|
9
|
-
|
10
|
-
class HamlTemplateTest < Test::Unit::TestCase
|
11
|
-
test "registered for '.haml' files" do
|
12
|
-
assert_equal Tilt::HamlTemplate, Tilt['test.haml']
|
13
|
-
end
|
14
|
-
|
15
|
-
test "preparing and evaluating templates on #render" do
|
16
|
-
template = Tilt::HamlTemplate.new { |t| "%p Hello World!" }
|
17
|
-
assert_equal "<p>Hello World!</p>\n", template.render
|
18
|
-
end
|
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
|
-
|
25
|
-
test "passing locals" do
|
26
|
-
template = Tilt::HamlTemplate.new { "%p= 'Hey ' + name + '!'" }
|
27
|
-
assert_equal "<p>Hey Joe!</p>\n", template.render(Object.new, :name => 'Joe')
|
28
|
-
end
|
29
|
-
|
30
|
-
test "evaluating in an object scope" do
|
31
|
-
template = Tilt::HamlTemplate.new { "%p= 'Hey ' + @name + '!'" }
|
32
|
-
scope = Object.new
|
33
|
-
scope.instance_variable_set :@name, 'Joe'
|
34
|
-
assert_equal "<p>Hey Joe!</p>\n", template.render(scope)
|
35
|
-
end
|
36
|
-
|
37
|
-
test "passing a block for yield" do
|
38
|
-
template = Tilt::HamlTemplate.new { "%p= 'Hey ' + yield + '!'" }
|
39
|
-
assert_equal "<p>Hey Joe!</p>\n", template.render { 'Joe' }
|
40
|
-
end
|
41
|
-
|
42
|
-
test "backtrace file and line reporting without locals" do
|
43
|
-
data = File.read(__FILE__).split("\n__END__\n").last
|
44
|
-
fail unless data[0] == ?%
|
45
|
-
template = Tilt::HamlTemplate.new('test.haml', 10) { data }
|
46
|
-
begin
|
47
|
-
template.render
|
48
|
-
fail 'should have raised an exception'
|
49
|
-
rescue => boom
|
50
|
-
assert_kind_of NameError, boom
|
51
|
-
line = boom.backtrace.grep(/^test\.haml:/).first
|
52
|
-
assert line, "Backtrace didn't contain test.haml"
|
53
|
-
file, line, meth = line.split(":")
|
54
|
-
assert_equal '12', line
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
test "backtrace file and line reporting with locals" do
|
59
|
-
data = File.read(__FILE__).split("\n__END__\n").last
|
60
|
-
fail unless data[0] == ?%
|
61
|
-
template = Tilt::HamlTemplate.new('test.haml') { data }
|
62
|
-
begin
|
63
|
-
res = template.render(Object.new, :name => 'Joe', :foo => 'bar')
|
64
|
-
rescue => boom
|
65
|
-
assert_kind_of MockError, boom
|
66
|
-
line = boom.backtrace.first
|
67
|
-
file, line, meth = line.split(":")
|
68
|
-
assert_equal 'test.haml', file
|
69
|
-
assert_equal '5', line
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
class CompiledHamlTemplateTest < Test::Unit::TestCase
|
75
|
-
class Scope
|
76
|
-
end
|
77
|
-
|
78
|
-
test "compiling template source to a method" do
|
79
|
-
template = Tilt::HamlTemplate.new { |t| "Hello World!" }
|
80
|
-
template.render(Scope.new)
|
81
|
-
method = template.send(:compiled_method, [])
|
82
|
-
assert_kind_of UnboundMethod, method
|
83
|
-
end
|
84
|
-
|
85
|
-
test "passing locals" do
|
86
|
-
template = Tilt::HamlTemplate.new { "%p= 'Hey ' + name + '!'" }
|
87
|
-
assert_equal "<p>Hey Joe!</p>\n", template.render(Scope.new, :name => 'Joe')
|
88
|
-
end
|
89
|
-
|
90
|
-
test "evaluating in an object scope" do
|
91
|
-
template = Tilt::HamlTemplate.new { "%p= 'Hey ' + @name + '!'" }
|
92
|
-
scope = Scope.new
|
93
|
-
scope.instance_variable_set :@name, 'Joe'
|
94
|
-
assert_equal "<p>Hey Joe!</p>\n", template.render(scope)
|
95
|
-
end
|
96
|
-
|
97
|
-
test "passing a block for yield" do
|
98
|
-
template = Tilt::HamlTemplate.new { "%p= 'Hey ' + yield + '!'" }
|
99
|
-
assert_equal "<p>Hey Joe!</p>\n", template.render(Scope.new) { 'Joe' }
|
100
|
-
end
|
101
|
-
|
102
|
-
test "backtrace file and line reporting without locals" do
|
103
|
-
data = File.read(__FILE__).split("\n__END__\n").last
|
104
|
-
fail unless data[0] == ?%
|
105
|
-
template = Tilt::HamlTemplate.new('test.haml', 10) { data }
|
106
|
-
begin
|
107
|
-
template.render(Scope.new)
|
108
|
-
fail 'should have raised an exception'
|
109
|
-
rescue => boom
|
110
|
-
assert_kind_of NameError, boom
|
111
|
-
line = boom.backtrace.grep(/^test\.haml:/).first
|
112
|
-
assert line, "Backtrace didn't contain test.haml"
|
113
|
-
file, line, meth = line.split(":")
|
114
|
-
assert_equal '12', line
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
test "backtrace file and line reporting with locals" do
|
119
|
-
data = File.read(__FILE__).split("\n__END__\n").last
|
120
|
-
fail unless data[0] == ?%
|
121
|
-
template = Tilt::HamlTemplate.new('test.haml') { data }
|
122
|
-
begin
|
123
|
-
res = template.render(Scope.new, :name => 'Joe', :foo => 'bar')
|
124
|
-
rescue => boom
|
125
|
-
assert_kind_of MockError, boom
|
126
|
-
line = boom.backtrace.first
|
127
|
-
file, line, meth = line.split(":")
|
128
|
-
assert_equal 'test.haml', file
|
129
|
-
assert_equal '5', line
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
rescue LoadError => boom
|
134
|
-
warn "Tilt::HamlTemplate (disabled)"
|
135
|
-
end
|
136
|
-
|
137
|
-
__END__
|
138
|
-
%html
|
139
|
-
%body
|
140
|
-
%h1= "Hey #{name}"
|
141
|
-
|
142
|
-
= raise MockError
|
143
|
-
|
144
|
-
%p we never get here
|
data/test/tilt_kramdown_test.rb
DELETED
@@ -1,42 +0,0 @@
|
|
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)"
|
42
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
@text-color: #ffc0cb;
|
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'contest'
|
2
|
-
require 'tilt'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'pathname'
|
6
|
-
require 'less'
|
7
|
-
|
8
|
-
class LessTemplateTest < Test::Unit::TestCase
|
9
|
-
def assert_similar(a, b)
|
10
|
-
assert_equal a.gsub(/\s+/m, ' '), b.gsub(/\s+/m, ' ')
|
11
|
-
end
|
12
|
-
|
13
|
-
test "is registered for '.less' files" do
|
14
|
-
assert_equal Tilt::LessTemplate, Tilt['test.less']
|
15
|
-
end
|
16
|
-
|
17
|
-
test "compiles and evaluates the template on #render" do
|
18
|
-
template = Tilt::LessTemplate.new { |t| ".bg { background-color: #0000ff; } \n#main\n { .bg; }\n" }
|
19
|
-
assert_similar ".bg {\n background-color: #0000ff;\n}\n#main {\n background-color: #0000ff;\n}\n", template.render
|
20
|
-
end
|
21
|
-
|
22
|
-
test "can be rendered more than once" do
|
23
|
-
template = Tilt::LessTemplate.new { |t| ".bg { background-color: #0000ff; } \n#main\n { .bg; }\n" }
|
24
|
-
3.times { assert_similar ".bg {\n background-color: #0000ff;\n}\n#main {\n background-color: #0000ff;\n}\n", template.render }
|
25
|
-
end
|
26
|
-
|
27
|
-
test "can be passed a load path" do
|
28
|
-
template = Tilt::LessTemplate.new({
|
29
|
-
:paths => [Pathname(__FILE__).dirname]
|
30
|
-
}) {
|
31
|
-
<<-EOLESS
|
32
|
-
@import 'tilt_lesstemplate_test.less';
|
33
|
-
.bg {background-color: @text-color;}
|
34
|
-
EOLESS
|
35
|
-
}
|
36
|
-
assert_similar ".bg {\n background-color: #ffc0cb;\n}\n", template.render
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
rescue LoadError => boom
|
41
|
-
warn "Tilt::LessTemplate (disabled)"
|
42
|
-
end
|
@@ -1,78 +0,0 @@
|
|
1
|
-
require 'contest'
|
2
|
-
require 'tilt'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'liquid'
|
6
|
-
|
7
|
-
class LiquidTemplateTest < Test::Unit::TestCase
|
8
|
-
test "registered for '.liquid' files" do
|
9
|
-
assert_equal Tilt::LiquidTemplate, Tilt['test.liquid']
|
10
|
-
end
|
11
|
-
|
12
|
-
test "preparing and evaluating templates on #render" do
|
13
|
-
template = Tilt::LiquidTemplate.new { |t| "Hello World!" }
|
14
|
-
assert_equal "Hello World!", template.render
|
15
|
-
end
|
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
|
-
|
22
|
-
test "passing locals" do
|
23
|
-
template = Tilt::LiquidTemplate.new { "Hey {{ name }}!" }
|
24
|
-
assert_equal "Hey Joe!", template.render(nil, :name => 'Joe')
|
25
|
-
end
|
26
|
-
|
27
|
-
# Object's passed as "scope" to LiquidTemplate may respond to
|
28
|
-
# #to_h with a Hash. The Hash's contents are merged underneath
|
29
|
-
# Tilt locals.
|
30
|
-
class ExampleLiquidScope
|
31
|
-
def to_h
|
32
|
-
{ :beer => 'wet', :whisky => 'wetter' }
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
test "combining scope and locals when scope responds to #to_h" do
|
37
|
-
template =
|
38
|
-
Tilt::LiquidTemplate.new {
|
39
|
-
'Beer is {{ beer }} but Whisky is {{ whisky }}.'
|
40
|
-
}
|
41
|
-
scope = ExampleLiquidScope.new
|
42
|
-
assert_equal "Beer is wet but Whisky is wetter.", template.render(scope)
|
43
|
-
end
|
44
|
-
|
45
|
-
test "precedence when locals and scope define same variables" do
|
46
|
-
template =
|
47
|
-
Tilt::LiquidTemplate.new {
|
48
|
-
'Beer is {{ beer }} but Whisky is {{ whisky }}.'
|
49
|
-
}
|
50
|
-
scope = ExampleLiquidScope.new
|
51
|
-
assert_equal "Beer is great but Whisky is greater.",
|
52
|
-
template.render(scope, :beer => 'great', :whisky => 'greater')
|
53
|
-
end
|
54
|
-
|
55
|
-
# Object's passed as "scope" to LiquidTemplate that do not
|
56
|
-
# respond to #to_h are silently ignored.
|
57
|
-
class ExampleIgnoredLiquidScope
|
58
|
-
end
|
59
|
-
|
60
|
-
test "handling scopes that do not respond to #to_h" do
|
61
|
-
template = Tilt::LiquidTemplate.new { 'Whisky' }
|
62
|
-
scope = ExampleIgnoredLiquidScope.new
|
63
|
-
assert_equal "Whisky", template.render(scope)
|
64
|
-
end
|
65
|
-
|
66
|
-
test "passing a block for yield" do
|
67
|
-
template =
|
68
|
-
Tilt::LiquidTemplate.new {
|
69
|
-
'Beer is {{ yield }} but Whisky is {{ content }}ter.'
|
70
|
-
}
|
71
|
-
assert_equal "Beer is wet but Whisky is wetter.",
|
72
|
-
template.render({}) { 'wet' }
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
rescue LoadError => boom
|
77
|
-
warn "Tilt::LiquidTemplate (disabled)"
|
78
|
-
end
|
data/test/tilt_markaby_test.rb
DELETED
@@ -1,88 +0,0 @@
|
|
1
|
-
require 'contest'
|
2
|
-
require 'tilt'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'markaby'
|
6
|
-
|
7
|
-
class MarkabyTiltTest < Test::Unit::TestCase
|
8
|
-
def setup
|
9
|
-
@block = lambda do |t|
|
10
|
-
File.read(File.dirname(__FILE__) + "/#{t.file}")
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
test "should be able to render a markaby template with static html" do
|
15
|
-
tilt = Tilt::MarkabyTemplate.new("markaby/markaby.mab", &@block)
|
16
|
-
assert_equal "hello from markaby!", tilt.render
|
17
|
-
end
|
18
|
-
|
19
|
-
test "should use the contents of the template" do
|
20
|
-
tilt = ::Tilt::MarkabyTemplate.new("markaby/markaby_other_static.mab", &@block)
|
21
|
-
assert_equal "_why?", tilt.render
|
22
|
-
end
|
23
|
-
|
24
|
-
test "should render from a string (given as data)" do
|
25
|
-
tilt = ::Tilt::MarkabyTemplate.new { "html do; end" }
|
26
|
-
assert_equal "<html></html>", tilt.render
|
27
|
-
end
|
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
|
-
|
34
|
-
test "should evaluate a template file in the scope given" do
|
35
|
-
scope = Object.new
|
36
|
-
def scope.foo
|
37
|
-
"bar"
|
38
|
-
end
|
39
|
-
|
40
|
-
tilt = ::Tilt::MarkabyTemplate.new("markaby/scope.mab", &@block)
|
41
|
-
assert_equal "<li>bar</li>", tilt.render(scope)
|
42
|
-
end
|
43
|
-
|
44
|
-
test "should pass locals to the template" do
|
45
|
-
tilt = ::Tilt::MarkabyTemplate.new("markaby/locals.mab", &@block)
|
46
|
-
assert_equal "<li>bar</li>", tilt.render(Object.new, { :foo => "bar" })
|
47
|
-
end
|
48
|
-
|
49
|
-
test "should yield to the block given" do
|
50
|
-
tilt = ::Tilt::MarkabyTemplate.new("markaby/yielding.mab", &@block)
|
51
|
-
eval_scope = Markaby::Builder.new
|
52
|
-
|
53
|
-
output = tilt.render(Object.new, {}) do
|
54
|
-
text("Joe")
|
55
|
-
end
|
56
|
-
|
57
|
-
assert_equal "Hey Joe", output
|
58
|
-
end
|
59
|
-
|
60
|
-
test "should be able to render two templates in a row" do
|
61
|
-
tilt = ::Tilt::MarkabyTemplate.new("markaby/render_twice.mab", &@block)
|
62
|
-
|
63
|
-
assert_equal "foo", tilt.render
|
64
|
-
assert_equal "foo", tilt.render
|
65
|
-
end
|
66
|
-
|
67
|
-
test "should retrieve a Tilt::MarkabyTemplate when calling Tilt['hello.mab']" do
|
68
|
-
assert_equal Tilt::MarkabyTemplate, ::Tilt['./markaby/markaby.mab']
|
69
|
-
end
|
70
|
-
|
71
|
-
test "should return a new instance of the implementation class (when calling Tilt.new)" do
|
72
|
-
assert ::Tilt.new(File.dirname(__FILE__) + "/markaby/markaby.mab").kind_of?(Tilt::MarkabyTemplate)
|
73
|
-
end
|
74
|
-
|
75
|
-
test "should be able to evaluate block style templates" do
|
76
|
-
tilt = Tilt::MarkabyTemplate.new { |t| lambda { h1 "Hello World!" }}
|
77
|
-
assert_equal "<h1>Hello World!</h1>", tilt.render
|
78
|
-
end
|
79
|
-
|
80
|
-
test "should pass locals to block style templates" do
|
81
|
-
tilt = Tilt::MarkabyTemplate.new { |t| lambda { h1 "Hello #{name}!" }}
|
82
|
-
assert_equal "<h1>Hello _why!</h1>", tilt.render(nil, :name => "_why")
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
rescue LoadError => boom
|
87
|
-
warn "Tilt::MarkabyTemplate (disabled)"
|
88
|
-
end
|