tenjin 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/CHANGES.txt +46 -0
  2. data/MIT-LICENSE +1 -1
  3. data/README.txt +7 -7
  4. data/bin/rbtenjin +2 -2
  5. data/doc-api/classes/Tenjin.html +2 -2
  6. data/doc-api/classes/Tenjin/ArrayBufferTemplate.html +28 -28
  7. data/doc-api/classes/Tenjin/BaseContext.html +61 -44
  8. data/doc-api/classes/Tenjin/ContextHelper.html +85 -57
  9. data/doc-api/classes/Tenjin/Engine.html +88 -88
  10. data/doc-api/classes/Tenjin/ErubisTemplate.html +7 -7
  11. data/doc-api/classes/Tenjin/Preprocessor.html +28 -28
  12. data/doc-api/classes/Tenjin/Template.html +142 -142
  13. data/doc-api/created.rid +1 -1
  14. data/doc-api/files/README_txt.html +10 -10
  15. data/doc-api/files/lib/tenjin_rb.html +2 -2
  16. data/doc-api/fr_method_index.html +55 -53
  17. data/doc/examples.html +2 -2
  18. data/doc/faq.html +2 -2
  19. data/doc/users-guide.html +47 -4
  20. data/examples/form/Makefile +5 -0
  21. data/examples/form/Rakefile +7 -0
  22. data/examples/form/create.rbhtml +4 -0
  23. data/examples/form/form.rbhtml +14 -0
  24. data/examples/form/layout.rbhtml +8 -0
  25. data/examples/form/main.rb +9 -0
  26. data/examples/form/update.rbhtml +4 -0
  27. data/examples/preprocessing/Makefile +8 -0
  28. data/examples/preprocessing/Rakefile +11 -0
  29. data/examples/preprocessing/helper.rb +16 -0
  30. data/examples/preprocessing/main.rb +11 -0
  31. data/examples/preprocessing/select.rbhtml +15 -0
  32. data/examples/table/Makefile +5 -0
  33. data/examples/table/Rakefile +7 -0
  34. data/examples/table/table.rb +9 -0
  35. data/examples/table/table.rbhtml +16 -0
  36. data/lib/tenjin.rb +28 -18
  37. data/setup.rb +861 -607
  38. data/tenjin.gemspec +16 -12
  39. data/test/assert-text-equal.rb +2 -2
  40. data/test/data/users_guide/example16d.rb +27 -0
  41. data/test/data/users_guide/example16d.result +4 -0
  42. data/test/test_all.rb +2 -2
  43. data/test/test_engine.rb +2 -2
  44. data/test/test_examples.rb +2 -2
  45. data/test/test_faq.rb +2 -2
  46. data/test/test_htmlhelper.rb +2 -2
  47. data/test/test_main.rb +2 -2
  48. data/test/test_template.rb +2 -2
  49. data/test/test_users_guide.rb +2 -2
  50. data/test/testcase-helper.rb +2 -2
  51. metadata +64 -35
@@ -1 +1 @@
1
- Sat, 04 Aug 2007 14:02:32 +0900
1
+ Thu, 07 Feb 2008 11:07:39 +0900
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Sat Aug 04 06:36:16 +0900 2007</td>
59
+ <td>Thu Feb 07 11:04:47 +0900 2008</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -71,25 +71,25 @@
71
71
  <div id="description">
72
72
  <h1>README</h1>
73
73
  <table>
74
- <tr><td valign="top">release:</td><td>0.6.0
74
+ <tr><td valign="top">release:</td><td>0.6.1
75
75
 
76
76
  </td></tr>
77
- <tr><td valign="top">copyright:</td><td>copyright(c) 2007 kuwata-lab all rights reserved.
77
+ <tr><td valign="top">copyright:</td><td>copyright(c) 2007-2008 kuwata-lab.com all rights reserved.
78
78
 
79
79
  </td></tr>
80
80
  </table>
81
81
  <h2>About</h2>
82
82
  <p>
83
- rbTenjin is a very fast and full-featured template engine based on embedded
84
- Ruby. You can embed Ruby statements and expressions into your text file.
85
- rbTenjin converts it into Ruby program and evaluate it.
83
+ rbTenjin is a very fast and full-featured template engine. You can embed
84
+ Ruby statements and expressions into your text file. rbTenjin converts it
85
+ into Ruby program and evaluate it.
86
86
  </p>
87
87
  <h2>Features</h2>
88
88
  <ul>
89
89
  <li>Very fast (twice faster than eruby and three times faster than ERB)
90
90
 
91
91
  </li>
92
- <li>Lightweight (only one file which contains about 1000 lines)
92
+ <li>Lightweight (only a file which contains about 1000 lines)
93
93
 
94
94
  </li>
95
95
  <li>Not break HTML design because it uses XML Processing Instructions (PI) as
@@ -129,13 +129,13 @@ See doc/*.html for details.
129
129
  $ sudo gem install tenjin
130
130
  </pre>
131
131
  </li>
132
- <li>Else download rbtenjin-X.X.X.tar.bz2 and just copy
132
+ <li>Else download rbtenjin-0.6.1.tar.bz2 and just copy
133
133
  &#8216;lib/tenjin.rb&#8217; and &#8216;bin/rbtenjin&#8217; into proper
134
134
  directory.
135
135
 
136
136
  <pre>
137
- $ tar xjf rbtenjin-X.X.X.tar.bz2
138
- $ cd rbtenjin-X.X.X/
137
+ $ tar xjf rbtenjin-0.6.1.tar.bz2
138
+ $ cd rbtenjin-0.6.1/
139
139
  $ sudo copy lib/tenjin.rb /usr/local/lib/ruby/1.8/site_ruby/1.8/
140
140
  $ sudo copy bin/rbtenjin /usr/local/bin/
141
141
  </pre>
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Sat Aug 04 10:04:29 +0900 2007</td>
59
+ <td>Wed Feb 06 12:44:46 +0900 2008</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -70,7 +70,7 @@
70
70
 
71
71
  <div id="description">
72
72
  <p>
73
- copyright(c) 2007 kuwata-lab all rights reserved.
73
+ copyright(c) 2007-2008 kuwata-lab.com all rights reserved.
74
74
  </p>
75
75
  <p>
76
76
  Permission is hereby granted, free of charge, to any person obtaining a
@@ -20,68 +20,70 @@
20
20
  <div id="index">
21
21
  <h1 class="section-bar">Methods</h1>
22
22
  <div id="index-entries">
23
- <a href="classes/Tenjin/BaseContext.html#M000023">[] (Tenjin::BaseContext)</a><br />
24
- <a href="classes/Tenjin/BaseContext.html#M000024">[]= (Tenjin::BaseContext)</a><br />
25
- <a href="classes/Tenjin/ContextHelper.html#M000015">_P (Tenjin::ContextHelper)</a><br />
26
- <a href="classes/Tenjin/ContextHelper.html#M000016">_decode_params (Tenjin::ContextHelper)</a><br />
27
- <a href="classes/Tenjin/ContextHelper.html#M000014">_p (Tenjin::ContextHelper)</a><br />
28
- <a href="classes/Tenjin/Template.html#M000061">add_expr (Tenjin::Template)</a><br />
29
- <a href="classes/Tenjin/Preprocessor.html#M000044">add_expr (Tenjin::Preprocessor)</a><br />
30
- <a href="classes/Tenjin/Template.html#M000062">add_stmt (Tenjin::Template)</a><br />
31
- <a href="classes/Tenjin/Template.html#M000059">add_text (Tenjin::Template)</a><br />
32
- <a href="classes/Tenjin/Template.html#M000049">after_convert (Tenjin::Template)</a><br />
33
- <a href="classes/Tenjin/Template.html#M000048">before_convert (Tenjin::Template)</a><br />
34
- <a href="classes/Tenjin/Engine.html#M000034">cachename (Tenjin::Engine)</a><br />
35
- <a href="classes/Tenjin/ContextHelper.html#M000013">captured_as (Tenjin::ContextHelper)</a><br />
23
+ <a href="classes/Tenjin/BaseContext.html#M000024">[] (Tenjin::BaseContext)</a><br />
24
+ <a href="classes/Tenjin/BaseContext.html#M000025">[]= (Tenjin::BaseContext)</a><br />
25
+ <a href="classes/Tenjin/ContextHelper.html#M000016">_P (Tenjin::ContextHelper)</a><br />
26
+ <a href="classes/Tenjin/ContextHelper.html#M000017">_decode_params (Tenjin::ContextHelper)</a><br />
27
+ <a href="classes/Tenjin/ContextHelper.html#M000015">_p (Tenjin::ContextHelper)</a><br />
28
+ <a href="classes/Tenjin/Preprocessor.html#M000046">add_expr (Tenjin::Preprocessor)</a><br />
29
+ <a href="classes/Tenjin/Template.html#M000063">add_expr (Tenjin::Template)</a><br />
30
+ <a href="classes/Tenjin/Template.html#M000064">add_stmt (Tenjin::Template)</a><br />
31
+ <a href="classes/Tenjin/Template.html#M000061">add_text (Tenjin::Template)</a><br />
32
+ <a href="classes/Tenjin/Template.html#M000051">after_convert (Tenjin::Template)</a><br />
33
+ <a href="classes/Tenjin/Template.html#M000050">before_convert (Tenjin::Template)</a><br />
34
+ <a href="classes/Tenjin/Engine.html#M000036">cachename (Tenjin::Engine)</a><br />
35
+ <a href="classes/Tenjin/ContextHelper.html#M000014">captured_as (Tenjin::ContextHelper)</a><br />
36
36
  <a href="classes/Tenjin/HtmlHelper.html#M000004">checked (Tenjin::HtmlHelper)</a><br />
37
- <a href="classes/Tenjin/Template.html#M000050">compile_stmt_pattern (Tenjin::Template)</a><br />
38
- <a href="classes/Tenjin/Template.html#M000047">convert (Tenjin::Template)</a><br />
39
- <a href="classes/Tenjin/Template.html#M000046">convert_file (Tenjin::Template)</a><br />
40
- <a href="classes/Tenjin/Engine.html#M000035">create_template (Tenjin::Engine)</a><br />
37
+ <a href="classes/Tenjin/Template.html#M000052">compile_stmt_pattern (Tenjin::Template)</a><br />
38
+ <a href="classes/Tenjin/Template.html#M000049">convert (Tenjin::Template)</a><br />
39
+ <a href="classes/Tenjin/Template.html#M000048">convert_file (Tenjin::Template)</a><br />
40
+ <a href="classes/Tenjin/Engine.html#M000037">create_template (Tenjin::Engine)</a><br />
41
41
  <a href="classes/Tenjin/HtmlHelper.html#M000006">disabled (Tenjin::HtmlHelper)</a><br />
42
- <a href="classes/Tenjin/BaseContext.html#M000028">each (Tenjin::BaseContext)</a><br />
43
- <a href="classes/Tenjin/ContextHelper.html#M000010">echo (Tenjin::ContextHelper)</a><br />
42
+ <a href="classes/Tenjin/BaseContext.html#M000030">each (Tenjin::BaseContext)</a><br />
43
+ <a href="classes/Tenjin/ContextHelper.html#M000011">echo (Tenjin::ContextHelper)</a><br />
44
+ <a href="classes/Tenjin/ContextHelper.html#M000009">escape (Tenjin::ContextHelper)</a><br />
44
45
  <a href="classes/Tenjin/HtmlHelper.html#M000002">escape (Tenjin::HtmlHelper)</a><br />
45
- <a href="classes/Tenjin/BaseContext.html#M000025">escape (Tenjin::BaseContext)</a><br />
46
- <a href="classes/Tenjin/Preprocessor.html#M000043">escape_str (Tenjin::Preprocessor)</a><br />
47
- <a href="classes/Tenjin/Template.html#M000060">escape_str (Tenjin::Template)</a><br />
46
+ <a href="classes/Tenjin/Template.html#M000062">escape_str (Tenjin::Template)</a><br />
47
+ <a href="classes/Tenjin/Preprocessor.html#M000045">escape_str (Tenjin::Preprocessor)</a><br />
48
48
  <a href="classes/Tenjin/HtmlHelper.html#M000001">escape_xml (Tenjin::HtmlHelper)</a><br />
49
- <a href="classes/Tenjin/ArrayBufferTemplate.html#M000018">expr_pattern (Tenjin::ArrayBufferTemplate)</a><br />
50
- <a href="classes/Tenjin/Preprocessor.html#M000042">expr_pattern (Tenjin::Preprocessor)</a><br />
51
- <a href="classes/Tenjin/Template.html#M000053">expr_pattern (Tenjin::Template)</a><br />
52
- <a href="classes/Tenjin/Engine.html#M000031">find_template_file (Tenjin::Engine)</a><br />
53
- <a href="classes/Tenjin/Template.html#M000054">get_expr_and_escapeflag (Tenjin::Template)</a><br />
54
- <a href="classes/Tenjin/Engine.html#M000038">get_template (Tenjin::Engine)</a><br />
55
- <a href="classes/Tenjin/Engine.html#M000040">hook_context (Tenjin::Engine)</a><br />
56
- <a href="classes/Tenjin/ContextHelper.html#M000009">import (Tenjin::ContextHelper)</a><br />
49
+ <a href="classes/Tenjin/ArrayBufferTemplate.html#M000019">expr_pattern (Tenjin::ArrayBufferTemplate)</a><br />
50
+ <a href="classes/Tenjin/Template.html#M000055">expr_pattern (Tenjin::Template)</a><br />
51
+ <a href="classes/Tenjin/Preprocessor.html#M000044">expr_pattern (Tenjin::Preprocessor)</a><br />
52
+ <a href="classes/Tenjin/Engine.html#M000033">find_template_file (Tenjin::Engine)</a><br />
53
+ <a href="classes/Tenjin/Template.html#M000056">get_expr_and_escapeflag (Tenjin::Template)</a><br />
54
+ <a href="classes/Tenjin/Engine.html#M000040">get_template (Tenjin::Engine)</a><br />
55
+ <a href="classes/Tenjin/BaseContext.html#M000029">has_key? (Tenjin::BaseContext)</a><br />
56
+ <a href="classes/Tenjin/Engine.html#M000042">hook_context (Tenjin::Engine)</a><br />
57
+ <a href="classes/Tenjin/ContextHelper.html#M000010">import (Tenjin::ContextHelper)</a><br />
57
58
  <a href="classes/Tenjin/BaseContext.html#M000027">key? (Tenjin::BaseContext)</a><br />
58
- <a href="classes/Tenjin/Engine.html#M000037">load_cachefile (Tenjin::Engine)</a><br />
59
- <a href="classes/Tenjin/BaseContext.html#M000022">new (Tenjin::BaseContext)</a><br />
60
- <a href="classes/Tenjin/Engine.html#M000029">new (Tenjin::Engine)</a><br />
61
- <a href="classes/Tenjin/Template.html#M000045">new (Tenjin::Template)</a><br />
59
+ <a href="classes/Tenjin/BaseContext.html#M000028">key? (Tenjin::BaseContext)</a><br />
60
+ <a href="classes/Tenjin/Engine.html#M000039">load_cachefile (Tenjin::Engine)</a><br />
61
+ <a href="classes/Tenjin/BaseContext.html#M000023">new (Tenjin::BaseContext)</a><br />
62
+ <a href="classes/Tenjin/Template.html#M000047">new (Tenjin::Template)</a><br />
63
+ <a href="classes/Tenjin/Engine.html#M000031">new (Tenjin::Engine)</a><br />
62
64
  <a href="classes/Tenjin/HtmlHelper.html#M000007">nl2br (Tenjin::HtmlHelper)</a><br />
63
- <a href="classes/Tenjin/ArrayBufferTemplate.html#M000019">parse_exprs (Tenjin::ArrayBufferTemplate)</a><br />
64
- <a href="classes/Tenjin/Template.html#M000055">parse_exprs (Tenjin::Template)</a><br />
65
- <a href="classes/Tenjin/Template.html#M000052">parse_stmts (Tenjin::Template)</a><br />
66
- <a href="classes/Tenjin/ErubisTemplate.html#M000017">parse_stmts (Tenjin::ErubisTemplate)</a><br />
67
- <a href="classes/Tenjin/ArrayBufferTemplate.html#M000021">quote_expr (Tenjin::ArrayBufferTemplate)</a><br />
68
- <a href="classes/Tenjin/ArrayBufferTemplate.html#M000020">quote_str (Tenjin::ArrayBufferTemplate)</a><br />
69
- <a href="classes/Tenjin/Engine.html#M000032">read_template_file (Tenjin::Engine)</a><br />
70
- <a href="classes/Tenjin/Engine.html#M000033">register_template (Tenjin::Engine)</a><br />
71
- <a href="classes/Tenjin/Engine.html#M000039">render (Tenjin::Engine)</a><br />
72
- <a href="classes/Tenjin/Template.html#M000063">render (Tenjin::Template)</a><br />
65
+ <a href="classes/Tenjin/Template.html#M000057">parse_exprs (Tenjin::Template)</a><br />
66
+ <a href="classes/Tenjin/ArrayBufferTemplate.html#M000020">parse_exprs (Tenjin::ArrayBufferTemplate)</a><br />
67
+ <a href="classes/Tenjin/Template.html#M000054">parse_stmts (Tenjin::Template)</a><br />
68
+ <a href="classes/Tenjin/ErubisTemplate.html#M000018">parse_stmts (Tenjin::ErubisTemplate)</a><br />
69
+ <a href="classes/Tenjin/ArrayBufferTemplate.html#M000022">quote_expr (Tenjin::ArrayBufferTemplate)</a><br />
70
+ <a href="classes/Tenjin/ArrayBufferTemplate.html#M000021">quote_str (Tenjin::ArrayBufferTemplate)</a><br />
71
+ <a href="classes/Tenjin/Engine.html#M000034">read_template_file (Tenjin::Engine)</a><br />
72
+ <a href="classes/Tenjin/Engine.html#M000035">register_template (Tenjin::Engine)</a><br />
73
+ <a href="classes/Tenjin/Engine.html#M000041">render (Tenjin::Engine)</a><br />
74
+ <a href="classes/Tenjin/Template.html#M000065">render (Tenjin::Template)</a><br />
73
75
  <a href="classes/Tenjin/HtmlHelper.html#M000005">selected (Tenjin::HtmlHelper)</a><br />
74
- <a href="classes/Tenjin/ContextHelper.html#M000011">start_capture (Tenjin::ContextHelper)</a><br />
75
- <a href="classes/Tenjin/Template.html#M000057">start_text_part (Tenjin::Template)</a><br />
76
- <a href="classes/Tenjin/Template.html#M000056">statement_hook (Tenjin::Template)</a><br />
77
- <a href="classes/Tenjin/Template.html#M000051">stmt_pattern (Tenjin::Template)</a><br />
78
- <a href="classes/Tenjin/Preprocessor.html#M000041">stmt_pattern (Tenjin::Preprocessor)</a><br />
79
- <a href="classes/Tenjin/ContextHelper.html#M000012">stop_capture (Tenjin::ContextHelper)</a><br />
80
- <a href="classes/Tenjin/Template.html#M000058">stop_text_part (Tenjin::Template)</a><br />
81
- <a href="classes/Tenjin/Engine.html#M000036">store_cachefile (Tenjin::Engine)</a><br />
76
+ <a href="classes/Tenjin/ContextHelper.html#M000012">start_capture (Tenjin::ContextHelper)</a><br />
77
+ <a href="classes/Tenjin/Template.html#M000059">start_text_part (Tenjin::Template)</a><br />
78
+ <a href="classes/Tenjin/Template.html#M000058">statement_hook (Tenjin::Template)</a><br />
79
+ <a href="classes/Tenjin/Template.html#M000053">stmt_pattern (Tenjin::Template)</a><br />
80
+ <a href="classes/Tenjin/Preprocessor.html#M000043">stmt_pattern (Tenjin::Preprocessor)</a><br />
81
+ <a href="classes/Tenjin/ContextHelper.html#M000013">stop_capture (Tenjin::ContextHelper)</a><br />
82
+ <a href="classes/Tenjin/Template.html#M000060">stop_text_part (Tenjin::Template)</a><br />
83
+ <a href="classes/Tenjin/Engine.html#M000038">store_cachefile (Tenjin::Engine)</a><br />
82
84
  <a href="classes/Tenjin/HtmlHelper.html#M000003">tagattr (Tenjin::HtmlHelper)</a><br />
83
85
  <a href="classes/Tenjin/HtmlHelper.html#M000008">text2html (Tenjin::HtmlHelper)</a><br />
84
- <a href="classes/Tenjin/Engine.html#M000030">to_filename (Tenjin::Engine)</a><br />
86
+ <a href="classes/Tenjin/Engine.html#M000032">to_filename (Tenjin::Engine)</a><br />
85
87
  <a href="classes/Tenjin/BaseContext.html#M000026">update (Tenjin::BaseContext)</a><br />
86
88
  </div>
87
89
  </div>
@@ -14,10 +14,10 @@
14
14
 
15
15
  <div align="left"><h1>rbTenjin Examples</h1></div>
16
16
  <div align="left">
17
- last update: $Date: 2007-08-04 13:23:33 +0900 (Sat, 04 Aug 2007) $<br>
17
+ last update: $Date: 2007-10-23 15:29:14 +0900 (Tue, 23 Oct 2007) $<br>
18
18
  </div>
19
19
 
20
- <p>Release: 0.6.0
20
+ <p>Release: 0.6.1
21
21
  </p>
22
22
  <p>Table of Contents:
23
23
  <ul>
@@ -14,10 +14,10 @@
14
14
 
15
15
  <div align="left"><h1>rbTenjin FAQ</h1></div>
16
16
  <div align="left">
17
- last update: $Date: 2007-08-04 13:23:33 +0900 (Sat, 04 Aug 2007) $<br>
17
+ last update: $Date: 2008-02-04 22:21:53 +0900 (Mon, 04 Feb 2008) $<br>
18
18
  </div>
19
19
 
20
- <p>Release: 0.6.0
20
+ <p>Release: 0.6.1
21
21
  </p>
22
22
  <p>Table of contents:
23
23
  <ul>
@@ -14,10 +14,10 @@
14
14
 
15
15
  <div align="left"><h1>rbTenjin User's Guide</h1></div>
16
16
  <div align="left">
17
- last update: $Date: 2007-08-04 13:23:33 +0900 (Sat, 04 Aug 2007) $<br>
17
+ last update: $Date: 2008-02-06 12:44:46 +0900 (Wed, 06 Feb 2008) $<br>
18
18
  </div>
19
19
 
20
- <p>Release: 0.6.0
20
+ <p>Release: 0.6.1
21
21
  </p>
22
22
  <p>Table of Contents:
23
23
  <ul>
@@ -430,7 +430,7 @@ Result:</div>
430
430
  <pre class="terminal">$ rbtenjin <strong>-wz</strong> example3.rbhtml
431
431
  example3.rbhtml:5: syntax error, unexpected $end, expecting kEND
432
432
  </pre>
433
- <p>Command-line option '-wz' is more convenient than '<code>rbtenjin -s file | ruby -wz</code>'
433
+ <p>Command-line option '-wz' is more convenient than '<code>rbtenjin -s file | ruby -wc</code>'
434
434
  because the former can take several filenames.
435
435
  </p>
436
436
  <p>Command-line option '-q' (quiet-mode) prints nothing if it has no errors.
@@ -521,7 +521,7 @@ Result:</div>
521
521
 
522
522
  <a name="des-cmlinecontext"></a>
523
523
  <h3 class="section2">Command-line Context Data</h3>
524
- <p>Command-line option '<code>-z</code>' specifies context data in YAML format or Ruby code.
524
+ <p>Command-line option '<code>-c</code>' specifies context data in YAML format or Ruby code.
525
525
  </p>
526
526
  <a name="example5.rbhtml"></a>
527
527
  <div class="program_caption">
@@ -1150,6 +1150,8 @@ filename = 'file.rbhtml'
1150
1150
  output = engine.render(filename, context)
1151
1151
  print output
1152
1152
  </pre>
1153
+ <p>If you want to define helper functions for template, see <a href="#dev-helpers">Add Your Helper Functions</a> section.
1154
+ </p>
1153
1155
  <br>
1154
1156
 
1155
1157
 
@@ -1657,6 +1659,47 @@ Result:</div>
1657
1659
  &lt;li&gt;&lt;a href="/"&gt;Top&lt;/a&gt;&lt;/li&gt;
1658
1660
  &lt;/ul&gt;
1659
1661
  </pre>
1662
+ <p>(D) Define helper functions in current class, set context data as instance variables, and pass self as context object
1663
+ </p>
1664
+ <a name="example16d.rb"></a>
1665
+ <div class="program_caption">
1666
+ File 'example16d.rb':</div>
1667
+ <pre class="program">require 'tenjin'
1668
+
1669
+ class MyClass
1670
+ <strong>include Tenjin::ContextHelper</strong>
1671
+ <strong>#include Tenjin::HtmlHelper</strong> # optional
1672
+
1673
+ def link_to(label, url) # define helper functions in current class
1674
+ return "&lt;a href=\"#{escape(url)}\"&gt;#{escape(label)}&lt;/a&gt;"
1675
+ end
1676
+
1677
+ def render_template(template_name)
1678
+ engine = Tenjin::Engine.new()
1679
+ output = engine.render(template_name, <strong>self</strong>) # pass self as context object
1680
+ return output
1681
+ end
1682
+
1683
+ def main
1684
+ ## set context data as instance variables
1685
+ <strong>@label = 'Top'</strong>
1686
+ <strong>@url = '/'</strong>
1687
+ output = render_template('example16.rbhtml')
1688
+ print output
1689
+ end
1690
+
1691
+ end
1692
+
1693
+ MyClass.new.main()
1694
+ </pre>
1695
+ <a name="example16d.result"></a>
1696
+ <div class="terminal_caption">
1697
+ Result:</div>
1698
+ <pre class="terminal">$ ruby example16d.rb
1699
+ &lt;ul&gt;
1700
+ &lt;li&gt;&lt;a href="/"&gt;Top&lt;/a&gt;&lt;/li&gt;
1701
+ &lt;/ul&gt;
1702
+ </pre>
1660
1703
  <br>
1661
1704
 
1662
1705
 
@@ -0,0 +1,5 @@
1
+ all:
2
+ ruby main.rb
3
+
4
+ clean:
5
+ rm -f *.cache
@@ -0,0 +1,7 @@
1
+ task 'default' do
2
+ load 'main.rb'
3
+ end
4
+
5
+ task 'clean' do
6
+ rm_f Dir.glob('*.cache')
7
+ end
@@ -0,0 +1,4 @@
1
+ <?rb @title = 'Create user' ?>
2
+ <?rb @label = 'Create' ?>
3
+ <?rb @action = 'action.cgi' ?>
4
+ <?rb import(:form) ?>
@@ -0,0 +1,14 @@
1
+ <?rb #@ARGS action, params, label ?>
2
+ <form action="${@action}" method="post">
3
+ <p>
4
+ <label>Name:</label>
5
+ <input type="text" name="name" value="${@params[:name]}" />
6
+ </p>
7
+ <p>
8
+ <label>Gender:</label>
9
+ <?rb gender = @params[:gender] ?>
10
+ <input type="radio" name="gender" value="M" #{checked(gender=='M')} />Man
11
+ <input type="radio" name="gender" value="W" #{checked(gender=='W')} />Woman
12
+ </p>
13
+ <input type="submit" value="${@label}" />
14
+ </form>
@@ -0,0 +1,8 @@
1
+ <html>
2
+ <body>
3
+ <h1>${@title}</h1>
4
+ <div class="main-content">
5
+ #{@_content}
6
+ </div>
7
+ </body>
8
+ </html>
@@ -0,0 +1,9 @@
1
+ ## create Engine object
2
+ require 'tenjin'
3
+ engine = Tenjin::Engine.new(:postfix=>'.rbhtml', :layout=>'layout.rbhtml')
4
+
5
+ ## render template with context data
6
+ params = { :name=>'Foo', :gender=>'M' }
7
+ context = { :params=>params }
8
+ output = engine.render(:update, context) # :update == 'update'+postfix
9
+ puts output
@@ -0,0 +1,4 @@
1
+ <?rb @title = 'Update user' ?>
2
+ <?rb @label = 'Update' ?>
3
+ <?rb @action = 'update.cgi' ?>
4
+ <?rb import(:form) ?>
@@ -0,0 +1,8 @@
1
+ all:
2
+ ruby main.rb
3
+
4
+ preprocess:
5
+ rbtenjin -a preprocess select.rbhtml
6
+
7
+ clean:
8
+ rm -f *.cache
@@ -0,0 +1,11 @@
1
+ task 'default' do
2
+ load 'main.rb'
3
+ end
4
+
5
+ task 'preprocess' do
6
+ system 'rbtenjin -a preprocess select.rbhtml'
7
+ end
8
+
9
+ task 'clean' do
10
+ rm_f Dir.glob('*.cache')
11
+ end
@@ -0,0 +1,16 @@
1
+ LANGUAGES = [
2
+ ['en', 'Engilish'],
3
+ ['fr', 'French'],
4
+ ['de', 'German'],
5
+ ['es', 'Spanish'],
6
+ ['ch', 'Chinese'],
7
+ ['ja', 'Japanese'],
8
+ ]
9
+
10
+ def link_to(label, options={})
11
+ action, id = options[:action], options[:id]
12
+ url = '/app'
13
+ url << '/' << action if action && !action.empty?
14
+ url << '/' << id if id
15
+ return "<a href=\"#{CGI::escape(url).gsub(/%2F/i, '/')}\">#{label}</a>"
16
+ end
@@ -0,0 +1,11 @@
1
+ require 'helper'
2
+
3
+ ## create engine
4
+ require 'tenjin'
5
+ engine = Tenjin::Engine.new(:postfix=>'.rbhtml', :preprocess=>true)
6
+
7
+ ## render template with context data
8
+ params = { :id=>1234, :name=>'Foo', :lang=>'ch' }
9
+ context = { :params => params }
10
+ output = engine.render(:select, context)
11
+ puts output
@@ -0,0 +1,15 @@
1
+ <?RB require 'helper' ?>
2
+ <form>
3
+ <label>Select your language:</label>
4
+ <select name="lang">
5
+ <?rb table = { @params[:lang] => ' selected="selected"' } ?>
6
+ <?RB for val, name in LANGUAGES ?>
7
+ <option value="${{val}}" #{table[#{{val.inspect}}]}>${{name}}</option>
8
+ <?RB end ?>
9
+ </select>
10
+ <input type="submit" value="OK" />
11
+ </form>
12
+ <p>
13
+ #{{link_to('Back', :action=>'index')}} |
14
+ #{{link_to('Show '+_P('@params[:name]'), :action=>'show', :id=>_p('@params[:id]'))}}
15
+ </p>