tilt 2.0.0 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +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
@@ -1,151 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'tilt'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'tilt/erubis'
|
6
|
-
class ErubisTemplateTest < Minitest::Test
|
7
|
-
test "registered for '.erubis' files" do
|
8
|
-
assert_equal Tilt::ErubisTemplate, Tilt['test.erubis']
|
9
|
-
assert_equal Tilt::ErubisTemplate, Tilt['test.html.erubis']
|
10
|
-
end
|
11
|
-
|
12
|
-
test "registered above ERB" do
|
13
|
-
%w[erb rhtml].each do |ext|
|
14
|
-
lazy = Tilt.lazy_map[ext]
|
15
|
-
erubis_idx = lazy.index { |klass, file| klass == 'Tilt::ErubisTemplate' }
|
16
|
-
erb_idx = lazy.index { |klass, file| klass == 'Tilt::ERBTemplate' }
|
17
|
-
assert erubis_idx < erb_idx,
|
18
|
-
"#{erubis_idx} should be lower than #{erb_idx}"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
test "preparing and evaluating templates on #render" do
|
23
|
-
template = Tilt::ErubisTemplate.new { |t| "Hello World!" }
|
24
|
-
assert_equal "Hello World!", template.render
|
25
|
-
end
|
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
|
-
|
32
|
-
test "passing locals" do
|
33
|
-
template = Tilt::ErubisTemplate.new { 'Hey <%= name %>!' }
|
34
|
-
assert_equal "Hey Joe!", template.render(Object.new, :name => 'Joe')
|
35
|
-
end
|
36
|
-
|
37
|
-
test "evaluating in an object scope" do
|
38
|
-
template = Tilt::ErubisTemplate.new { 'Hey <%= @name %>!' }
|
39
|
-
scope = Object.new
|
40
|
-
scope.instance_variable_set :@name, 'Joe'
|
41
|
-
assert_equal "Hey Joe!", template.render(scope)
|
42
|
-
end
|
43
|
-
|
44
|
-
class MockOutputVariableScope
|
45
|
-
attr_accessor :exposed_buffer
|
46
|
-
end
|
47
|
-
|
48
|
-
test "exposing the buffer to the template by default" do
|
49
|
-
begin
|
50
|
-
Tilt::ErubisTemplate.default_output_variable = '@_out_buf'
|
51
|
-
template = Tilt::ErubisTemplate.new { '<% self.exposed_buffer = @_out_buf %>hey' }
|
52
|
-
scope = MockOutputVariableScope.new
|
53
|
-
template.render(scope)
|
54
|
-
refute_nil scope.exposed_buffer
|
55
|
-
assert_equal scope.exposed_buffer, 'hey'
|
56
|
-
ensure
|
57
|
-
Tilt::ErubisTemplate.default_output_variable = '_erbout'
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
test "passing a block for yield" do
|
62
|
-
template = Tilt::ErubisTemplate.new { 'Hey <%= yield %>!' }
|
63
|
-
assert_equal "Hey Joe!", template.render { 'Joe' }
|
64
|
-
end
|
65
|
-
|
66
|
-
test "backtrace file and line reporting without locals" do
|
67
|
-
data = File.read(__FILE__).split("\n__END__\n").last
|
68
|
-
fail unless data[0] == ?<
|
69
|
-
template = Tilt::ErubisTemplate.new('test.erubis', 11) { data }
|
70
|
-
begin
|
71
|
-
template.render
|
72
|
-
fail 'should have raised an exception'
|
73
|
-
rescue => boom
|
74
|
-
assert_kind_of NameError, boom
|
75
|
-
line = boom.backtrace.grep(/^test\.erubis:/).first
|
76
|
-
assert line, "Backtrace didn't contain test.erubis"
|
77
|
-
file, line, meth = line.split(":")
|
78
|
-
assert_equal '13', line
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
test "backtrace file and line reporting with locals" do
|
83
|
-
data = File.read(__FILE__).split("\n__END__\n").last
|
84
|
-
fail unless data[0] == ?<
|
85
|
-
template = Tilt::ErubisTemplate.new('test.erubis', 1) { data }
|
86
|
-
begin
|
87
|
-
template.render(nil, :name => 'Joe', :foo => 'bar')
|
88
|
-
fail 'should have raised an exception'
|
89
|
-
rescue => boom
|
90
|
-
assert_kind_of RuntimeError, boom
|
91
|
-
line = boom.backtrace.first
|
92
|
-
file, line, meth = line.split(":")
|
93
|
-
assert_equal 'test.erubis', file
|
94
|
-
assert_equal '6', line
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
test "erubis template options" do
|
99
|
-
template = Tilt::ErubisTemplate.new(nil, :pattern => '\{% %\}') { 'Hey {%= @name %}!' }
|
100
|
-
scope = Object.new
|
101
|
-
scope.instance_variable_set :@name, 'Joe'
|
102
|
-
assert_equal "Hey Joe!", template.render(scope)
|
103
|
-
end
|
104
|
-
|
105
|
-
test "using an instance variable as the outvar" do
|
106
|
-
template = Tilt::ErubisTemplate.new(nil, :outvar => '@buf') { "<%= 1 + 1 %>" }
|
107
|
-
scope = Object.new
|
108
|
-
scope.instance_variable_set(:@buf, 'original value')
|
109
|
-
assert_equal '2', template.render(scope)
|
110
|
-
assert_equal 'original value', scope.instance_variable_get(:@buf)
|
111
|
-
end
|
112
|
-
|
113
|
-
test "using Erubis::EscapedEruby subclass via :engine_class option" do
|
114
|
-
template = Tilt::ErubisTemplate.new(nil, :engine_class => ::Erubis::EscapedEruby) { |t| %(<%= "<p>Hello World!</p>" %>) }
|
115
|
-
assert_equal "<p>Hello World!</p>", template.render
|
116
|
-
end
|
117
|
-
|
118
|
-
test "using :escape_html => true option" do
|
119
|
-
template = Tilt::ErubisTemplate.new(nil, :escape_html => true) { |t| %(<%= "<p>Hello World!</p>" %>) }
|
120
|
-
assert_equal "<p>Hello World!</p>", template.render
|
121
|
-
end
|
122
|
-
|
123
|
-
test "using :escape_html => false option" do
|
124
|
-
template = Tilt::ErubisTemplate.new(nil, :escape_html => false) { |t| %(<%= "<p>Hello World!</p>" %>) }
|
125
|
-
assert_equal "<p>Hello World!</p>", template.render
|
126
|
-
end
|
127
|
-
|
128
|
-
test "erubis default does not escape html" do
|
129
|
-
template = Tilt::ErubisTemplate.new { |t| %(<%= "<p>Hello World!</p>" %>) }
|
130
|
-
assert_equal "<p>Hello World!</p>", template.render
|
131
|
-
end
|
132
|
-
|
133
|
-
test "does not modify options argument" do
|
134
|
-
options_hash = {:escape_html => true}
|
135
|
-
template = Tilt::ErubisTemplate.new(nil, options_hash) { |t| "Hello World!" }
|
136
|
-
assert_equal({:escape_html => true}, options_hash)
|
137
|
-
end
|
138
|
-
end
|
139
|
-
rescue LoadError => boom
|
140
|
-
warn "Tilt::ErubisTemplate (disabled)"
|
141
|
-
end
|
142
|
-
|
143
|
-
__END__
|
144
|
-
<html>
|
145
|
-
<body>
|
146
|
-
<h1>Hey <%= name %>!</h1>
|
147
|
-
|
148
|
-
|
149
|
-
<p><% fail %></p>
|
150
|
-
</body>
|
151
|
-
</html>
|
@@ -1,174 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'tilt'
|
3
|
-
require 'tilt/etanni'
|
4
|
-
|
5
|
-
class EtanniTemplateTest < Minitest::Test
|
6
|
-
test "registered for '.etn' files" do
|
7
|
-
assert_equal Tilt::EtanniTemplate, Tilt['test.etn']
|
8
|
-
end
|
9
|
-
|
10
|
-
test "registered for '.etanni' files" do
|
11
|
-
assert_equal Tilt::EtanniTemplate, Tilt['test.etanni']
|
12
|
-
end
|
13
|
-
|
14
|
-
test "loading and evaluating templates on #render" do
|
15
|
-
template = Tilt::EtanniTemplate.new { |t| "Hello World!" }
|
16
|
-
assert_equal "Hello World!", template.render
|
17
|
-
end
|
18
|
-
|
19
|
-
test "can be rendered more than once" do
|
20
|
-
template = Tilt::EtanniTemplate.new { |t| "Hello World!" }
|
21
|
-
3.times { assert_equal "Hello World!", template.render }
|
22
|
-
end
|
23
|
-
|
24
|
-
test "passing locals" do
|
25
|
-
template = Tilt::EtanniTemplate.new { 'Hey #{name}!' }
|
26
|
-
assert_equal "Hey Joe!", template.render(Object.new, :name => 'Joe')
|
27
|
-
end
|
28
|
-
|
29
|
-
test "evaluating in an object scope" do
|
30
|
-
template = Tilt::EtanniTemplate.new { 'Hey #{@name}!' }
|
31
|
-
scope = Object.new
|
32
|
-
scope.instance_variable_set :@name, 'Joe'
|
33
|
-
assert_equal "Hey Joe!", template.render(scope)
|
34
|
-
end
|
35
|
-
|
36
|
-
test "passing a block for yield" do
|
37
|
-
template = Tilt::EtanniTemplate.new { 'Hey #{yield}!' }
|
38
|
-
assert_equal "Hey Joe!", template.render { 'Joe' }
|
39
|
-
assert_equal "Hey Moe!", template.render { 'Moe' }
|
40
|
-
end
|
41
|
-
|
42
|
-
test "multiline templates" do
|
43
|
-
template = Tilt::EtanniTemplate.new { "Hello\nWorld!\n" }
|
44
|
-
assert_equal "Hello\nWorld!", template.render
|
45
|
-
end
|
46
|
-
|
47
|
-
test "backtrace file and line reporting without locals" do
|
48
|
-
data = File.read(__FILE__).split("\n__END__\n").last
|
49
|
-
fail unless data[0] == ?<
|
50
|
-
template = Tilt::EtanniTemplate.new('test.etn', 11) { data }
|
51
|
-
begin
|
52
|
-
template.render
|
53
|
-
fail 'should have raised an exception'
|
54
|
-
rescue => boom
|
55
|
-
assert_kind_of NameError, boom
|
56
|
-
line = boom.backtrace.grep(/^test\.etn:/).first
|
57
|
-
assert line, "Backtrace didn't contain test.etn"
|
58
|
-
file, line, meth = line.split(":")
|
59
|
-
assert_equal '13', line
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
test "backtrace file and line reporting with locals" do
|
64
|
-
data = File.read(__FILE__).split("\n__END__\n").last
|
65
|
-
fail unless data[0] == ?<
|
66
|
-
template = Tilt::EtanniTemplate.new('test.etn', 1) { data }
|
67
|
-
begin
|
68
|
-
template.render(nil, :name => 'Joe', :foo => 'bar')
|
69
|
-
fail 'should have raised an exception'
|
70
|
-
rescue => boom
|
71
|
-
assert_kind_of RuntimeError, boom
|
72
|
-
line = boom.backtrace.first
|
73
|
-
file, line, meth = line.split(":")
|
74
|
-
assert_equal 'test.etn', file
|
75
|
-
assert_equal '6', line
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
|
81
|
-
class CompiledEtanniTemplateTest < Minitest::Test
|
82
|
-
def teardown
|
83
|
-
GC.start
|
84
|
-
end
|
85
|
-
|
86
|
-
class Scope
|
87
|
-
end
|
88
|
-
|
89
|
-
test "compiling template source to a method" do
|
90
|
-
template = Tilt::EtanniTemplate.new { |t| "Hello World!" }
|
91
|
-
template.render(Scope.new)
|
92
|
-
method = template.send(:compiled_method, [])
|
93
|
-
assert_kind_of UnboundMethod, method
|
94
|
-
end
|
95
|
-
|
96
|
-
test "loading and evaluating templates on #render" do
|
97
|
-
template = Tilt::EtanniTemplate.new { |t| "Hello World!" }
|
98
|
-
assert_equal "Hello World!", template.render(Scope.new)
|
99
|
-
end
|
100
|
-
|
101
|
-
test "passing locals" do
|
102
|
-
template = Tilt::EtanniTemplate.new { 'Hey #{name}!' }
|
103
|
-
assert_equal "Hey Joe!", template.render(Scope.new, :name => 'Joe')
|
104
|
-
assert_equal "Hey Moe!", template.render(Scope.new, :name => 'Moe')
|
105
|
-
end
|
106
|
-
|
107
|
-
test "evaluating in an object scope" do
|
108
|
-
template = Tilt::EtanniTemplate.new { 'Hey #{@name}!' }
|
109
|
-
scope = Scope.new
|
110
|
-
scope.instance_variable_set :@name, 'Joe'
|
111
|
-
assert_equal "Hey Joe!", template.render(scope)
|
112
|
-
scope.instance_variable_set :@name, 'Moe'
|
113
|
-
assert_equal "Hey Moe!", template.render(scope)
|
114
|
-
end
|
115
|
-
|
116
|
-
test "passing a block for yield" do
|
117
|
-
template = Tilt::EtanniTemplate.new { 'Hey #{yield}!' }
|
118
|
-
assert_equal "Hey Joe!", template.render(Scope.new) { 'Joe' }
|
119
|
-
assert_equal "Hey Moe!", template.render(Scope.new) { 'Moe' }
|
120
|
-
end
|
121
|
-
|
122
|
-
test "multiline templates" do
|
123
|
-
template = Tilt::EtanniTemplate.new { "Hello\nWorld!\n" }
|
124
|
-
assert_equal "Hello\nWorld!", template.render(Scope.new)
|
125
|
-
end
|
126
|
-
|
127
|
-
test "template with '}'" do
|
128
|
-
template = Tilt::EtanniTemplate.new { "Hello }" }
|
129
|
-
assert_equal "Hello }", template.render
|
130
|
-
end
|
131
|
-
|
132
|
-
test "backtrace file and line reporting without locals" do
|
133
|
-
data = File.read(__FILE__).split("\n__END__\n").last
|
134
|
-
fail unless data[0] == ?<
|
135
|
-
template = Tilt::EtanniTemplate.new('test.etn', 11) { data }
|
136
|
-
begin
|
137
|
-
template.render(Scope.new)
|
138
|
-
fail 'should have raised an exception'
|
139
|
-
rescue => boom
|
140
|
-
assert_kind_of NameError, boom
|
141
|
-
line = boom.backtrace.first
|
142
|
-
line = boom.backtrace.grep(/^test\.etn:/).first
|
143
|
-
assert line, "Backtrace didn't contain test.etn"
|
144
|
-
file, line, meth = line.split(":")
|
145
|
-
assert_equal '13', line
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
test "backtrace file and line reporting with locals" do
|
150
|
-
data = File.read(__FILE__).split("\n__END__\n").last
|
151
|
-
fail unless data[0] == ?<
|
152
|
-
template = Tilt::EtanniTemplate.new('test.etn') { data }
|
153
|
-
begin
|
154
|
-
template.render(Scope.new, :name => 'Joe', :foo => 'bar')
|
155
|
-
fail 'should have raised an exception'
|
156
|
-
rescue => boom
|
157
|
-
assert_kind_of RuntimeError, boom
|
158
|
-
line = boom.backtrace.first
|
159
|
-
file, line, meth = line.split(":")
|
160
|
-
assert_equal 'test.etn', file
|
161
|
-
assert_equal '6', line
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
__END__
|
167
|
-
<html>
|
168
|
-
<body>
|
169
|
-
<h1>Hey #{name}!</h1>
|
170
|
-
|
171
|
-
|
172
|
-
<p>#{fail}</p>
|
173
|
-
</body>
|
174
|
-
</html>
|
@@ -1,144 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'tilt'
|
3
|
-
|
4
|
-
begin
|
5
|
-
class ::MockError < NameError
|
6
|
-
end
|
7
|
-
|
8
|
-
require 'tilt/haml'
|
9
|
-
|
10
|
-
class HamlTemplateTest < Minitest::Test
|
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 < Minitest::Test
|
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,20 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'tilt'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'tilt/kramdown'
|
6
|
-
|
7
|
-
class KramdownTemplateTest < Minitest::Test
|
8
|
-
test "preparing and evaluating templates on #render" do
|
9
|
-
template = Tilt::KramdownTemplate.new { |t| "# Hello World!" }
|
10
|
-
assert_equal '<h1 id="hello-world">Hello World!</h1>', template.render.strip
|
11
|
-
end
|
12
|
-
|
13
|
-
test "can be rendered more than once" do
|
14
|
-
template = Tilt::KramdownTemplate.new { |t| "# Hello World!" }
|
15
|
-
3.times { assert_equal '<h1 id="hello-world">Hello World!</h1>', template.render.strip }
|
16
|
-
end
|
17
|
-
end
|
18
|
-
rescue LoadError => boom
|
19
|
-
warn "Tilt::KramdownTemplate (disabled)"
|
20
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
@text-color: #ffc0cb;
|
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'tilt'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'pathname'
|
6
|
-
require 'tilt/less'
|
7
|
-
|
8
|
-
class LessTemplateTest < Minitest::Test
|
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 'test_helper'
|
2
|
-
require 'tilt'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'tilt/liquid'
|
6
|
-
|
7
|
-
class LiquidTemplateTest < Minitest::Test
|
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
|