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.
Files changed (222) hide show
  1. data/.autotest +9 -0
  2. data/ARTISTIC +131 -0
  3. data/History.txt +4 -0
  4. data/LGPL +504 -0
  5. data/Manifest.txt +221 -0
  6. data/README.rdoc +52 -0
  7. data/Rakefile +18 -0
  8. data/benchmark.rb +136 -0
  9. data/config/website.yml +2 -0
  10. data/ext/html/template/internal/Pro.xs +679 -0
  11. data/ext/html/template/internal/builtin_findfile.inc +361 -0
  12. data/ext/html/template/internal/calc.h +26 -0
  13. data/ext/html/template/internal/calc.inc +120 -0
  14. data/ext/html/template/internal/callback_stubs.inc +63 -0
  15. data/ext/html/template/internal/expr.c +2267 -0
  16. data/ext/html/template/internal/expr.y +476 -0
  17. data/ext/html/template/internal/expr_iface.c +94 -0
  18. data/ext/html/template/internal/exprpstr.h +36 -0
  19. data/ext/html/template/internal/exprpstr.inc +144 -0
  20. data/ext/html/template/internal/exprtool.h +99 -0
  21. data/ext/html/template/internal/exprtool.inc +289 -0
  22. data/ext/html/template/internal/exprtype.h +62 -0
  23. data/ext/html/template/internal/exprval.h +30 -0
  24. data/ext/html/template/internal/extconf.rb +6 -0
  25. data/ext/html/template/internal/internal.c +449 -0
  26. data/ext/html/template/internal/loadfile.h +11 -0
  27. data/ext/html/template/internal/loadfile.inc +171 -0
  28. data/ext/html/template/internal/pabidecl.h +54 -0
  29. data/ext/html/template/internal/pabstract.h +426 -0
  30. data/ext/html/template/internal/parse_expr.h +15 -0
  31. data/ext/html/template/internal/pbuffer.c +76 -0
  32. data/ext/html/template/internal/pbuffer.h +31 -0
  33. data/ext/html/template/internal/pmiscdef.h +54 -0
  34. data/ext/html/template/internal/pparam.h +101 -0
  35. data/ext/html/template/internal/ppport.h +1098 -0
  36. data/ext/html/template/internal/procore.c +1189 -0
  37. data/ext/html/template/internal/procore.h +18 -0
  38. data/ext/html/template/internal/proparam.c +443 -0
  39. data/ext/html/template/internal/proparam.h +571 -0
  40. data/ext/html/template/internal/proscope.h +32 -0
  41. data/ext/html/template/internal/proscope.inc +107 -0
  42. data/ext/html/template/internal/prostate.h +49 -0
  43. data/ext/html/template/internal/prostate.inc +24 -0
  44. data/ext/html/template/internal/provalue.h +14 -0
  45. data/ext/html/template/internal/pstring.h +60 -0
  46. data/ext/html/template/internal/pstrutils.h +25 -0
  47. data/ext/html/template/internal/pstrutils.inc +150 -0
  48. data/ext/html/template/internal/tagstack.h +30 -0
  49. data/ext/html/template/internal/tagstack.inc +65 -0
  50. data/ext/html/template/internal/tmpllog.c +62 -0
  51. data/ext/html/template/internal/tmpllog.h +27 -0
  52. data/ext/html/template/internal/tmplpro.h +218 -0
  53. data/ext/html/template/internal/tmplpro_version.c +35 -0
  54. data/lib/html/template/pro.rb +225 -0
  55. data/script/console +10 -0
  56. data/script/destroy +14 -0
  57. data/script/generate +14 -0
  58. data/script/txt2html +71 -0
  59. data/tasks/extconf.rake +13 -0
  60. data/tasks/extconf/tmplpro.rake +43 -0
  61. data/templates-Pro/a.incl +1 -0
  62. data/templates-Pro/empty.incl +0 -0
  63. data/templates-Pro/include/1/a.incl +1 -0
  64. data/templates-Pro/include/2.out +3 -0
  65. data/templates-Pro/include/2.tmpl +1 -0
  66. data/templates-Pro/include/2/a.incl +1 -0
  67. data/templates-Pro/include/3.tmpl +1 -0
  68. data/templates-Pro/include/4.tmpl +1 -0
  69. data/templates-Pro/include/a.incl +1 -0
  70. data/templates-Pro/test_broken.tmpl +25 -0
  71. data/templates-Pro/test_broken1.out +1 -0
  72. data/templates-Pro/test_broken1.tmpl +1 -0
  73. data/templates-Pro/test_esc1.out +4 -0
  74. data/templates-Pro/test_esc1.tmpl +4 -0
  75. data/templates-Pro/test_esc2.out +5 -0
  76. data/templates-Pro/test_esc2.tmpl +6 -0
  77. data/templates-Pro/test_esc3.out +4 -0
  78. data/templates-Pro/test_esc3.tmpl +4 -0
  79. data/templates-Pro/test_esc4.out +3 -0
  80. data/templates-Pro/test_esc4.tmpl +4 -0
  81. data/templates-Pro/test_expr1.out +26 -0
  82. data/templates-Pro/test_expr1.tmpl +26 -0
  83. data/templates-Pro/test_expr2.out +34 -0
  84. data/templates-Pro/test_expr2.tmpl +34 -0
  85. data/templates-Pro/test_expr3.out +6 -0
  86. data/templates-Pro/test_expr3.tmpl +6 -0
  87. data/templates-Pro/test_expr4.out +4 -0
  88. data/templates-Pro/test_expr4.tmpl +4 -0
  89. data/templates-Pro/test_expr5.out +18 -0
  90. data/templates-Pro/test_expr5.tmpl +18 -0
  91. data/templates-Pro/test_expr6.out +18 -0
  92. data/templates-Pro/test_expr6.tmpl +18 -0
  93. data/templates-Pro/test_expr7.out +44 -0
  94. data/templates-Pro/test_expr7.tmpl +20 -0
  95. data/templates-Pro/test_expr8.out +15 -0
  96. data/templates-Pro/test_expr8.tmpl +15 -0
  97. data/templates-Pro/test_if1.out +25 -0
  98. data/templates-Pro/test_if1.tmpl +28 -0
  99. data/templates-Pro/test_if2.out +17 -0
  100. data/templates-Pro/test_if2.tmpl +25 -0
  101. data/templates-Pro/test_if3.out +12 -0
  102. data/templates-Pro/test_if3.tmpl +14 -0
  103. data/templates-Pro/test_if4.out +15 -0
  104. data/templates-Pro/test_if4.tmpl +31 -0
  105. data/templates-Pro/test_if5.out +16 -0
  106. data/templates-Pro/test_if5.tmpl +16 -0
  107. data/templates-Pro/test_if6.out +15 -0
  108. data/templates-Pro/test_if6.tmpl +31 -0
  109. data/templates-Pro/test_if7.out +14 -0
  110. data/templates-Pro/test_if7.tmpl +18 -0
  111. data/templates-Pro/test_include1.out +23 -0
  112. data/templates-Pro/test_include1.tmpl +7 -0
  113. data/templates-Pro/test_include2.out +120 -0
  114. data/templates-Pro/test_include2.tmpl +10 -0
  115. data/templates-Pro/test_include3.out +8 -0
  116. data/templates-Pro/test_include3.tmpl +8 -0
  117. data/templates-Pro/test_include4.out +7 -0
  118. data/templates-Pro/test_include4.tmpl +6 -0
  119. data/templates-Pro/test_include5.out +7 -0
  120. data/templates-Pro/test_include5.tmpl +6 -0
  121. data/templates-Pro/test_loop1.erb +17 -0
  122. data/templates-Pro/test_loop1.out +12 -0
  123. data/templates-Pro/test_loop1.tmpl +16 -0
  124. data/templates-Pro/test_loop2.erb +19 -0
  125. data/templates-Pro/test_loop2.out +40 -0
  126. data/templates-Pro/test_loop2.tmpl +19 -0
  127. data/templates-Pro/test_loop3.out +38 -0
  128. data/templates-Pro/test_loop3.tmpl +40 -0
  129. data/templates-Pro/test_loop4.out +44 -0
  130. data/templates-Pro/test_loop4.tmpl +20 -0
  131. data/templates-Pro/test_loop5.out +9 -0
  132. data/templates-Pro/test_loop5.tmpl +11 -0
  133. data/templates-Pro/test_loop6.out +33 -0
  134. data/templates-Pro/test_loop6.tmpl +15 -0
  135. data/templates-Pro/test_malloc.tmpl +1 -0
  136. data/templates-Pro/test_userfunc1.out +14 -0
  137. data/templates-Pro/test_userfunc1.tmpl +14 -0
  138. data/templates-Pro/test_userfunc2.out +35 -0
  139. data/templates-Pro/test_userfunc2.tmpl +5 -0
  140. data/templates-Pro/test_userfunc3.out +5 -0
  141. data/templates-Pro/test_userfunc3.tmpl +5 -0
  142. data/templates-Pro/test_userfunc4.out +10 -0
  143. data/templates-Pro/test_userfunc4.tmpl +10 -0
  144. data/templates-Pro/test_userfunc5.out +4 -0
  145. data/templates-Pro/test_userfunc5.tmpl +4 -0
  146. data/templates-Pro/test_userfunc6.out +4 -0
  147. data/templates-Pro/test_userfunc6.tmpl +4 -0
  148. data/templates-Pro/test_var1.erb +23 -0
  149. data/templates-Pro/test_var1.out +20 -0
  150. data/templates-Pro/test_var1.tmpl +23 -0
  151. data/templates-Pro/test_var2.erb +7 -0
  152. data/templates-Pro/test_var2.out +6 -0
  153. data/templates-Pro/test_var2.tmpl +7 -0
  154. data/templates-Pro/test_var3.out +14 -0
  155. data/templates-Pro/test_var3.tmpl +16 -0
  156. data/templates/case_loop.tmpl +3 -0
  157. data/templates/context.tmpl +3 -0
  158. data/templates/counter.tmpl +2 -0
  159. data/templates/default.tmpl +1 -0
  160. data/templates/default_escape.tmpl +4 -0
  161. data/templates/double_loop.tmpl +7 -0
  162. data/templates/escape.tmpl +5 -0
  163. data/templates/global-loops.tmpl +9 -0
  164. data/templates/globals.tmpl +11 -0
  165. data/templates/if.tmpl +7 -0
  166. data/templates/ifelse.tmpl +6 -0
  167. data/templates/include.tmpl +14 -0
  168. data/templates/include_path/a.tmpl +2 -0
  169. data/templates/include_path/b.tmpl +1 -0
  170. data/templates/include_path/inner.tmpl +1 -0
  171. data/templates/include_path/one.tmpl +2 -0
  172. data/templates/include_path2/inner.tmpl +1 -0
  173. data/templates/included.tmpl +4 -0
  174. data/templates/included2.tmpl +3 -0
  175. data/templates/js.tmpl +1 -0
  176. data/templates/long_loops.tmpl +307 -0
  177. data/templates/loop-context.tmpl +2 -0
  178. data/templates/loop-if.tmpl +9 -0
  179. data/templates/medium.tmpl +217 -0
  180. data/templates/multiline_tags.tmpl +7 -0
  181. data/templates/newline_test1.tmpl +1 -0
  182. data/templates/newline_test2.tmpl +1 -0
  183. data/templates/other-loop.tmpl +7 -0
  184. data/templates/outer.tmpl +3 -0
  185. data/templates/query-test.tmpl +21 -0
  186. data/templates/query-test2.tmpl +12 -0
  187. data/templates/recursive.tmpl +2 -0
  188. data/templates/searchpath/included.tmpl +4 -0
  189. data/templates/searchpath/three.tmpl +1 -0
  190. data/templates/searchpath/two.tmpl +2 -0
  191. data/templates/simple-loop-nonames.tmpl +13 -0
  192. data/templates/simple-loop.tmpl +12 -0
  193. data/templates/simple.tmpl +9 -0
  194. data/templates/unless.tmpl +5 -0
  195. data/templates/urlescape.tmpl +3 -0
  196. data/templates/vanguard1.tmpl +2 -0
  197. data/templates/vanguard2.tmpl +3 -0
  198. data/test/templates/complex.tmpl +24 -0
  199. data/test/templates/foo.tmpl +6 -0
  200. data/test/templates/func.tmpl +2 -0
  201. data/test/templates/loop.tmpl +14 -0
  202. data/test/templates/negative.tmpl +1 -0
  203. data/test/templates/numerics.tmpl +6 -0
  204. data/test/templates/register.tmpl +2 -0
  205. data/test/test_basic.rb +23 -0
  206. data/test/test_coderefs.rb +16 -0
  207. data/test/test_complex.rb +106 -0
  208. data/test/test_helper.rb +3 -0
  209. data/test/test_html_template.rb +583 -0
  210. data/test/test_html_template_internal_extn.rb +10 -0
  211. data/test/test_html_template_pro.rb +177 -0
  212. data/test/test_path_like_variable_scope.rb +59 -0
  213. data/test/test_random.rb +21 -0
  214. data/test/test_realloc.rb +16 -0
  215. data/test/test_register.rb +25 -0
  216. data/test/test_tmplpro.rb +9 -0
  217. data/test/tests.rb +9 -0
  218. data/website/index.txt +57 -0
  219. data/website/javascripts/rounded_corners_lite.inc.js +285 -0
  220. data/website/stylesheets/screen.css +159 -0
  221. data/website/template.html.erb +50 -0
  222. metadata +303 -0
@@ -0,0 +1,7 @@
1
+ <TMPL_VAR
2
+ FOO>
3
+ <TMPL_LOOP
4
+
5
+ BAR><TMPL_VAR FOO><TMPL_VAR
6
+ FOO>
7
+ </TMPL_LOOP>
@@ -0,0 +1 @@
1
+ START<TMPL_INCLUDE newline_test2.tmpl>END
@@ -0,0 +1 @@
1
+ include
@@ -0,0 +1,7 @@
1
+ OUTSIDE
2
+
3
+ <TMPL_LOOP LOOP>
4
+ INSIDE <TMPL_VAR NAME=IN>
5
+ </TMPL_LOOP>
6
+
7
+ <TMPL_VAR NAME=OUT>
@@ -0,0 +1,3 @@
1
+ I AM OUTER
2
+ <tmpl_include inner.tmpl>
3
+ I AM OUTER
@@ -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,12 @@
1
+ <TMPL_LOOP NAME="LOOP_FOO">
2
+ <TMPL_LOOP NAME="LOOP_BAR">
3
+ <TMPL_VAR NAME="FOO">
4
+ <TMPL_VAR NAME="BAR">
5
+ </TMPL_LOOP>
6
+ </TMPL_LOOP>
7
+
8
+ <TMPL_LOOP NAME="LOOP_FOO">
9
+ <TMPL_LOOP NAME="LOOP_BAR">
10
+ <TMPL_VAR NAME="BASH">
11
+ </TMPL_LOOP>
12
+ </TMPL_LOOP>
@@ -0,0 +1,2 @@
1
+ I am infinity.
2
+ <TMPL_INCLUDE NAME="recursive.tmpl">
@@ -0,0 +1,4 @@
1
+ 9
2
+ 9
3
+ 9
4
+ <TMPL_INCLUDE NAME="included2.tmpl">
@@ -0,0 +1 @@
1
+ THREE
@@ -0,0 +1,2 @@
1
+ TWO
2
+ <tmpl_include three.tmpl>
@@ -0,0 +1,13 @@
1
+ <HTML>
2
+ <HEAD>
3
+ <TITLE>
4
+ Simple Template
5
+ </TITLE>
6
+ <BODY>
7
+ I am a
8
+ <TMPL_LOOP ADJECTIVE_LOOP>
9
+ <TMPL_VAR "ADJECTIVE">
10
+ </TMPL_LOOP>
11
+ simple loop template.
12
+ </BODY>
13
+ </HTML>
@@ -0,0 +1,12 @@
1
+ <HTML>
2
+ <HEAD>
3
+ <TITLE>
4
+ Simple Template
5
+ </TITLE>
6
+ <BODY>
7
+ I am a
8
+ <TMPL_LOOP NAME=ADJECTIVE_LOOP><TMPL_VAR NAME="ADJECTIVE">
9
+ </TMPL_LOOP>
10
+ simple loop template.
11
+ </BODY>
12
+ </HTML>
@@ -0,0 +1,9 @@
1
+ <HTML>
2
+ <HEAD>
3
+ <TITLE>
4
+ Simple Template
5
+ </TITLE>
6
+ <BODY>
7
+ IIII am a <TMPL_VAR NAME="ADJECTIVE"> simple template.
8
+ </BODY>
9
+ </HTML>
@@ -0,0 +1,5 @@
1
+ <TMPL_UNLESS BOOL>
2
+ INSIDE UNLESS
3
+ <TMPL_ELSE>
4
+ INSIDE ELSE
5
+ </TMPL_UNLESS>
@@ -0,0 +1,3 @@
1
+ Some URL escaped stuff:
2
+ <TMPL_VAR ESCAPE=URL STUFF>
3
+
@@ -0,0 +1,2 @@
1
+ %foo%
2
+ <TMPL_INCLUDE vanguard2.tmpl>
@@ -0,0 +1,3 @@
1
+ %baz%
2
+ sdfsdgsdhsgf
3
+
@@ -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,6 @@
1
+ Foo: <tmpl_var foo>
2
+ <!-- tmpl_if expr="foo > 11" -->
3
+ Foo is greater than 11.
4
+ <tmpl_else>
5
+ Foo is less than or equal to 11.
6
+ </tmpl_if>
@@ -0,0 +1,2 @@
1
+ <tmpl_var expr="repeat(repeat_me, 4)">
2
+ <tmpl_var expr="uc(repeat(repeat_me, 4))">
@@ -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>
@@ -0,0 +1,6 @@
1
+ INT: <tmpl_var expr="int(float)">
2
+ SQRT: <tmpl_var expr="sqrt(four)">
3
+ SQRT2: <tmpl_var expr="sqrt((four * 4))">
4
+ SUM: <tmpl_var expr="int(four + 10.1)">
5
+ SPRINTF: <tmpl_var expr="sprintf('%0.4f', (four + 10.1))">
6
+
@@ -0,0 +1,2 @@
1
+ <tmpl_if expr="directory_exists('test')">OK</tmpl_if>
2
+ <tmpl_var expr="commify(2000)">
@@ -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
@@ -0,0 +1,3 @@
1
+ require 'stringio'
2
+ require 'test/unit'
3
+
@@ -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&amp;with&quot;cruft}, output)
579
+ assert_match(%r{&lt;&amp;&gt;&gt;&amp;&lt;}, output)
580
+ assert_match(%r{because it\'s &lt;b&gt;}, output)
581
+ end
582
+ end
583
+