tilt 1.2 → 1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +54 -24
- data/TEMPLATES.md +250 -175
- data/lib/tilt/builder.rb +40 -0
- data/lib/tilt/coffee.rb +50 -0
- data/lib/tilt/creole.rb +28 -0
- data/lib/tilt/css.rb +67 -0
- data/lib/tilt/erb.rb +110 -0
- data/lib/tilt/haml.rb +64 -0
- data/lib/tilt/liquid.rb +41 -0
- data/lib/tilt/markaby.rb +52 -0
- data/lib/tilt/markdown.rb +131 -0
- data/lib/tilt/nokogiri.rb +43 -0
- data/lib/tilt/radius.rb +51 -0
- data/lib/tilt/rdoc.rb +32 -0
- data/lib/tilt/string.rb +21 -0
- data/lib/tilt/template.rb +285 -0
- data/lib/tilt/textile.rb +25 -0
- data/lib/tilt.rb +104 -805
- data/test/tilt_blueclothtemplate_test.rb +11 -25
- data/test/tilt_buildertemplate_test.rb +16 -1
- data/test/tilt_coffeescripttemplate_test.rb +36 -1
- data/test/tilt_creoletemplate_test.rb +24 -0
- data/test/tilt_erbtemplate_test.rb +23 -19
- data/test/tilt_erubistemplate_test.rb +17 -2
- data/test/tilt_fallback_test.rb +122 -0
- data/test/tilt_hamltemplate_test.rb +9 -4
- data/test/tilt_kramdown_test.rb +42 -0
- data/test/tilt_lesstemplate_test.rb +5 -0
- data/test/tilt_liquidtemplate_test.rb +5 -0
- data/test/tilt_markaby_test.rb +5 -0
- data/test/tilt_markdown_test.rb +149 -0
- data/test/tilt_marukutemplate_test.rb +48 -0
- data/test/tilt_nokogiritemplate_test.rb +20 -7
- data/test/tilt_radiustemplate_test.rb +5 -0
- data/test/tilt_rdiscounttemplate_test.rb +21 -6
- data/test/tilt_rdoctemplate_test.rb +6 -1
- data/test/tilt_redcarpettemplate_test.rb +55 -0
- data/test/tilt_redclothtemplate_test.rb +4 -0
- data/test/tilt_sasstemplate_test.rb +10 -0
- data/test/tilt_stringtemplate_test.rb +15 -3
- data/test/tilt_template_test.rb +6 -0
- data/tilt.gemspec +28 -2
- metadata +86 -49
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# coding: UTF-8
|
|
2
|
+
require 'tilt'
|
|
3
|
+
require 'nokogiri'
|
|
4
|
+
|
|
5
|
+
module MarkdownTests
|
|
6
|
+
def self.included(mod)
|
|
7
|
+
class << mod
|
|
8
|
+
def template(t = nil)
|
|
9
|
+
t.nil? ? @template : @template = t
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def render(text, options = {})
|
|
15
|
+
self.class.template.new(options) { text }.render
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def normalize(html)
|
|
19
|
+
Nokogiri::HTML.fragment(html).to_s
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def nrender(text, options = {})
|
|
23
|
+
html = render(text, options)
|
|
24
|
+
html.encode!("UTF-8") if html.respond_to?(:encode)
|
|
25
|
+
normalize(html)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def test_escape_html
|
|
29
|
+
html = nrender "Hello <b>World</b>"
|
|
30
|
+
assert_equal "<p>Hello <b>World</b></p>", html
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_escape_html_false
|
|
34
|
+
html = nrender "Hello <b>World</b>", :escape_html => false
|
|
35
|
+
assert_equal "<p>Hello <b>World</b></p>", html
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def test_escape_html_true
|
|
39
|
+
html = nrender "Hello <b>World</b>", :escape_html => true
|
|
40
|
+
assert_equal "<p>Hello <b>World</b></p>", html
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_smart_quotes
|
|
44
|
+
html = nrender 'Hello "World"'
|
|
45
|
+
assert_equal '<p>Hello "World"</p>', html
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def test_smart_quotes_false
|
|
49
|
+
html = nrender 'Hello "World"', :smartypants => false
|
|
50
|
+
assert_equal '<p>Hello "World"</p>', html
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def test_smart_quotes_true
|
|
54
|
+
html = nrender 'Hello "World"', :smartypants => true
|
|
55
|
+
assert_equal '<p>Hello “World”</p>', html
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def test_smarty_pants
|
|
59
|
+
html = nrender "Hello ``World'' -- This is --- a test ..."
|
|
60
|
+
assert_equal "<p>Hello ``World'' -- This is --- a test ...</p>", html
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def test_smarty_pants_false
|
|
64
|
+
html = nrender "Hello ``World'' -- This is --- a test ...", :smartypants => false
|
|
65
|
+
assert_equal "<p>Hello ``World'' -- This is --- a test ...</p>", html
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def test_smarty_pants_true
|
|
69
|
+
if self.class.template == Tilt::RedcarpetTemplate
|
|
70
|
+
warn "\nsmartypants not yet fully supported by redcarpet (#{__FILE__}:#{__LINE__})"
|
|
71
|
+
else
|
|
72
|
+
html = nrender "Hello ``World'' -- This is --- a test ...", :smartypants => true
|
|
73
|
+
assert_equal "<p>Hello “World” — This is —– a test …</p>", html
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
begin
|
|
79
|
+
require 'rdiscount'
|
|
80
|
+
|
|
81
|
+
class MarkdownRDiscountTest < Test::Unit::TestCase
|
|
82
|
+
include MarkdownTests
|
|
83
|
+
template Tilt::RDiscountTemplate
|
|
84
|
+
end
|
|
85
|
+
rescue LoadError => boom
|
|
86
|
+
# It should already be warned in the main tests
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
begin
|
|
90
|
+
require 'redcarpet'
|
|
91
|
+
|
|
92
|
+
class MarkdownRedcarpetTest < Test::Unit::TestCase
|
|
93
|
+
include MarkdownTests
|
|
94
|
+
template Tilt::RedcarpetTemplate
|
|
95
|
+
end
|
|
96
|
+
rescue LoadError => boom
|
|
97
|
+
# It should already be warned in the main tests
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
begin
|
|
101
|
+
require 'bluecloth'
|
|
102
|
+
|
|
103
|
+
class MarkdownBlueClothTest < Test::Unit::TestCase
|
|
104
|
+
include MarkdownTests
|
|
105
|
+
template Tilt::BlueClothTemplate
|
|
106
|
+
end
|
|
107
|
+
rescue LoadError => boom
|
|
108
|
+
# It should already be warned in the main tests
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
begin
|
|
112
|
+
require 'kramdown'
|
|
113
|
+
|
|
114
|
+
class MarkdownKramdownTest < Test::Unit::TestCase
|
|
115
|
+
include MarkdownTests
|
|
116
|
+
template Tilt::KramdownTemplate
|
|
117
|
+
# Doesn't support escaping
|
|
118
|
+
undef test_escape_html_true
|
|
119
|
+
# Smarty Pants is *always* on, but doesn't support it fully
|
|
120
|
+
undef test_smarty_pants
|
|
121
|
+
undef test_smarty_pants_false
|
|
122
|
+
undef test_smarty_pants_true
|
|
123
|
+
end
|
|
124
|
+
rescue LoadError => boom
|
|
125
|
+
# It should already be warned in the main tests
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
begin
|
|
130
|
+
require 'maruku'
|
|
131
|
+
|
|
132
|
+
class MarkdownMarukuTest < Test::Unit::TestCase
|
|
133
|
+
include MarkdownTests
|
|
134
|
+
template Tilt::MarukuTemplate
|
|
135
|
+
# Doesn't support escaping
|
|
136
|
+
undef test_escape_html_true
|
|
137
|
+
# Doesn't support Smarty Pants, and even fails on ``Foobar''
|
|
138
|
+
undef test_smarty_pants
|
|
139
|
+
undef test_smarty_pants_false
|
|
140
|
+
undef test_smarty_pants_true
|
|
141
|
+
# Smart Quotes is always on
|
|
142
|
+
undef test_smart_quotes
|
|
143
|
+
undef test_smart_quotes_false
|
|
144
|
+
end
|
|
145
|
+
rescue LoadError => boom
|
|
146
|
+
# It should already be warned in the main tests
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
require 'contest'
|
|
2
|
+
require 'tilt'
|
|
3
|
+
|
|
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
|
|
19
|
+
|
|
20
|
+
test "registered below Kramdown" 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 maru_idx > kram_idx,
|
|
26
|
+
"#{maru_idx} should be higher than #{kram_idx}"
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
test "preparing and evaluating templates on #render" do
|
|
31
|
+
template = Tilt::MarukuTemplate.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::MarukuTemplate.new { |t| "# Hello World!" }
|
|
37
|
+
3.times { assert_equal "<h1 id='hello_world'>Hello World!</h1>", template.render }
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
test "removes HTML when :filter_html is set" do
|
|
41
|
+
template = Tilt::MarukuTemplate.new(:filter_html => true) { |t|
|
|
42
|
+
"HELLO <blink>WORLD</blink>" }
|
|
43
|
+
assert_equal "<p>HELLO </p>", template.render
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
rescue LoadError => boom
|
|
47
|
+
warn "Tilt::MarukuTemplate (disabled)\n"
|
|
48
|
+
end
|
|
@@ -16,6 +16,15 @@ begin
|
|
|
16
16
|
assert_equal 'em', doc.root.name
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
+
test "can be rendered more than once" do
|
|
20
|
+
template = Tilt::NokogiriTemplate.new { |t| "xml.em 'Hello World!'" }
|
|
21
|
+
3.times do
|
|
22
|
+
doc = Nokogiri.XML template.render
|
|
23
|
+
assert_equal 'Hello World!', doc.root.text
|
|
24
|
+
assert_equal 'em', doc.root.name
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
19
28
|
test "passing locals" do
|
|
20
29
|
template = Tilt::NokogiriTemplate.new { "xml.em('Hey ' + name + '!')" }
|
|
21
30
|
doc = Nokogiri.XML template.render(Object.new, :name => 'Joe')
|
|
@@ -34,9 +43,11 @@ begin
|
|
|
34
43
|
|
|
35
44
|
test "passing a block for yield" do
|
|
36
45
|
template = Tilt::NokogiriTemplate.new { "xml.em('Hey ' + yield + '!')" }
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
46
|
+
3.times do
|
|
47
|
+
doc = Nokogiri.XML template.render { 'Joe' }
|
|
48
|
+
assert_equal 'Hey Joe!', doc.root.text
|
|
49
|
+
assert_equal 'em', doc.root.name
|
|
50
|
+
end
|
|
40
51
|
end
|
|
41
52
|
|
|
42
53
|
test "block style templates" do
|
|
@@ -52,10 +63,12 @@ begin
|
|
|
52
63
|
test "allows nesting raw XML, API-compatible to Builder" do
|
|
53
64
|
subtemplate = Tilt::NokogiriTemplate.new { "xml.em 'Hello World!'" }
|
|
54
65
|
template = Tilt::NokogiriTemplate.new { "xml.strong { xml << yield }" }
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
66
|
+
3.times do
|
|
67
|
+
options = { :xml => Nokogiri::XML::Builder.new }
|
|
68
|
+
doc = Nokogiri.XML(template.render(options) { subtemplate.render(options) })
|
|
69
|
+
assert_equal 'Hello World!', doc.root.text.strip
|
|
70
|
+
assert_equal 'strong', doc.root.name
|
|
71
|
+
end
|
|
59
72
|
end
|
|
60
73
|
end
|
|
61
74
|
rescue LoadError
|
|
@@ -18,6 +18,11 @@ begin
|
|
|
18
18
|
assert_equal "Hello World!", template.render
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
+
test "can be rendered more than once" do
|
|
22
|
+
template = Tilt::RadiusTemplate.new { |t| "Hello World!" }
|
|
23
|
+
3.times { assert_equal "Hello World!", template.render }
|
|
24
|
+
end
|
|
25
|
+
|
|
21
26
|
test "passing locals" do
|
|
22
27
|
template = Tilt::RadiusTemplate.new { "Hey <r:name />!" }
|
|
23
28
|
assert_equal "Hey Joe!", template.render(nil, :name => 'Joe')
|
|
@@ -5,16 +5,26 @@ begin
|
|
|
5
5
|
require 'rdiscount'
|
|
6
6
|
|
|
7
7
|
class RDiscountTemplateTest < Test::Unit::TestCase
|
|
8
|
-
test "registered for '.markdown' files" do
|
|
9
|
-
assert_equal Tilt::RDiscountTemplate, Tilt['test.markdown']
|
|
10
|
-
end
|
|
11
|
-
|
|
12
8
|
test "registered for '.md' files" do
|
|
13
|
-
|
|
9
|
+
assert Tilt.mappings['md'].include?(Tilt::RDiscountTemplate)
|
|
14
10
|
end
|
|
15
11
|
|
|
16
12
|
test "registered for '.mkd' files" do
|
|
17
|
-
|
|
13
|
+
assert Tilt.mappings['mkd'].include?(Tilt::RDiscountTemplate)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
test "registered for '.markdown' files" do
|
|
17
|
+
assert Tilt.mappings['markdown'].include?(Tilt::RDiscountTemplate)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
test "registered above BlueCloth" do
|
|
21
|
+
%w[md mkd markdown].each do |ext|
|
|
22
|
+
mappings = Tilt.mappings[ext]
|
|
23
|
+
blue_idx = mappings.index(Tilt::BlueClothTemplate)
|
|
24
|
+
rdis_idx = mappings.index(Tilt::RDiscountTemplate)
|
|
25
|
+
assert rdis_idx < blue_idx,
|
|
26
|
+
"#{rdis_idx} should be lower than #{blue_idx}"
|
|
27
|
+
end
|
|
18
28
|
end
|
|
19
29
|
|
|
20
30
|
test "preparing and evaluating templates on #render" do
|
|
@@ -22,6 +32,11 @@ begin
|
|
|
22
32
|
assert_equal "<h1>Hello World!</h1>\n", template.render
|
|
23
33
|
end
|
|
24
34
|
|
|
35
|
+
test "can be rendered more than once" do
|
|
36
|
+
template = Tilt::RDiscountTemplate.new { |t| "# Hello World!" }
|
|
37
|
+
3.times { assert_equal "<h1>Hello World!</h1>\n", template.render }
|
|
38
|
+
end
|
|
39
|
+
|
|
25
40
|
test "smartypants when :smart is set" do
|
|
26
41
|
template = Tilt::RDiscountTemplate.new(:smart => true) { |t|
|
|
27
42
|
"OKAY -- 'Smarty Pants'" }
|
|
@@ -11,7 +11,12 @@ begin
|
|
|
11
11
|
|
|
12
12
|
test "preparing and evaluating the template with #render" do
|
|
13
13
|
template = Tilt::RDocTemplate.new { |t| "= Hello World!" }
|
|
14
|
-
assert_equal "<h1>Hello World!</h1
|
|
14
|
+
assert_equal "<h1>Hello World!</h1>", template.render.strip
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
test "can be rendered more than once" do
|
|
18
|
+
template = Tilt::RDocTemplate.new { |t| "= Hello World!" }
|
|
19
|
+
3.times { assert_equal "<h1>Hello World!</h1>", template.render.strip }
|
|
15
20
|
end
|
|
16
21
|
end
|
|
17
22
|
rescue LoadError => boom
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
require 'contest'
|
|
2
|
+
require 'tilt'
|
|
3
|
+
|
|
4
|
+
begin
|
|
5
|
+
require 'redcarpet'
|
|
6
|
+
|
|
7
|
+
class RedcarpetTemplateTest < Test::Unit::TestCase
|
|
8
|
+
test "registered for '.md' files" do
|
|
9
|
+
assert Tilt.mappings['md'].include?(Tilt::RedcarpetTemplate)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
test "registered for '.mkd' files" do
|
|
13
|
+
assert Tilt.mappings['mkd'].include?(Tilt::RedcarpetTemplate)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
test "registered for '.markdown' files" do
|
|
17
|
+
assert Tilt.mappings['markdown'].include?(Tilt::RedcarpetTemplate)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
test "registered above BlueCloth" do
|
|
21
|
+
%w[md mkd markdown].each do |ext|
|
|
22
|
+
mappings = Tilt.mappings[ext]
|
|
23
|
+
blue_idx = mappings.index(Tilt::BlueClothTemplate)
|
|
24
|
+
rdis_idx = mappings.index(Tilt::RedcarpetTemplate)
|
|
25
|
+
assert rdis_idx < blue_idx,
|
|
26
|
+
"#{rdis_idx} should be lower than #{blue_idx}"
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
test "preparing and evaluating templates on #render" do
|
|
31
|
+
template = Tilt::RedcarpetTemplate.new { |t| "# Hello World!" }
|
|
32
|
+
assert_equal "<h1>Hello World!</h1>\n", template.render
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
test "can be rendered more than once" do
|
|
36
|
+
template = Tilt::RedcarpetTemplate.new { |t| "# Hello World!" }
|
|
37
|
+
3.times { assert_equal "<h1>Hello World!</h1>\n", template.render }
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
test "smartypants when :smart is set" do
|
|
41
|
+
template = Tilt::RedcarpetTemplate.new(:smart => true) { |t|
|
|
42
|
+
"OKAY -- 'Smarty Pants'" }
|
|
43
|
+
assert_equal "<p>OKAY — ‘Smarty Pants’</p>\n",
|
|
44
|
+
template.render
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
test "stripping HTML when :filter_html is set" do
|
|
48
|
+
template = Tilt::RedcarpetTemplate.new(:filter_html => true) { |t|
|
|
49
|
+
"HELLO <blink>WORLD</blink>" }
|
|
50
|
+
assert_equal "<p>HELLO <blink>WORLD</blink></p>\n", template.render
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
rescue LoadError => boom
|
|
54
|
+
warn "Tilt::RedcarpetTemplate (disabled)\n"
|
|
55
|
+
end
|
|
@@ -14,6 +14,10 @@ begin
|
|
|
14
14
|
assert_equal "<h1>Hello World!</h1>", template.render
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
+
test "can be rendered more than once" do
|
|
18
|
+
template = Tilt::RedClothTemplate.new { |t| "h1. Hello World!" }
|
|
19
|
+
3.times { assert_equal "<h1>Hello World!</h1>", template.render }
|
|
20
|
+
end
|
|
17
21
|
end
|
|
18
22
|
rescue LoadError => boom
|
|
19
23
|
warn "Tilt::RedClothTemplate (disabled)\n"
|
|
@@ -14,6 +14,11 @@ begin
|
|
|
14
14
|
template = Tilt::SassTemplate.new { |t| "#main\n :background-color #0000f1" }
|
|
15
15
|
assert_equal "#main {\n background-color: #0000f1; }\n", template.render
|
|
16
16
|
end
|
|
17
|
+
|
|
18
|
+
test "can be rendered more than once" do
|
|
19
|
+
template = Tilt::SassTemplate.new { |t| "#main\n :background-color #0000f1" }
|
|
20
|
+
3.times { assert_equal "#main {\n background-color: #0000f1; }\n", template.render }
|
|
21
|
+
end
|
|
17
22
|
end
|
|
18
23
|
|
|
19
24
|
class ScssTemplateTest < Test::Unit::TestCase
|
|
@@ -25,6 +30,11 @@ begin
|
|
|
25
30
|
template = Tilt::ScssTemplate.new { |t| "#main {\n background-color: #0000f1;\n}" }
|
|
26
31
|
assert_equal "#main {\n background-color: #0000f1; }\n", template.render
|
|
27
32
|
end
|
|
33
|
+
|
|
34
|
+
test "can be rendered more than once" do
|
|
35
|
+
template = Tilt::ScssTemplate.new { |t| "#main {\n background-color: #0000f1;\n}" }
|
|
36
|
+
3.times { assert_equal "#main {\n background-color: #0000f1; }\n", template.render }
|
|
37
|
+
end
|
|
28
38
|
end
|
|
29
39
|
|
|
30
40
|
rescue LoadError => boom
|
|
@@ -11,6 +11,11 @@ class StringTemplateTest < Test::Unit::TestCase
|
|
|
11
11
|
assert_equal "Hello World!", template.render
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
+
test "can be rendered more than once" do
|
|
15
|
+
template = Tilt::StringTemplate.new { |t| "Hello World!" }
|
|
16
|
+
3.times { assert_equal "Hello World!", template.render }
|
|
17
|
+
end
|
|
18
|
+
|
|
14
19
|
test "passing locals" do
|
|
15
20
|
template = Tilt::StringTemplate.new { 'Hey #{name}!' }
|
|
16
21
|
assert_equal "Hey Joe!", template.render(Object.new, :name => 'Joe')
|
|
@@ -43,9 +48,9 @@ class StringTemplateTest < Test::Unit::TestCase
|
|
|
43
48
|
fail 'should have raised an exception'
|
|
44
49
|
rescue => boom
|
|
45
50
|
assert_kind_of NameError, boom
|
|
46
|
-
line = boom.backtrace.first
|
|
51
|
+
line = boom.backtrace.grep(/^test\.str:/).first
|
|
52
|
+
assert line, "Backtrace didn't contain test.str"
|
|
47
53
|
file, line, meth = line.split(":")
|
|
48
|
-
assert_equal 'test.str', file
|
|
49
54
|
assert_equal '13', line
|
|
50
55
|
end
|
|
51
56
|
end
|
|
@@ -114,6 +119,12 @@ class CompiledStringTemplateTest < Test::Unit::TestCase
|
|
|
114
119
|
assert_equal "Hello\nWorld!\n", template.render(Scope.new)
|
|
115
120
|
end
|
|
116
121
|
|
|
122
|
+
|
|
123
|
+
test "template with '}'" do
|
|
124
|
+
template = Tilt::StringTemplate.new { "Hello }" }
|
|
125
|
+
assert_equal "Hello }", template.render
|
|
126
|
+
end
|
|
127
|
+
|
|
117
128
|
test "backtrace file and line reporting without locals" do
|
|
118
129
|
data = File.read(__FILE__).split("\n__END__\n").last
|
|
119
130
|
fail unless data[0] == ?<
|
|
@@ -124,8 +135,9 @@ class CompiledStringTemplateTest < Test::Unit::TestCase
|
|
|
124
135
|
rescue => boom
|
|
125
136
|
assert_kind_of NameError, boom
|
|
126
137
|
line = boom.backtrace.first
|
|
138
|
+
line = boom.backtrace.grep(/^test\.str:/).first
|
|
139
|
+
assert line, "Backtrace didn't contain test.str"
|
|
127
140
|
file, line, meth = line.split(":")
|
|
128
|
-
assert_equal 'test.str', file
|
|
129
141
|
assert_equal '13', line
|
|
130
142
|
end
|
|
131
143
|
end
|
data/test/tilt_template_test.rb
CHANGED
|
@@ -121,6 +121,12 @@ class TiltTemplateTest < Test::Unit::TestCase
|
|
|
121
121
|
assert inst.prepared?
|
|
122
122
|
end
|
|
123
123
|
|
|
124
|
+
test "template_source with locals of strings" do
|
|
125
|
+
inst = SourceGeneratingMockTemplate.new { |t| 'Hey #{name}!' }
|
|
126
|
+
assert_equal "Hey Joe!", inst.render(Object.new, 'name' => 'Joe')
|
|
127
|
+
assert inst.prepared?
|
|
128
|
+
end
|
|
129
|
+
|
|
124
130
|
class Person
|
|
125
131
|
CONSTANT = "Bob"
|
|
126
132
|
|
data/tilt.gemspec
CHANGED
|
@@ -3,8 +3,8 @@ Gem::Specification.new do |s|
|
|
|
3
3
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
4
4
|
|
|
5
5
|
s.name = 'tilt'
|
|
6
|
-
s.version = '1.
|
|
7
|
-
s.date = '
|
|
6
|
+
s.version = '1.3'
|
|
7
|
+
s.date = '2011-04-26'
|
|
8
8
|
|
|
9
9
|
s.description = "Generic interface to multiple Ruby template engines"
|
|
10
10
|
s.summary = s.description
|
|
@@ -20,6 +20,21 @@ Gem::Specification.new do |s|
|
|
|
20
20
|
TEMPLATES.md
|
|
21
21
|
bin/tilt
|
|
22
22
|
lib/tilt.rb
|
|
23
|
+
lib/tilt/builder.rb
|
|
24
|
+
lib/tilt/coffee.rb
|
|
25
|
+
lib/tilt/creole.rb
|
|
26
|
+
lib/tilt/css.rb
|
|
27
|
+
lib/tilt/erb.rb
|
|
28
|
+
lib/tilt/haml.rb
|
|
29
|
+
lib/tilt/liquid.rb
|
|
30
|
+
lib/tilt/markaby.rb
|
|
31
|
+
lib/tilt/markdown.rb
|
|
32
|
+
lib/tilt/nokogiri.rb
|
|
33
|
+
lib/tilt/radius.rb
|
|
34
|
+
lib/tilt/rdoc.rb
|
|
35
|
+
lib/tilt/string.rb
|
|
36
|
+
lib/tilt/template.rb
|
|
37
|
+
lib/tilt/textile.rb
|
|
23
38
|
test/contest.rb
|
|
24
39
|
test/markaby/locals.mab
|
|
25
40
|
test/markaby/markaby.mab
|
|
@@ -32,16 +47,22 @@ Gem::Specification.new do |s|
|
|
|
32
47
|
test/tilt_cache_test.rb
|
|
33
48
|
test/tilt_coffeescripttemplate_test.rb
|
|
34
49
|
test/tilt_compilesite_test.rb
|
|
50
|
+
test/tilt_creoletemplate_test.rb
|
|
35
51
|
test/tilt_erbtemplate_test.rb
|
|
36
52
|
test/tilt_erubistemplate_test.rb
|
|
53
|
+
test/tilt_fallback_test.rb
|
|
37
54
|
test/tilt_hamltemplate_test.rb
|
|
55
|
+
test/tilt_kramdown_test.rb
|
|
38
56
|
test/tilt_lesstemplate_test.rb
|
|
39
57
|
test/tilt_liquidtemplate_test.rb
|
|
40
58
|
test/tilt_markaby_test.rb
|
|
59
|
+
test/tilt_markdown_test.rb
|
|
60
|
+
test/tilt_marukutemplate_test.rb
|
|
41
61
|
test/tilt_nokogiritemplate_test.rb
|
|
42
62
|
test/tilt_radiustemplate_test.rb
|
|
43
63
|
test/tilt_rdiscounttemplate_test.rb
|
|
44
64
|
test/tilt_rdoctemplate_test.rb
|
|
65
|
+
test/tilt_redcarpettemplate_test.rb
|
|
45
66
|
test/tilt_redclothtemplate_test.rb
|
|
46
67
|
test/tilt_sasstemplate_test.rb
|
|
47
68
|
test/tilt_stringtemplate_test.rb
|
|
@@ -66,6 +87,11 @@ Gem::Specification.new do |s|
|
|
|
66
87
|
s.add_development_dependency 'nokogiri'
|
|
67
88
|
s.add_development_dependency 'markaby'
|
|
68
89
|
s.add_development_dependency 'coffee-script'
|
|
90
|
+
s.add_development_dependency 'bluecloth'
|
|
91
|
+
s.add_development_dependency 'RedCloth'
|
|
92
|
+
s.add_development_dependency 'maruku'
|
|
93
|
+
s.add_development_dependency 'creole'
|
|
94
|
+
s.add_development_dependency 'kramdown'
|
|
69
95
|
|
|
70
96
|
s.extra_rdoc_files = %w[COPYING]
|
|
71
97
|
|