html-template-pro 0.0.1
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/.autotest +9 -0
- data/ARTISTIC +131 -0
- data/History.txt +4 -0
- data/LGPL +504 -0
- data/Manifest.txt +221 -0
- data/README.rdoc +52 -0
- data/Rakefile +18 -0
- data/benchmark.rb +136 -0
- data/config/website.yml +2 -0
- data/ext/html/template/internal/Pro.xs +679 -0
- data/ext/html/template/internal/builtin_findfile.inc +361 -0
- data/ext/html/template/internal/calc.h +26 -0
- data/ext/html/template/internal/calc.inc +120 -0
- data/ext/html/template/internal/callback_stubs.inc +63 -0
- data/ext/html/template/internal/expr.c +2267 -0
- data/ext/html/template/internal/expr.y +476 -0
- data/ext/html/template/internal/expr_iface.c +94 -0
- data/ext/html/template/internal/exprpstr.h +36 -0
- data/ext/html/template/internal/exprpstr.inc +144 -0
- data/ext/html/template/internal/exprtool.h +99 -0
- data/ext/html/template/internal/exprtool.inc +289 -0
- data/ext/html/template/internal/exprtype.h +62 -0
- data/ext/html/template/internal/exprval.h +30 -0
- data/ext/html/template/internal/extconf.rb +6 -0
- data/ext/html/template/internal/internal.c +449 -0
- data/ext/html/template/internal/loadfile.h +11 -0
- data/ext/html/template/internal/loadfile.inc +171 -0
- data/ext/html/template/internal/pabidecl.h +54 -0
- data/ext/html/template/internal/pabstract.h +426 -0
- data/ext/html/template/internal/parse_expr.h +15 -0
- data/ext/html/template/internal/pbuffer.c +76 -0
- data/ext/html/template/internal/pbuffer.h +31 -0
- data/ext/html/template/internal/pmiscdef.h +54 -0
- data/ext/html/template/internal/pparam.h +101 -0
- data/ext/html/template/internal/ppport.h +1098 -0
- data/ext/html/template/internal/procore.c +1189 -0
- data/ext/html/template/internal/procore.h +18 -0
- data/ext/html/template/internal/proparam.c +443 -0
- data/ext/html/template/internal/proparam.h +571 -0
- data/ext/html/template/internal/proscope.h +32 -0
- data/ext/html/template/internal/proscope.inc +107 -0
- data/ext/html/template/internal/prostate.h +49 -0
- data/ext/html/template/internal/prostate.inc +24 -0
- data/ext/html/template/internal/provalue.h +14 -0
- data/ext/html/template/internal/pstring.h +60 -0
- data/ext/html/template/internal/pstrutils.h +25 -0
- data/ext/html/template/internal/pstrutils.inc +150 -0
- data/ext/html/template/internal/tagstack.h +30 -0
- data/ext/html/template/internal/tagstack.inc +65 -0
- data/ext/html/template/internal/tmpllog.c +62 -0
- data/ext/html/template/internal/tmpllog.h +27 -0
- data/ext/html/template/internal/tmplpro.h +218 -0
- data/ext/html/template/internal/tmplpro_version.c +35 -0
- data/lib/html/template/pro.rb +225 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +71 -0
- data/tasks/extconf.rake +13 -0
- data/tasks/extconf/tmplpro.rake +43 -0
- data/templates-Pro/a.incl +1 -0
- data/templates-Pro/empty.incl +0 -0
- data/templates-Pro/include/1/a.incl +1 -0
- data/templates-Pro/include/2.out +3 -0
- data/templates-Pro/include/2.tmpl +1 -0
- data/templates-Pro/include/2/a.incl +1 -0
- data/templates-Pro/include/3.tmpl +1 -0
- data/templates-Pro/include/4.tmpl +1 -0
- data/templates-Pro/include/a.incl +1 -0
- data/templates-Pro/test_broken.tmpl +25 -0
- data/templates-Pro/test_broken1.out +1 -0
- data/templates-Pro/test_broken1.tmpl +1 -0
- data/templates-Pro/test_esc1.out +4 -0
- data/templates-Pro/test_esc1.tmpl +4 -0
- data/templates-Pro/test_esc2.out +5 -0
- data/templates-Pro/test_esc2.tmpl +6 -0
- data/templates-Pro/test_esc3.out +4 -0
- data/templates-Pro/test_esc3.tmpl +4 -0
- data/templates-Pro/test_esc4.out +3 -0
- data/templates-Pro/test_esc4.tmpl +4 -0
- data/templates-Pro/test_expr1.out +26 -0
- data/templates-Pro/test_expr1.tmpl +26 -0
- data/templates-Pro/test_expr2.out +34 -0
- data/templates-Pro/test_expr2.tmpl +34 -0
- data/templates-Pro/test_expr3.out +6 -0
- data/templates-Pro/test_expr3.tmpl +6 -0
- data/templates-Pro/test_expr4.out +4 -0
- data/templates-Pro/test_expr4.tmpl +4 -0
- data/templates-Pro/test_expr5.out +18 -0
- data/templates-Pro/test_expr5.tmpl +18 -0
- data/templates-Pro/test_expr6.out +18 -0
- data/templates-Pro/test_expr6.tmpl +18 -0
- data/templates-Pro/test_expr7.out +44 -0
- data/templates-Pro/test_expr7.tmpl +20 -0
- data/templates-Pro/test_expr8.out +15 -0
- data/templates-Pro/test_expr8.tmpl +15 -0
- data/templates-Pro/test_if1.out +25 -0
- data/templates-Pro/test_if1.tmpl +28 -0
- data/templates-Pro/test_if2.out +17 -0
- data/templates-Pro/test_if2.tmpl +25 -0
- data/templates-Pro/test_if3.out +12 -0
- data/templates-Pro/test_if3.tmpl +14 -0
- data/templates-Pro/test_if4.out +15 -0
- data/templates-Pro/test_if4.tmpl +31 -0
- data/templates-Pro/test_if5.out +16 -0
- data/templates-Pro/test_if5.tmpl +16 -0
- data/templates-Pro/test_if6.out +15 -0
- data/templates-Pro/test_if6.tmpl +31 -0
- data/templates-Pro/test_if7.out +14 -0
- data/templates-Pro/test_if7.tmpl +18 -0
- data/templates-Pro/test_include1.out +23 -0
- data/templates-Pro/test_include1.tmpl +7 -0
- data/templates-Pro/test_include2.out +120 -0
- data/templates-Pro/test_include2.tmpl +10 -0
- data/templates-Pro/test_include3.out +8 -0
- data/templates-Pro/test_include3.tmpl +8 -0
- data/templates-Pro/test_include4.out +7 -0
- data/templates-Pro/test_include4.tmpl +6 -0
- data/templates-Pro/test_include5.out +7 -0
- data/templates-Pro/test_include5.tmpl +6 -0
- data/templates-Pro/test_loop1.erb +17 -0
- data/templates-Pro/test_loop1.out +12 -0
- data/templates-Pro/test_loop1.tmpl +16 -0
- data/templates-Pro/test_loop2.erb +19 -0
- data/templates-Pro/test_loop2.out +40 -0
- data/templates-Pro/test_loop2.tmpl +19 -0
- data/templates-Pro/test_loop3.out +38 -0
- data/templates-Pro/test_loop3.tmpl +40 -0
- data/templates-Pro/test_loop4.out +44 -0
- data/templates-Pro/test_loop4.tmpl +20 -0
- data/templates-Pro/test_loop5.out +9 -0
- data/templates-Pro/test_loop5.tmpl +11 -0
- data/templates-Pro/test_loop6.out +33 -0
- data/templates-Pro/test_loop6.tmpl +15 -0
- data/templates-Pro/test_malloc.tmpl +1 -0
- data/templates-Pro/test_userfunc1.out +14 -0
- data/templates-Pro/test_userfunc1.tmpl +14 -0
- data/templates-Pro/test_userfunc2.out +35 -0
- data/templates-Pro/test_userfunc2.tmpl +5 -0
- data/templates-Pro/test_userfunc3.out +5 -0
- data/templates-Pro/test_userfunc3.tmpl +5 -0
- data/templates-Pro/test_userfunc4.out +10 -0
- data/templates-Pro/test_userfunc4.tmpl +10 -0
- data/templates-Pro/test_userfunc5.out +4 -0
- data/templates-Pro/test_userfunc5.tmpl +4 -0
- data/templates-Pro/test_userfunc6.out +4 -0
- data/templates-Pro/test_userfunc6.tmpl +4 -0
- data/templates-Pro/test_var1.erb +23 -0
- data/templates-Pro/test_var1.out +20 -0
- data/templates-Pro/test_var1.tmpl +23 -0
- data/templates-Pro/test_var2.erb +7 -0
- data/templates-Pro/test_var2.out +6 -0
- data/templates-Pro/test_var2.tmpl +7 -0
- data/templates-Pro/test_var3.out +14 -0
- data/templates-Pro/test_var3.tmpl +16 -0
- data/templates/case_loop.tmpl +3 -0
- data/templates/context.tmpl +3 -0
- data/templates/counter.tmpl +2 -0
- data/templates/default.tmpl +1 -0
- data/templates/default_escape.tmpl +4 -0
- data/templates/double_loop.tmpl +7 -0
- data/templates/escape.tmpl +5 -0
- data/templates/global-loops.tmpl +9 -0
- data/templates/globals.tmpl +11 -0
- data/templates/if.tmpl +7 -0
- data/templates/ifelse.tmpl +6 -0
- data/templates/include.tmpl +14 -0
- data/templates/include_path/a.tmpl +2 -0
- data/templates/include_path/b.tmpl +1 -0
- data/templates/include_path/inner.tmpl +1 -0
- data/templates/include_path/one.tmpl +2 -0
- data/templates/include_path2/inner.tmpl +1 -0
- data/templates/included.tmpl +4 -0
- data/templates/included2.tmpl +3 -0
- data/templates/js.tmpl +1 -0
- data/templates/long_loops.tmpl +307 -0
- data/templates/loop-context.tmpl +2 -0
- data/templates/loop-if.tmpl +9 -0
- data/templates/medium.tmpl +217 -0
- data/templates/multiline_tags.tmpl +7 -0
- data/templates/newline_test1.tmpl +1 -0
- data/templates/newline_test2.tmpl +1 -0
- data/templates/other-loop.tmpl +7 -0
- data/templates/outer.tmpl +3 -0
- data/templates/query-test.tmpl +21 -0
- data/templates/query-test2.tmpl +12 -0
- data/templates/recursive.tmpl +2 -0
- data/templates/searchpath/included.tmpl +4 -0
- data/templates/searchpath/three.tmpl +1 -0
- data/templates/searchpath/two.tmpl +2 -0
- data/templates/simple-loop-nonames.tmpl +13 -0
- data/templates/simple-loop.tmpl +12 -0
- data/templates/simple.tmpl +9 -0
- data/templates/unless.tmpl +5 -0
- data/templates/urlescape.tmpl +3 -0
- data/templates/vanguard1.tmpl +2 -0
- data/templates/vanguard2.tmpl +3 -0
- data/test/templates/complex.tmpl +24 -0
- data/test/templates/foo.tmpl +6 -0
- data/test/templates/func.tmpl +2 -0
- data/test/templates/loop.tmpl +14 -0
- data/test/templates/negative.tmpl +1 -0
- data/test/templates/numerics.tmpl +6 -0
- data/test/templates/register.tmpl +2 -0
- data/test/test_basic.rb +23 -0
- data/test/test_coderefs.rb +16 -0
- data/test/test_complex.rb +106 -0
- data/test/test_helper.rb +3 -0
- data/test/test_html_template.rb +583 -0
- data/test/test_html_template_internal_extn.rb +10 -0
- data/test/test_html_template_pro.rb +177 -0
- data/test/test_path_like_variable_scope.rb +59 -0
- data/test/test_random.rb +21 -0
- data/test/test_realloc.rb +16 -0
- data/test/test_register.rb +25 -0
- data/test/test_tmplpro.rb +9 -0
- data/test/tests.rb +9 -0
- data/website/index.txt +57 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +159 -0
- data/website/template.html.erb +50 -0
- metadata +303 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
START<TMPL_INCLUDE newline_test2.tmpl>END
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
include
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
<TMPL_LOOP NAME="EXAMPLE_LOOP">
|
|
4
|
+
<TMPL_VAR NAME="BEE">
|
|
5
|
+
</TMPL_LOOP>
|
|
6
|
+
|
|
7
|
+
<TMPL_LOOP NAME="EXAMPLE_LOOP">
|
|
8
|
+
<TMPL_VAR NAME="BOP">
|
|
9
|
+
<TMPL_LOOP NAME="EXAMPLE_INNER_LOOP">
|
|
10
|
+
<TMPL_VAR NAME="INNER_BEE">
|
|
11
|
+
<TMPL_VAR NAME="INNER_BOP">
|
|
12
|
+
</TMPL_LOOP>
|
|
13
|
+
</TMPL_LOOP>
|
|
14
|
+
|
|
15
|
+
<TMPL_LOOP NAME="EXAMPLE_LOOP">
|
|
16
|
+
<TMPL_VAR NAME="BOP">
|
|
17
|
+
<TMPL_VAR NAME="BEE">
|
|
18
|
+
</TMPL_LOOP>
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
<TMPL_VAR NAME=VAR>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
THREE
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<tmpl_if expr="defined(unused)">...</tmpl_if>
|
|
2
|
+
<tmpl_if expr="(foo + 10) > 20">
|
|
3
|
+
Foo is greater than 10.
|
|
4
|
+
</tmpl_if>
|
|
5
|
+
|
|
6
|
+
<tmpl_if expr="bar && foo">
|
|
7
|
+
Bar and Foo.
|
|
8
|
+
</tmpl_if>
|
|
9
|
+
|
|
10
|
+
<tmpl_if expr="bar || foo">
|
|
11
|
+
Bar or Foo.
|
|
12
|
+
</tmpl_if>
|
|
13
|
+
|
|
14
|
+
Bar - Foo = <tmpl_var expr="bar - foo">
|
|
15
|
+
|
|
16
|
+
<tmpl_if expr="((foo * foo) > (foo + foo))">
|
|
17
|
+
Math Works, Alright
|
|
18
|
+
</tmpl_if>
|
|
19
|
+
|
|
20
|
+
My name is <tmpl_var expr="ucfirst(fname)"> <tmpl_var expr="ucfirst(lname)">.
|
|
21
|
+
|
|
22
|
+
Yo, <tmpl_var expr="ucfirst(substr(fname, 1))"> Alien is phat.
|
|
23
|
+
|
|
24
|
+
<tmpl_var expr="ucfirst(substr(fname, 1))"> has <tmpl_var expr="length(ucfirst(substr(fname, 1)))"> letters, which is <tmpl_if expr="length(ucfirst(substr(fname, 1))) < 10">less than 10<tmpl_else>greater than 10</tmpl_if> and <tmpl_if expr="length(ucfirst(substr(fname, 1))) > 5">greater than 5<tmpl_else>less than 5</tmpl_if>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<tmpl_loop simple>Foo is <tmpl_if expr="(foo > 10)">greater than<tmpl_else>less than</tmpl_if> 10.
|
|
2
|
+
</tmpl_loop>
|
|
3
|
+
|
|
4
|
+
<tmpl_loop complex>
|
|
5
|
+
<tmpl_if expr="color eq 'blue'"><blue></tmpl_if>
|
|
6
|
+
Name: <tmpl_var expr="ucfirst(fname)"> <tmpl_var expr="ucfirst(lname)">
|
|
7
|
+
Stats:
|
|
8
|
+
<tmpl_if expr="color eq 'blue'"><blue></tmpl_if>
|
|
9
|
+
<tmpl_loop inner><tmpl_var stat_name> <tmpl_if expr="stat_value > 10">[high]<tmpl_else><tmpl_if expr="stat_value < 1">[low]<tmpl_else>[medium]</tmpl_if></tmpl_if>
|
|
10
|
+
Color: <tmpl_var color>
|
|
11
|
+
</tmpl_loop>
|
|
12
|
+
<tmpl_if expr="color eq 'blue'"></blue></tmpl_if>
|
|
13
|
+
<tmpl_if expr="color eq 'blue'"></blue></tmpl_if>
|
|
14
|
+
</tmpl_loop>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<tmpl_if expr="foo > -1">Yes</tmpl_if>
|
data/test/test_basic.rb
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'test/unit'
|
|
2
|
+
require 'html/template/pro'
|
|
3
|
+
|
|
4
|
+
class TestBasic < Test::Unit::TestCase
|
|
5
|
+
def test_basic
|
|
6
|
+
template = HTML::Template::Expr.new(:path => ['test/templates'],
|
|
7
|
+
:filename => 'foo.tmpl')
|
|
8
|
+
template.param(:foo => 100)
|
|
9
|
+
output = template.output()
|
|
10
|
+
assert_match(/greater than/i, output, "greater than")
|
|
11
|
+
|
|
12
|
+
template.param(:foo => 10)
|
|
13
|
+
output = template.output()
|
|
14
|
+
assert_match(/less than/i, output, "less than")
|
|
15
|
+
|
|
16
|
+
template = HTML::Template::Expr.new(:path => ['test/templates'],
|
|
17
|
+
:filename => 'negative.tmpl')
|
|
18
|
+
template.param(:foo => 100)
|
|
19
|
+
output = template.output()
|
|
20
|
+
assert_match(/Yes/, output, "negative numbers work")
|
|
21
|
+
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'test/unit'
|
|
4
|
+
require 'html/template/pro'
|
|
5
|
+
|
|
6
|
+
class TestCodeRefs < Test::Unit::TestCase
|
|
7
|
+
def test_coderefs
|
|
8
|
+
template = HTML::Template::Pro.new(:path => 'templates',
|
|
9
|
+
:filename => 'escape.tmpl')
|
|
10
|
+
template.param(:STUFF) do
|
|
11
|
+
'<>"\''
|
|
12
|
+
end
|
|
13
|
+
output = template.output
|
|
14
|
+
assert_no_match(/[<>"']/, output)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
require 'test/unit'
|
|
2
|
+
require 'html/template/pro'
|
|
3
|
+
|
|
4
|
+
class TestComplex < Test::Unit::TestCase
|
|
5
|
+
def test_complex
|
|
6
|
+
|
|
7
|
+
template = HTML::Template::Expr.new(:path => ['test/templates'],
|
|
8
|
+
:filename => 'complex.tmpl')
|
|
9
|
+
template.param(:foo => 11,
|
|
10
|
+
:bar => 0,
|
|
11
|
+
:fname => 'president',
|
|
12
|
+
:lname => 'clinton',
|
|
13
|
+
:unused => 0,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
output = template.output()
|
|
17
|
+
|
|
18
|
+
assert_match(/Foo is greater than 10/i, output, "greater than")
|
|
19
|
+
assert_no_match(/Bar and Foo/i, output, "and")
|
|
20
|
+
assert_match(/Bar or Foo/i, output, "or")
|
|
21
|
+
assert_match(/Bar - Foo = -11/i, output, "subtraction")
|
|
22
|
+
assert_match(/Math Works, Alright/i, output, "math")
|
|
23
|
+
assert_match(/My name is President Clinton/, output, "string op 1")
|
|
24
|
+
assert_match(/Resident Alien is phat/, output, "string op 2")
|
|
25
|
+
assert_match(/Resident has 8 letters, which is less than 10 and greater than 5/, output, "string length")
|
|
26
|
+
|
|
27
|
+
template = HTML::Template::Expr.new(:path => ['test/templates'],
|
|
28
|
+
:filename => 'loop.tmpl',
|
|
29
|
+
:global_vars => 1)
|
|
30
|
+
template.param(:simple => [
|
|
31
|
+
{ :foo => 10 },
|
|
32
|
+
{ :foo => 100 },
|
|
33
|
+
{ :foo => 1000 },
|
|
34
|
+
])
|
|
35
|
+
template.param(:color => 'blue')
|
|
36
|
+
template.param(:complex => [
|
|
37
|
+
{
|
|
38
|
+
:fname => 'Yasunari',
|
|
39
|
+
:lname => 'Kawabata',
|
|
40
|
+
:inner => [
|
|
41
|
+
{ :stat_name => 'style',
|
|
42
|
+
:stat_value => 100 ,
|
|
43
|
+
},
|
|
44
|
+
{ :stat_name => 'shock',
|
|
45
|
+
:stat_value => 1,
|
|
46
|
+
},
|
|
47
|
+
{ :stat_name => 'poetry',
|
|
48
|
+
:stat_value => 100
|
|
49
|
+
},
|
|
50
|
+
{ :stat_name => 'machismo',
|
|
51
|
+
:stat_value => 50
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
:fname => 'Yukio',
|
|
57
|
+
:lname => 'Mishima',
|
|
58
|
+
:inner => [
|
|
59
|
+
{ :stat_name => 'style',
|
|
60
|
+
:stat_value => 50,
|
|
61
|
+
},
|
|
62
|
+
{ :stat_name => 'shock',
|
|
63
|
+
:stat_value => 100,
|
|
64
|
+
},
|
|
65
|
+
{ :stat_name => 'poetry',
|
|
66
|
+
:stat_value => 1
|
|
67
|
+
},
|
|
68
|
+
{ :stat_name => 'machismo',
|
|
69
|
+
:stat_value => 100
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
},
|
|
73
|
+
])
|
|
74
|
+
|
|
75
|
+
output = template.output
|
|
76
|
+
assert_match(/Foo is less than 10.\s+Foo is greater than 10.\s+Foo is greater than 10./, output, "math in loops")
|
|
77
|
+
|
|
78
|
+
# test user-defined functions
|
|
79
|
+
repeat = ->(x, y) { x * y }
|
|
80
|
+
|
|
81
|
+
template = HTML::Template::Expr.new(:path => ['test/templates'],
|
|
82
|
+
:filename => 'func.tmpl',
|
|
83
|
+
:functions => {
|
|
84
|
+
:repeat => repeat,
|
|
85
|
+
})
|
|
86
|
+
template.param(:repeat_me => 'foo ');
|
|
87
|
+
output = template.output();
|
|
88
|
+
|
|
89
|
+
assert_match(/foo foo foo foo/, output, "user defined function")
|
|
90
|
+
assert_match(/FOO FOO FOO FOO/, output, "user defined function with uc()")
|
|
91
|
+
|
|
92
|
+
# test numeric functions
|
|
93
|
+
template = HTML::Template::Expr.new(:path => ['test/templates'],
|
|
94
|
+
:filename => 'numerics.tmpl')
|
|
95
|
+
template.param(:float => 5.1,
|
|
96
|
+
:four => 4)
|
|
97
|
+
output = template.output
|
|
98
|
+
|
|
99
|
+
assert_match(/INT: 5/, output, "int()")
|
|
100
|
+
assert_match(/SQRT: 2/, output, "sqrt()")
|
|
101
|
+
assert_match(/SQRT2: 4/, output, "sqrt() 2")
|
|
102
|
+
assert_match(/SUM: 14/, output, "int(4 + 10.1)")
|
|
103
|
+
assert_match(/SPRINTF: 14.1000/, output, "sprintf('%0.4f', (10.1 + 4))")
|
|
104
|
+
|
|
105
|
+
end
|
|
106
|
+
end
|
data/test/test_helper.rb
ADDED
|
@@ -0,0 +1,583 @@
|
|
|
1
|
+
require 'test/unit'
|
|
2
|
+
require 'html/template/pro'
|
|
3
|
+
|
|
4
|
+
class TestHtmlTemplate < Test::Unit::TestCase
|
|
5
|
+
def test_tmplpro
|
|
6
|
+
template = HTML::Template::Pro.new(:path => 'templates',
|
|
7
|
+
:filename => 'simple.tmpl',
|
|
8
|
+
:debug => 0)
|
|
9
|
+
template.param(:ADJECTIVE => 'very')
|
|
10
|
+
output = template.output
|
|
11
|
+
assert((output !~ /ADJECTIVE/ && template.param(:ADJECTIVE) == 'very'))
|
|
12
|
+
|
|
13
|
+
template = HTML::Template::Pro.new(:path => 'templates',
|
|
14
|
+
:filename => 'medium.tmpl',
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
template.param(:ALERT => 'I am alert.')
|
|
18
|
+
template.param(:COMPANY_NAME => "MY NAME IS")
|
|
19
|
+
template.param(:COMPANY_ID => "10001")
|
|
20
|
+
template.param(:OFFICE_ID => "10103214")
|
|
21
|
+
template.param(:NAME => 'SAM I AM')
|
|
22
|
+
template.param(:ADDRESS => '101011 North Something Something')
|
|
23
|
+
template.param(:CITY => 'NEW York')
|
|
24
|
+
template.param(:STATE => 'NEw York')
|
|
25
|
+
template.param(:ZIP =>'10014')
|
|
26
|
+
template.param(:PHONE =>'212-929-4315')
|
|
27
|
+
template.param(:PHONE2 =>'')
|
|
28
|
+
template.param(:SUBCATEGORIES =>'kfldjaldsf')
|
|
29
|
+
template.param(:DESCRIPTION =>"dsa;kljkldasfjkldsajflkjdsfklfjdsgkfld\nalskdjklajsdlkajfdlkjsfd\n\talksjdklajsfdkljdsf\ndsa;klfjdskfj")
|
|
30
|
+
template.param(:WEBSITE =>'http://www.assforyou.com/')
|
|
31
|
+
template.param(:INTRANET_URL =>'http://www.something.com')
|
|
32
|
+
template.param(:REMOVE_BUTTON => "<INPUT TYPE=SUBMIT NAME=command VALUE=\"Remove Office\">")
|
|
33
|
+
template.param(:COMPANY_ADMIN_AREA => "<A HREF=administrator.cgi?office_id={office_id}&command=manage>Manage Office Administrators</A>")
|
|
34
|
+
template.param(:CASESTUDIES_LIST => "adsfkljdskldszfgfdfdsgdsfgfdshghdmfldkgjfhdskjfhdskjhfkhdsakgagsfjhbvdsaj hsgbf jhfg sajfjdsag ffasfj hfkjhsdkjhdsakjfhkj kjhdsfkjhdskfjhdskjfkjsda kjjsafdkjhds kjds fkj skjh fdskjhfkj kj kjhf kjh sfkjhadsfkj hadskjfhkjhs ajhdsfkj akj fkj kj kj kkjdsfhk skjhadskfj haskjh fkjsahfkjhsfk ksjfhdkjh sfkjhdskjfhakj shiou weryheuwnjcinuc 3289u4234k 5 i 43iundsinfinafiunai saiufhiudsaf afiuhahfwefna uwhf u auiu uh weiuhfiuh iau huwehiucnaiuncianweciuninc iuaciun iucniunciunweiucniuwnciwe")
|
|
35
|
+
template.param(:NUMBER_OF_CONTACTS => "aksfjdkldsajfkljds")
|
|
36
|
+
template.param(:COUNTRY_SELECTOR => "klajslkjdsafkljds")
|
|
37
|
+
template.param(:LOGO_LINK => "dsfpkjdsfkgljdsfkglj")
|
|
38
|
+
template.param(:PHOTO_LINK => "lsadfjlkfjdsgkljhfgklhasgh")
|
|
39
|
+
|
|
40
|
+
output = template.output;
|
|
41
|
+
assert_no_match(/<TMPL_VAR/, output)
|
|
42
|
+
|
|
43
|
+
template = HTML::Template::Pro.new(:path => 'templates',
|
|
44
|
+
:filename => 'simple-loop.tmpl',
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
template.param(:ADJECTIVE_LOOP => [ { :ADJECTIVE => 'really' },
|
|
48
|
+
{ :ADJECTIVE => 'very' } ] )
|
|
49
|
+
|
|
50
|
+
output = template.output
|
|
51
|
+
assert_no_match(/ADJECTIVE_LOOP/, output)
|
|
52
|
+
assert_match(/really.*very/m, output)
|
|
53
|
+
|
|
54
|
+
template = HTML::Template::Pro.new(:path => 'templates',
|
|
55
|
+
:filename => 'simple-loop-nonames.tmpl',
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
template.param(:ADJECTIVE_LOOP => [ { :ADJECTIVE => 'really' },
|
|
59
|
+
{ :ADJECTIVE => 'very' } ] )
|
|
60
|
+
|
|
61
|
+
output = template.output
|
|
62
|
+
assert_no_match(/ADJECTIVE_LOOP/, output)
|
|
63
|
+
assert_match(/really.*very/m, output)
|
|
64
|
+
|
|
65
|
+
template = HTML::Template::Pro.new(:path => 'templates',
|
|
66
|
+
:filename => 'long_loops.tmpl',
|
|
67
|
+
)
|
|
68
|
+
output = template.output
|
|
69
|
+
assert(true)
|
|
70
|
+
|
|
71
|
+
template = HTML::Template::Pro.new(:path => 'templates',
|
|
72
|
+
:filename => 'include.tmpl',
|
|
73
|
+
)
|
|
74
|
+
output = template.output
|
|
75
|
+
assert_match(/5/, output)
|
|
76
|
+
assert_match(/6/, output)
|
|
77
|
+
|
|
78
|
+
template = HTML::Template::Pro.new(:path => 'templates',
|
|
79
|
+
:filename => 'include.tmpl',
|
|
80
|
+
:cache => true,
|
|
81
|
+
)
|
|
82
|
+
output = template.output
|
|
83
|
+
assert_match(/5/, output)
|
|
84
|
+
assert_match(/6/, output)
|
|
85
|
+
|
|
86
|
+
template_one = HTML::Template::Pro.new(:path => 'templates',
|
|
87
|
+
:filename => 'simple.tmpl',
|
|
88
|
+
)
|
|
89
|
+
template_one.param(:ADJECTIVE => 'very')
|
|
90
|
+
|
|
91
|
+
template_two = HTML::Template::Pro.new(:path => 'templates',
|
|
92
|
+
:filename => 'simple.tmpl',
|
|
93
|
+
:associate => template_one,
|
|
94
|
+
)
|
|
95
|
+
output = template_two.output
|
|
96
|
+
assert_no_match(/ADJECTIVE/, output)
|
|
97
|
+
assert_match(/very/, output)
|
|
98
|
+
|
|
99
|
+
template_l = HTML::Template::Pro.new(:path => 'templates',
|
|
100
|
+
:filename => 'other-loop.tmpl',
|
|
101
|
+
)
|
|
102
|
+
output = template_l.output
|
|
103
|
+
assert_no_match(/INSIDE/, output)
|
|
104
|
+
|
|
105
|
+
template_i = HTML::Template::Pro.new(:path => 'templates',
|
|
106
|
+
:filename => 'if.tmpl',
|
|
107
|
+
)
|
|
108
|
+
output = template_i.output
|
|
109
|
+
assert_no_match(/INSIDE/, output)
|
|
110
|
+
|
|
111
|
+
template_i2 = HTML::Template::Pro.new(:path => 'templates',
|
|
112
|
+
:filename => 'if.tmpl',
|
|
113
|
+
)
|
|
114
|
+
template_i2.param(:BOOL => 1)
|
|
115
|
+
output = template_i2.output
|
|
116
|
+
assert_match(/INSIDE/, output)
|
|
117
|
+
|
|
118
|
+
template_ie = HTML::Template::Pro.new(:path => 'templates',
|
|
119
|
+
:filename => 'ifelse.tmpl',
|
|
120
|
+
)
|
|
121
|
+
output = template_ie.output
|
|
122
|
+
assert_match(/INSIDE ELSE/, output)
|
|
123
|
+
|
|
124
|
+
template_ie2 = HTML::Template::Pro.new(:path => 'templates',
|
|
125
|
+
:filename => 'ifelse.tmpl',
|
|
126
|
+
)
|
|
127
|
+
template_ie2.param(:BOOL => 1)
|
|
128
|
+
output = template_ie2.output
|
|
129
|
+
assert_match(/INSIDE IF/, output)
|
|
130
|
+
assert_no_match(/INSIDE ELSE/, output)
|
|
131
|
+
|
|
132
|
+
template = HTML::Template::Pro.new(:path => 'templates',
|
|
133
|
+
:filename => 'double_loop.tmpl',
|
|
134
|
+
)
|
|
135
|
+
template.param(:myloop => [
|
|
136
|
+
{ :var => 'first'},
|
|
137
|
+
{ :var => 'second' },
|
|
138
|
+
{ :var => 'third' }
|
|
139
|
+
]
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
output = template.output
|
|
143
|
+
assert_match(/David/, output)
|
|
144
|
+
|
|
145
|
+
template = HTML::Template::Pro.new(:path => 'templates',
|
|
146
|
+
:filename => 'escape.tmpl',
|
|
147
|
+
)
|
|
148
|
+
template.param(:STUFF => '<>"\'')
|
|
149
|
+
output = template.output
|
|
150
|
+
assert_no_match(/[<>\"\']/, output)
|
|
151
|
+
|
|
152
|
+
template = HTML::Template::Pro.new(:path => 'templates',
|
|
153
|
+
:filename => 'simple.tmpl',
|
|
154
|
+
)
|
|
155
|
+
template.param({ :ADJECTIVE => 'very' })
|
|
156
|
+
output = template.output
|
|
157
|
+
assert_no_match(/ADJECTIVE/, output)
|
|
158
|
+
assert_match(/very/, output)
|
|
159
|
+
|
|
160
|
+
template = HTML::Template::Pro.new(:path => 'templates',
|
|
161
|
+
:filename => 'unless.tmpl',
|
|
162
|
+
)
|
|
163
|
+
template.param(:BOOL => true)
|
|
164
|
+
output = template.output
|
|
165
|
+
assert_no_match(/INSIDE UNLESS/, output)
|
|
166
|
+
assert_match(/INSIDE ELSE/, output)
|
|
167
|
+
|
|
168
|
+
template = HTML::Template::Pro.new(:path => 'templates',
|
|
169
|
+
:filename => 'unless.tmpl',
|
|
170
|
+
)
|
|
171
|
+
template.param(:BOOL => false)
|
|
172
|
+
output = template.output
|
|
173
|
+
assert_match(/INSIDE UNLESS/, output)
|
|
174
|
+
assert_no_match(/INSIDE ELSE/, output)
|
|
175
|
+
|
|
176
|
+
template = HTML::Template::Pro.new(:path => 'templates',
|
|
177
|
+
:filename => 'context.tmpl',
|
|
178
|
+
:loop_context_vars => true,
|
|
179
|
+
)
|
|
180
|
+
template.param(:FRUIT => [
|
|
181
|
+
{:KIND => 'Apples'},
|
|
182
|
+
{:KIND => 'Oranges'},
|
|
183
|
+
{:KIND => 'Brains'},
|
|
184
|
+
{:KIND => 'Toes'},
|
|
185
|
+
{:KIND => 'Kiwi'}
|
|
186
|
+
])
|
|
187
|
+
template.param(:PINGPONG => [ {}, {}, {}, {}, {}, {} ])
|
|
188
|
+
|
|
189
|
+
output = template.output
|
|
190
|
+
assert_match(/Apples, Oranges, Brains, Toes, and Kiwi./, output)
|
|
191
|
+
assert_match(/pingpongpingpongpingpong/, output)
|
|
192
|
+
|
|
193
|
+
template = HTML::Template::Pro.new(:path => 'templates',
|
|
194
|
+
:filename => 'loop-if.tmpl',
|
|
195
|
+
)
|
|
196
|
+
output = template.output
|
|
197
|
+
assert_match(/Loop not filled in/, output)
|
|
198
|
+
|
|
199
|
+
template = HTML::Template::Pro.new(:path => 'templates',
|
|
200
|
+
:filename => 'loop-if.tmpl',
|
|
201
|
+
)
|
|
202
|
+
template.param(:LOOP_ONE => [{:VAR => "foo"}])
|
|
203
|
+
output = template.output
|
|
204
|
+
assert_no_match(/Loop not filled in/, output)
|
|
205
|
+
|
|
206
|
+
template = HTML::Template::Pro.new(:path => 'templates',
|
|
207
|
+
:filename => 'simple.tmpl',
|
|
208
|
+
:debug => 0,
|
|
209
|
+
)
|
|
210
|
+
template.param(:ADJECTIVE) { 'v' + '1e' + '2r' + '3y' }
|
|
211
|
+
output = template.output
|
|
212
|
+
assert_match(/v1e2r3y/, output)
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
template = HTML::Template::Pro.new(:path => ['templates'],
|
|
216
|
+
:filename => 'simple.tmpl',
|
|
217
|
+
:cache => 1,
|
|
218
|
+
:debug => 0,
|
|
219
|
+
)
|
|
220
|
+
template.param(:ADJECTIVE) { 'v' + '1e' + '2r' + '3y' }
|
|
221
|
+
output = template.output
|
|
222
|
+
template = HTML::Template::Pro.new(:path => ['templates/'],
|
|
223
|
+
:filename => 'simple.tmpl',
|
|
224
|
+
:cache => 1,
|
|
225
|
+
:debug => 0,
|
|
226
|
+
)
|
|
227
|
+
assert_match(/v1e2r3y/, output)
|
|
228
|
+
|
|
229
|
+
template = HTML::Template::Pro.new(:path => ['templates/'],
|
|
230
|
+
:filename => 'urlescape.tmpl',
|
|
231
|
+
)
|
|
232
|
+
template.param(:STUFF => '<>"; %FA')
|
|
233
|
+
output = template.output
|
|
234
|
+
assert_no_match(/[<>\"]/, output)
|
|
235
|
+
|
|
236
|
+
template = HTML::Template::Pro.new(:path => 'templates',
|
|
237
|
+
:filename => 'globals.tmpl',
|
|
238
|
+
:global_vars => true,
|
|
239
|
+
)
|
|
240
|
+
template.param(:outer_loop => [{:loop => [{:LOCAL => 'foo'}]}])
|
|
241
|
+
template.param(:global => 'bar')
|
|
242
|
+
template.param(:hidden_global => 'foo')
|
|
243
|
+
result = template.output
|
|
244
|
+
assert_match(/foobar/, result)
|
|
245
|
+
|
|
246
|
+
template = HTML::Template::Pro.new(:path => 'templates',
|
|
247
|
+
:filename => 'loop-context.tmpl',
|
|
248
|
+
:loop_context_vars => true,
|
|
249
|
+
)
|
|
250
|
+
template.param(:TEST_LOOP => [ { :NUM => 1 } ])
|
|
251
|
+
result = template.output
|
|
252
|
+
assert_match(/1:FIRST::LAST:ODD/, result)
|
|
253
|
+
|
|
254
|
+
template = HTML::Template::Pro.new(:path => ['templates/searchpath',
|
|
255
|
+
'templates'],
|
|
256
|
+
:filename => 'include.tmpl',
|
|
257
|
+
:search_path_on_include => true,
|
|
258
|
+
)
|
|
259
|
+
output = template.output
|
|
260
|
+
assert_match(/9/, output)
|
|
261
|
+
assert_match(/6/, output)
|
|
262
|
+
|
|
263
|
+
template = HTML::Template::Pro.new(:path => ['templates'],
|
|
264
|
+
:filename => 'simple.tmpl',
|
|
265
|
+
:file_cache_dir => './blib/temp_cache_dir',
|
|
266
|
+
:file_cache => true,
|
|
267
|
+
)
|
|
268
|
+
template.param(:ADJECTIVE) { "3y" }
|
|
269
|
+
output = template.output
|
|
270
|
+
template = HTML::Template::Pro.new(:path => ['templates/'],
|
|
271
|
+
:filename => 'simple.tmpl',
|
|
272
|
+
:file_cache_dir => './blib/temp_cache_dir',
|
|
273
|
+
:file_cache => true,
|
|
274
|
+
)
|
|
275
|
+
assert_match(/3y/, output)
|
|
276
|
+
|
|
277
|
+
x = nil
|
|
278
|
+
template = HTML::Template::Pro.new(:filename => 'templates/simple-loop.tmpl',
|
|
279
|
+
:filter => {
|
|
280
|
+
:sub => lambda { |args|
|
|
281
|
+
x = 1
|
|
282
|
+
args.each do |e|
|
|
283
|
+
e = "#{x} : #{e}"
|
|
284
|
+
x+=1
|
|
285
|
+
end
|
|
286
|
+
},
|
|
287
|
+
:format => 'array',
|
|
288
|
+
},
|
|
289
|
+
:file_cache_dir => './blib/temp_cache_dir',
|
|
290
|
+
:file_cache => true,
|
|
291
|
+
:global_vars => true,
|
|
292
|
+
)
|
|
293
|
+
template.param(:ADJECTIVE_LOOP => [ { :ADJECTIVE => 'really' },
|
|
294
|
+
{ :ADJECTIVE => 'very' } ] )
|
|
295
|
+
output = template.output
|
|
296
|
+
assert_match(/very/, output)
|
|
297
|
+
|
|
298
|
+
template = HTML::Template::Pro.new(:filename => './templates/include_path/a.tmpl')
|
|
299
|
+
output = template.output
|
|
300
|
+
assert_match(/Bar/, output)
|
|
301
|
+
|
|
302
|
+
File.open('test.out', 'w') do |file|
|
|
303
|
+
template = HTML::Template::Pro.new(:filename => './templates/include_path/a.tmpl')
|
|
304
|
+
template.output(:print_to => file);
|
|
305
|
+
end
|
|
306
|
+
File.open('test.out', 'r') do |file|
|
|
307
|
+
output = file.read
|
|
308
|
+
end
|
|
309
|
+
assert_match(/Bar/, output)
|
|
310
|
+
File.delete('test.out')
|
|
311
|
+
|
|
312
|
+
template_source = <<END_OF_TMPL
|
|
313
|
+
I am a <TMPL_VAR NAME="adverb"> <TMPL_VAR NAME="ADVERB"> simple template.
|
|
314
|
+
END_OF_TMPL
|
|
315
|
+
|
|
316
|
+
template = HTML::Template::Pro.new(
|
|
317
|
+
:scalarref => template_source,
|
|
318
|
+
:case_sensitive => true,
|
|
319
|
+
:debug => 0,
|
|
320
|
+
)
|
|
321
|
+
template.param(:adverb => 'very')
|
|
322
|
+
template.param(:ADVERB => 'painfully')
|
|
323
|
+
output = template.output
|
|
324
|
+
assert_no_match(/ADVERB/i, output)
|
|
325
|
+
assert_equal('painfully', template.param(:ADVERB))
|
|
326
|
+
assert_equal('very', template.param(:adverb))
|
|
327
|
+
assert_match(/very painfully/, output)
|
|
328
|
+
|
|
329
|
+
template_source = <<END_OF_TMPL;
|
|
330
|
+
I am a <TMPL_VAR NAME="adverb"> <TMPL_VAR NAME="ADVERB"> simple template.
|
|
331
|
+
END_OF_TMPL
|
|
332
|
+
template = HTML::Template::Pro.new(
|
|
333
|
+
:scalarref => template_source,
|
|
334
|
+
:case_sensitive => false,
|
|
335
|
+
:debug => 0,
|
|
336
|
+
)
|
|
337
|
+
|
|
338
|
+
template.param(:adverb => 'very')
|
|
339
|
+
template.param(:ADVERB => 'painfully')
|
|
340
|
+
output = template.output
|
|
341
|
+
assert_no_match(/ADVERB/i, output)
|
|
342
|
+
assert_equal('painfully', template.param(:ADVERB))
|
|
343
|
+
assert_equal('painfully', template.param(:adverb))
|
|
344
|
+
assert_match(/painfully painfully/, output)
|
|
345
|
+
|
|
346
|
+
template = HTML::Template::Pro.new(:filename => './templates/include_path/a.tmpl',
|
|
347
|
+
:filter => lambda { |src|
|
|
348
|
+
src.gsub(/Bar/, 'Zanzabar')
|
|
349
|
+
},
|
|
350
|
+
)
|
|
351
|
+
output = template.output
|
|
352
|
+
assert_match(/Zanzabar/, output)
|
|
353
|
+
|
|
354
|
+
template = HTML::Template::Pro.new(:filename => './templates/include_path/a.tmpl',
|
|
355
|
+
:filter => [
|
|
356
|
+
{
|
|
357
|
+
:sub => lambda { |src|
|
|
358
|
+
src.gsub(/Bar/, 'Zanzabar')
|
|
359
|
+
},
|
|
360
|
+
:format => 'scalar'
|
|
361
|
+
},
|
|
362
|
+
{
|
|
363
|
+
:sub => lambda { |src|
|
|
364
|
+
src.gsub(/bar/, 'bar!!!')
|
|
365
|
+
},
|
|
366
|
+
:format => 'scalar'
|
|
367
|
+
}
|
|
368
|
+
]
|
|
369
|
+
)
|
|
370
|
+
output = template.output
|
|
371
|
+
assert_match(/Zanzabar!!!/, output)
|
|
372
|
+
|
|
373
|
+
template = HTML::Template::Pro.new(:filename => './templates/include_path/a.tmpl',
|
|
374
|
+
:filter => {
|
|
375
|
+
:sub => lambda { |args|
|
|
376
|
+
x = 1
|
|
377
|
+
args.map do |e|
|
|
378
|
+
e = "#{x} : #{e}"
|
|
379
|
+
x+=1
|
|
380
|
+
e
|
|
381
|
+
end
|
|
382
|
+
},
|
|
383
|
+
:format => 'array',
|
|
384
|
+
},
|
|
385
|
+
)
|
|
386
|
+
output = template.output
|
|
387
|
+
assert_match(/1 : Foo/, output)
|
|
388
|
+
|
|
389
|
+
template = HTML::Template::Pro.new(
|
|
390
|
+
:scalarref => "\n<TMPL_INCLUDE templates/simple.tmpl>",
|
|
391
|
+
)
|
|
392
|
+
template.param(:ADJECTIVE => "3y")
|
|
393
|
+
output = template.output
|
|
394
|
+
assert_match(/3y/, output)
|
|
395
|
+
|
|
396
|
+
template = HTML::Template::Pro.new(:path => ['templates'],
|
|
397
|
+
:filename => 'newline_test1.tmpl',
|
|
398
|
+
:filter => lambda { |src| src },
|
|
399
|
+
)
|
|
400
|
+
output = template.output
|
|
401
|
+
assert_match(/STARTincludeEND/, output)
|
|
402
|
+
|
|
403
|
+
template = HTML::Template::Pro.new(:path => ['templates'],
|
|
404
|
+
:filename => 'multiline_tags.tmpl',
|
|
405
|
+
:global_vars => true,
|
|
406
|
+
)
|
|
407
|
+
template.param(:FOO => 'foo!', :bar => [{}, {}])
|
|
408
|
+
output = template.output
|
|
409
|
+
assert_match(/foo!\n/, output)
|
|
410
|
+
assert_match(/foo!foo!\nfoo!foo!/, output)
|
|
411
|
+
|
|
412
|
+
# test new() from filehandle
|
|
413
|
+
File.open("templates/simple.tmpl") do |file|
|
|
414
|
+
template = HTML::Template::Pro.new(:filehandle => file)
|
|
415
|
+
template.param(:ADJECTIVE => 'very')
|
|
416
|
+
output = template.output
|
|
417
|
+
assert_no_match(/ADJECTIVE/, output)
|
|
418
|
+
assert_equal('very', template.param(:ADJECTIVE))
|
|
419
|
+
end
|
|
420
|
+
|
|
421
|
+
# test new_() from filehandle
|
|
422
|
+
File.open("templates/simple.tmpl") do |file|
|
|
423
|
+
template = HTML::Template::Pro.new_filehandle(file)
|
|
424
|
+
template.param(:ADJECTIVE => 'very')
|
|
425
|
+
output = template.output
|
|
426
|
+
assert_no_match(/ADJECTIVE/, output)
|
|
427
|
+
assert_equal('very', template.param(:ADJECTIVE))
|
|
428
|
+
end
|
|
429
|
+
|
|
430
|
+
# test case sensitive loop variables
|
|
431
|
+
template = HTML::Template::Pro.new(:path => ['templates'],
|
|
432
|
+
:filename => 'case_loop.tmpl',
|
|
433
|
+
:case_sensitive => true,
|
|
434
|
+
);
|
|
435
|
+
template.param(:loop => [ { :foo => 'bar', :FOO => 'BAR' } ])
|
|
436
|
+
output = template.output
|
|
437
|
+
assert_match(/bar BAR/, output)
|
|
438
|
+
|
|
439
|
+
# test ifs with code refd
|
|
440
|
+
template = HTML::Template::Pro.new(:path => ['templates'],
|
|
441
|
+
:filename => 'if.tmpl')
|
|
442
|
+
template.param(:bool) { false }
|
|
443
|
+
output = template.output
|
|
444
|
+
assert_no_match(/INSIDE/, output)
|
|
445
|
+
assert_match(/unless/, output)
|
|
446
|
+
|
|
447
|
+
# test global_vars for loops within loops
|
|
448
|
+
template = HTML::Template::Pro.new(:path => ['templates'],
|
|
449
|
+
:filename => 'global-loops.tmpl',
|
|
450
|
+
:global_vars => true)
|
|
451
|
+
template.param(:global => "global val")
|
|
452
|
+
template.param(:outer_loop => [
|
|
453
|
+
{
|
|
454
|
+
:foo => 'foo val 1',
|
|
455
|
+
:inner_loop => [
|
|
456
|
+
{ :bar => 'bar val 1' },
|
|
457
|
+
{ :bar => 'bar val 2' },
|
|
458
|
+
],
|
|
459
|
+
},
|
|
460
|
+
{
|
|
461
|
+
:foo => 'foo val 2',
|
|
462
|
+
:inner_loop => [
|
|
463
|
+
{ :bar => 'bar val 3' },
|
|
464
|
+
{ :bar => 'bar val 4' },
|
|
465
|
+
],
|
|
466
|
+
}
|
|
467
|
+
])
|
|
468
|
+
output = template.output
|
|
469
|
+
assert_match(/inner loop foo: foo val 1/, output)
|
|
470
|
+
assert_match(/inner loop foo: foo val 2/, output)
|
|
471
|
+
|
|
472
|
+
# test nested include path handling
|
|
473
|
+
template = HTML::Template::Pro.new(:path => ['templates'],
|
|
474
|
+
:filename => 'include_path/one.tmpl')
|
|
475
|
+
output = template.output
|
|
476
|
+
assert_match(/ONE/, output)
|
|
477
|
+
assert_match(/TWO/, output)
|
|
478
|
+
assert_match(/THREE/, output)
|
|
479
|
+
|
|
480
|
+
# test using HTML_TEMPLATE_ROOT with path
|
|
481
|
+
ENV['HTML_TEMPLATE_ROOT'] = 'templates'
|
|
482
|
+
template = HTML::Template::Pro.new(
|
|
483
|
+
:path => ['searchpath'],
|
|
484
|
+
:filename => 'three.tmpl',
|
|
485
|
+
)
|
|
486
|
+
output = template.output
|
|
487
|
+
assert_match(/THREE/, output)
|
|
488
|
+
ENV.delete('HTML_TEMPLATE_ROOT')
|
|
489
|
+
|
|
490
|
+
# test __counter__
|
|
491
|
+
template = HTML::Template::Pro.new(:path => ['templates'],
|
|
492
|
+
:filename => 'counter.tmpl',
|
|
493
|
+
:loop_context_vars => true)
|
|
494
|
+
template.param(:foo => [ {:a => 'a'}, {:a => 'b'}, {:a => 'c'} ])
|
|
495
|
+
template.param(:outer => [ {:inner => [ {:a => 'a'}, {:a => 'b'}, {:a => 'c'} ] },
|
|
496
|
+
{:inner => [ {:a => 'x'}, {:a => 'y'}, {:a => 'z'} ] },
|
|
497
|
+
])
|
|
498
|
+
output = template.output
|
|
499
|
+
assert_match(/^1a2b3c$/m, output)
|
|
500
|
+
assert_match(/^11a2b3c21x2y3z$/m, output)
|
|
501
|
+
|
|
502
|
+
# test default
|
|
503
|
+
template = HTML::Template::Pro.new(:path => ['templates'],
|
|
504
|
+
:filename => 'default.tmpl')
|
|
505
|
+
template.param(:cl => 'clothes')
|
|
506
|
+
template.param(:start => 'start')
|
|
507
|
+
output = template.output
|
|
508
|
+
assert_match(/cause it\'s getting hard to think, and my clothes are starting to shrink/, output)
|
|
509
|
+
|
|
510
|
+
# test a case where a different path should stimulate a cache miss
|
|
511
|
+
# even though the main template is the same
|
|
512
|
+
template = HTML::Template::Pro.new(:path => ['templates',
|
|
513
|
+
'templates/include_path'],
|
|
514
|
+
:filename => 'outer.tmpl',
|
|
515
|
+
:search_path_on_include => true,
|
|
516
|
+
:cache => true,
|
|
517
|
+
)
|
|
518
|
+
output = template.output
|
|
519
|
+
assert_match(/I AM OUTER/, output)
|
|
520
|
+
assert_match(/I AM INNER 1/, output)
|
|
521
|
+
|
|
522
|
+
template = HTML::Template::Pro.new(:path => ['templates',
|
|
523
|
+
'templates/include_path2'],
|
|
524
|
+
:filename => 'outer.tmpl',
|
|
525
|
+
:search_path_on_include => true,
|
|
526
|
+
:cache => true,
|
|
527
|
+
)
|
|
528
|
+
output = template.output
|
|
529
|
+
assert_match(/I AM OUTER/, output)
|
|
530
|
+
assert_match(/I AM INNER 2/, output)
|
|
531
|
+
|
|
532
|
+
# try the same thing with the file cache
|
|
533
|
+
template = HTML::Template::Pro.new(:path => ['templates',
|
|
534
|
+
'templates/include_path'],
|
|
535
|
+
:filename => 'outer.tmpl',
|
|
536
|
+
:search_path_on_include => true,
|
|
537
|
+
:file_cache_dir => './blib/temp_cache_dir',
|
|
538
|
+
:file_cache => true,
|
|
539
|
+
)
|
|
540
|
+
output = template.output
|
|
541
|
+
assert_match(/I AM OUTER/, output)
|
|
542
|
+
assert_match(/I AM INNER 1/, output)
|
|
543
|
+
|
|
544
|
+
template = HTML::Template::Pro.new(:path => ['templates',
|
|
545
|
+
'templates/include_path2'],
|
|
546
|
+
:filename => 'outer.tmpl',
|
|
547
|
+
:search_path_on_include => true,
|
|
548
|
+
:file_cache_dir => './blib/temp_cache_dir',
|
|
549
|
+
:file_cache => true,
|
|
550
|
+
)
|
|
551
|
+
output = template.output
|
|
552
|
+
assert_match(/I AM OUTER/, output)
|
|
553
|
+
assert_match(/I AM INNER 2/, output)
|
|
554
|
+
|
|
555
|
+
# test javascript escaping
|
|
556
|
+
template = HTML::Template::Pro.new(:path => ['templates'],
|
|
557
|
+
:filename => 'js.tmpl')
|
|
558
|
+
template.param(:msg => %{"He said 'Hello'.\n\r"})
|
|
559
|
+
output = template.output
|
|
560
|
+
assert_equal(%q{\\"He said \\'Hello\\'.\\n\\r\\"}, output)
|
|
561
|
+
|
|
562
|
+
# test default escaping
|
|
563
|
+
template = HTML::Template::Pro.new(:path => ['templates'],
|
|
564
|
+
:filename => 'default_escape.tmpl',
|
|
565
|
+
:default_escape => 'UrL')
|
|
566
|
+
template.param(:STUFF => %q{Joined with space})
|
|
567
|
+
output = template.output
|
|
568
|
+
assert_match(%r{^Joined%20with%20space}, output)
|
|
569
|
+
|
|
570
|
+
template = HTML::Template::Pro.new(:path => ['templates'],
|
|
571
|
+
:filename => 'default_escape.tmpl',
|
|
572
|
+
:default_escape => 'html')
|
|
573
|
+
template.param(:STUFF => 'Joined&with"cruft')
|
|
574
|
+
template.param(:LOOP => [ { :MORE_STUFF => '<&>' }, { :MORE_STUFF => '>&<' } ])
|
|
575
|
+
template.param(:a => '<b>')
|
|
576
|
+
output = template.output
|
|
577
|
+
|
|
578
|
+
assert_match(%r{^Joined&with"cruft}, output)
|
|
579
|
+
assert_match(%r{<&>>&<}, output)
|
|
580
|
+
assert_match(%r{because it\'s <b>}, output)
|
|
581
|
+
end
|
|
582
|
+
end
|
|
583
|
+
|