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
@@ -0,0 +1,29 @@
1
+ $ ruby main.rb
2
+ <!DOCTYPE>
3
+ <html>
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6
+ <title>Tenjin: Layout Template Example</title>
7
+ </head>
8
+ <body>
9
+ <div class="header">
10
+ <h1>Tenjin: Layout Template Example</h1>
11
+ </div>
12
+ <h2>Tenjin Example</h2>
13
+ <table>
14
+ <tr class="odd">
15
+ <td>&lt;AAA&gt;</td>
16
+ </tr>
17
+ <tr class="even">
18
+ <td>B&amp;B</td>
19
+ </tr>
20
+ <tr class="odd">
21
+ <td>&quot;CCC&quot;</td>
22
+ </tr>
23
+ </table>
24
+
25
+ <address>
26
+ copyright(c) 2010 kuwata-lab.com all rights reserved
27
+ </address>
28
+ </body>
29
+ </html>
@@ -0,0 +1,3 @@
1
+ <address>
2
+ copyright(c) 2010 kuwata-lab.com all rights reserved
3
+ </address>
@@ -0,0 +1,3 @@
1
+ <div class="header">
2
+ <h1>${@page_title}</h1>
3
+ </div>
@@ -0,0 +1,13 @@
1
+ <?rb #@ARGS _content, page_title ?>
2
+ <!DOCTYPE>
3
+ <html>
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6
+ <title>${@page_title}</title>
7
+ </head>
8
+ <body>
9
+ <?rb import('_header.rbhtml') ?>
10
+ #{@_content}
11
+ <?rb import('_footer.rbhtml') ?>
12
+ </body>
13
+ </html>
@@ -0,0 +1,13 @@
1
+ <?rb #@ARGS title, items ?>
2
+ <?rb @page_title = 'Tenjin: Layout Template Example' ?>
3
+ <h2>${title}</h2>
4
+ <table>
5
+ <?rb i = 0 ?>
6
+ <?rb for item in items ?>
7
+ <?rb i += 1 ?>
8
+ <?rb klass = i % 2 == 1 ? 'odd' : 'even' ?>
9
+ <tr class="#{klass}">
10
+ <td>${item}</td>
11
+ </tr>
12
+ <?rb end ?>
13
+ </table>
@@ -0,0 +1,14 @@
1
+ require 'tenjin'
2
+
3
+ ## context data
4
+ context = {
5
+ :title => 'Tenjin Example',
6
+ :items => ['<AAA>', 'B&B', '"CCC"'],
7
+ }
8
+
9
+ ## cleate engine object
10
+ engine = Tenjin::Engine.new(:path=>['views'], :postfix=>'.rbhtml', :layout=>:_layout)
11
+
12
+ ## render template with context data
13
+ html = engine.render(:page, context)
14
+ puts html
@@ -0,0 +1,29 @@
1
+ $ ruby main.rb
2
+ <!DOCTYPE>
3
+ <html>
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6
+ <title>Tenjin: Layout Template Example</title>
7
+ </head>
8
+ <body>
9
+ <div class="header">
10
+ <h1>Tenjin: Layout Template Example</h1>
11
+ </div>
12
+ <h2>Tenjin Example</h2>
13
+ <table>
14
+ <tr class="odd">
15
+ <td>&lt;AAA&gt;</td>
16
+ </tr>
17
+ <tr class="even">
18
+ <td>B&amp;B</td>
19
+ </tr>
20
+ <tr class="odd">
21
+ <td>&quot;CCC&quot;</td>
22
+ </tr>
23
+ </table>
24
+
25
+ <address>
26
+ copyright(c) 2010 kuwata-lab.com all rights reserved
27
+ </address>
28
+ </body>
29
+ </html>
@@ -0,0 +1,3 @@
1
+ <address>
2
+ copyright(c) 2010 kuwata-lab.com all rights reserved
3
+ </address>
@@ -0,0 +1,3 @@
1
+ <div class="header">
2
+ <h1>${@page_title}</h1>
3
+ </div>
@@ -0,0 +1,13 @@
1
+ <?rb #@ARGS _content, page_title ?>
2
+ <!DOCTYPE>
3
+ <html>
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6
+ <title>${@page_title}</title>
7
+ </head>
8
+ <body>
9
+ <?rb import(:_header) ?>
10
+ #{@_content}
11
+ <?rb import(:_footer) ?>
12
+ </body>
13
+ </html>
@@ -0,0 +1,13 @@
1
+ <?rb #@ARGS title, items ?>
2
+ <?rb @page_title = 'Tenjin: Layout Template Example' ?>
3
+ <h2>${title}</h2>
4
+ <table>
5
+ <?rb i = 0 ?>
6
+ <?rb for item in items ?>
7
+ <?rb i += 1 ?>
8
+ <?rb klass = i % 2 == 1 ? 'odd' : 'even' ?>
9
+ <tr class="#{klass}">
10
+ <td>${item}</td>
11
+ </tr>
12
+ <?rb end ?>
13
+ </table>
@@ -0,0 +1,24 @@
1
+ ## context data
2
+ post_content = <<END
3
+ Tenjin has great features.
4
+ - Very Fast
5
+ - Full Featured
6
+ - Easy to Use
7
+ END
8
+ context = {
9
+ :blog_post => {
10
+ :title => 'Tenjin is Great',
11
+ :content => post_content,
12
+ },
13
+ :recent_posts => [
14
+ {:id=>1, :title=>'Tenjin is Fast' },
15
+ {:id=>2, :title=>'Tenjin is Full-Featured' },
16
+ {:id=>3, :title=>'Tenjin is Easy-to-Use' },
17
+ ]
18
+ }
19
+
20
+ ## render template
21
+ require 'tenjin'
22
+ engine = Tenjin::Engine.new(:path=>['views'], :layout=>'_layout.rbhtml')
23
+ html = engine.render('blog-post.rbhtml', context)
24
+ puts html
@@ -0,0 +1,28 @@
1
+ $ ruby main.rb
2
+ <html>
3
+ <body>
4
+ <div id="header-part">
5
+ <h1>My Great Blog</h1>
6
+ </div>
7
+ <div id="main-content">
8
+ <h2>Tenjin is Great</h2>
9
+ <div class="blog-post">
10
+ Tenjin has great features.<br />
11
+ - Very Fast<br />
12
+ - Full Featured<br />
13
+ - Easy to Use<br />
14
+
15
+ </div>
16
+
17
+
18
+ </div>
19
+ <div id="sidebar-part">
20
+ <h3>Recent Posts</h3>
21
+ <ul>
22
+ <a href="/blog/1">Tenjin is Fast</a>
23
+ <a href="/blog/2">Tenjin is Full-Featured</a>
24
+ <a href="/blog/3">Tenjin is Easy-to-Use</a>
25
+ </ul>
26
+ </div>
27
+ </body>
28
+ </html>
@@ -0,0 +1,21 @@
1
+ <html>
2
+ <body>
3
+ <div id="header-part">
4
+ <?rb if ! captured_as(:header) ?>
5
+ <h1>My Great Blog</h1>
6
+ <?rb end ?>
7
+ </div>
8
+ <div id="main-content">
9
+ #{@_content}
10
+ </div>
11
+ <div id="sidebar-part">
12
+ <?rb if ! captured_as(:sidebar) ?>
13
+ <h3>Links</h3>
14
+ <ul>
15
+ <a href="http://google.com/">Google</a>
16
+ <a href="http://yahoo.com/">Yahoo!</a>
17
+ </ul>
18
+ <?rb end ?>
19
+ </div>
20
+ </body>
21
+ </html>
@@ -0,0 +1,13 @@
1
+ <h2>#{@blog_post[:title]}</h2>
2
+ <div class="blog-post">
3
+ #{text2html(@blog_post[:content])}
4
+ </div>
5
+
6
+ <?rb start_capture('sidebar') do ?>
7
+ <h3>Recent Posts</h3>
8
+ <ul>
9
+ <?rb for post in @recent_posts ?>
10
+ <a href="/blog/#{post[:id]}">${post[:title]}</a>
11
+ <?rb end ?>
12
+ </ul>
13
+ <?rb end ?>
@@ -0,0 +1,5 @@
1
+ @items = [
2
+ "AAA",
3
+ 123,
4
+ true,
5
+ ]
@@ -0,0 +1,4 @@
1
+ items:
2
+ - AAA
3
+ - 123
4
+ - true
@@ -0,0 +1,5 @@
1
+ <ul>
2
+ <?rb for item in @items ?>
3
+ <li>${item}</li>
4
+ <?rb end ?>
5
+ </ul>
@@ -0,0 +1,6 @@
1
+ $ rbtenjin -c '@items=["A","B","C"]' example.rbhtml
2
+ <ul>
3
+ <li>A</li>
4
+ <li>B</li>
5
+ <li>C</li>
6
+ </ul>
@@ -0,0 +1,6 @@
1
+ $ rbtenjin -c '{items: [A, B, C]}' example.rbhtml
2
+ <ul>
3
+ <li>A</li>
4
+ <li>B</li>
5
+ <li>C</li>
6
+ </ul>
@@ -0,0 +1,6 @@
1
+ $ rbtenjin -f context.rb example.rbhtml
2
+ <ul>
3
+ <li>AAA</li>
4
+ <li>123</li>
5
+ <li>true</li>
6
+ </ul>
@@ -0,0 +1,6 @@
1
+ $ rbtenjin -f context.yaml example.rbhtml
2
+ <ul>
3
+ <li>AAA</li>
4
+ <li>123</li>
5
+ <li>true</li>
6
+ </ul>
@@ -0,0 +1,5 @@
1
+ <ul>
2
+ <?rb for item in @items ?>
3
+ <li>${item}</li>
4
+ <?rb end ?>
5
+ </ul>
@@ -0,0 +1,7 @@
1
+ $ rbtenjin -s example.rbhtml
2
+ _buf = ''; _buf << %Q`<ul>\n`
3
+ for item in @items
4
+ _buf << %Q` <li>#{escape((item).to_s)}</li>\n`
5
+ end
6
+ _buf << %Q`</ul>\n`
7
+ _buf.to_s
@@ -0,0 +1,6 @@
1
+ $ rbtenjin -sb example.rbhtml
2
+ _buf << %Q`<ul>\n`
3
+ for item in @items
4
+ _buf << %Q` <li>#{escape((item).to_s)}</li>\n`
5
+ end
6
+ _buf << %Q`</ul>\n`
@@ -0,0 +1,4 @@
1
+ require 'tenjin'
2
+ require 'erb'
3
+ engine = Tenjin::Engine.new(:path=>['views'], :escapefunc=>'ERB::Util.h')
4
+ puts engine.get_template('page.rbhtml').script
@@ -0,0 +1,5 @@
1
+ $ ruby main.rb
2
+ _buf << %Q`<p>
3
+ escaped: #{ERB::Util.h((@value).to_s)}
4
+ not escaped: #{@value}
5
+ </p>\n`
@@ -0,0 +1,4 @@
1
+ <p>
2
+ escaped: ${@value}
3
+ not escaped: #{@value}
4
+ </p>
@@ -0,0 +1,6 @@
1
+ <?rb @items = ['<AAA>', 'B&B', '"CCC"'] ?>
2
+ <ul>
3
+ <?rb for item in @items ?>
4
+ <li>${item}</li>
5
+ <?rb end ?>
6
+ </ul>
@@ -0,0 +1,6 @@
1
+ $ rbtenjin example.rbhtml
2
+ <ul>
3
+ <li>&lt;AAA&gt;</li>
4
+ <li>B&amp;B</li>
5
+ <li>&quot;CCC&quot;</li>
6
+ </ul>
@@ -0,0 +1,5 @@
1
+ <ul>
2
+ <li>AAA</li>
3
+ <li>BBB</li>
4
+ <li>CCC</li>
5
+ </ul>
@@ -0,0 +1,21 @@
1
+ require 'tenjin'
2
+
3
+ ## create key-value store object
4
+ Dir.mkdir('cache.d') unless File.exist?('cache.d')
5
+ kv_store = Tenjin::FileBaseStore.new('cache.d') # file based
6
+
7
+ ## set key-value store into tenjin.helpers.fagment_cache object
8
+ Tenjin::Engine.data_cache = kv_store
9
+
10
+ ## context data
11
+ ## (it is strongly recommended to create Proc object
12
+ ## to provide pull-style context data)
13
+ get_items = proc { # called only when cache is expired
14
+ ['AAA', 'BBB', 'CCC']
15
+ }
16
+ context = {:get_items => get_items}
17
+
18
+ ## render html
19
+ engine = Tenjin::Engine.new(:path=>['views'])
20
+ html = engine.render('items.rbhtml', context)
21
+ puts html
@@ -0,0 +1,8 @@
1
+ $ ruby main.rb
2
+ <div>
3
+ <ul>
4
+ <li>AAA</li>
5
+ <li>BBB</li>
6
+ <li>CCC</li>
7
+ </ul>
8
+ </div>
@@ -0,0 +1,6 @@
1
+ $ cat cache.d/items/1
2
+ <ul>
3
+ <li>AAA</li>
4
+ <li>BBB</li>
5
+ <li>CCC</li>
6
+ </ul>
@@ -0,0 +1,10 @@
1
+ <div>
2
+ <?rb # fragment cache with key ('items/1') and lifetime (60sec) ?>
3
+ <?rb cache_with('items/1', 60) do ?>
4
+ <ul>
5
+ <?rb for item in @get_items.call() ?>
6
+ <li>${item}</li>
7
+ <?rb end ?>
8
+ </ul>
9
+ <?rb end ?>
10
+ </div>
@@ -0,0 +1,11 @@
1
+ require 'tenjin'
2
+
3
+ ## set logger object
4
+ require 'logger'
5
+ Tenjin.logger = Logger.new($stdout)
6
+ Tenjin.logger.datetime_format = ""
7
+
8
+ engine = Tenjin::Engine.new()
9
+ context = {:name => 'World'}
10
+ html = engine.render('example.rbhtml', context)
11
+ #print html
@@ -0,0 +1,3 @@
1
+ $ ruby ex-logger.rb
2
+ D, [#3700] DEBUG -- : [tenjin.rb:1022] cache not found (cachefile="example.rbhtml.cache").
3
+ D, [#3700] DEBUG -- : [tenjin.rb:1005] cache saved (cachefile="example.rbhtml.cache").
@@ -0,0 +1,2 @@
1
+ $ ruby ex-logger.rb
2
+ D, [#3730] DEBUG -- : [tenjin.rb:1028] cache found (cachefile="example.rbhtml.cache").
@@ -0,0 +1,44 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'tenjin'
3
+
4
+ ##
5
+ ## message catalog to translate message
6
+ ##
7
+ MESSAGE_CATALOG = {
8
+ 'en' => { 'Hello'=>"Hello", 'Good bye'=>"Good bye" },
9
+ 'fr' => { 'Hello'=>"Bonjour", 'Good bye'=>"Au revoir" },
10
+ }
11
+
12
+ ##
13
+ ## create translation function and return it.
14
+ ## ex.
15
+ ## _ = create_m17n_obj('fr')
16
+ ## print _['Hello'] #=> 'Bonjour'
17
+ ##
18
+ def create_m17n_obj(lang)
19
+ hash = MESSAGE_CATALOG[lang] or
20
+ raise Error.new("#{lang}: unknown lang.")
21
+ _ = proc {|message_key| hash[message_key] }
22
+ return _
23
+ end
24
+
25
+ ##
26
+ ## test program
27
+ ##
28
+ if __FILE__ == $0
29
+ ## render html for English
30
+ engine_en = Tenjin::Engine.new(:preprocess=>true, :lang=>'en')
31
+ context = { :username => 'World' }
32
+ context[:_] = create_m17n_obj('en')
33
+ html = engine_en.render('m17n.rbhtml', context)
34
+ puts "--- lang: en ---"
35
+ puts html
36
+
37
+ ## render html for French
38
+ engine_fr = Tenjin::Engine.new(:preprocess=>true, :lang=>'fr')
39
+ context = { :username => 'World' }
40
+ context[:_] = create_m17n_obj('fr')
41
+ html = engine_fr.render('m17n.rbhtml', context)
42
+ puts "--- lang: fr ---"
43
+ puts html
44
+ end