tilt 2.0.9 → 2.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tilt.rb +1 -1
- data/lib/tilt/template.rb +7 -12
- metadata +3 -104
- data/CHANGELOG.md +0 -132
- data/Gemfile +0 -70
- 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 -28
- 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 -42
- 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,75 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'tilt'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'tilt/radius'
|
6
|
-
|
7
|
-
# Disable radius tests under Ruby versions >= 1.9.1 since it's still buggy.
|
8
|
-
# Remove when fixed upstream.
|
9
|
-
raise LoadError if RUBY_VERSION >= "1.9.1" and Radius.version < "0.7"
|
10
|
-
|
11
|
-
class RadiusTemplateTest < Minitest::Test
|
12
|
-
test "registered for '.radius' files" do
|
13
|
-
assert_equal Tilt::RadiusTemplate, Tilt['test.radius']
|
14
|
-
end
|
15
|
-
|
16
|
-
test "preparing and evaluating templates on #render" do
|
17
|
-
template = Tilt::RadiusTemplate.new { |t| "Hello World!" }
|
18
|
-
assert_equal "Hello World!", template.render
|
19
|
-
end
|
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
|
-
|
26
|
-
test "passing locals" do
|
27
|
-
template = Tilt::RadiusTemplate.new { "Hey <r:name />!" }
|
28
|
-
assert_equal "Hey Joe!", template.render(nil, :name => 'Joe')
|
29
|
-
end
|
30
|
-
|
31
|
-
class ExampleRadiusScope
|
32
|
-
def beer; 'wet'; end
|
33
|
-
def whisky; 'wetter'; end
|
34
|
-
end
|
35
|
-
|
36
|
-
test "combining scope and locals when scope responds" do
|
37
|
-
template = Tilt::RadiusTemplate.new {
|
38
|
-
'Beer is <r:beer /> but Whisky is <r:whisky />.'
|
39
|
-
}
|
40
|
-
scope = ExampleRadiusScope.new
|
41
|
-
assert_equal "Beer is wet but Whisky is wetter.", template.render(scope)
|
42
|
-
end
|
43
|
-
|
44
|
-
test "precedence when locals and scope define same variables" do
|
45
|
-
template = Tilt::RadiusTemplate.new {
|
46
|
-
'Beer is <r:beer /> but Whisky is <r:whisky />.'
|
47
|
-
}
|
48
|
-
scope = ExampleRadiusScope.new
|
49
|
-
assert_equal "Beer is great but Whisky is greater.",
|
50
|
-
template.render(scope, :beer => 'great', :whisky => 'greater')
|
51
|
-
end
|
52
|
-
|
53
|
-
#test "handles local scope" do
|
54
|
-
# beer = 'wet'
|
55
|
-
# whisky = 'wetter'
|
56
|
-
#
|
57
|
-
# template = Tilt::RadiusTemplate.new {
|
58
|
-
# 'Beer is <r:beer /> but Whisky is <r:whisky />.'
|
59
|
-
# }
|
60
|
-
# assert_equal "Beer is wet but Whisky is wetter.", template.render(self)
|
61
|
-
#end
|
62
|
-
|
63
|
-
test "passing a block for yield" do
|
64
|
-
template = Tilt::RadiusTemplate.new {
|
65
|
-
'Beer is <r:yield /> but Whisky is <r:yield />ter.'
|
66
|
-
}
|
67
|
-
assert_equal "Beer is wet but Whisky is wetter.",
|
68
|
-
template.render({}) { 'wet' }
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
rescue LoadError
|
73
|
-
warn "Tilt::RadiusTemplate (disabled)"
|
74
|
-
end
|
75
|
-
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'tilt'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'tilt/rdiscount'
|
6
|
-
|
7
|
-
class RDiscountTemplateTest < Minitest::Test
|
8
|
-
test "registered above BlueCloth" do
|
9
|
-
%w[md mkd markdown].each do |ext|
|
10
|
-
lazy = Tilt.lazy_map[ext]
|
11
|
-
rdis_idx = lazy.index { |klass, file| klass == 'Tilt::RDiscountTemplate' }
|
12
|
-
blue_idx = lazy.index { |klass, file| klass == 'Tilt::BlueClothTemplate' }
|
13
|
-
assert rdis_idx < blue_idx,
|
14
|
-
"#{rdis_idx} should be lower than #{blue_idx}"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
test "preparing and evaluating templates on #render" do
|
19
|
-
template = Tilt::RDiscountTemplate.new { |t| "# Hello World!" }
|
20
|
-
assert_equal "<h1>Hello World!</h1>\n", template.render
|
21
|
-
end
|
22
|
-
|
23
|
-
test "can be rendered more than once" do
|
24
|
-
template = Tilt::RDiscountTemplate.new { |t| "# Hello World!" }
|
25
|
-
3.times { assert_equal "<h1>Hello World!</h1>\n", template.render }
|
26
|
-
end
|
27
|
-
|
28
|
-
test "smartypants when :smart is set" do
|
29
|
-
template = Tilt::RDiscountTemplate.new(:smart => true) { |t|
|
30
|
-
"OKAY -- 'Smarty Pants'" }
|
31
|
-
assert_equal "<p>OKAY – ‘Smarty Pants’</p>\n",
|
32
|
-
template.render
|
33
|
-
end
|
34
|
-
|
35
|
-
test "stripping HTML when :filter_html is set" do
|
36
|
-
template = Tilt::RDiscountTemplate.new(:filter_html => true) { |t|
|
37
|
-
"HELLO <blink>WORLD</blink>" }
|
38
|
-
assert_equal "<p>HELLO <blink>WORLD</blink></p>\n", template.render
|
39
|
-
end
|
40
|
-
end
|
41
|
-
rescue LoadError
|
42
|
-
warn "Tilt::RDiscountTemplate (disabled)"
|
43
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'tilt'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'tilt/rdoc'
|
6
|
-
class RDocTemplateTest < Minitest::Test
|
7
|
-
test "is registered for '.rdoc' files" do
|
8
|
-
assert_equal Tilt::RDocTemplate, Tilt['test.rdoc']
|
9
|
-
end
|
10
|
-
|
11
|
-
test "preparing and evaluating the template with #render" do
|
12
|
-
template = Tilt::RDocTemplate.new { |t| "= Hello World!" }
|
13
|
-
result = template.render.strip
|
14
|
-
assert_match %r(<h1), result
|
15
|
-
assert_match %r(>Hello World!<), result
|
16
|
-
end
|
17
|
-
|
18
|
-
test "can be rendered more than once" do
|
19
|
-
template = Tilt::RDocTemplate.new { |t| "= Hello World!" }
|
20
|
-
3.times do
|
21
|
-
result = template.render.strip
|
22
|
-
assert_match %r(<h1), result
|
23
|
-
assert_match %r(>Hello World!<), result
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
rescue LoadError => boom
|
28
|
-
warn "Tilt::RDocTemplate (disabled) [#{boom}]"
|
29
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'tilt'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'tilt/redcarpet'
|
6
|
-
|
7
|
-
class RedcarpetTemplateTest < Minitest::Test
|
8
|
-
test "registered above BlueCloth" do
|
9
|
-
%w[md mkd markdown].each do |ext|
|
10
|
-
lazy = Tilt.lazy_map[ext]
|
11
|
-
blue_idx = lazy.index { |klass, file| klass == 'Tilt::BlueClothTemplate' }
|
12
|
-
redc_idx = lazy.index { |klass, file| klass == 'Tilt::RedcarpetTemplate' }
|
13
|
-
assert redc_idx < blue_idx,
|
14
|
-
"#{redc_idx} should be lower than #{blue_idx}"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
test "registered above RDiscount" do
|
19
|
-
%w[md mkd markdown].each do |ext|
|
20
|
-
lazy = Tilt.lazy_map[ext]
|
21
|
-
rdis_idx = lazy.index { |klass, file| klass == 'Tilt::RDiscountTemplate' }
|
22
|
-
redc_idx = lazy.index { |klass, file| klass == 'Tilt::RedcarpetTemplate' }
|
23
|
-
assert redc_idx < rdis_idx,
|
24
|
-
"#{redc_idx} should be lower than #{rdis_idx}"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
test "preparing and evaluating templates on #render" do
|
29
|
-
template = Tilt::RedcarpetTemplate.new { |t| "# Hello World!" }
|
30
|
-
assert_equal "<h1>Hello World!</h1>\n", template.render
|
31
|
-
end
|
32
|
-
|
33
|
-
test "can be rendered more than once" do
|
34
|
-
template = Tilt::RedcarpetTemplate.new { |t| "# Hello World!" }
|
35
|
-
3.times { assert_equal "<h1>Hello World!</h1>\n", template.render }
|
36
|
-
end
|
37
|
-
|
38
|
-
test "smartypants when :smart is set" do
|
39
|
-
template = Tilt::RedcarpetTemplate.new(:smartypants => true) { |t|
|
40
|
-
"OKAY -- 'Smarty Pants'" }
|
41
|
-
assert_match %r!<p>OKAY – ('|‘)Smarty Pants('|’)<\/p>!,
|
42
|
-
template.render
|
43
|
-
end
|
44
|
-
|
45
|
-
test "smartypants with a rendererer instance" do
|
46
|
-
template = Tilt::RedcarpetTemplate.new(:renderer => Redcarpet::Render::HTML.new(:hard_wrap => true), :smartypants => true) { |t|
|
47
|
-
"OKAY -- 'Smarty Pants'" }
|
48
|
-
assert_match %r!<p>OKAY – ('|‘)Smarty Pants('|’)<\/p>!,
|
49
|
-
template.render
|
50
|
-
end
|
51
|
-
end
|
52
|
-
rescue LoadError
|
53
|
-
warn "Tilt::RedcarpetTemplate (disabled)"
|
54
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'tilt'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'tilt/redcloth'
|
6
|
-
|
7
|
-
class RedClothTemplateTest < Minitest::Test
|
8
|
-
test "is registered for '.textile' files" do
|
9
|
-
assert_equal Tilt::RedClothTemplate, Tilt['test.textile']
|
10
|
-
end
|
11
|
-
|
12
|
-
test "compiles and evaluates the template on #render" do
|
13
|
-
template = Tilt::RedClothTemplate.new { |t| "h1. Hello World!" }
|
14
|
-
assert_equal "<h1>Hello World!</h1>", template.render
|
15
|
-
end
|
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
|
21
|
-
|
22
|
-
test "ignores unknown options" do
|
23
|
-
template = Tilt::RedClothTemplate.new(:foo => "bar") { |t| "h1. Hello World!" }
|
24
|
-
3.times { assert_equal "<h1>Hello World!</h1>", template.render }
|
25
|
-
end
|
26
|
-
|
27
|
-
test "passes in RedCloth options" do
|
28
|
-
template = Tilt::RedClothTemplate.new { |t| "Hard breaks are\ninserted by default." }
|
29
|
-
assert_equal "<p>Hard breaks are<br />\ninserted by default.</p>", template.render
|
30
|
-
template = Tilt::RedClothTemplate.new(:hard_breaks => false) { |t| "But they can be\nturned off." }
|
31
|
-
assert_equal "<p>But they can be\nturned off.</p>", template.render
|
32
|
-
end
|
33
|
-
end
|
34
|
-
rescue LoadError
|
35
|
-
warn "Tilt::RedClothTemplate (disabled)"
|
36
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'tilt'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'tilt/rst-pandoc'
|
6
|
-
|
7
|
-
class RstPandocTemplateTest < Minitest::Test
|
8
|
-
test "is registered for '.rst' files" do
|
9
|
-
assert_equal Tilt::RstPandocTemplate, Tilt['test.rst']
|
10
|
-
end
|
11
|
-
|
12
|
-
test "compiles and evaluates the template on #render" do
|
13
|
-
template = Tilt::RstPandocTemplate.new { |t| "Hello World!\n============" }
|
14
|
-
assert_equal "<h1 id=\"hello-world\">Hello World!</h1>", template.render
|
15
|
-
end
|
16
|
-
|
17
|
-
test "can be rendered more than once" do
|
18
|
-
template = Tilt::RstPandocTemplate.new { |t| "Hello World!\n============" }
|
19
|
-
3.times do
|
20
|
-
assert_equal "<h1 id=\"hello-world\">Hello World!</h1>", template.render
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
test "doens't use markdown options" do
|
25
|
-
template = Tilt::RstPandocTemplate.new(:escape_html => true) { |t| "HELLO <blink>WORLD</blink>" }
|
26
|
-
err = assert_raises(RuntimeError) { template.render }
|
27
|
-
assert_match %r(pandoc: unrecognized option `--escape-html), err.message
|
28
|
-
end
|
29
|
-
end
|
30
|
-
rescue LoadError => boom
|
31
|
-
warn "Tilt::RstPandocTemplate (disabled) [#{boom}]"
|
32
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'tilt'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'tilt/sass'
|
6
|
-
|
7
|
-
class SassTemplateTest < Minitest::Test
|
8
|
-
test "is registered for '.sass' files" do
|
9
|
-
assert_equal Tilt::SassTemplate, Tilt['test.sass']
|
10
|
-
end
|
11
|
-
|
12
|
-
test "compiles and evaluates the template on #render" do
|
13
|
-
template = Tilt::SassTemplate.new { |t| "#main\n :background-color #0000f1" }
|
14
|
-
assert_equal "#main {\n background-color: #0000f1; }\n", template.render
|
15
|
-
end
|
16
|
-
|
17
|
-
test "can be rendered more than once" do
|
18
|
-
template = Tilt::SassTemplate.new { |t| "#main\n :background-color #0000f1" }
|
19
|
-
3.times { assert_equal "#main {\n background-color: #0000f1; }\n", template.render }
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
class ScssTemplateTest < Minitest::Test
|
24
|
-
test "is registered for '.scss' files" do
|
25
|
-
assert_equal Tilt::ScssTemplate, Tilt['test.scss']
|
26
|
-
end
|
27
|
-
|
28
|
-
test "compiles and evaluates the template on #render" do
|
29
|
-
template = Tilt::ScssTemplate.new { |t| "#main {\n background-color: #0000f1;\n}" }
|
30
|
-
assert_equal "#main {\n background-color: #0000f1; }\n", template.render
|
31
|
-
end
|
32
|
-
|
33
|
-
test "can be rendered more than once" do
|
34
|
-
template = Tilt::ScssTemplate.new { |t| "#main {\n background-color: #0000f1;\n}" }
|
35
|
-
3.times { assert_equal "#main {\n background-color: #0000f1; }\n", template.render }
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
rescue LoadError => err
|
40
|
-
raise err if ENV['FORCE_SASS']
|
41
|
-
warn "Tilt::SassTemplate (disabled)"
|
42
|
-
end
|
data/test/tilt_sigil_test.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'tilt'
|
3
|
-
require 'tilt/sigil'
|
4
|
-
|
5
|
-
system('sigil -v')
|
6
|
-
|
7
|
-
if $?.success?
|
8
|
-
class SigilTemplateTest < Minitest::Test
|
9
|
-
test "registered for '.sigil' files" do
|
10
|
-
assert_equal Tilt::SigilTemplate, Tilt['test.sigil']
|
11
|
-
end
|
12
|
-
|
13
|
-
test "loading and evaluating templates on #render" do
|
14
|
-
template = Tilt::SigilTemplate.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::SigilTemplate.new { |t| "Hello World!" }
|
20
|
-
3.times { assert_equal "Hello World!", template.render }
|
21
|
-
end
|
22
|
-
|
23
|
-
test "passing locals" do
|
24
|
-
template = Tilt::SigilTemplate.new { 'Hey $name!' }
|
25
|
-
assert_equal "Hey Joe!", template.render(Object.new, :name => 'Joe')
|
26
|
-
end
|
27
|
-
|
28
|
-
test "error message" do
|
29
|
-
template = Tilt::SigilTemplate.new('test.sigil') { '{{undef_func}}' }
|
30
|
-
begin
|
31
|
-
template.render
|
32
|
-
fail 'should have raised an exception'
|
33
|
-
rescue => boom
|
34
|
-
assert_kind_of RuntimeError, boom
|
35
|
-
assert_equal 'template: test.sigil:1: function "undef_func" not defined', boom.message
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
else
|
40
|
-
warn "Tilt::SigilTemplate (disabled)"
|
41
|
-
end
|
@@ -1,171 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'tilt'
|
3
|
-
require 'tilt/string'
|
4
|
-
|
5
|
-
class StringTemplateTest < Minitest::Test
|
6
|
-
test "registered for '.str' files" do
|
7
|
-
assert_equal Tilt::StringTemplate, Tilt['test.str']
|
8
|
-
end
|
9
|
-
|
10
|
-
test "loading and evaluating templates on #render" do
|
11
|
-
template = Tilt::StringTemplate.new { |t| "Hello World!" }
|
12
|
-
assert_equal "Hello World!", template.render
|
13
|
-
end
|
14
|
-
|
15
|
-
test "can be rendered more than once" do
|
16
|
-
template = Tilt::StringTemplate.new { |t| "Hello World!" }
|
17
|
-
3.times { assert_equal "Hello World!", template.render }
|
18
|
-
end
|
19
|
-
|
20
|
-
test "passing locals" do
|
21
|
-
template = Tilt::StringTemplate.new { 'Hey #{name}!' }
|
22
|
-
assert_equal "Hey Joe!", template.render(Object.new, :name => 'Joe')
|
23
|
-
end
|
24
|
-
|
25
|
-
test "evaluating in an object scope" do
|
26
|
-
template = Tilt::StringTemplate.new { 'Hey #{@name}!' }
|
27
|
-
scope = Object.new
|
28
|
-
scope.instance_variable_set :@name, 'Joe'
|
29
|
-
assert_equal "Hey Joe!", template.render(scope)
|
30
|
-
end
|
31
|
-
|
32
|
-
test "passing a block for yield" do
|
33
|
-
template = Tilt::StringTemplate.new { 'Hey #{yield}!' }
|
34
|
-
assert_equal "Hey Joe!", template.render { 'Joe' }
|
35
|
-
assert_equal "Hey Moe!", template.render { 'Moe' }
|
36
|
-
end
|
37
|
-
|
38
|
-
test "multiline templates" do
|
39
|
-
template = Tilt::StringTemplate.new { "Hello\nWorld!\n" }
|
40
|
-
assert_equal "Hello\nWorld!\n", template.render
|
41
|
-
end
|
42
|
-
|
43
|
-
test "backtrace file and line reporting without locals" do
|
44
|
-
data = File.read(__FILE__).split("\n__END__\n").last
|
45
|
-
fail unless data[0] == ?<
|
46
|
-
template = Tilt::StringTemplate.new('test.str', 11) { data }
|
47
|
-
begin
|
48
|
-
template.render
|
49
|
-
fail 'should have raised an exception'
|
50
|
-
rescue => boom
|
51
|
-
assert_kind_of NameError, boom
|
52
|
-
line = boom.backtrace.grep(/^test\.str:/).first
|
53
|
-
assert line, "Backtrace didn't contain test.str"
|
54
|
-
_file, line, _meth = line.split(":")
|
55
|
-
assert_equal '13', line
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
test "backtrace file and line reporting with locals" do
|
60
|
-
data = File.read(__FILE__).split("\n__END__\n").last
|
61
|
-
fail unless data[0] == ?<
|
62
|
-
template = Tilt::StringTemplate.new('test.str', 1) { data }
|
63
|
-
begin
|
64
|
-
template.render(nil, :name => 'Joe', :foo => 'bar')
|
65
|
-
fail 'should have raised an exception'
|
66
|
-
rescue => boom
|
67
|
-
assert_kind_of RuntimeError, boom
|
68
|
-
line = boom.backtrace.first
|
69
|
-
file, line, _meth = line.split(":")
|
70
|
-
assert_equal 'test.str', file
|
71
|
-
assert_equal '6', line
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
|
77
|
-
class CompiledStringTemplateTest < Minitest::Test
|
78
|
-
def teardown
|
79
|
-
GC.start
|
80
|
-
end
|
81
|
-
|
82
|
-
class Scope
|
83
|
-
end
|
84
|
-
|
85
|
-
test "compiling template source to a method" do
|
86
|
-
template = Tilt::StringTemplate.new { |t| "Hello World!" }
|
87
|
-
template.render(Scope.new)
|
88
|
-
method = template.send(:compiled_method, [])
|
89
|
-
assert_kind_of UnboundMethod, method
|
90
|
-
end
|
91
|
-
|
92
|
-
test "loading and evaluating templates on #render" do
|
93
|
-
template = Tilt::StringTemplate.new { |t| "Hello World!" }
|
94
|
-
assert_equal "Hello World!", template.render(Scope.new)
|
95
|
-
end
|
96
|
-
|
97
|
-
test "passing locals" do
|
98
|
-
template = Tilt::StringTemplate.new { 'Hey #{name}!' }
|
99
|
-
assert_equal "Hey Joe!", template.render(Scope.new, :name => 'Joe')
|
100
|
-
assert_equal "Hey Moe!", template.render(Scope.new, :name => 'Moe')
|
101
|
-
end
|
102
|
-
|
103
|
-
test "evaluating in an object scope" do
|
104
|
-
template = Tilt::StringTemplate.new { 'Hey #{@name}!' }
|
105
|
-
scope = Scope.new
|
106
|
-
scope.instance_variable_set :@name, 'Joe'
|
107
|
-
assert_equal "Hey Joe!", template.render(scope)
|
108
|
-
scope.instance_variable_set :@name, 'Moe'
|
109
|
-
assert_equal "Hey Moe!", template.render(scope)
|
110
|
-
end
|
111
|
-
|
112
|
-
test "passing a block for yield" do
|
113
|
-
template = Tilt::StringTemplate.new { 'Hey #{yield}!' }
|
114
|
-
assert_equal "Hey Joe!", template.render(Scope.new) { 'Joe' }
|
115
|
-
assert_equal "Hey Moe!", template.render(Scope.new) { 'Moe' }
|
116
|
-
end
|
117
|
-
|
118
|
-
test "multiline templates" do
|
119
|
-
template = Tilt::StringTemplate.new { "Hello\nWorld!\n" }
|
120
|
-
assert_equal "Hello\nWorld!\n", template.render(Scope.new)
|
121
|
-
end
|
122
|
-
|
123
|
-
|
124
|
-
test "template with '}'" do
|
125
|
-
template = Tilt::StringTemplate.new { "Hello }" }
|
126
|
-
assert_equal "Hello }", template.render
|
127
|
-
end
|
128
|
-
|
129
|
-
test "backtrace file and line reporting without locals" do
|
130
|
-
data = File.read(__FILE__).split("\n__END__\n").last
|
131
|
-
fail unless data[0] == ?<
|
132
|
-
template = Tilt::StringTemplate.new('test.str', 11) { data }
|
133
|
-
begin
|
134
|
-
template.render(Scope.new)
|
135
|
-
fail 'should have raised an exception'
|
136
|
-
rescue => boom
|
137
|
-
assert_kind_of NameError, boom
|
138
|
-
line = boom.backtrace.first
|
139
|
-
line = boom.backtrace.grep(/^test\.str:/).first
|
140
|
-
assert line, "Backtrace didn't contain test.str"
|
141
|
-
_file, line, _meth = line.split(":")
|
142
|
-
assert_equal '13', line
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
test "backtrace file and line reporting with locals" do
|
147
|
-
data = File.read(__FILE__).split("\n__END__\n").last
|
148
|
-
fail unless data[0] == ?<
|
149
|
-
template = Tilt::StringTemplate.new('test.str') { data }
|
150
|
-
begin
|
151
|
-
template.render(Scope.new, :name => 'Joe', :foo => 'bar')
|
152
|
-
fail 'should have raised an exception'
|
153
|
-
rescue => boom
|
154
|
-
assert_kind_of RuntimeError, boom
|
155
|
-
line = boom.backtrace.first
|
156
|
-
file, line, _meth = line.split(":")
|
157
|
-
assert_equal 'test.str', file
|
158
|
-
assert_equal '6', line
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
__END__
|
164
|
-
<html>
|
165
|
-
<body>
|
166
|
-
<h1>Hey #{name}!</h1>
|
167
|
-
|
168
|
-
|
169
|
-
<p>#{fail}</p>
|
170
|
-
</body>
|
171
|
-
</html>
|