tilt 1.4.1 → 2.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +8 -0
- data/Gemfile +33 -26
- data/README.md +21 -48
- data/Rakefile +21 -30
- data/{TEMPLATES.md → docs/TEMPLATES.md} +10 -4
- data/docs/common.css +14 -0
- data/lib/tilt.rb +85 -154
- data/lib/tilt/asciidoc.rb +1 -8
- data/lib/tilt/bluecloth.rb +24 -0
- data/lib/tilt/builder.rb +1 -8
- data/lib/tilt/coffee.rb +1 -8
- data/lib/tilt/creole.rb +25 -0
- data/lib/tilt/csv.rb +7 -13
- data/lib/tilt/erb.rb +2 -55
- data/lib/tilt/erubis.rb +43 -0
- data/lib/tilt/haml.rb +1 -8
- data/lib/tilt/kramdown.rb +33 -0
- data/lib/tilt/less.rb +38 -0
- data/lib/tilt/liquid.rb +1 -8
- data/lib/tilt/mapping.rb +247 -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/radius.rb +1 -8
- data/lib/tilt/rdiscount.rb +39 -0
- data/lib/tilt/rdoc.rb +3 -10
- data/lib/tilt/redcarpet.rb +104 -0
- data/lib/tilt/{textile.rb → redcloth.rb} +1 -8
- data/lib/tilt/sass.rb +41 -0
- data/lib/tilt/template.rb +85 -92
- data/lib/tilt/wikicloth.rb +22 -0
- data/lib/tilt/yajl.rb +1 -8
- data/test/{contest.rb → test_helper.rb} +5 -11
- data/test/tilt_asciidoctor_test.rb +6 -6
- data/test/tilt_blueclothtemplate_test.rb +3 -15
- data/test/tilt_buildertemplate_test.rb +3 -3
- data/test/tilt_cache_test.rb +2 -2
- data/test/tilt_coffeescripttemplate_test.rb +8 -18
- data/test/tilt_compilesite_test.rb +2 -2
- data/test/tilt_creoletemplate_test.rb +3 -7
- data/test/tilt_csv_test.rb +5 -9
- data/test/tilt_erbtemplate_test.rb +7 -7
- data/test/tilt_erubistemplate_test.rb +7 -7
- data/test/tilt_etannitemplate_test.rb +4 -3
- data/test/tilt_hamltemplate_test.rb +4 -4
- data/test/tilt_kramdown_test.rb +5 -27
- data/test/tilt_lesstemplate_test.rb +3 -3
- data/test/tilt_liquidtemplate_test.rb +3 -3
- data/test/tilt_mapping.rb +215 -0
- data/test/tilt_markaby_test.rb +4 -4
- data/test/tilt_markdown_test.rb +13 -14
- data/test/tilt_marukutemplate_test.rb +6 -18
- data/test/tilt_metadata_test.rb +42 -0
- data/test/tilt_nokogiritemplate_test.rb +3 -3
- data/test/tilt_radiustemplate_test.rb +3 -3
- data/test/tilt_rdiscounttemplate_test.rb +6 -18
- data/test/tilt_rdoctemplate_test.rb +3 -5
- data/test/tilt_redcarpettemplate_test.rb +11 -23
- data/test/tilt_redclothtemplate_test.rb +3 -3
- data/test/tilt_sasstemplate_test.rb +4 -4
- data/test/tilt_stringtemplate_test.rb +4 -3
- data/test/tilt_template_test.rb +35 -49
- data/test/tilt_test.rb +10 -15
- data/test/tilt_wikiclothtemplate_test.rb +3 -3
- data/test/tilt_yajltemplate_test.rb +3 -3
- data/tilt.gemspec +19 -32
- metadata +26 -386
- data/lib/tilt/css.rb +0 -80
- data/lib/tilt/markdown.rb +0 -214
- data/lib/tilt/wiki.rb +0 -58
- data/test/tilt_fallback_test.rb +0 -122
@@ -1,11 +1,11 @@
|
|
1
|
-
require '
|
1
|
+
require 'test_helper'
|
2
2
|
require 'tilt'
|
3
3
|
|
4
4
|
begin
|
5
5
|
require 'pathname'
|
6
|
-
require 'less'
|
6
|
+
require 'tilt/less'
|
7
7
|
|
8
|
-
class LessTemplateTest < Test
|
8
|
+
class LessTemplateTest < Minitest::Test
|
9
9
|
def assert_similar(a, b)
|
10
10
|
assert_equal a.gsub(/\s+/m, ' '), b.gsub(/\s+/m, ' ')
|
11
11
|
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
require '
|
1
|
+
require 'test_helper'
|
2
2
|
require 'tilt'
|
3
3
|
|
4
4
|
begin
|
5
|
-
require 'liquid'
|
5
|
+
require 'tilt/liquid'
|
6
6
|
|
7
|
-
class LiquidTemplateTest < Test
|
7
|
+
class LiquidTemplateTest < Minitest::Test
|
8
8
|
test "registered for '.liquid' files" do
|
9
9
|
assert_equal Tilt::LiquidTemplate, Tilt['test.liquid']
|
10
10
|
end
|
@@ -0,0 +1,215 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'tilt'
|
3
|
+
require 'tilt/mapping'
|
4
|
+
|
5
|
+
module Tilt
|
6
|
+
|
7
|
+
class MappingTest < Minitest::Test
|
8
|
+
class Stub
|
9
|
+
end
|
10
|
+
|
11
|
+
class Stub2
|
12
|
+
end
|
13
|
+
|
14
|
+
setup do
|
15
|
+
@mapping = Mapping.new
|
16
|
+
end
|
17
|
+
|
18
|
+
test "registered?" do
|
19
|
+
@mapping.register(Stub, 'foo', 'bar')
|
20
|
+
assert @mapping.registered?('foo')
|
21
|
+
assert @mapping.registered?('bar')
|
22
|
+
refute @mapping.registered?('baz')
|
23
|
+
end
|
24
|
+
|
25
|
+
test "lookups on registered" do
|
26
|
+
@mapping.register(Stub, 'foo', 'bar')
|
27
|
+
assert_equal Stub, @mapping['foo']
|
28
|
+
assert_equal Stub, @mapping['bar']
|
29
|
+
assert_equal Stub, @mapping['hello.foo']
|
30
|
+
assert_nil @mapping['foo.baz']
|
31
|
+
end
|
32
|
+
|
33
|
+
test "can be dup'd" do
|
34
|
+
@mapping.register(Stub, 'foo')
|
35
|
+
other = @mapping.dup
|
36
|
+
assert other.registered?('foo')
|
37
|
+
|
38
|
+
# @mapping doesn't leak to other
|
39
|
+
@mapping.register(Stub, 'bar')
|
40
|
+
refute other.registered?('bar')
|
41
|
+
|
42
|
+
# other doesn't leak to @mapping
|
43
|
+
other.register(Stub, 'baz')
|
44
|
+
refute @mapping.registered?('baz')
|
45
|
+
end
|
46
|
+
|
47
|
+
context "lazy with one template class" do
|
48
|
+
setup do
|
49
|
+
@mapping.register_lazy('MyTemplate', 'my_template', 'mt')
|
50
|
+
end
|
51
|
+
|
52
|
+
teardown do
|
53
|
+
Object.send :remove_const, :MyTemplate if defined? ::MyTemplate
|
54
|
+
end
|
55
|
+
|
56
|
+
test "registered?" do
|
57
|
+
assert @mapping.registered?('mt')
|
58
|
+
end
|
59
|
+
|
60
|
+
test "basic lookup" do
|
61
|
+
req = proc do |file|
|
62
|
+
assert_equal 'my_template', file
|
63
|
+
class ::MyTemplate; end
|
64
|
+
true
|
65
|
+
end
|
66
|
+
|
67
|
+
@mapping.stub :require, req do
|
68
|
+
klass = @mapping['hello.mt']
|
69
|
+
assert_equal ::MyTemplate, klass
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
test "doesn't require when template class is present" do
|
74
|
+
class ::MyTemplate; end
|
75
|
+
|
76
|
+
req = proc do |file|
|
77
|
+
flunk "#require shouldn't be called"
|
78
|
+
end
|
79
|
+
|
80
|
+
@mapping.stub :require, req do
|
81
|
+
klass = @mapping['hello.mt']
|
82
|
+
assert_equal ::MyTemplate, klass
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
test "raises NameError when the class name is defined" do
|
87
|
+
req = proc do |file|
|
88
|
+
# do nothing
|
89
|
+
end
|
90
|
+
|
91
|
+
@mapping.stub :require, req do
|
92
|
+
assert_raises(NameError) do
|
93
|
+
@mapping['hello.mt']
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
test "warns when there's multiple threads" do
|
99
|
+
Thread.new do
|
100
|
+
req = proc do |file|
|
101
|
+
class ::MyTemplate; end
|
102
|
+
end
|
103
|
+
|
104
|
+
@mapping.stub :require, req do
|
105
|
+
assert_output '', /autoloading 'my_template'/ do
|
106
|
+
@mapping['hello.mt']
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end.join
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context "lazy with two template classes" do
|
114
|
+
setup do
|
115
|
+
@mapping.register_lazy('MyTemplate1', 'my_template1', 'mt')
|
116
|
+
@mapping.register_lazy('MyTemplate2', 'my_template2', 'mt')
|
117
|
+
end
|
118
|
+
|
119
|
+
teardown do
|
120
|
+
Object.send :remove_const, :MyTemplate1 if defined? ::MyTemplate1
|
121
|
+
Object.send :remove_const, :MyTemplate2 if defined? ::MyTemplate2
|
122
|
+
end
|
123
|
+
|
124
|
+
test "registered?" do
|
125
|
+
assert @mapping.registered?('mt')
|
126
|
+
end
|
127
|
+
|
128
|
+
test "only attempt to load the last template" do
|
129
|
+
req = proc do |file|
|
130
|
+
assert_equal 'my_template2', file
|
131
|
+
class ::MyTemplate2; end
|
132
|
+
true
|
133
|
+
end
|
134
|
+
|
135
|
+
@mapping.stub :require, req do
|
136
|
+
klass = @mapping['hello.mt']
|
137
|
+
assert_equal ::MyTemplate2, klass
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
test "uses the first template if it's present" do
|
142
|
+
class ::MyTemplate1; end
|
143
|
+
|
144
|
+
req = proc do |file|
|
145
|
+
flunk
|
146
|
+
end
|
147
|
+
|
148
|
+
@mapping.stub :require, req do
|
149
|
+
klass = @mapping['hello.mt']
|
150
|
+
assert_equal ::MyTemplate1, klass
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
test "falls back when LoadError is thrown" do
|
155
|
+
req = proc do |file|
|
156
|
+
raise LoadError unless file == 'my_template1'
|
157
|
+
class ::MyTemplate1; end
|
158
|
+
true
|
159
|
+
end
|
160
|
+
|
161
|
+
@mapping.stub :require, req do
|
162
|
+
klass = @mapping['hello.mt']
|
163
|
+
assert_equal ::MyTemplate1, klass
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
test "raises the first LoadError when everything fails" do
|
168
|
+
req = proc do |file|
|
169
|
+
raise LoadError, file
|
170
|
+
end
|
171
|
+
|
172
|
+
@mapping.stub :require, req do
|
173
|
+
err = assert_raises(LoadError) do
|
174
|
+
klass = @mapping['hello.mt']
|
175
|
+
end
|
176
|
+
|
177
|
+
assert_equal 'my_template2', err.message
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
test "handles autoloaded constants" do
|
182
|
+
Object.autoload :MyTemplate2, 'my_template2'
|
183
|
+
class ::MyTemplate1; end
|
184
|
+
|
185
|
+
assert_equal MyTemplate1, @mapping['hello.mt']
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
test "raises NameError on invalid class name" do
|
190
|
+
@mapping.register_lazy '#foo', 'my_template', 'mt'
|
191
|
+
|
192
|
+
req = proc do |file|
|
193
|
+
# do nothing
|
194
|
+
end
|
195
|
+
|
196
|
+
@mapping.stub :require, req do
|
197
|
+
assert_raises(NameError) do
|
198
|
+
@mapping['hello.mt']
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
context "#templates_for" do
|
204
|
+
setup do
|
205
|
+
@mapping.register Stub, 'a'
|
206
|
+
@mapping.register Stub2, 'b'
|
207
|
+
end
|
208
|
+
|
209
|
+
test "handles multiple engines" do
|
210
|
+
assert_equal [Stub2, Stub], @mapping.templates_for('hello/world.a.b')
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
data/test/tilt_markaby_test.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require '
|
1
|
+
require 'test_helper'
|
2
2
|
require 'tilt'
|
3
3
|
|
4
4
|
begin
|
5
|
-
require 'markaby'
|
5
|
+
require 'tilt/markaby'
|
6
6
|
|
7
|
-
class MarkabyTiltTest < Test
|
7
|
+
class MarkabyTiltTest < Minitest::Test
|
8
8
|
def setup
|
9
9
|
@block = lambda do |t|
|
10
10
|
File.read(File.dirname(__FILE__) + "/#{t.file}")
|
@@ -85,4 +85,4 @@ begin
|
|
85
85
|
|
86
86
|
rescue LoadError => boom
|
87
87
|
warn "Tilt::MarkabyTemplate (disabled)"
|
88
|
-
end
|
88
|
+
end
|
data/test/tilt_markdown_test.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# coding: UTF-8
|
2
2
|
require 'tilt'
|
3
|
+
require 'test_helper'
|
3
4
|
|
4
5
|
begin
|
5
6
|
require 'nokogiri'
|
@@ -38,9 +39,6 @@ module MarkdownTests
|
|
38
39
|
end
|
39
40
|
|
40
41
|
def test_escape_html_true
|
41
|
-
if self.class.template == Tilt::RedcarpetTemplate
|
42
|
-
flunk "redcarpet doesn't support :escape_html yet"
|
43
|
-
end
|
44
42
|
html = nrender "Hello <b>World</b>", :escape_html => true
|
45
43
|
assert_equal "<p>Hello <b>World</b></p>", html
|
46
44
|
end
|
@@ -77,9 +75,9 @@ module MarkdownTests
|
|
77
75
|
end
|
78
76
|
|
79
77
|
begin
|
80
|
-
require 'rdiscount'
|
78
|
+
require 'tilt/rdiscount'
|
81
79
|
|
82
|
-
class MarkdownRDiscountTest < Test
|
80
|
+
class MarkdownRDiscountTest < Minitest::Test
|
83
81
|
include MarkdownTests
|
84
82
|
template Tilt::RDiscountTemplate
|
85
83
|
end
|
@@ -88,17 +86,18 @@ rescue LoadError => boom
|
|
88
86
|
end
|
89
87
|
|
90
88
|
begin
|
91
|
-
require 'redcarpet'
|
89
|
+
require 'tilt/redcarpet'
|
92
90
|
|
93
|
-
class MarkdownRedcarpetTest < Test
|
91
|
+
class MarkdownRedcarpetTest < Minitest::Test
|
94
92
|
include MarkdownTests
|
95
93
|
template Tilt::RedcarpetTemplate
|
96
94
|
# Doesn't support escaping
|
97
95
|
undef test_escape_html_true
|
98
96
|
|
99
97
|
def test_smarty_pants_true
|
98
|
+
# Various versions of Redcarpet support various versions of Smart pants.
|
100
99
|
html = nrender "Hello ``World'' -- This is --- a test ...", :smartypants => true
|
101
|
-
|
100
|
+
assert_match /<p>Hello “World(''|”) – This is — a test …<\/p>/, html
|
102
101
|
end
|
103
102
|
|
104
103
|
def test_fenced_code_blocks_with_lang
|
@@ -117,9 +116,9 @@ rescue LoadError => boom
|
|
117
116
|
end
|
118
117
|
|
119
118
|
begin
|
120
|
-
require 'bluecloth'
|
119
|
+
require 'tilt/bluecloth'
|
121
120
|
|
122
|
-
class MarkdownBlueClothTest < Test
|
121
|
+
class MarkdownBlueClothTest < Minitest::Test
|
123
122
|
include MarkdownTests
|
124
123
|
template Tilt::BlueClothTemplate
|
125
124
|
end
|
@@ -128,9 +127,9 @@ rescue LoadError => boom
|
|
128
127
|
end
|
129
128
|
|
130
129
|
begin
|
131
|
-
require 'kramdown'
|
130
|
+
require 'tilt/kramdown'
|
132
131
|
|
133
|
-
class MarkdownKramdownTest < Test
|
132
|
+
class MarkdownKramdownTest < Minitest::Test
|
134
133
|
include MarkdownTests
|
135
134
|
template Tilt::KramdownTemplate
|
136
135
|
# Doesn't support escaping
|
@@ -146,9 +145,9 @@ end
|
|
146
145
|
|
147
146
|
|
148
147
|
begin
|
149
|
-
require 'maruku'
|
148
|
+
require 'tilt/maruku'
|
150
149
|
|
151
|
-
class MarkdownMarukuTest < Test
|
150
|
+
class MarkdownMarukuTest < Minitest::Test
|
152
151
|
include MarkdownTests
|
153
152
|
template Tilt::MarukuTemplate
|
154
153
|
# Doesn't support escaping
|
@@ -1,27 +1,15 @@
|
|
1
|
-
require '
|
1
|
+
require 'test_helper'
|
2
2
|
require 'tilt'
|
3
3
|
|
4
4
|
begin
|
5
|
-
require 'maruku'
|
6
|
-
|
7
|
-
class MarukuTemplateTest < Test::Unit::TestCase
|
8
|
-
test "registered for '.md' files" do
|
9
|
-
assert Tilt.mappings['md'].include?(Tilt::MarukuTemplate)
|
10
|
-
end
|
11
|
-
|
12
|
-
test "registered for '.mkd' files" do
|
13
|
-
assert Tilt.mappings['mkd'].include?(Tilt::MarukuTemplate)
|
14
|
-
end
|
15
|
-
|
16
|
-
test "registered for '.markdown' files" do
|
17
|
-
assert Tilt.mappings['markdown'].include?(Tilt::MarukuTemplate)
|
18
|
-
end
|
5
|
+
require 'tilt/maruku'
|
19
6
|
|
7
|
+
class MarukuTemplateTest < Minitest::Test
|
20
8
|
test "registered below Kramdown" do
|
21
9
|
%w[md mkd markdown].each do |ext|
|
22
|
-
|
23
|
-
kram_idx =
|
24
|
-
maru_idx =
|
10
|
+
lazy = Tilt.lazy_map[ext]
|
11
|
+
kram_idx = lazy.index { |klass, file| klass == 'Tilt::KramdownTemplate' }
|
12
|
+
maru_idx = lazy.index { |klass, file| klass == 'Tilt::MarukuTemplate' }
|
25
13
|
assert maru_idx > kram_idx,
|
26
14
|
"#{maru_idx} should be higher than #{kram_idx}"
|
27
15
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'tilt/template'
|
3
|
+
|
4
|
+
module Tilt
|
5
|
+
class TemplateMetadataTest < Minitest::Test
|
6
|
+
class MyTemplate < Template
|
7
|
+
metadata[:global] = 1
|
8
|
+
self.default_mime_type = 'text/html'
|
9
|
+
|
10
|
+
def prepare
|
11
|
+
end
|
12
|
+
|
13
|
+
def allows_script?
|
14
|
+
true
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
test "global metadata" do
|
19
|
+
assert MyTemplate.metadata
|
20
|
+
assert_equal 1, MyTemplate.metadata[:global]
|
21
|
+
end
|
22
|
+
|
23
|
+
test "instance metadata" do
|
24
|
+
tmpl = MyTemplate.new { '' }
|
25
|
+
assert_equal 1, tmpl.metadata[:global]
|
26
|
+
end
|
27
|
+
|
28
|
+
test "gracefully handles default_mime_type" do
|
29
|
+
assert_equal 'text/html', MyTemplate.metadata[:mime_type]
|
30
|
+
end
|
31
|
+
|
32
|
+
test "still allows .default_mime_type" do
|
33
|
+
assert_equal 'text/html', MyTemplate.default_mime_type
|
34
|
+
end
|
35
|
+
|
36
|
+
test "gracefully handles allows_script?" do
|
37
|
+
tmpl = MyTemplate.new { '' }
|
38
|
+
assert_equal true, tmpl.metadata[:allows_script]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
@@ -1,9 +1,9 @@
|
|
1
|
-
require '
|
1
|
+
require 'test_helper'
|
2
2
|
require 'tilt'
|
3
3
|
|
4
4
|
begin
|
5
|
-
require 'nokogiri'
|
6
|
-
class NokogiriTemplateTest < Test
|
5
|
+
require 'tilt/nokogiri'
|
6
|
+
class NokogiriTemplateTest < Minitest::Test
|
7
7
|
test "registered for '.nokogiri' files" do
|
8
8
|
assert_equal Tilt::NokogiriTemplate, Tilt['test.nokogiri']
|
9
9
|
assert_equal Tilt::NokogiriTemplate, Tilt['test.xml.nokogiri']
|
@@ -1,14 +1,14 @@
|
|
1
|
-
require '
|
1
|
+
require 'test_helper'
|
2
2
|
require 'tilt'
|
3
3
|
|
4
4
|
begin
|
5
|
-
require 'radius'
|
5
|
+
require 'tilt/radius'
|
6
6
|
|
7
7
|
# Disable radius tests under Ruby versions >= 1.9.1 since it's still buggy.
|
8
8
|
# Remove when fixed upstream.
|
9
9
|
raise LoadError if RUBY_VERSION >= "1.9.1" and Radius.version < "0.7"
|
10
10
|
|
11
|
-
class RadiusTemplateTest < Test
|
11
|
+
class RadiusTemplateTest < Minitest::Test
|
12
12
|
test "registered for '.radius' files" do
|
13
13
|
assert_equal Tilt::RadiusTemplate, Tilt['test.radius']
|
14
14
|
end
|