tilt 2.0.8 → 2.0.11
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/lib/tilt/commonmarker.rb +68 -1
- data/lib/tilt/csv.rb +1 -1
- data/lib/tilt/erb.rb +7 -1
- data/lib/tilt/haml.rb +2 -2
- data/lib/tilt/pandoc.rb +23 -15
- data/lib/tilt/redcarpet.rb +5 -2
- data/lib/tilt/rst-pandoc.rb +12 -7
- data/lib/tilt/sass.rb +40 -3
- data/lib/tilt/template.rb +18 -12
- data/lib/tilt.rb +2 -1
- metadata +8 -110
- data/CHANGELOG.md +0 -127
- data/Gemfile +0 -65
- data/HACKING +0 -16
- data/README.md +0 -233
- data/Rakefile +0 -106
- data/docs/TEMPLATES.md +0 -555
- data/docs/common.css +0 -14
- data/man/index.txt +0 -2
- data/man/tilt.1.ronn +0 -59
- data/test/markaby/locals.mab +0 -1
- data/test/markaby/markaby.mab +0 -1
- data/test/markaby/markaby_other_static.mab +0 -1
- data/test/markaby/render_twice.mab +0 -1
- data/test/markaby/scope.mab +0 -1
- data/test/markaby/yielding.mab +0 -2
- data/test/mytemplate.rb +0 -2
- data/test/test_helper.rb +0 -64
- data/test/tilt_asciidoctor_test.rb +0 -50
- data/test/tilt_babeltemplate.rb +0 -33
- data/test/tilt_blueclothtemplate_test.rb +0 -33
- data/test/tilt_buildertemplate_test.rb +0 -72
- data/test/tilt_cache_test.rb +0 -43
- data/test/tilt_coffeescripttemplate_test.rb +0 -141
- data/test/tilt_commonmarkertemplate_test.rb +0 -20
- data/test/tilt_compilesite_test.rb +0 -51
- data/test/tilt_creoletemplate_test.rb +0 -24
- data/test/tilt_csv_test.rb +0 -77
- data/test/tilt_erbtemplate_test.rb +0 -239
- data/test/tilt_erubistemplate_test.rb +0 -151
- data/test/tilt_erubitemplate_test.rb +0 -158
- data/test/tilt_etannitemplate_test.rb +0 -174
- data/test/tilt_hamltemplate_test.rb +0 -166
- data/test/tilt_kramdown_test.rb +0 -20
- data/test/tilt_lesstemplate_test.less +0 -1
- data/test/tilt_lesstemplate_test.rb +0 -42
- data/test/tilt_liquidtemplate_test.rb +0 -87
- data/test/tilt_livescripttemplate_test.rb +0 -37
- data/test/tilt_mapping_test.rb +0 -232
- data/test/tilt_markaby_test.rb +0 -88
- data/test/tilt_markdown_test.rb +0 -186
- data/test/tilt_marukutemplate_test.rb +0 -36
- data/test/tilt_metadata_test.rb +0 -42
- data/test/tilt_nokogiritemplate_test.rb +0 -87
- data/test/tilt_pandoctemplate_test.rb +0 -67
- data/test/tilt_prawntemplate.prawn +0 -1
- data/test/tilt_prawntemplate_test.rb +0 -75
- data/test/tilt_radiustemplate_test.rb +0 -75
- data/test/tilt_rdiscounttemplate_test.rb +0 -43
- data/test/tilt_rdoctemplate_test.rb +0 -29
- data/test/tilt_redcarpettemplate_test.rb +0 -54
- data/test/tilt_redclothtemplate_test.rb +0 -36
- data/test/tilt_rstpandoctemplate_test.rb +0 -32
- data/test/tilt_sasstemplate_test.rb +0 -41
- data/test/tilt_sigil_test.rb +0 -41
- data/test/tilt_stringtemplate_test.rb +0 -171
- data/test/tilt_template_test.rb +0 -314
- data/test/tilt_test.rb +0 -60
- data/test/tilt_typescript_test.rb +0 -38
- data/test/tilt_wikiclothtemplate_test.rb +0 -32
- data/test/tilt_yajltemplate_test.rb +0 -101
- data/tilt.gemspec +0 -130
@@ -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,166 +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 default/nil scope' do
|
31
|
-
template = Tilt::HamlTemplate.new { |t| '%p Hey unknown!' }
|
32
|
-
assert_equal "<p>Hey unknown!</p>\n", template.render
|
33
|
-
assert_equal "<p>Hey unknown!</p>\n", template.render(nil)
|
34
|
-
end
|
35
|
-
|
36
|
-
test 'evaluating in invalid, frozen scope' do
|
37
|
-
template = Tilt::HamlTemplate.new { |t| '%p Hey unknown!' }
|
38
|
-
assert_raises(ArgumentError) { template.render(Object.new.freeze) }
|
39
|
-
end
|
40
|
-
|
41
|
-
test "evaluating in an object scope" do
|
42
|
-
template = Tilt::HamlTemplate.new { "%p= 'Hey ' + @name + '!'" }
|
43
|
-
scope = Object.new
|
44
|
-
scope.instance_variable_set :@name, 'Joe'
|
45
|
-
assert_equal "<p>Hey Joe!</p>\n", template.render(scope)
|
46
|
-
end
|
47
|
-
|
48
|
-
test "passing a block for yield" do
|
49
|
-
template = Tilt::HamlTemplate.new { "%p= 'Hey ' + yield + '!'" }
|
50
|
-
assert_equal "<p>Hey Joe!</p>\n", template.render { 'Joe' }
|
51
|
-
end
|
52
|
-
|
53
|
-
test "backtrace file and line reporting without locals" do
|
54
|
-
data = File.read(__FILE__).split("\n__END__\n").last
|
55
|
-
fail unless data[0] == ?%
|
56
|
-
template = Tilt::HamlTemplate.new('test.haml', 10) { data }
|
57
|
-
begin
|
58
|
-
template.render
|
59
|
-
fail 'should have raised an exception'
|
60
|
-
rescue => boom
|
61
|
-
assert_kind_of NameError, boom
|
62
|
-
line = boom.backtrace.grep(/^test\.haml:/).first
|
63
|
-
assert line, "Backtrace didn't contain test.haml"
|
64
|
-
_file, line, _meth = line.split(":")
|
65
|
-
assert_equal '12', line
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
test "backtrace file and line reporting with locals" do
|
70
|
-
data = File.read(__FILE__).split("\n__END__\n").last
|
71
|
-
fail unless data[0] == ?%
|
72
|
-
template = Tilt::HamlTemplate.new('test.haml') { data }
|
73
|
-
begin
|
74
|
-
template.render(Object.new, :name => 'Joe', :foo => 'bar')
|
75
|
-
rescue => boom
|
76
|
-
assert_kind_of MockError, boom
|
77
|
-
line = boom.backtrace.first
|
78
|
-
file, line, _meth = line.split(":")
|
79
|
-
assert_equal 'test.haml', file
|
80
|
-
assert_equal '5', line
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
class CompiledHamlTemplateTest < Minitest::Test
|
86
|
-
class Scope
|
87
|
-
end
|
88
|
-
|
89
|
-
test "compiling template source to a method" do
|
90
|
-
template = Tilt::HamlTemplate.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 "passing locals" do
|
97
|
-
template = Tilt::HamlTemplate.new { "%p= 'Hey ' + name + '!'" }
|
98
|
-
assert_equal "<p>Hey Joe!</p>\n", template.render(Scope.new, :name => 'Joe')
|
99
|
-
end
|
100
|
-
|
101
|
-
test 'evaluating in default/nil scope' do
|
102
|
-
template = Tilt::HamlTemplate.new { |t| '%p Hey unknown!' }
|
103
|
-
assert_equal "<p>Hey unknown!</p>\n", template.render
|
104
|
-
assert_equal "<p>Hey unknown!</p>\n", template.render(nil)
|
105
|
-
end
|
106
|
-
|
107
|
-
test 'evaluating in invalid, frozen scope' do
|
108
|
-
template = Tilt::HamlTemplate.new { |t| '%p Hey unknown!' }
|
109
|
-
assert_raises(ArgumentError) { template.render(Object.new.freeze) }
|
110
|
-
end
|
111
|
-
|
112
|
-
test "evaluating in an object scope" do
|
113
|
-
template = Tilt::HamlTemplate.new { "%p= 'Hey ' + @name + '!'" }
|
114
|
-
scope = Scope.new
|
115
|
-
scope.instance_variable_set :@name, 'Joe'
|
116
|
-
assert_equal "<p>Hey Joe!</p>\n", template.render(scope)
|
117
|
-
end
|
118
|
-
|
119
|
-
test "passing a block for yield" do
|
120
|
-
template = Tilt::HamlTemplate.new { "%p= 'Hey ' + yield + '!'" }
|
121
|
-
assert_equal "<p>Hey Joe!</p>\n", template.render(Scope.new) { 'Joe' }
|
122
|
-
end
|
123
|
-
|
124
|
-
test "backtrace file and line reporting without locals" do
|
125
|
-
data = File.read(__FILE__).split("\n__END__\n").last
|
126
|
-
fail unless data[0] == ?%
|
127
|
-
template = Tilt::HamlTemplate.new('test.haml', 10) { data }
|
128
|
-
begin
|
129
|
-
template.render(Scope.new)
|
130
|
-
fail 'should have raised an exception'
|
131
|
-
rescue => boom
|
132
|
-
assert_kind_of NameError, boom
|
133
|
-
line = boom.backtrace.grep(/^test\.haml:/).first
|
134
|
-
assert line, "Backtrace didn't contain test.haml"
|
135
|
-
_file, line, _meth = line.split(":")
|
136
|
-
assert_equal '12', line
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
test "backtrace file and line reporting with locals" do
|
141
|
-
data = File.read(__FILE__).split("\n__END__\n").last
|
142
|
-
fail unless data[0] == ?%
|
143
|
-
template = Tilt::HamlTemplate.new('test.haml') { data }
|
144
|
-
begin
|
145
|
-
template.render(Scope.new, :name => 'Joe', :foo => 'bar')
|
146
|
-
rescue => boom
|
147
|
-
assert_kind_of MockError, boom
|
148
|
-
line = boom.backtrace.first
|
149
|
-
file, line, _meth = line.split(":")
|
150
|
-
assert_equal 'test.haml', file
|
151
|
-
assert_equal '5', line
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|
155
|
-
rescue LoadError
|
156
|
-
warn "Tilt::HamlTemplate (disabled)"
|
157
|
-
end
|
158
|
-
|
159
|
-
__END__
|
160
|
-
%html
|
161
|
-
%body
|
162
|
-
%h1= "Hey #{name}"
|
163
|
-
|
164
|
-
= raise MockError
|
165
|
-
|
166
|
-
%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
|
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
|
41
|
-
warn "Tilt::LessTemplate (disabled)"
|
42
|
-
end
|
@@ -1,87 +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
|
-
test "options can be set" do
|
28
|
-
err = assert_raises(Liquid::SyntaxError) do
|
29
|
-
options = { line_numbers: false, error_mode: :strict }
|
30
|
-
Tilt::LiquidTemplate.new(options) { "{{%%%}}" }.render
|
31
|
-
end
|
32
|
-
assert_equal 'Liquid syntax error: Unexpected character % in "{{%%%}}"',
|
33
|
-
err.message
|
34
|
-
end
|
35
|
-
|
36
|
-
# Object's passed as "scope" to LiquidTemplate may respond to
|
37
|
-
# #to_h with a Hash. The Hash's contents are merged underneath
|
38
|
-
# Tilt locals.
|
39
|
-
class ExampleLiquidScope
|
40
|
-
def to_h
|
41
|
-
{ :beer => 'wet', :whisky => 'wetter' }
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
test "combining scope and locals when scope responds to #to_h" 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 wet but Whisky is wetter.", template.render(scope)
|
52
|
-
end
|
53
|
-
|
54
|
-
test "precedence when locals and scope define same variables" do
|
55
|
-
template =
|
56
|
-
Tilt::LiquidTemplate.new {
|
57
|
-
'Beer is {{ beer }} but Whisky is {{ whisky }}.'
|
58
|
-
}
|
59
|
-
scope = ExampleLiquidScope.new
|
60
|
-
assert_equal "Beer is great but Whisky is greater.",
|
61
|
-
template.render(scope, :beer => 'great', :whisky => 'greater')
|
62
|
-
end
|
63
|
-
|
64
|
-
# Object's passed as "scope" to LiquidTemplate that do not
|
65
|
-
# respond to #to_h are silently ignored.
|
66
|
-
class ExampleIgnoredLiquidScope
|
67
|
-
end
|
68
|
-
|
69
|
-
test "handling scopes that do not respond to #to_h" do
|
70
|
-
template = Tilt::LiquidTemplate.new { 'Whisky' }
|
71
|
-
scope = ExampleIgnoredLiquidScope.new
|
72
|
-
assert_equal "Whisky", template.render(scope)
|
73
|
-
end
|
74
|
-
|
75
|
-
test "passing a block for yield" do
|
76
|
-
template =
|
77
|
-
Tilt::LiquidTemplate.new {
|
78
|
-
'Beer is {{ yield }} but Whisky is {{ content }}ter.'
|
79
|
-
}
|
80
|
-
assert_equal "Beer is wet but Whisky is wetter.",
|
81
|
-
template.render({}) { 'wet' }
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
rescue LoadError
|
86
|
-
warn "Tilt::LiquidTemplate (disabled)"
|
87
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'tilt'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'tilt/livescript'
|
6
|
-
|
7
|
-
class LiveScriptTemplateTest < Minitest::Test
|
8
|
-
setup do
|
9
|
-
@code_without_variables = "puts 'Hello, World!'\n"
|
10
|
-
@renderer = Tilt::LiveScriptTemplate
|
11
|
-
end
|
12
|
-
|
13
|
-
test "compiles and evaluates the template on #render" do
|
14
|
-
template = @renderer.new { |t| @code_without_variables }
|
15
|
-
assert_match "puts('Hello, World!');", template.render
|
16
|
-
end
|
17
|
-
|
18
|
-
test "can be rendered more than once" do
|
19
|
-
template = @renderer.new { |t| @code_without_variables }
|
20
|
-
3.times { assert_match "puts('Hello, World!');", template.render }
|
21
|
-
end
|
22
|
-
|
23
|
-
test "supports bare-option" do
|
24
|
-
template = @renderer.new(:bare => false) { |t| @code_without_variables }
|
25
|
-
assert_match "function", template.render
|
26
|
-
|
27
|
-
template = @renderer.new(:bare => true) { |t| @code_without_variables }
|
28
|
-
refute_match "function", template.render
|
29
|
-
end
|
30
|
-
|
31
|
-
test "is registered for '.ls' files" do
|
32
|
-
assert_equal @renderer, Tilt['test.ls']
|
33
|
-
end
|
34
|
-
end
|
35
|
-
rescue LoadError
|
36
|
-
warn "Tilt::LiveScriptTemplate (disabled)"
|
37
|
-
end
|