tenjin 0.6.2 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (282) hide show
  1. data/CHANGES.txt +163 -0
  2. data/MIT-LICENSE +16 -17
  3. data/README.txt +5 -5
  4. data/benchmark/Makefile +9 -0
  5. data/benchmark/bench.rb +3 -2
  6. data/bin/rbtenjin +6 -3
  7. data/doc/docstyle.css +25 -4
  8. data/doc/users-guide.html +2088 -1563
  9. data/lib/tenjin.rb +784 -158
  10. data/public_html/_layout.rbhtml +33 -0
  11. data/public_html/css/style.css +77 -0
  12. data/public_html/env.rbhtml +15 -0
  13. data/public_html/favicon.ico +0 -0
  14. data/public_html/hello.rbhtml +14 -0
  15. data/public_html/index.rbhtml +39 -0
  16. data/public_html/rbtenjin.cgi +188 -0
  17. data/tenjin.gemspec +9 -6
  18. data/test/data/examples/preprocessing/main.rb +1 -1
  19. data/test/data/examples/preprocessing/select.rbhtml +1 -1
  20. data/test/data/faq/{ex11-bench.rb → ex10-bench.rb} +3 -3
  21. data/test/data/faq/ex10-content.rbhtml +8 -11
  22. data/test/data/faq/{ex11-layout1.rbhtml → ex10-layout1.rbhtml} +0 -0
  23. data/test/data/faq/{ex11-layout2.rbhtml → ex10-layout2.rbhtml} +0 -0
  24. data/test/data/faq/{ex11.rb → ex10.rb} +1 -1
  25. data/test/data/faq/{ex11.rbhtml → ex10.rbhtml} +0 -0
  26. data/test/data/faq/{ex11.source → ex10.source} +2 -2
  27. data/test/data/faq/{ex11_arraybuffer.result → ex10_arraybuffer.result} +1 -1
  28. data/test/data/faq/{ex5.rbhtml → ex2.rbhtml} +0 -0
  29. data/test/data/faq/{ex5_template_args.source → ex2_template_args.source} +1 -1
  30. data/test/data/faq/{ex7-expr-pattern.rb → ex4-expr-pattern.rb} +1 -1
  31. data/test/data/faq/{ex7-expr-pattern.rbhtml → ex4-expr-pattern.rbhtml} +0 -0
  32. data/test/data/faq/{ex7_expr_pattern.result → ex4_expr_pattern.result} +1 -1
  33. data/test/data/faq/{ex6-content.rhtml → ex5-content.rhtml} +0 -0
  34. data/test/data/faq/{ex6-layout.rhtml → ex5-layout.rhtml} +0 -0
  35. data/test/data/faq/{ex6.rb → ex5.rb} +2 -2
  36. data/test/data/faq/{ex6_eruby.result → ex5_eruby.result} +1 -1
  37. data/test/data/faq/{ex2-content.rbhtml → ex6-content.rbhtml} +0 -0
  38. data/test/data/faq/{ex2-layout.rbhtml → ex6-layout.rbhtml} +0 -0
  39. data/test/data/faq/{ex2_removenl.result → ex6_removenl.result} +1 -1
  40. data/test/data/faq/ex7-m18n.rb +48 -0
  41. data/test/data/faq/{ex8-m18n.rbhtml → ex7-m18n.rbhtml} +0 -0
  42. data/test/data/faq/{ex8_m18n.result → ex7_m18n.result} +1 -1
  43. data/test/data/faq/ex8-baselayout.rbhtml +8 -0
  44. data/test/data/faq/ex8-content.rbhtml +6 -0
  45. data/test/data/faq/{ex9-mylayout.rbhtml → ex8-mylayout.rbhtml} +0 -0
  46. data/test/data/faq/{ex9_changelayout.result → ex8_changelayout.result} +1 -1
  47. data/test/data/faq/ex9-baselayout.rbhtml +24 -5
  48. data/test/data/faq/ex9-content.rbhtml +12 -6
  49. data/test/data/faq/{ex10-customlayout.rbhtml → ex9-customlayout.rbhtml} +1 -1
  50. data/test/data/faq/{ex10_inherit.result → ex9_inherit.result} +1 -1
  51. data/test/data/faq/helpers1.rb +17 -0
  52. data/test/data/faq/helpers1.rbhtml +4 -0
  53. data/test/data/faq/helpers1.result +11 -0
  54. data/test/data/faq/helpers2.rb +21 -0
  55. data/test/data/faq/helpers2.rbhtml +4 -0
  56. data/test/data/faq/helpers2.result +11 -0
  57. data/test/data/faq/weekday1.rb +6 -0
  58. data/test/data/faq/weekday1.rbhtml +9 -0
  59. data/test/data/faq/weekday1.result +23 -0
  60. data/test/data/faq/weekday2.rb +8 -0
  61. data/test/data/faq/weekday2.rbhtml +10 -0
  62. data/test/data/faq/weekday2.result +24 -0
  63. data/test/data/faq/weekday3.rb +22 -0
  64. data/test/data/faq/weekday3.rbhtml +3 -0
  65. data/test/data/faq/weekday3.result +28 -0
  66. data/test/data/users_guide/test_010/main.rb +14 -0
  67. data/test/data/users_guide/test_010/result.output +13 -0
  68. data/test/data/users_guide/test_010/views/page.rbhtml +11 -0
  69. data/test/data/users_guide/test_011/main.rb +14 -0
  70. data/test/data/users_guide/test_011/result.output +2 -0
  71. data/test/data/users_guide/test_011/views/page.rbhtml +11 -0
  72. data/test/data/users_guide/test_020/main.rb +14 -0
  73. data/test/data/users_guide/test_020/result.output +13 -0
  74. data/test/data/users_guide/test_020/views/page.rbhtml +11 -0
  75. data/test/data/users_guide/test_021/main.rb +12 -0
  76. data/test/data/users_guide/test_021/result.output +12 -0
  77. data/test/data/users_guide/test_021/views/page.rbhtml +11 -0
  78. data/test/data/users_guide/test_030/main.rb +14 -0
  79. data/test/data/users_guide/test_030/result.output +23 -0
  80. data/test/data/users_guide/test_030/views/_layout.rbhtml +10 -0
  81. data/test/data/users_guide/test_030/views/page.rbhtml +11 -0
  82. data/test/data/users_guide/test_040/main.rb +14 -0
  83. data/test/data/users_guide/test_040/result.output +23 -0
  84. data/test/data/users_guide/test_040/views/_layout.rbhtml +10 -0
  85. data/test/data/users_guide/test_040/views/page.rbhtml +12 -0
  86. data/test/data/users_guide/test_050/main.rb +14 -0
  87. data/test/data/users_guide/test_050/result.output +14 -0
  88. data/test/data/users_guide/test_050/views/_layout.rbhtml +10 -0
  89. data/test/data/users_guide/test_050/views/page.rbhtml +13 -0
  90. data/test/data/users_guide/test_051/main.rb +14 -0
  91. data/test/data/users_guide/test_051/result.output +12 -0
  92. data/test/data/users_guide/test_051/views/_layout.rbhtml +11 -0
  93. data/test/data/users_guide/test_051/views/page.rbhtml +13 -0
  94. data/test/data/users_guide/test_060/main.rb +14 -0
  95. data/test/data/users_guide/test_060/result.output +29 -0
  96. data/test/data/users_guide/test_060/views/_footer.rbhtml +3 -0
  97. data/test/data/users_guide/test_060/views/_header.rbhtml +3 -0
  98. data/test/data/users_guide/test_060/views/_layout.rbhtml +13 -0
  99. data/test/data/users_guide/test_060/views/page.rbhtml +13 -0
  100. data/test/data/users_guide/test_070/main.rb +14 -0
  101. data/test/data/users_guide/test_070/result.output +29 -0
  102. data/test/data/users_guide/test_070/views/_footer.rbhtml +3 -0
  103. data/test/data/users_guide/test_070/views/_header.rbhtml +3 -0
  104. data/test/data/users_guide/test_070/views/_layout.rbhtml +13 -0
  105. data/test/data/users_guide/test_070/views/page.rbhtml +13 -0
  106. data/test/data/users_guide/test_capturing/main.rb +24 -0
  107. data/test/data/users_guide/test_capturing/result.output +28 -0
  108. data/test/data/users_guide/test_capturing/views/_layout.rbhtml +21 -0
  109. data/test/data/users_guide/test_capturing/views/blog-post.rbhtml +13 -0
  110. data/test/data/users_guide/test_context/context.rb +5 -0
  111. data/test/data/users_guide/test_context/context.yaml +4 -0
  112. data/test/data/users_guide/test_context/example.rbhtml +5 -0
  113. data/test/data/users_guide/test_context/result1.output +6 -0
  114. data/test/data/users_guide/test_context/result2.output +6 -0
  115. data/test/data/users_guide/test_context/result3.output +6 -0
  116. data/test/data/users_guide/test_context/result4.output +6 -0
  117. data/test/data/users_guide/test_convert/example.rbhtml +5 -0
  118. data/test/data/users_guide/test_convert/result1.output +7 -0
  119. data/test/data/users_guide/test_convert/result2.output +6 -0
  120. data/test/data/users_guide/test_escape/main.rb +4 -0
  121. data/test/data/users_guide/test_escape/result.output +5 -0
  122. data/test/data/users_guide/test_escape/views/page.rbhtml +4 -0
  123. data/test/data/users_guide/test_execute/example.rbhtml +6 -0
  124. data/test/data/users_guide/test_execute/result.output +6 -0
  125. data/test/data/users_guide/test_fragmentcache/cache.d/items/1 +5 -0
  126. data/test/data/users_guide/test_fragmentcache/main.rb +21 -0
  127. data/test/data/users_guide/test_fragmentcache/result.output +8 -0
  128. data/test/data/users_guide/test_fragmentcache/result2.output +6 -0
  129. data/test/data/users_guide/test_fragmentcache/views/items.rbhtml +10 -0
  130. data/test/data/users_guide/test_logging/ex-logger.rb +11 -0
  131. data/test/data/users_guide/test_logging/example.rbhtml +0 -0
  132. data/test/data/users_guide/test_logging/result1.output +3 -0
  133. data/test/data/users_guide/test_logging/result2.output +2 -0
  134. data/test/data/users_guide/test_m17n/m17n.rb +44 -0
  135. data/test/data/users_guide/test_m17n/m17n.rbhtml +5 -0
  136. data/test/data/users_guide/test_m17n/result.output +9 -0
  137. data/test/data/users_guide/test_m17n/result_en.output +4 -0
  138. data/test/data/users_guide/test_m17n/result_fr.output +4 -0
  139. data/test/data/users_guide/test_nested/main.rb +8 -0
  140. data/test/data/users_guide/test_nested/result.output +15 -0
  141. data/test/data/users_guide/test_nested/views/_blog_layout.rbhtml +5 -0
  142. data/test/data/users_guide/{layout8_html.rbhtml → test_nested/views/_site_layout.rbhtml} +0 -0
  143. data/test/data/users_guide/test_nested/views/blog_post.rbhtml +4 -0
  144. data/test/data/users_guide/test_preprocessing/pp-example1.rb +14 -0
  145. data/test/data/users_guide/test_preprocessing/result1a.output +11 -0
  146. data/test/data/users_guide/test_preprocessing/result1b.output +5 -0
  147. data/test/data/users_guide/test_preprocessing/result1c.output +6 -0
  148. data/test/data/users_guide/test_preprocessing/result2a.output +10 -0
  149. data/test/data/users_guide/test_preprocessing/result2b.output +10 -0
  150. data/test/data/users_guide/test_preprocessing/result3a.output +2 -0
  151. data/test/data/users_guide/test_preprocessing/result3b.output +2 -0
  152. data/test/data/users_guide/test_preprocessing/views/pp-example1.rbhtml +4 -0
  153. data/test/data/users_guide/{example12.rbhtml → test_preprocessing/views/pp-example2.rbhtml} +4 -4
  154. data/test/data/users_guide/test_preprocessing/views/pp-example3.rbhtml +7 -0
  155. data/test/data/users_guide/test_retrieve/example.rbhtml +10 -0
  156. data/test/data/users_guide/test_retrieve/result1.output +11 -0
  157. data/test/data/users_guide/test_retrieve/result2.output +11 -0
  158. data/test/data/users_guide/test_retrieve/result3.output +11 -0
  159. data/test/data/users_guide/test_retrieve/result4.output +8 -0
  160. data/test/data/users_guide/test_retrieve/result5.output +5 -0
  161. data/test/data/users_guide/test_safe/result.output +6 -0
  162. data/test/data/users_guide/test_safe/safe-test.rb +21 -0
  163. data/test/data/users_guide/test_safehelper/main.rb +16 -0
  164. data/test/data/users_guide/test_safehelper/result.output +8 -0
  165. data/test/data/users_guide/{example3.rbhtml → test_syntax_check/example.rbhtml} +0 -0
  166. data/test/data/users_guide/test_syntax_check/result.output +2 -0
  167. data/test/data/users_guide/test_trace/layout.rbhtml +7 -0
  168. data/test/data/users_guide/test_trace/main.rbhtml +5 -0
  169. data/test/data/users_guide/test_trace/result.output +16 -0
  170. data/test/data/users_guide/test_trace/trace-example.rb +4 -0
  171. data/test/oktest.rb +755 -0
  172. data/test/test_all.rb +24 -14
  173. data/test/test_engine.rb +628 -63
  174. data/test/test_engine.yaml +40 -3
  175. data/test/test_examples.rb +14 -12
  176. data/test/test_faq.rb +17 -12
  177. data/test/test_htmlhelper.rb +104 -33
  178. data/test/test_main.rb +32 -21
  179. data/test/test_main.yaml +2 -2
  180. data/test/test_safe.rb +206 -0
  181. data/test/test_store.rb +220 -0
  182. data/test/test_tcache.rb +94 -0
  183. data/test/test_template.rb +65 -23
  184. data/test/test_template.yaml +7 -7
  185. data/test/test_users_guide.rb +75 -29
  186. data/test/testcase-helper.rb +20 -18
  187. data/test/testunit-assertions.rb +71 -0
  188. metadata +185 -159
  189. data/doc-api/classes/Tenjin.html +0 -141
  190. data/doc-api/classes/Tenjin/ArrayBufferTemplate.html +0 -270
  191. data/doc-api/classes/Tenjin/BaseContext.html +0 -329
  192. data/doc-api/classes/Tenjin/Context.html +0 -126
  193. data/doc-api/classes/Tenjin/ContextHelper.html +0 -461
  194. data/doc-api/classes/Tenjin/Engine.html +0 -616
  195. data/doc-api/classes/Tenjin/ErubisTemplate.html +0 -166
  196. data/doc-api/classes/Tenjin/HtmlHelper.html +0 -359
  197. data/doc-api/classes/Tenjin/Preprocessor.html +0 -242
  198. data/doc-api/classes/Tenjin/Template.html +0 -916
  199. data/doc-api/created.rid +0 -1
  200. data/doc-api/files/README_txt.html +0 -188
  201. data/doc-api/files/lib/tenjin_rb.html +0 -136
  202. data/doc-api/fr_class_index.html +0 -36
  203. data/doc-api/fr_file_index.html +0 -28
  204. data/doc-api/fr_method_index.html +0 -91
  205. data/doc-api/index.html +0 -24
  206. data/doc-api/rdoc-style.css +0 -208
  207. data/doc/examples.html +0 -312
  208. data/doc/faq.html +0 -909
  209. data/examples/preprocessing/select.rbhtml.cache +0 -17
  210. data/test/Rookbook.yaml +0 -14
  211. data/test/assert-text-equal.rb +0 -45
  212. data/test/data/faq/ex10-baselayout.rbhtml +0 -27
  213. data/test/data/faq/ex11-content.rbhtml +0 -9
  214. data/test/data/faq/ex8-m18n.rb +0 -77
  215. data/test/data/users_guide/content6.rbhtml +0 -3
  216. data/test/data/users_guide/content7.rbhtml +0 -5
  217. data/test/data/users_guide/content8.rbhtml +0 -2
  218. data/test/data/users_guide/contextdata.rb +0 -7
  219. data/test/data/users_guide/datafile.rb +0 -5
  220. data/test/data/users_guide/datafile.yaml +0 -10
  221. data/test/data/users_guide/ex.rbhtml +0 -6
  222. data/test/data/users_guide/ex.result +0 -7
  223. data/test/data/users_guide/ex.script +0 -5
  224. data/test/data/users_guide/ex_script.result +0 -7
  225. data/test/data/users_guide/ex_source.result +0 -8
  226. data/test/data/users_guide/example1.rbhtml +0 -12
  227. data/test/data/users_guide/example1.result +0 -17
  228. data/test/data/users_guide/example10.rbhtml +0 -4
  229. data/test/data/users_guide/example10_template_args.result +0 -6
  230. data/test/data/users_guide/example11.rbhtml +0 -5
  231. data/test/data/users_guide/example11_template_args_result +0 -2
  232. data/test/data/users_guide/example12_preprocessed.result +0 -10
  233. data/test/data/users_guide/example12_preprocessed_source.result +0 -10
  234. data/test/data/users_guide/example13.rbhtml +0 -6
  235. data/test/data/users_guide/example13_preprocessed.result +0 -2
  236. data/test/data/users_guide/example13_preprocessed_source.result +0 -2
  237. data/test/data/users_guide/example14.rb +0 -32
  238. data/test/data/users_guide/example14.rbhtml +0 -6
  239. data/test/data/users_guide/example14_tmplclass.result +0 -15
  240. data/test/data/users_guide/example15.rb +0 -10
  241. data/test/data/users_guide/example15_escapefunc.result +0 -14
  242. data/test/data/users_guide/example16.rbhtml +0 -4
  243. data/test/data/users_guide/example16a.rb +0 -10
  244. data/test/data/users_guide/example16a.result +0 -4
  245. data/test/data/users_guide/example16b.rb +0 -13
  246. data/test/data/users_guide/example16b.result +0 -4
  247. data/test/data/users_guide/example16c.rb +0 -12
  248. data/test/data/users_guide/example16c.result +0 -4
  249. data/test/data/users_guide/example16d.rb +0 -27
  250. data/test/data/users_guide/example16d.result +0 -4
  251. data/test/data/users_guide/example1_S.result +0 -14
  252. data/test/data/users_guide/example1_SXNC.result +0 -10
  253. data/test/data/users_guide/example1_source.result +0 -14
  254. data/test/data/users_guide/example2.rbhtml +0 -3
  255. data/test/data/users_guide/example2_sb.result2 +0 -9
  256. data/test/data/users_guide/example3_syntaxcheck.result +0 -2
  257. data/test/data/users_guide/example4.rbhtml +0 -13
  258. data/test/data/users_guide/example4_datafile_rb.result +0 -13
  259. data/test/data/users_guide/example4_yaml.result +0 -13
  260. data/test/data/users_guide/example5.rbhtml +0 -9
  261. data/test/data/users_guide/example5_datastr_rb.result +0 -9
  262. data/test/data/users_guide/example5_datastr_yaml.result +0 -9
  263. data/test/data/users_guide/example6.rbhtml +0 -19
  264. data/test/data/users_guide/example6_layout.result +0 -29
  265. data/test/data/users_guide/example6_nested.result +0 -28
  266. data/test/data/users_guide/example7_layout2.result +0 -13
  267. data/test/data/users_guide/example8_layout3.result +0 -8
  268. data/test/data/users_guide/example9.rbhtml +0 -18
  269. data/test/data/users_guide/example9_capture.result +0 -26
  270. data/test/data/users_guide/footer.html +0 -5
  271. data/test/data/users_guide/footer.rbhtml +0 -4
  272. data/test/data/users_guide/layout6.rbhtml +0 -17
  273. data/test/data/users_guide/layout7.rbhtml +0 -9
  274. data/test/data/users_guide/layout8_xhtml.rbhtml +0 -6
  275. data/test/data/users_guide/layout9.rbhtml +0 -25
  276. data/test/data/users_guide/sidemenu.rbhtml +0 -5
  277. data/test/data/users_guide/user_app.cgi +0 -39
  278. data/test/data/users_guide/user_app.result +0 -30
  279. data/test/data/users_guide/user_create.rbhtml +0 -6
  280. data/test/data/users_guide/user_edit.rbhtml +0 -7
  281. data/test/data/users_guide/user_form.rbhtml +0 -10
  282. data/test/data/users_guide/user_layout.rbhtml +0 -16
@@ -1,6 +1,6 @@
1
1
  ###
2
- ### $Rev: 61 $
3
- ### $Date: 2007-08-04 13:23:33 +0900 (Sat, 04 Aug 2007) $
2
+ ### $Rev$
3
+ ### $Date$
4
4
  ###
5
5
 
6
6
  ###
@@ -0,0 +1,206 @@
1
+ ###
2
+ ### $Rev$
3
+ ### $Release: 0.7.0 $
4
+ ### copyright(c) 2007-2011 kuwata-lab.com all rights reserved
5
+ ###
6
+
7
+ require "#{File.dirname(File.expand_path(__FILE__))}/test_all"
8
+
9
+
10
+ class SafeStringTest
11
+ include Oktest::TestCase
12
+
13
+ def test_to_s
14
+ spec "return self" do
15
+ sstr = Tenjin::SafeString.new('<>')
16
+ ok_(sstr.to_s).same?(sstr)
17
+ ok_(sstr) == '<>' # not escaped!
18
+ end
19
+ end
20
+
21
+ end
22
+
23
+
24
+ class SefeHelperTest
25
+ include Oktest::TestCase
26
+ include Tenjin::ContextHelper
27
+ include Tenjin::HtmlHelper
28
+ include Tenjin::SafeHelper
29
+
30
+ def test_safe_str
31
+ spec "convert value into SafeString object" do
32
+ ok_(safe_str('<>')).is_a?(Tenjin::SafeString)
33
+ ok_(safe_str(nil)).is_a?(Tenjin::SafeString)
34
+ ok_(safe_str(123)).is_a?(Tenjin::SafeString)
35
+ end
36
+ end
37
+
38
+ def test_safe_str?
39
+ spec "return true if arg is SafeString" do
40
+ sstr = Tenjin::SafeString.new('<>')
41
+ ok_(safe_str?(sstr)) == true
42
+ end
43
+ spec "return false if arg is not SafeString" do
44
+ ok_(safe_str?('<>')) == false
45
+ end
46
+ end
47
+
48
+ def test_safe_escape
49
+ sstr = safe_str('<>')
50
+ spec "escape arg if it is not SafeString" do
51
+ ok_(safe_escape('<>')) == '&lt;&gt;'
52
+ end
53
+ spec "don't escape arg if it is SafeString" do
54
+ ok_(safe_escape(sstr)) == '<>'
55
+ end
56
+ spec "return SafeString object regardless arg is SafeString or not" do
57
+ ok_(safe_escape('<>')).is_a?(Tenjin::SafeString)
58
+ ok_(safe_escape(sstr)).is_a?(Tenjin::SafeString)
59
+ end
60
+ end
61
+
62
+ def test_FUNC
63
+ #include Tenjin::HtmlHelper
64
+ #include Tenjin::SafeHelper
65
+ ##
66
+ #s = "<AAA>"
67
+ #puts safe_str?(s) #=> false
68
+ #s = safe_escape(s) # same as SafeString.new(escape(s))
69
+ #puts safe_str?(s) #=> true
70
+ #puts s #=> &lt;AAA&gt;
71
+ #puts safe_escape(s) #=> &lt;AAA&gt;
72
+ ##
73
+ #s = "<AAA>"
74
+ #s = safe_str(s) # same as SafeString.new(s0
75
+ #puts safe_str?(s) #=> true
76
+ #puts s #=> <AAA>
77
+ #puts safe_escape(s) #=> <AAA>
78
+ #
79
+ s = "<AAA>"
80
+ ok_(safe_str?(s)) == false
81
+ s = safe_escape(s)
82
+ ok_(safe_str?(s)) == true
83
+ ok_(s.to_s) == "&lt;AAA&gt;"
84
+ ok_(safe_escape(s).to_s) == "&lt;AAA&gt;"
85
+ #
86
+ s = "<AAA>"
87
+ s = safe_str(s) # same as SafeString.new(s)
88
+ ok_(safe_str?(s)) == true
89
+ ok_(s.to_s) == "<AAA>"
90
+ ok_(safe_escape(s).to_s) == "<AAA>"
91
+ end
92
+
93
+ end
94
+
95
+
96
+ class SafeTemplateTest
97
+ include Oktest::TestCase
98
+
99
+ def test_initialize
100
+ t = Tenjin::SafeTemplate.new(nil)
101
+ spec "default escapefunc is 'safe_escape'." do
102
+ ok_(t.escapefunc) == 'safe_escape'
103
+ end
104
+ end
105
+
106
+ def test_escape_str
107
+ t = Tenjin::SafeTemplate.new(nil)
108
+ t.instance_variable_set('@newline', nil) # avoid warning
109
+ spec "escapes '#'" do
110
+ ok_(t.escape_str('<#><`><\\>')) == '<\\#><\\`><\\\\>'
111
+ end
112
+ end
113
+
114
+ def test_FUNCTEST_convert_and_render
115
+ input = <<'END'
116
+ <p>@v1=${@v1}</p>
117
+ <p>@v2=${@v2}</p>
118
+ <p>safe_str(@v1)=${safe_str(@v1)}</p>
119
+ <p>safe_str(@v2)=${safe_str(@v2)}</p>
120
+ END
121
+ script = <<'END'
122
+ _buf << %Q`<p>@v1=#{safe_escape((@v1).to_s)}</p>
123
+ <p>@v2=#{safe_escape((@v2).to_s)}</p>
124
+ <p>safe_str(@v1)=#{safe_escape((safe_str(@v1)).to_s)}</p>
125
+ <p>safe_str(@v2)=#{safe_escape((safe_str(@v2)).to_s)}</p>\n`
126
+ END
127
+ output = <<'END'
128
+ <p>@v1=&lt;&gt;</p>
129
+ <p>@v2=<></p>
130
+ <p>safe_str(@v1)=<></p>
131
+ <p>safe_str(@v2)=<></p>
132
+ END
133
+ t = Tenjin::SafeTemplate.new(nil)
134
+ spec "'\#' should be escaped with backslash." do
135
+ ok_(t.convert('<<#{true}>>')) == ' _buf << %Q`<<\\#{true}>>`; ' + "\n"
136
+ end
137
+ spec "use safe_escape() as escape function." do
138
+ ok_(t.convert(input)) == script
139
+ end
140
+ spec "'${s}' doesn't escape if s is SafeString object." do
141
+ context = {:v1=>'<>', :v2=>Tenjin::SafeString.new('<>')}
142
+ ok_(t.render(context)) == output
143
+ end
144
+ spec "escapes when input text is passed via :input option" do
145
+ t = Tenjin::SafeTemplate.new(:input=>input)
146
+ ok_(t.script) == script
147
+ end
148
+ end
149
+
150
+ end
151
+
152
+
153
+ class SafeEngineTest
154
+ include Oktest::TestCase
155
+
156
+ def test_initialize
157
+ spec "use SafeTemplate as default template class." do
158
+ e = Tenjin::SafeEngine.new
159
+ ok_(e.templateclass) == Tenjin::SafeTemplate
160
+ end
161
+ end
162
+
163
+ def test_FUNCTEST_render
164
+ input = <<'END'
165
+ <?rb for item in @items ?>
166
+ <tr>
167
+ <td>#{item}</td>
168
+ <td>${item}</td>
169
+ <td>${safe_str(item)}</td>
170
+ </tr>
171
+ <?rb end ?>
172
+ END
173
+ expected = <<'END'
174
+ <tr>
175
+ <td>#{item}</td>
176
+ <td>&lt;&gt;</td>
177
+ <td><></td>
178
+ </tr>
179
+ <tr>
180
+ <td>#{item}</td>
181
+ <td><></td>
182
+ <td><></td>
183
+ </tr>
184
+ END
185
+ begin
186
+ fname = 'test_safeengine.rbhtml'
187
+ File.open(fname, 'w') {|f| f.write(input) }
188
+ spec "String is escaped but SafeString is not." do
189
+ engine = Tenjin::SafeEngine.new(:postfix=>'.rbhtml')
190
+ context = {:items=>['<>', Tenjin::SafeString.new('<>')]}
191
+ output = engine.render(fname, context)
192
+ ok_(output) == expected
193
+ end
194
+ ensure
195
+ [fname, fname+'.cache'].each do |f|
196
+ File.unlink(f) if File.exist?(f)
197
+ end
198
+ end
199
+ end
200
+
201
+ end
202
+
203
+
204
+ if __FILE__ == $0
205
+ Oktest.run_all()
206
+ end
@@ -0,0 +1,220 @@
1
+ ###
2
+ ### $Rev$
3
+ ### $Release: 0.7.0 $
4
+ ### copyright(c) 2007-2011 kuwata-lab.com all rights reserved
5
+ ###
6
+
7
+ require "#{File.dirname(File.expand_path(__FILE__))}/test_all"
8
+ require 'fileutils'
9
+ require 'oktest'
10
+
11
+
12
+ class KeyValueStoreTest
13
+ include Oktest::TestCase
14
+
15
+ def before
16
+ @store = Tenjin::MemoryBaseStore.new()
17
+ end
18
+
19
+ def test_setter
20
+ @store['key1'] = 'value1'
21
+ ok_(@store.get('key1')) == 'value1'
22
+ end
23
+
24
+ def test_getter
25
+ @store.set('key1', 'value1')
26
+ ok_(@store['key1']) == 'value1'
27
+ ok_(@store['key9']) == nil
28
+ end
29
+
30
+ end
31
+
32
+
33
+ class MemoryBaseStoreTest
34
+ include Oktest::TestCase
35
+
36
+ def before
37
+ @store = Tenjin::MemoryBaseStore.new()
38
+ @key = "foo/123[456]"
39
+ @value = "FOOOOOO"
40
+ end
41
+
42
+ def test_set
43
+ spec "store key and value with current and expired timestamp" do
44
+ now = Time.now
45
+ @store.set(@key, @value)
46
+ ok_(@store.values.length) == 1
47
+ #ok_(now, now + @store.lifetime], @store.values[@key]) == [@value
48
+ ok_(@store.values[@key].inspect) == [@value, now, now + @store.lifetime].inspect
49
+ end
50
+ end
51
+
52
+ def test_get
53
+ now = Time.now
54
+ @store.set(@key, @value)
55
+ spec "return cache data" do
56
+ ok_(@store.get(@key)) == @value
57
+ end
58
+ spec "if cache data is not found, return nil" do
59
+ ok_(@store.get('hogehoge')) == nil
60
+ end
61
+ spec "if cache data is older than original data, remove it and return nil" do
62
+ ok_(@store.get(@key, now - 1)) == @value # cache data is newer than original
63
+ ok_(@store.values.length) == 1
64
+ ok_(@store.get(@key, now + 1)) == nil # cache data is older than original
65
+ ok_(@store.values.length) == 0
66
+ end
67
+ spec "if cache data is expired then remove it and return nil" do
68
+ @store.set(@key, @value)
69
+ @store.values[@key][-1] = now - 1
70
+ ok_(@store.get(@key)) == nil
71
+ ok_(@store.values.length) == 0
72
+ end
73
+ end
74
+
75
+ def test_del
76
+ @store.set(@key, @value)
77
+ spec "remove data" do
78
+ ok_(@store.values.length) == 1
79
+ @store.del(@key)
80
+ ok_(@store.values.length) == 0
81
+ end
82
+ spec "don't raise error even if key doesn't exist" do
83
+ not_ok_(proc { @store.del(@key) }).raise?(Exception)
84
+ end
85
+ end
86
+
87
+ def test_has?
88
+ spec "if key exists then return true else return false" do
89
+ ok_(@store.has?(@key)) == false
90
+ @store.set(@key, @value)
91
+ ok_(@store.has?(@key)) == true
92
+ end
93
+ end
94
+
95
+
96
+
97
+ end
98
+
99
+
100
+ class FileBaseStoreTest
101
+ include Oktest::TestCase
102
+
103
+ def before
104
+ @klass = Tenjin::FileBaseStore
105
+ @cachedir = '.test.store'
106
+ Dir.mkdir(@cachedir)
107
+ @store = @klass.new(@cachedir)
108
+ @key = "foo/123[456]"
109
+ @data = "FOOOOO"
110
+ @fpath = @store.filepath(@key)
111
+ end
112
+
113
+ def after
114
+ FileUtils.rm_rf(@cachedir)
115
+ end
116
+
117
+ def test_initialize
118
+ spec "if passed root dir doesn't exist then raise error" do
119
+ ok_(proc { @klass.new('/voo/doo') }).raise?(ArgumentError, "/voo/doo: not found.")
120
+ end
121
+ spec "if passed non-directory then raise error" do
122
+ ok_(proc { @klass.new(__FILE__) }).raise?(ArgumentError, "#{__FILE__}: not a directory.")
123
+ end
124
+ spec "if path ends with '/' then remove it" do
125
+ ok_(@klass.new(@cachedir + '/').root) == @cachedir
126
+ end
127
+ end
128
+
129
+ def test_filepath
130
+ spec "return file path for cache key" do
131
+ store = @klass.new(@cachedir)
132
+ cache_key = "obj/123[456]"
133
+ ok_(store.filepath(cache_key)) == "#{@cachedir}/obj/123_456_"
134
+ end
135
+ end
136
+
137
+ def test_set
138
+ store, key, data, fpath = @store, @key, @data, @fpath
139
+ spec "create directory for cache" do
140
+ not_ok_("#{@cachedir}/foo").exist?
141
+ not_ok_(fpath).exist?
142
+ store.set(key, data)
143
+ ok_("#{@cachedir}/foo").dir?
144
+ ok_(fpath).file?
145
+ end
146
+ spec "create temporary file and rename it to cache file (in order not to flock)" do
147
+ # pass
148
+ end
149
+ spec "set mtime (which is regarded as cache expired timestamp)" do
150
+ store.set(key, data)
151
+ ts = Time.now + store.lifetime
152
+ #ok_(File.mtime(fpath)) == ts
153
+ ok_(File.mtime(fpath).to_s) == ts.to_s
154
+ now = Time.now
155
+ store.set(key, data, 30)
156
+ now2 = Time.now
157
+ if now != now2
158
+ store.set(key, data, 30)
159
+ now = now2
160
+ end
161
+ #ok_(File.mtime(fpath)) == now + 30
162
+ ok_(File.mtime(fpath).to_s) == (now + 30).to_s
163
+ end
164
+ end
165
+
166
+ def test_get
167
+ store, key, data, fpath = @store, @key, @data, @fpath
168
+ now = Time.now
169
+ store.set(key, data)
170
+ ok_(store.filepath(key)).exist?
171
+ spec "if cache file is not found, return nil" do
172
+ ok_(store.get("kkkk")) == nil
173
+ end
174
+ spec "returns cache file content" do
175
+ ok_(store.get(key)) == data
176
+ end
177
+ spec "if cache file is older than original data, remove it and return nil" do
178
+ ok_(store.get(key, now-1)) == data # cache is newer than original
179
+ ok_(fpath).exist?
180
+ ok_(store.get(key, now+1)) == nil # cache is older than original
181
+ not_ok_(fpath).exist?
182
+ end
183
+ spec "if cache file is expired then remove it and return nil" do
184
+ store.set(key, data)
185
+ ok_(store.get(key)) == data # not expired
186
+ ts = Time.now - 1
187
+ File.utime(ts, ts, fpath) # expire cache file
188
+ ok_(store.get(key)) == nil
189
+ end
190
+ end
191
+
192
+ def test_del
193
+ store, key, data, fpath = @store, @key, @data, @fpath
194
+ spec "delete data file" do
195
+ store.set(key, data)
196
+ ok_(fpath).exist?
197
+ store.del(key)
198
+ not_ok_(fpath).exist?
199
+ end
200
+ spec "if data file doesn't exist, don't raise error" do
201
+ not_ok_(proc { store.del(key) }).raise?(Exception)
202
+ end
203
+ end
204
+
205
+ def test_has?
206
+ spec "if key exists then return true else return false" do
207
+ ok_(@store.has?(@key)) == false
208
+ @store.set(@key, @data)
209
+ ok_(@store.has?(@key)) == true
210
+ end
211
+ end
212
+
213
+
214
+
215
+ end
216
+
217
+
218
+ if __FILE__ == $0
219
+ Oktest.run_all()
220
+ end
@@ -0,0 +1,94 @@
1
+ ###
2
+ ### $Rev$
3
+ ### $Release: 0.7.0 $
4
+ ### copyright(c) 2007-2011 kuwata-lab.com all rights reserved
5
+ ###
6
+
7
+ require "#{File.dirname(File.expand_path(__FILE__))}/test_all"
8
+
9
+
10
+ class FileBaseTemplateCacheTest
11
+ include Oktest::TestCase
12
+
13
+ def before
14
+ @klass = Tenjin::FileBaseTemplateCache
15
+ @cache = @klass.new
16
+ @filepath = "_test_example.rbhtml"
17
+ @input = <<'END'
18
+ <?rb #@ARGS name, items ?>
19
+ <p>Hello ${@name}!</p>
20
+ <?rb for item in @items ?>
21
+ <p>${item}</p>
22
+ <?rb end ?>
23
+ END
24
+ @script = <<'END'
25
+ name = @name; items = @items;
26
+ _buf << %Q`<p>Hello #{escape((@name).to_s)}!</p>\n`
27
+ for item in @items
28
+ _buf << %Q`<p>#{escape((item).to_s)}</p>\n`
29
+ end
30
+ END
31
+ @cached = "\#@ARGS name,items\n" + @script
32
+ @template = Tenjin::Template.new(@filepath, :input=>@input)
33
+ end
34
+
35
+ def after
36
+ [@filepath, "#{@filepath}.cache"].each do |fpath|
37
+ File.unlink(fpath) if File.exist?(fpath)
38
+ end
39
+ end
40
+
41
+ def test_save
42
+ cachepath = @filepath + '.cache'
43
+ spec "save template script and args into cache file." do
44
+ not_ok_(cachepath).exist?
45
+ @cache.save(cachepath, @template)
46
+ ok_(cachepath).exist?
47
+ ok_(File.open(cachepath, 'rb') {|f| f.read }) == @cached
48
+ end
49
+ spec "set cache file's mtime to template timestamp." do
50
+ t = Time.now - 30
51
+ @template.timestamp = t
52
+ @cache.save(cachepath, @template)
53
+ ok_(File.mtime(cachepath).inspect) == t.inspect
54
+ end
55
+ end
56
+
57
+ def test_load
58
+ filepath = @filepath
59
+ cachepath = @filepath + '.cache'
60
+ File.open(filepath, 'wb') {|f| f.write(@input) }
61
+ File.open(cachepath, 'wb') {|f| f.write(@cached) }
62
+ ts = nil
63
+ spec "load template data from cache file." do
64
+ ts = File.mtime(cachepath)
65
+ File.utime(ts-9, ts-9, filepath)
66
+ ret = @cache.load(cachepath, ts)
67
+ ok_(ret).is_a?(Array)
68
+ args = ['name', 'items']
69
+ spec "get template args data from cached data."
70
+ spec "return script, template args, and mtime of cache file." do
71
+ ok_(ret) == [@script, args, ts]
72
+ end
73
+ end
74
+ spec "if template timestamp is specified and different from that of cache file, return nil" do
75
+ File.utime(ts, ts, filepath)
76
+ File.utime(ts, ts, cachepath)
77
+ ok_(@cache.load(filepath, ts + 1)) == nil
78
+ end
79
+ spec "if cache file is not found, return nil." do
80
+ File.rename(cachepath, cachepath + '.bkup')
81
+ begin
82
+ ok_(@cache.load(cachepath, ts)) == nil
83
+ ensure
84
+ File.rename(cachepath + '.bkup', cachepath)
85
+ end
86
+ end
87
+ end
88
+
89
+ end
90
+
91
+
92
+ if __FILE__ == $0
93
+ Oktest.run_all()
94
+ end