tenjin 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (170) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.txt +54 -0
  3. data/benchmark/bench.rb +502 -0
  4. data/benchmark/bench_context.rb +17 -0
  5. data/benchmark/bench_context.yaml +141 -0
  6. data/benchmark/templates/_footer.html +4 -0
  7. data/benchmark/templates/_header.html +52 -0
  8. data/benchmark/templates/bench_eruby.rhtml +29 -0
  9. data/benchmark/templates/bench_tenjin.rbhtml +29 -0
  10. data/bin/rbtenjin +449 -0
  11. data/doc-api/classes/Tenjin.html +141 -0
  12. data/doc-api/classes/Tenjin/ArrayBufferTemplate.html +270 -0
  13. data/doc-api/classes/Tenjin/BaseContext.html +312 -0
  14. data/doc-api/classes/Tenjin/Context.html +126 -0
  15. data/doc-api/classes/Tenjin/ContextHelper.html +433 -0
  16. data/doc-api/classes/Tenjin/Engine.html +616 -0
  17. data/doc-api/classes/Tenjin/ErubisTemplate.html +166 -0
  18. data/doc-api/classes/Tenjin/HtmlHelper.html +359 -0
  19. data/doc-api/classes/Tenjin/Preprocessor.html +242 -0
  20. data/doc-api/classes/Tenjin/Template.html +916 -0
  21. data/doc-api/created.rid +1 -0
  22. data/doc-api/files/README_txt.html +185 -0
  23. data/doc-api/files/lib/tenjin_rb.html +136 -0
  24. data/doc-api/fr_class_index.html +36 -0
  25. data/doc-api/fr_file_index.html +28 -0
  26. data/doc-api/fr_method_index.html +89 -0
  27. data/doc-api/index.html +24 -0
  28. data/doc-api/rdoc-style.css +208 -0
  29. data/doc/docstyle.css +188 -0
  30. data/doc/examples.html +312 -0
  31. data/doc/faq.html +909 -0
  32. data/doc/users-guide.html +1691 -0
  33. data/lib/tenjin.rb +959 -0
  34. data/setup.rb +1331 -0
  35. data/tenjin.gemspec +58 -0
  36. data/test/assert-text-equal.rb +45 -0
  37. data/test/data/examples/form/create.rbhtml +4 -0
  38. data/test/data/examples/form/form.rbhtml +14 -0
  39. data/test/data/examples/form/layout.rbhtml +8 -0
  40. data/test/data/examples/form/main.rb +9 -0
  41. data/test/data/examples/form/main.result +21 -0
  42. data/test/data/examples/form/update.rbhtml +4 -0
  43. data/test/data/examples/preprocessing/helper.rb +16 -0
  44. data/test/data/examples/preprocessing/main.rb +11 -0
  45. data/test/data/examples/preprocessing/main.result +17 -0
  46. data/test/data/examples/preprocessing/select.rbhtml +15 -0
  47. data/test/data/examples/preprocessing/select_P.result +18 -0
  48. data/test/data/examples/table/table.rb +9 -0
  49. data/test/data/examples/table/table.rbhtml +16 -0
  50. data/test/data/examples/table/table.result +20 -0
  51. data/test/data/examples/table/table_s.result +18 -0
  52. data/test/data/faq/ex1.rbhtml +5 -0
  53. data/test/data/faq/ex10-baselayout.rbhtml +27 -0
  54. data/test/data/faq/ex10-content.rbhtml +12 -0
  55. data/test/data/faq/ex10-customlayout.rbhtml +11 -0
  56. data/test/data/faq/ex10_inherit.result +25 -0
  57. data/test/data/faq/ex11-bench.rb +28 -0
  58. data/test/data/faq/ex11-content.rbhtml +9 -0
  59. data/test/data/faq/ex11-layout1.rbhtml +5 -0
  60. data/test/data/faq/ex11-layout2.rbhtml +6 -0
  61. data/test/data/faq/ex11.rb +5 -0
  62. data/test/data/faq/ex11.rbhtml +8 -0
  63. data/test/data/faq/ex11.source +11 -0
  64. data/test/data/faq/ex11_arraybuffer.result +15 -0
  65. data/test/data/faq/ex1_chksyntax.result +3 -0
  66. data/test/data/faq/ex2-content.rbhtml +3 -0
  67. data/test/data/faq/ex2-layout.rbhtml +11 -0
  68. data/test/data/faq/ex2_removenl.result +19 -0
  69. data/test/data/faq/ex3.rb +4 -0
  70. data/test/data/faq/ex3.rbhtml +1 -0
  71. data/test/data/faq/ex3_escapefunc1.result +2 -0
  72. data/test/data/faq/ex3_escapefunc2.result +2 -0
  73. data/test/data/faq/ex5.rbhtml +7 -0
  74. data/test/data/faq/ex5_template_args.source +9 -0
  75. data/test/data/faq/ex6-content.rhtml +6 -0
  76. data/test/data/faq/ex6-layout.rhtml +6 -0
  77. data/test/data/faq/ex6.rb +10 -0
  78. data/test/data/faq/ex6_eruby.result +12 -0
  79. data/test/data/faq/ex7-expr-pattern.rb +34 -0
  80. data/test/data/faq/ex7-expr-pattern.rbhtml +3 -0
  81. data/test/data/faq/ex7_expr_pattern.result +4 -0
  82. data/test/data/faq/ex8-m18n.rb +77 -0
  83. data/test/data/faq/ex8-m18n.rbhtml +4 -0
  84. data/test/data/faq/ex8_m18n.result +10 -0
  85. data/test/data/faq/ex9-baselayout.rbhtml +8 -0
  86. data/test/data/faq/ex9-content.rbhtml +6 -0
  87. data/test/data/faq/ex9-mylayout.rbhtml +5 -0
  88. data/test/data/faq/ex9_changelayout.result +11 -0
  89. data/test/data/users_guide/content6.rbhtml +3 -0
  90. data/test/data/users_guide/content7.rbhtml +5 -0
  91. data/test/data/users_guide/content8.rbhtml +2 -0
  92. data/test/data/users_guide/contextdata.rb +7 -0
  93. data/test/data/users_guide/datafile.rb +5 -0
  94. data/test/data/users_guide/datafile.yaml +10 -0
  95. data/test/data/users_guide/ex.rbhtml +6 -0
  96. data/test/data/users_guide/ex.result +7 -0
  97. data/test/data/users_guide/ex.script +5 -0
  98. data/test/data/users_guide/ex_script.result +7 -0
  99. data/test/data/users_guide/ex_source.result +8 -0
  100. data/test/data/users_guide/example1.rbhtml +12 -0
  101. data/test/data/users_guide/example1.result +17 -0
  102. data/test/data/users_guide/example10.rbhtml +4 -0
  103. data/test/data/users_guide/example10_template_args.result +6 -0
  104. data/test/data/users_guide/example11.rbhtml +5 -0
  105. data/test/data/users_guide/example11_template_args_result +2 -0
  106. data/test/data/users_guide/example12.rbhtml +12 -0
  107. data/test/data/users_guide/example12_preprocessed.result +10 -0
  108. data/test/data/users_guide/example12_preprocessed_source.result +10 -0
  109. data/test/data/users_guide/example13.rbhtml +6 -0
  110. data/test/data/users_guide/example13_preprocessed.result +2 -0
  111. data/test/data/users_guide/example13_preprocessed_source.result +2 -0
  112. data/test/data/users_guide/example14.rb +32 -0
  113. data/test/data/users_guide/example14.rbhtml +6 -0
  114. data/test/data/users_guide/example14_tmplclass.result +15 -0
  115. data/test/data/users_guide/example15.rb +10 -0
  116. data/test/data/users_guide/example15_escapefunc.result +14 -0
  117. data/test/data/users_guide/example16.rbhtml +4 -0
  118. data/test/data/users_guide/example16a.rb +10 -0
  119. data/test/data/users_guide/example16a.result +4 -0
  120. data/test/data/users_guide/example16b.rb +13 -0
  121. data/test/data/users_guide/example16b.result +4 -0
  122. data/test/data/users_guide/example16c.rb +12 -0
  123. data/test/data/users_guide/example16c.result +4 -0
  124. data/test/data/users_guide/example1_S.result +14 -0
  125. data/test/data/users_guide/example1_SXNC.result +10 -0
  126. data/test/data/users_guide/example1_source.result +14 -0
  127. data/test/data/users_guide/example2.rbhtml +3 -0
  128. data/test/data/users_guide/example2_sb.result2 +9 -0
  129. data/test/data/users_guide/example3.rbhtml +5 -0
  130. data/test/data/users_guide/example3_syntaxcheck.result +2 -0
  131. data/test/data/users_guide/example4.rbhtml +13 -0
  132. data/test/data/users_guide/example4_datafile_rb.result +13 -0
  133. data/test/data/users_guide/example4_yaml.result +13 -0
  134. data/test/data/users_guide/example5.rbhtml +9 -0
  135. data/test/data/users_guide/example5_datastr_rb.result +9 -0
  136. data/test/data/users_guide/example5_datastr_yaml.result +9 -0
  137. data/test/data/users_guide/example6.rbhtml +19 -0
  138. data/test/data/users_guide/example6_layout.result +29 -0
  139. data/test/data/users_guide/example6_nested.result +28 -0
  140. data/test/data/users_guide/example7_layout2.result +13 -0
  141. data/test/data/users_guide/example8_layout3.result +8 -0
  142. data/test/data/users_guide/example9.rbhtml +18 -0
  143. data/test/data/users_guide/example9_capture.result +26 -0
  144. data/test/data/users_guide/footer.html +5 -0
  145. data/test/data/users_guide/footer.rbhtml +4 -0
  146. data/test/data/users_guide/layout6.rbhtml +17 -0
  147. data/test/data/users_guide/layout7.rbhtml +9 -0
  148. data/test/data/users_guide/layout8_html.rbhtml +5 -0
  149. data/test/data/users_guide/layout8_xhtml.rbhtml +6 -0
  150. data/test/data/users_guide/layout9.rbhtml +25 -0
  151. data/test/data/users_guide/sidemenu.rbhtml +5 -0
  152. data/test/data/users_guide/user_app.cgi +39 -0
  153. data/test/data/users_guide/user_app.result +30 -0
  154. data/test/data/users_guide/user_create.rbhtml +6 -0
  155. data/test/data/users_guide/user_edit.rbhtml +7 -0
  156. data/test/data/users_guide/user_form.rbhtml +10 -0
  157. data/test/data/users_guide/user_layout.rbhtml +16 -0
  158. data/test/test_all.rb +23 -0
  159. data/test/test_engine.rb +526 -0
  160. data/test/test_engine.yaml +2039 -0
  161. data/test/test_examples.rb +81 -0
  162. data/test/test_faq.rb +60 -0
  163. data/test/test_htmlhelper.rb +78 -0
  164. data/test/test_main.rb +564 -0
  165. data/test/test_main.yaml +174 -0
  166. data/test/test_template.rb +113 -0
  167. data/test/test_template.yaml +1244 -0
  168. data/test/test_users_guide.rb +75 -0
  169. data/test/testcase-helper.rb +166 -0
  170. metadata +226 -0
@@ -0,0 +1,24 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
5
+
6
+ <!--
7
+
8
+ RDoc Documentation
9
+
10
+ -->
11
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
12
+ <head>
13
+ <title>RDoc Documentation</title>
14
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
15
+ </head>
16
+ <frameset rows="20%, 80%">
17
+ <frameset cols="25%,35%,45%">
18
+ <frame src="fr_file_index.html" title="Files" name="Files" />
19
+ <frame src="fr_class_index.html" name="Classes" />
20
+ <frame src="fr_method_index.html" name="Methods" />
21
+ </frameset>
22
+ <frame src="files/README_txt.html" name="docwin" />
23
+ </frameset>
24
+ </html>
@@ -0,0 +1,208 @@
1
+
2
+ body {
3
+ font-family: Verdana,Arial,Helvetica,sans-serif;
4
+ font-size: 90%;
5
+ margin: 0;
6
+ margin-left: 40px;
7
+ padding: 0;
8
+ background: white;
9
+ }
10
+
11
+ h1,h2,h3,h4 { margin: 0; color: #efefef; background: transparent; }
12
+ h1 { font-size: 150%; }
13
+ h2,h3,h4 { margin-top: 1em; }
14
+
15
+ a { background: #eef; color: #039; text-decoration: none; }
16
+ a:hover { background: #039; color: #eef; }
17
+
18
+ /* Override the base stylesheet's Anchor inside a table cell */
19
+ td > a {
20
+ background: transparent;
21
+ color: #039;
22
+ text-decoration: none;
23
+ }
24
+
25
+ /* and inside a section title */
26
+ .section-title > a {
27
+ background: transparent;
28
+ color: #eee;
29
+ text-decoration: none;
30
+ }
31
+
32
+ /* === Structural elements =================================== */
33
+
34
+ div#index {
35
+ margin: 0;
36
+ margin-left: -40px;
37
+ padding: 0;
38
+ font-size: 90%;
39
+ }
40
+
41
+
42
+ div#index a {
43
+ margin-left: 0.7em;
44
+ }
45
+
46
+ div#index .section-bar {
47
+ margin-left: 0px;
48
+ padding-left: 0.7em;
49
+ background: #ccc;
50
+ font-size: small;
51
+ }
52
+
53
+
54
+ div#classHeader, div#fileHeader {
55
+ width: auto;
56
+ color: white;
57
+ padding: 0.5em 1.5em 0.5em 1.5em;
58
+ margin: 0;
59
+ margin-left: -40px;
60
+ border-bottom: 3px solid #006;
61
+ }
62
+
63
+ div#classHeader a, div#fileHeader a {
64
+ background: inherit;
65
+ color: white;
66
+ }
67
+
68
+ div#classHeader td, div#fileHeader td {
69
+ background: inherit;
70
+ color: white;
71
+ }
72
+
73
+
74
+ div#fileHeader {
75
+ background: #057;
76
+ }
77
+
78
+ div#classHeader {
79
+ background: #048;
80
+ }
81
+
82
+
83
+ .class-name-in-header {
84
+ font-size: 180%;
85
+ font-weight: bold;
86
+ }
87
+
88
+
89
+ div#bodyContent {
90
+ padding: 0 1.5em 0 1.5em;
91
+ }
92
+
93
+ div#description {
94
+ padding: 0.5em 1.5em;
95
+ background: #efefef;
96
+ border: 1px dotted #999;
97
+ }
98
+
99
+ div#description h1,h2,h3,h4,h5,h6 {
100
+ color: #125;;
101
+ background: transparent;
102
+ }
103
+
104
+ div#validator-badges {
105
+ text-align: center;
106
+ }
107
+ div#validator-badges img { border: 0; }
108
+
109
+ div#copyright {
110
+ color: #333;
111
+ background: #efefef;
112
+ font: 0.75em sans-serif;
113
+ margin-top: 5em;
114
+ margin-bottom: 0;
115
+ padding: 0.5em 2em;
116
+ }
117
+
118
+
119
+ /* === Classes =================================== */
120
+
121
+ table.header-table {
122
+ color: white;
123
+ font-size: small;
124
+ }
125
+
126
+ .type-note {
127
+ font-size: small;
128
+ color: #DEDEDE;
129
+ }
130
+
131
+ .xxsection-bar {
132
+ background: #eee;
133
+ color: #333;
134
+ padding: 3px;
135
+ }
136
+
137
+ .section-bar {
138
+ color: #333;
139
+ border-bottom: 1px solid #999;
140
+ margin-left: -20px;
141
+ }
142
+
143
+
144
+ .section-title {
145
+ background: #79a;
146
+ color: #eee;
147
+ padding: 3px;
148
+ margin-top: 2em;
149
+ margin-left: -30px;
150
+ border: 1px solid #999;
151
+ }
152
+
153
+ .top-aligned-row { vertical-align: top }
154
+ .bottom-aligned-row { vertical-align: bottom }
155
+
156
+ /* --- Context section classes ----------------------- */
157
+
158
+ .context-row { }
159
+ .context-item-name { font-family: monospace; font-weight: bold; color: black; }
160
+ .context-item-value { font-size: small; color: #448; }
161
+ .context-item-desc { color: #333; padding-left: 2em; }
162
+
163
+ /* --- Method classes -------------------------- */
164
+ .method-detail {
165
+ background: #efefef;
166
+ padding: 0;
167
+ margin-top: 0.5em;
168
+ margin-bottom: 1em;
169
+ border: 1px dotted #ccc;
170
+ }
171
+ .method-heading {
172
+ color: black;
173
+ background: #ccc;
174
+ border-bottom: 1px solid #666;
175
+ padding: 0.2em 0.5em 0 0.5em;
176
+ }
177
+ .method-signature { color: black; background: inherit; }
178
+ .method-name { font-weight: bold; }
179
+ .method-args { font-style: italic; }
180
+ .method-description { padding: 0 0.5em 0 0.5em; }
181
+
182
+ /* --- Source code sections -------------------- */
183
+
184
+ a.source-toggle { font-size: 90%; }
185
+ div.method-source-code {
186
+ background: #262626;
187
+ color: #ffdead;
188
+ margin: 1em;
189
+ padding: 0.5em;
190
+ border: 1px dashed #999;
191
+ overflow: hidden;
192
+ }
193
+
194
+ div.method-source-code pre { color: #ffdead; overflow: hidden; }
195
+
196
+ /* --- Ruby keyword styles --------------------- */
197
+
198
+ .standalone-code { background: #221111; color: #ffdead; overflow: hidden; }
199
+
200
+ .ruby-constant { color: #7fffd4; background: transparent; }
201
+ .ruby-keyword { color: #00ffff; background: transparent; }
202
+ .ruby-ivar { color: #eedd82; background: transparent; }
203
+ .ruby-operator { color: #00ffee; background: transparent; }
204
+ .ruby-identifier { color: #ffdead; background: transparent; }
205
+ .ruby-node { color: #ffa07a; background: transparent; }
206
+ .ruby-comment { color: #b22222; font-weight: bold; background: transparent; }
207
+ .ruby-regexp { color: #ffa07a; background: transparent; }
208
+ .ruby-value { color: #7fffd4; background: transparent; }
data/doc/docstyle.css ADDED
@@ -0,0 +1,188 @@
1
+ body {
2
+ background-color:#FFFFFF;
3
+ }
4
+
5
+ .mainbody {
6
+ color:#333333;
7
+ line-height:150%;
8
+ margin: 5px 30px 5px 30px;
9
+ }
10
+
11
+ a:link, a:active, a:hover {
12
+ color:#CC6600;
13
+ }
14
+
15
+ a:visited {
16
+ color:#DD9900;
17
+ }
18
+
19
+ p {
20
+ color:#333333;
21
+ line-height:150%;
22
+ }
23
+
24
+ pre {
25
+ width: 100%;
26
+ line-height:130%;
27
+ white-space:pre;
28
+ }
29
+
30
+ .program {
31
+ border-style:solid;
32
+ border-width:1px;
33
+ border-color:#6699FF;
34
+ color:#333333;
35
+ background-color:#DDEEFF;
36
+ padding:8px 9px 8px 9px;
37
+ margin:0px;
38
+ word-break:break-all;
39
+ }
40
+
41
+ .terminal {
42
+ border-style:solid;
43
+ border-width:1;
44
+ border-color:#999999;
45
+ color:#333333;
46
+ background-color:#E0E0E0;
47
+ padding:9px 10px 9px 10px;
48
+ margin:0px;
49
+ word-break:break-all;
50
+ }
51
+
52
+ .output {
53
+ border-style:solid;
54
+ border-width:1px;
55
+ border-color:#CCCCCC;
56
+ color:#333333;
57
+ background-color:#FFFFFF;
58
+ padding:8px 9px 8px 9px;
59
+ margin:0px;
60
+ word-break:break-all;
61
+ }
62
+
63
+
64
+ .program_caption {
65
+ margin-top: 20px;
66
+ }
67
+
68
+ .terminal_caption {
69
+ margin-top: 20px;
70
+ }
71
+
72
+ .output_caption {
73
+ margin-top: 20px;
74
+ }
75
+
76
+
77
+ ul,ol,dl {
78
+ /* margin:0px; */
79
+ /* padding:0px; */
80
+ color:#333333;
81
+ line-height:140%;
82
+ }
83
+
84
+ .dt2, .dt3 {
85
+ font-weight:bold;
86
+ }
87
+
88
+ .table1 {
89
+ padding:2px;
90
+ color:#333333;
91
+ background-color:#DDDDCC;
92
+ line-height:130%;
93
+ /*
94
+ border-width:1px;
95
+ border-style:solid;
96
+ border-color:#FFFFFF;
97
+ */
98
+ margin:5;
99
+ }
100
+
101
+ .th1, .th2 {
102
+ padding:1px;
103
+ color:#333333;
104
+ /* background-color:#DDDDCC; */
105
+ background-color:#CCCCBB;
106
+ line-height:130%;
107
+ }
108
+
109
+ .td1, .th2 {
110
+ padding:1px;
111
+ color:#333333;
112
+ background-color:#EEEEDD;
113
+ line-height:130%;
114
+ }
115
+
116
+ .caption1, .caption2 {
117
+ /* font-size:x-small; */
118
+ color:#333333;
119
+ }
120
+
121
+ .table2 {
122
+ padding:1px;
123
+ color:#333333;
124
+ background-color:#DDDDCC;
125
+ line-height:130%;
126
+ /*
127
+ border-width:1px;
128
+ border-style:solid;
129
+ border-color:#FFFFFF;
130
+ */
131
+ margin:5;
132
+ }
133
+
134
+ h1, .chapter, .doctitle {
135
+ color:#333333;
136
+ font-weight:bold;
137
+ padding:30px 0px 10px 0px;
138
+ }
139
+
140
+ h2, .section {
141
+ color:#333333;
142
+ font-weight:bold;
143
+ border-style:solid;
144
+ border-color:#6699FF;
145
+ border-width:0px 0px 2px 30px;
146
+ padding:10px 20px 0px 5px;
147
+ }
148
+
149
+ h3, .subsection {
150
+ color:#333333;
151
+ font-weight:bold;
152
+ border-style:solid;
153
+ border-color:#6699FF;
154
+ border-width: 0px 0px 0px 15px;
155
+ padding: 10px 20px 0px 5px;
156
+ }
157
+
158
+ .em {
159
+ font-weight:bold;
160
+ }
161
+
162
+ .toc {
163
+ /* font-size:small; */
164
+ /* line-height:100%; */
165
+ }
166
+
167
+ .footnote {
168
+ font-size:small;
169
+ }
170
+
171
+ .note {
172
+ background-color:#FFFFDD;
173
+ border-style:solid;
174
+ border-width:0px 1px 0px 1px;
175
+ border-color:#DDDD66;
176
+ color:#333300;
177
+ /* font-size:small; */
178
+ line-height:120%;
179
+ padding: 5px 20px 5px 20px;
180
+ }
181
+
182
+ .figure {
183
+ /*
184
+ border-width:1px;
185
+ border-color:#DDDD66;
186
+ white-space:pre;
187
+ */
188
+ }
data/doc/examples.html ADDED
@@ -0,0 +1,312 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html">
5
+ <title>rbTenjin Examples</title>
6
+ <meta name="generator" content="kwaser">
7
+ <meta http-equiv="Content-Style-Type" content="text/css">
8
+ <link rel="stylesheet" href="docstyle.css" type="text/css">
9
+ </head>
10
+ <body>
11
+
12
+ <blockquote>
13
+ <div class="mainbody">
14
+
15
+ <div align="left"><h1>rbTenjin Examples</h1></div>
16
+ <div align="left">
17
+ last update: $Date: 2007-08-04 13:23:33 +0900 (Sat, 04 Aug 2007) $<br>
18
+ </div>
19
+
20
+ <p>Release: 0.6.0
21
+ </p>
22
+ <p>Table of Contents:
23
+ <ul>
24
+ <li><a href="#bordered-table">Bordered Table</a>
25
+ </li>
26
+ <li><a href="#form">Form</a>
27
+ </li>
28
+ <li><a href="#preprocessing">Preprocessing</a>
29
+ </li>
30
+ </ul>
31
+ </p>
32
+ <a name="bordered-table"></a>
33
+ <h2 class="section1">Bordered Table</h2>
34
+ <a name="table/table.rbhtml"></a>
35
+ <div class="program_caption">
36
+ Template: 'table.rbhtml'</div>
37
+ <pre class="program">&lt;html&gt;
38
+ &lt;body&gt;
39
+ &lt;h1&gt;<strong>${@title}</strong>&lt;/h1&gt;
40
+ &lt;table&gt;
41
+ <strong>&lt;?rb i = 0 ?&gt;</strong>
42
+ <strong>&lt;?rb for item in @items ?&gt;</strong>
43
+ <strong>&lt;?rb i += 1 ?&gt;</strong>
44
+ <strong>&lt;?rb color = i % 2 == 0 ? '#FFCCCC' : '#CCCCFF' ?&gt;</strong>
45
+ &lt;tr bgcolor="<strong>#{color}</strong>"&gt;
46
+ &lt;td&gt;<strong>#{i}</strong>&lt;/td&gt;
47
+ &lt;td&gt;<strong>${item}</strong>&lt;/td&gt;
48
+ &lt;/tr&gt;
49
+ <strong>&lt;?rb end ?&gt;</strong>
50
+ &lt;/table&gt;
51
+ &lt;/body&gt;
52
+ &lt;/html&gt;
53
+ </pre>
54
+ <a name="table/table_s.result"></a>
55
+ <div class="terminal_caption">
56
+ Convert into Ruby script:</div>
57
+ <pre class="terminal">$ rbtenjin -a convert table.rbhtml
58
+ _buf = ''; _buf &lt;&lt; %Q`&lt;html&gt;
59
+ &lt;body&gt;
60
+ &lt;h1&gt;<strong>#{escape((@title).to_s)}</strong>&lt;/h1&gt;
61
+ &lt;table&gt;\n`
62
+ <strong>i = 0</strong>
63
+ <strong>for item in @items</strong>
64
+ <strong>i += 1</strong>
65
+ <strong>color = i % 2 == 0 ? '#FFCCCC' : '#CCCCFF'</strong>
66
+ _buf &lt;&lt; %Q` &lt;tr bgcolor="<strong>#{color}</strong>"&gt;
67
+ &lt;td&gt;<strong>#{i}</strong>&lt;/td&gt;
68
+ &lt;td&gt;<strong>#{escape((item).to_s)}</strong>&lt;/td&gt;
69
+ &lt;/tr&gt;\n`
70
+ <strong>end</strong>
71
+ _buf &lt;&lt; %Q` &lt;/table&gt;
72
+ &lt;/body&gt;
73
+ &lt;/html&gt;\n`
74
+ _buf.to_s
75
+ </pre>
76
+ <a name="table/table.rb"></a>
77
+ <div class="program_caption">
78
+ Main program: 'table.rb'</div>
79
+ <pre class="program">## create Engine object
80
+ require 'tenjin'
81
+ <strong>engine = Tenjin::Engine.new()</strong>
82
+
83
+ ## render template with context data
84
+ context = { :title =&gt; 'Bordered Table Example',
85
+ :items =&gt; [ '&lt;AAA&gt;', 'B&amp;B', '"CCC"' ] }
86
+ <strong>output = engine.render('table.rbhtml', context)</strong>
87
+ puts output
88
+ </pre>
89
+ <a name="table/table.result"></a>
90
+ <div class="terminal_caption">
91
+ Result:</div>
92
+ <pre class="terminal">$ ruby table.rb
93
+ &lt;html&gt;
94
+ &lt;body&gt;
95
+ &lt;h1&gt;Bordered Table Example&lt;/h1&gt;
96
+ &lt;table&gt;
97
+ &lt;tr bgcolor="<strong>#CCCCFF</strong>"&gt;
98
+ &lt;td&gt;<strong>1</strong>&lt;/td&gt;
99
+ &lt;td&gt;<strong>&amp;lt;AAA&amp;gt;</strong>&lt;/td&gt;
100
+ &lt;/tr&gt;
101
+ &lt;tr bgcolor="<strong>#FFCCCC</strong>"&gt;
102
+ &lt;td&gt;<strong>2</strong>&lt;/td&gt;
103
+ &lt;td&gt;<strong>B&amp;amp;B</strong>&lt;/td&gt;
104
+ &lt;/tr&gt;
105
+ &lt;tr bgcolor="<strong>#CCCCFF</strong>"&gt;
106
+ &lt;td&gt;<strong>3</strong>&lt;/td&gt;
107
+ &lt;td&gt;<strong>&amp;quot;CCC&amp;quot;</strong>&lt;/td&gt;
108
+ &lt;/tr&gt;
109
+ &lt;/table&gt;
110
+ &lt;/body&gt;
111
+ &lt;/html&gt;
112
+ </pre>
113
+ <br>
114
+
115
+
116
+ <a name="form"></a>
117
+ <h2 class="section1">Form</h2>
118
+ <a name="form/form.rbhtml"></a>
119
+ <div class="program_caption">
120
+ Template: 'form.rbhtml':</div>
121
+ <pre class="program"><strong>&lt;?rb #@ARGS action, params, label ?&gt;</strong>
122
+ &lt;form action="<strong>${@action}</strong>" method="post"&gt;
123
+ &lt;p&gt;
124
+ &lt;label&gt;Name:&lt;/label&gt;
125
+ &lt;input type="text" name="name" value="<strong>${@params[:name]}</strong>" /&gt;
126
+ &lt;/p&gt;
127
+ &lt;p&gt;
128
+ &lt;label&gt;Gender:&lt;/label&gt;
129
+ <strong>&lt;?rb gender = @params[:gender] ?&gt;</strong>
130
+ &lt;input type="radio" name="gender" value="M" <strong>#{checked(gender=='M')}</strong> /&gt;Man
131
+ &lt;input type="radio" name="gender" value="W" <strong>#{checked(gender=='W')}</strong> /&gt;Woman
132
+ &lt;/p&gt;
133
+ &lt;input type="submit" value="<strong>${@label}</strong>" /&gt;
134
+ &lt;/form&gt;
135
+ </pre>
136
+ <a name="form/create.rbhtml"></a>
137
+ <div class="program_caption">
138
+ Template: 'create.rbhtml':</div>
139
+ <pre class="program">&lt;?rb @title = 'Create user' ?&gt;
140
+ &lt;?rb @label = 'Create' ?&gt;
141
+ &lt;?rb @action = 'action.cgi' ?&gt;
142
+ <strong>&lt;?rb import(:form) ?&gt;</strong>
143
+ </pre>
144
+ <a name="form/update.rbhtml"></a>
145
+ <div class="program_caption">
146
+ Template: 'update.rbhtml':</div>
147
+ <pre class="program">&lt;?rb @title = 'Update user' ?&gt;
148
+ &lt;?rb @label = 'Update' ?&gt;
149
+ &lt;?rb @action = 'update.cgi' ?&gt;
150
+ <strong>&lt;?rb import(:form) ?&gt;</strong>
151
+ </pre>
152
+ <a name="form/layout.rbhtml"></a>
153
+ <div class="program_caption">
154
+ Layout template: 'layout.rbhtml'</div>
155
+ <pre class="program">&lt;html&gt;
156
+ &lt;body&gt;
157
+ &lt;h1&gt;${@title}&lt;/h1&gt;
158
+ &lt;div class="main-content"&gt;
159
+ <strong>#{@_content}</strong>
160
+ &lt;/div&gt;
161
+ &lt;/body&gt;
162
+ &lt;/html&gt;
163
+ </pre>
164
+ <a name="form/main.rb"></a>
165
+ <div class="program_caption">
166
+ Main program: 'main.rb':</div>
167
+ <pre class="program">## create Engine object
168
+ require 'tenjin'
169
+ <strong>engine = Tenjin::Engine.new(:postfix=&gt;'.rbhtml', :layout=&gt;'layout.rbhtml')</strong>
170
+
171
+ ## render template with context data
172
+ params = { :name=&gt;'Foo', :gender=&gt;'M' }
173
+ context = { :params=&gt;params }
174
+ <strong>output = engine.render(:update, context)</strong> # :update == 'update'+postfix
175
+ puts output
176
+ </pre>
177
+ <a name="form/main.result"></a>
178
+ <div class="terminal_caption">
179
+ Result:</div>
180
+ <pre class="terminal">$ ruby main.rb
181
+ &lt;html&gt;
182
+ &lt;body&gt;
183
+ &lt;h1&gt;<strong>Update user</strong>&lt;/h1&gt;
184
+ &lt;div class="main-content"&gt;
185
+ &lt;form action="<strong>update.cgi</strong>" method="post"&gt;
186
+ &lt;p&gt;
187
+ &lt;label&gt;Name:&lt;/label&gt;
188
+ &lt;input type="text" name="name" value="<strong>Foo</strong>" /&gt;
189
+ &lt;/p&gt;
190
+ &lt;p&gt;
191
+ &lt;label&gt;Gender:&lt;/label&gt;
192
+ &lt;input type="radio" name="gender" value="M" <strong> checked="checked"</strong> /&gt;Man
193
+ &lt;input type="radio" name="gender" value="W" /&gt;Woman
194
+ &lt;/p&gt;
195
+ &lt;input type="submit" value="<strong>Update</strong>" /&gt;
196
+ &lt;/form&gt;
197
+
198
+ &lt;/div&gt;
199
+ &lt;/body&gt;
200
+ &lt;/html&gt;
201
+ </pre>
202
+ <br>
203
+
204
+
205
+ <a name="preprocessing"></a>
206
+ <h2 class="section1">Preprocessing</h2>
207
+ <a name="preprocessing/helper.rb"></a>
208
+ <div class="program_caption">
209
+ Library: 'helper.rb'</div>
210
+ <pre class="program">LANGUAGES = [
211
+ ['en', 'Engilish'],
212
+ ['fr', 'French'],
213
+ ['de', 'German'],
214
+ ['es', 'Spanish'],
215
+ ['ch', 'Chinese'],
216
+ ['ja', 'Japanese'],
217
+ ]
218
+
219
+ def link_to(label, options={})
220
+ action, id = options[:action], options[:id]
221
+ url = '/app'
222
+ url &lt;&lt; '/' &lt;&lt; action if action &amp;&amp; !action.empty?
223
+ url &lt;&lt; '/' &lt;&lt; id if id
224
+ return "&lt;a href=\"#{CGI::escape(url).gsub(/%2F/i, '/')}\"&gt;#{label}&lt;/a&gt;"
225
+ end
226
+ </pre>
227
+ <a name="preprocessing/select.rbhtml"></a>
228
+ <div class="program_caption">
229
+ Template: 'select.rbhtml'</div>
230
+ <pre class="program">&lt;?RB require 'helper' ?&gt;
231
+ &lt;form&gt;
232
+ &lt;label&gt;Select your language:&lt;/label&gt;
233
+ &lt;select name="lang"&gt;
234
+ &lt;?rb table = { @params[:lang] =&gt; ' selected="selected"' } ?&gt;
235
+ <strong>&lt;?RB for val, name in LANGUAGES ?&gt;</strong>
236
+ &lt;option value="${{val}}" #{table[#{{val.inspect}}]}&gt;${{name}}&lt;/option&gt;
237
+ <strong>&lt;?RB end ?&gt;</strong>
238
+ &lt;/select&gt;
239
+ &lt;input type="submit" value="OK" /&gt;
240
+ &lt;/form&gt;
241
+ &lt;p&gt;
242
+ <strong>#{{</strong>link_to('Back', :action=&gt;'index')<strong>}}</strong> |
243
+ <strong>#{{</strong>link_to('Show '+<strong>_P('@params[:name]')</strong>, :action=&gt;'show', :id=&gt;<strong>_p('@params[:id]')</strong>)<strong>}}</strong>
244
+ &lt;/p&gt;
245
+ </pre>
246
+ <a name="preprocessing/select_P.result"></a>
247
+ <div class="terminal_caption">
248
+ Preprocessed code:</div>
249
+ <pre class="terminal">$ rbtenjin -a preprocess select.rbhtml
250
+ &lt;form&gt;
251
+ &lt;label&gt;Select your language:&lt;/label&gt;
252
+ &lt;select name="lang"&gt;
253
+ &lt;?rb table = { @params[:lang] =&gt; ' selected="selected"' } ?&gt;
254
+ &lt;option value="en" #{table["en"]}&gt;Engilish&lt;/option&gt;
255
+ &lt;option value="fr" #{table["fr"]}&gt;French&lt;/option&gt;
256
+ &lt;option value="de" #{table["de"]}&gt;German&lt;/option&gt;
257
+ &lt;option value="es" #{table["es"]}&gt;Spanish&lt;/option&gt;
258
+ &lt;option value="ch" #{table["ch"]}&gt;Chinese&lt;/option&gt;
259
+ &lt;option value="ja" #{table["ja"]}&gt;Japanese&lt;/option&gt;
260
+ &lt;/select&gt;
261
+ &lt;input type="submit" value="OK" /&gt;
262
+ &lt;/form&gt;
263
+ &lt;p&gt;
264
+ &lt;a href="/app/index"&gt;Back&lt;/a&gt; |
265
+ &lt;a href="/app/show/<strong>#{@params[:id]}</strong>"&gt;Show <strong>${@params[:name]}</strong>&lt;/a&gt;
266
+ &lt;/p&gt;
267
+ </pre>
268
+ <a name="preprocessing/main.rb"></a>
269
+ <div class="program_caption">
270
+ Main program: 'main.rb'</div>
271
+ <pre class="program">require 'helper'
272
+
273
+ ## create engine
274
+ require 'tenjin'
275
+ engine = Tenjin::Engine.new(:postfix=&gt;'.rbhtml', <strong>:preprocess=&gt;true</strong>)
276
+
277
+ ## render template with context data
278
+ params = { :id=&gt;1234, :name=&gt;'Foo', :lang=&gt;'ch' }
279
+ context = { :params =&gt; params }
280
+ output = engine.render(:select, context)
281
+ puts output
282
+ </pre>
283
+ <a name="preprocessing/main.result"></a>
284
+ <div class="terminal_caption">
285
+ Result:</div>
286
+ <pre class="terminal">$ ruby main.rb
287
+ &lt;form&gt;
288
+ &lt;label&gt;Select your language:&lt;/label&gt;
289
+ &lt;select name="lang"&gt;
290
+ &lt;option value="en" &gt;Engilish&lt;/option&gt;
291
+ &lt;option value="fr" &gt;French&lt;/option&gt;
292
+ &lt;option value="de" &gt;German&lt;/option&gt;
293
+ &lt;option value="es" &gt;Spanish&lt;/option&gt;
294
+ &lt;option value="ch" selected="selected"&gt;Chinese&lt;/option&gt;
295
+ &lt;option value="ja" &gt;Japanese&lt;/option&gt;
296
+ &lt;/select&gt;
297
+ &lt;input type="submit" value="OK" /&gt;
298
+ &lt;/form&gt;
299
+ &lt;p&gt;
300
+ &lt;a href="/app/index"&gt;Back&lt;/a&gt; |
301
+ &lt;a href="/app/show/1234"&gt;Show Foo&lt;/a&gt;
302
+ &lt;/p&gt;
303
+ </pre>
304
+ <br>
305
+
306
+
307
+
308
+ </div>
309
+ </blockquote>
310
+
311
+ </body>
312
+ </html>