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,616 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>Class: Tenjin::Engine</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="classHeader">
50
+ <table class="header-table">
51
+ <tr class="top-aligned-row">
52
+ <td><strong>Class</strong></td>
53
+ <td class="class-name-in-header">Tenjin::Engine</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../../files/lib/tenjin_rb.html">
59
+ lib/tenjin.rb
60
+ </a>
61
+ <br />
62
+ </td>
63
+ </tr>
64
+
65
+ <tr class="top-aligned-row">
66
+ <td><strong>Parent:</strong></td>
67
+ <td>
68
+ Object
69
+ </td>
70
+ </tr>
71
+ </table>
72
+ </div>
73
+ <!-- banner header -->
74
+
75
+ <div id="bodyContent">
76
+
77
+
78
+
79
+ <div id="contextContent">
80
+
81
+ <div id="description">
82
+ <p>
83
+ engine class for templates
84
+ </p>
85
+ <p>
86
+ <a href="Engine.html">Engine</a> class supports the followings.
87
+ </p>
88
+ <ul>
89
+ <li>template caching
90
+
91
+ </li>
92
+ <li>partial template
93
+
94
+ </li>
95
+ <li>layout template
96
+
97
+ </li>
98
+ <li>capturing (experimental)
99
+
100
+ </li>
101
+ </ul>
102
+ <p>
103
+ ex. file &#8216;ex_list.rbhtml&#8216;
104
+ </p>
105
+ <pre>
106
+ &lt;ul&gt;
107
+ &lt;?rb for item in @items ?&gt;
108
+ &lt;li&gt;#{item}&lt;/li&gt;
109
+ &lt;?rb end ?&gt;
110
+ &lt;/ul&gt;
111
+ </pre>
112
+ <p>
113
+ ex. file &#8216;ex_layout.rbhtml&#8216;
114
+ </p>
115
+ <pre>
116
+ &lt;html&gt;
117
+ &lt;body&gt;
118
+ &lt;h1&gt;${@title}&lt;/li&gt;
119
+ #{@_content}
120
+ &lt;?rb import 'footer.rbhtml' ?&gt;
121
+ &lt;/body&gt;
122
+ &lt;/html&gt;
123
+ </pre>
124
+ <p>
125
+ ex. file &#8216;main.rb&#8216;
126
+ </p>
127
+ <pre>
128
+ require 'tenjin'
129
+ options = {:prefix=&gt;'ex_', :postfix=&gt;'.rbhtml', :layout=&gt;'ex_layout.rbhtml'}
130
+ engine = Tenjin::Engine.new(options)
131
+ context = {:title=&gt;'Tenjin Example', :items=&gt;['foo', 'bar', 'baz']}
132
+ output = engine.render(:list, context) # or 'ex_list.rbhtml'
133
+ print output
134
+ </pre>
135
+
136
+ </div>
137
+
138
+
139
+ </div>
140
+
141
+ <div id="method-list">
142
+ <h3 class="section-bar">Methods</h3>
143
+
144
+ <div class="name-list">
145
+ <a href="#M000034">cachename</a>&nbsp;&nbsp;
146
+ <a href="#M000035">create_template</a>&nbsp;&nbsp;
147
+ <a href="#M000031">find_template_file</a>&nbsp;&nbsp;
148
+ <a href="#M000038">get_template</a>&nbsp;&nbsp;
149
+ <a href="#M000040">hook_context</a>&nbsp;&nbsp;
150
+ <a href="#M000037">load_cachefile</a>&nbsp;&nbsp;
151
+ <a href="#M000029">new</a>&nbsp;&nbsp;
152
+ <a href="#M000032">read_template_file</a>&nbsp;&nbsp;
153
+ <a href="#M000033">register_template</a>&nbsp;&nbsp;
154
+ <a href="#M000039">render</a>&nbsp;&nbsp;
155
+ <a href="#M000036">store_cachefile</a>&nbsp;&nbsp;
156
+ <a href="#M000030">to_filename</a>&nbsp;&nbsp;
157
+ </div>
158
+ </div>
159
+
160
+ </div>
161
+
162
+
163
+ <!-- if includes -->
164
+
165
+ <div id="section">
166
+
167
+
168
+
169
+
170
+
171
+
172
+
173
+
174
+ <!-- if method_list -->
175
+ <div id="methods">
176
+ <h3 class="section-bar">Public Class methods</h3>
177
+
178
+ <div id="method-M000029" class="method-detail">
179
+ <a name="M000029"></a>
180
+
181
+ <div class="method-heading">
182
+ <a href="#M000029" class="method-signature">
183
+ <span class="method-name">new</span><span class="method-args">(options={})</span>
184
+ </a>
185
+ </div>
186
+
187
+ <div class="method-description">
188
+ <p>
189
+ initializer of <a href="Engine.html">Engine</a> class.
190
+ </p>
191
+ <p>
192
+ options:
193
+ </p>
194
+ <table>
195
+ <tr><td valign="top">:prefix :</td><td>prefix string for template name (ex. &#8216;template/&#8217;)
196
+
197
+ </td></tr>
198
+ <tr><td valign="top">:postfix :</td><td>postfix string for template name (ex. &#8217;.rbhtml&#8217;)
199
+
200
+ </td></tr>
201
+ <tr><td valign="top">:layout :</td><td>layout template name (default nil)
202
+
203
+ </td></tr>
204
+ <tr><td valign="top">:path :</td><td>array of directory name (default nil)
205
+
206
+ </td></tr>
207
+ <tr><td valign="top">:cache :</td><td>save converted ruby code into file or not (default true)
208
+
209
+ </td></tr>
210
+ <tr><td valign="top">:path :</td><td>list of directory (default nil)
211
+
212
+ </td></tr>
213
+ <tr><td valign="top">:preprocess :</td><td>flag to activate preprocessing (default nil)
214
+
215
+ </td></tr>
216
+ <tr><td valign="top">:templateclass :</td><td>template class object (default <a
217
+ href="Template.html">Tenjin::Template</a>)
218
+
219
+ </td></tr>
220
+ </table>
221
+ <p><a class="source-toggle" href="#"
222
+ onclick="toggleCode('M000029-source');return false;">[Source]</a></p>
223
+ <div class="method-source-code" id="M000029-source">
224
+ <pre>
225
+ <span class="ruby-comment cmt"># File lib/tenjin.rb, line 812</span>
226
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">options</span>={})
227
+ <span class="ruby-ivar">@prefix</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:prefix</span>] <span class="ruby-operator">||</span> <span class="ruby-value str">''</span>
228
+ <span class="ruby-ivar">@postfix</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:postfix</span>] <span class="ruby-operator">||</span> <span class="ruby-value str">''</span>
229
+ <span class="ruby-ivar">@layout</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:layout</span>]
230
+ <span class="ruby-ivar">@cache</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">fetch</span>(<span class="ruby-identifier">:cache</span>, <span class="ruby-keyword kw">true</span>)
231
+ <span class="ruby-ivar">@path</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:path</span>]
232
+ <span class="ruby-ivar">@preprocess</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">fetch</span>(<span class="ruby-identifier">:preprocess</span>, <span class="ruby-keyword kw">nil</span>)
233
+ <span class="ruby-ivar">@templateclass</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">fetch</span>(<span class="ruby-identifier">:templateclass</span>, <span class="ruby-constant">Template</span>)
234
+ <span class="ruby-ivar">@init_opts_for_template</span> = <span class="ruby-identifier">options</span>
235
+ <span class="ruby-ivar">@templates</span> = {} <span class="ruby-comment cmt"># filename-&gt;template</span>
236
+ <span class="ruby-keyword kw">end</span>
237
+ </pre>
238
+ </div>
239
+ </div>
240
+ </div>
241
+
242
+ <h3 class="section-bar">Public Instance methods</h3>
243
+
244
+ <div id="method-M000034" class="method-detail">
245
+ <a name="M000034"></a>
246
+
247
+ <div class="method-heading">
248
+ <a href="#M000034" class="method-signature">
249
+ <span class="method-name">cachename</span><span class="method-args">(filename)</span>
250
+ </a>
251
+ </div>
252
+
253
+ <div class="method-description">
254
+ <p><a class="source-toggle" href="#"
255
+ onclick="toggleCode('M000034-source');return false;">[Source]</a></p>
256
+ <div class="method-source-code" id="M000034-source">
257
+ <pre>
258
+ <span class="ruby-comment cmt"># File lib/tenjin.rb, line 861</span>
259
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">cachename</span>(<span class="ruby-identifier">filename</span>)
260
+ <span class="ruby-keyword kw">return</span> (<span class="ruby-identifier">filename</span> <span class="ruby-operator">+</span> <span class="ruby-value str">'.cache'</span>).<span class="ruby-identifier">untaint</span>
261
+ <span class="ruby-keyword kw">end</span>
262
+ </pre>
263
+ </div>
264
+ </div>
265
+ </div>
266
+
267
+ <div id="method-M000035" class="method-detail">
268
+ <a name="M000035"></a>
269
+
270
+ <div class="method-heading">
271
+ <a href="#M000035" class="method-signature">
272
+ <span class="method-name">create_template</span><span class="method-args">(filename, _context=nil)</span>
273
+ </a>
274
+ </div>
275
+
276
+ <div class="method-description">
277
+ <p>
278
+ create template object from file
279
+ </p>
280
+ <p><a class="source-toggle" href="#"
281
+ onclick="toggleCode('M000035-source');return false;">[Source]</a></p>
282
+ <div class="method-source-code" id="M000035-source">
283
+ <pre>
284
+ <span class="ruby-comment cmt"># File lib/tenjin.rb, line 866</span>
285
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">create_template</span>(<span class="ruby-identifier">filename</span>, <span class="ruby-identifier">_context</span>=<span class="ruby-keyword kw">nil</span>)
286
+ <span class="ruby-identifier">template</span> = <span class="ruby-ivar">@templateclass</span>.<span class="ruby-identifier">new</span>(<span class="ruby-keyword kw">nil</span>, <span class="ruby-ivar">@init_opts_for_template</span>)
287
+ <span class="ruby-identifier">template</span>.<span class="ruby-identifier">timestamp</span> = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>()
288
+ <span class="ruby-identifier">cache_filename</span> = <span class="ruby-identifier">cachename</span>(<span class="ruby-identifier">filename</span>)
289
+ <span class="ruby-identifier">_context</span> = <span class="ruby-identifier">hook_context</span>(<span class="ruby-constant">Context</span>.<span class="ruby-identifier">new</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">_context</span>.<span class="ruby-identifier">nil?</span>
290
+ <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-ivar">@cache</span>
291
+ <span class="ruby-identifier">input</span> = <span class="ruby-identifier">read_template_file</span>(<span class="ruby-identifier">filename</span>, <span class="ruby-identifier">_context</span>)
292
+ <span class="ruby-identifier">template</span>.<span class="ruby-identifier">convert</span>(<span class="ruby-identifier">input</span>, <span class="ruby-identifier">filename</span>)
293
+ <span class="ruby-keyword kw">elsif</span> <span class="ruby-operator">!</span><span class="ruby-identifier">test</span>(<span class="ruby-value">?f</span>, <span class="ruby-identifier">cache_filename</span>) <span class="ruby-operator">||</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">mtime</span>(<span class="ruby-identifier">cache_filename</span>) <span class="ruby-operator">&lt;</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">mtime</span>(<span class="ruby-identifier">filename</span>)
294
+ <span class="ruby-comment cmt">#$stderr.puts &quot;*** debug: load original&quot;</span>
295
+ <span class="ruby-identifier">input</span> = <span class="ruby-identifier">read_template_file</span>(<span class="ruby-identifier">filename</span>, <span class="ruby-identifier">_context</span>)
296
+ <span class="ruby-identifier">template</span>.<span class="ruby-identifier">convert</span>(<span class="ruby-identifier">input</span>, <span class="ruby-identifier">filename</span>)
297
+ <span class="ruby-identifier">store_cachefile</span>(<span class="ruby-identifier">cache_filename</span>, <span class="ruby-identifier">template</span>)
298
+ <span class="ruby-keyword kw">else</span>
299
+ <span class="ruby-comment cmt">#$stderr.puts &quot;*** debug: load cache&quot;</span>
300
+ <span class="ruby-identifier">template</span>.<span class="ruby-identifier">filename</span> = <span class="ruby-identifier">filename</span>
301
+ <span class="ruby-identifier">load_cachefile</span>(<span class="ruby-identifier">cache_filename</span>, <span class="ruby-identifier">template</span>)
302
+ <span class="ruby-keyword kw">end</span>
303
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">template</span>
304
+ <span class="ruby-keyword kw">end</span>
305
+ </pre>
306
+ </div>
307
+ </div>
308
+ </div>
309
+
310
+ <div id="method-M000031" class="method-detail">
311
+ <a name="M000031"></a>
312
+
313
+ <div class="method-heading">
314
+ <a href="#M000031" class="method-signature">
315
+ <span class="method-name">find_template_file</span><span class="method-args">(template_name)</span>
316
+ </a>
317
+ </div>
318
+
319
+ <div class="method-description">
320
+ <p>
321
+ find template filename
322
+ </p>
323
+ <p><a class="source-toggle" href="#"
324
+ onclick="toggleCode('M000031-source');return false;">[Source]</a></p>
325
+ <div class="method-source-code" id="M000031-source">
326
+ <pre>
327
+ <span class="ruby-comment cmt"># File lib/tenjin.rb, line 831</span>
328
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">find_template_file</span>(<span class="ruby-identifier">template_name</span>)
329
+ <span class="ruby-identifier">filename</span> = <span class="ruby-identifier">to_filename</span>(<span class="ruby-identifier">template_name</span>)
330
+ <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@path</span>
331
+ <span class="ruby-keyword kw">for</span> <span class="ruby-identifier">dir</span> <span class="ruby-keyword kw">in</span> <span class="ruby-ivar">@path</span>
332
+ <span class="ruby-identifier">filepath</span> = <span class="ruby-node">&quot;#{dir}#{File::SEPARATOR}#{filename}&quot;</span>
333
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">filepath</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">test</span>(<span class="ruby-value">?f</span>, <span class="ruby-identifier">filepath</span>.<span class="ruby-identifier">untaint</span>)
334
+ <span class="ruby-keyword kw">end</span>
335
+ <span class="ruby-keyword kw">else</span>
336
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">filename</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">test</span>(<span class="ruby-value">?f</span>, <span class="ruby-identifier">filename</span>.<span class="ruby-identifier">dup</span>.<span class="ruby-identifier">untaint</span>) <span class="ruby-comment cmt"># dup is required for frozen string</span>
337
+ <span class="ruby-keyword kw">end</span>
338
+ <span class="ruby-identifier">raise</span> <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">ENOENT</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">&quot;#{filename} (path=#{@path.inspect})&quot;</span>)
339
+ <span class="ruby-keyword kw">end</span>
340
+ </pre>
341
+ </div>
342
+ </div>
343
+ </div>
344
+
345
+ <div id="method-M000038" class="method-detail">
346
+ <a name="M000038"></a>
347
+
348
+ <div class="method-heading">
349
+ <a href="#M000038" class="method-signature">
350
+ <span class="method-name">get_template</span><span class="method-args">(template_name, _context=nil)</span>
351
+ </a>
352
+ </div>
353
+
354
+ <div class="method-description">
355
+ <p>
356
+ get template object
357
+ </p>
358
+ <p><a class="source-toggle" href="#"
359
+ onclick="toggleCode('M000038-source');return false;">[Source]</a></p>
360
+ <div class="method-source-code" id="M000038-source">
361
+ <pre>
362
+ <span class="ruby-comment cmt"># File lib/tenjin.rb, line 908</span>
363
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">get_template</span>(<span class="ruby-identifier">template_name</span>, <span class="ruby-identifier">_context</span>=<span class="ruby-keyword kw">nil</span>)
364
+ <span class="ruby-identifier">template</span> = <span class="ruby-ivar">@templates</span>[<span class="ruby-identifier">template_name</span>]
365
+ <span class="ruby-identifier">t</span> = <span class="ruby-identifier">template</span>
366
+ <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">t</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">t</span>.<span class="ruby-identifier">timestamp</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">t</span>.<span class="ruby-identifier">filename</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">t</span>.<span class="ruby-identifier">timestamp</span> <span class="ruby-operator">&gt;=</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">mtime</span>(<span class="ruby-identifier">t</span>.<span class="ruby-identifier">filename</span>)
367
+ <span class="ruby-identifier">filename</span> = <span class="ruby-identifier">find_template_file</span>(<span class="ruby-identifier">template_name</span>)
368
+ <span class="ruby-identifier">template</span> = <span class="ruby-identifier">create_template</span>(<span class="ruby-identifier">filename</span>, <span class="ruby-identifier">_context</span>) <span class="ruby-comment cmt"># _context is passed only for preprocessor</span>
369
+ <span class="ruby-identifier">register_template</span>(<span class="ruby-identifier">template_name</span>, <span class="ruby-identifier">template</span>)
370
+ <span class="ruby-keyword kw">end</span>
371
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">template</span>
372
+ <span class="ruby-keyword kw">end</span>
373
+ </pre>
374
+ </div>
375
+ </div>
376
+ </div>
377
+
378
+ <div id="method-M000040" class="method-detail">
379
+ <a name="M000040"></a>
380
+
381
+ <div class="method-heading">
382
+ <a href="#M000040" class="method-signature">
383
+ <span class="method-name">hook_context</span><span class="method-args">(context)</span>
384
+ </a>
385
+ </div>
386
+
387
+ <div class="method-description">
388
+ <p><a class="source-toggle" href="#"
389
+ onclick="toggleCode('M000040-source');return false;">[Source]</a></p>
390
+ <div class="method-source-code" id="M000040-source">
391
+ <pre>
392
+ <span class="ruby-comment cmt"># File lib/tenjin.rb, line 945</span>
393
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">hook_context</span>(<span class="ruby-identifier">context</span>)
394
+ <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">context</span>
395
+ <span class="ruby-identifier">context</span> = <span class="ruby-constant">Context</span>.<span class="ruby-identifier">new</span>
396
+ <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">context</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>)
397
+ <span class="ruby-identifier">context</span> = <span class="ruby-constant">Context</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">context</span>)
398
+ <span class="ruby-keyword kw">end</span>
399
+ <span class="ruby-identifier">context</span>.<span class="ruby-identifier">_engine</span> = <span class="ruby-keyword kw">self</span>
400
+ <span class="ruby-identifier">context</span>.<span class="ruby-identifier">_layout</span> = <span class="ruby-keyword kw">nil</span>
401
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">context</span>
402
+ <span class="ruby-keyword kw">end</span>
403
+ </pre>
404
+ </div>
405
+ </div>
406
+ </div>
407
+
408
+ <div id="method-M000037" class="method-detail">
409
+ <a name="M000037"></a>
410
+
411
+ <div class="method-heading">
412
+ <a href="#M000037" class="method-signature">
413
+ <span class="method-name">load_cachefile</span><span class="method-args">(cache_filename, template)</span>
414
+ </a>
415
+ </div>
416
+
417
+ <div class="method-description">
418
+ <p>
419
+ load template from cache file
420
+ </p>
421
+ <p><a class="source-toggle" href="#"
422
+ onclick="toggleCode('M000037-source');return false;">[Source]</a></p>
423
+ <div class="method-source-code" id="M000037-source">
424
+ <pre>
425
+ <span class="ruby-comment cmt"># File lib/tenjin.rb, line 899</span>
426
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">load_cachefile</span>(<span class="ruby-identifier">cache_filename</span>, <span class="ruby-identifier">template</span>)
427
+ <span class="ruby-identifier">s</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">cache_filename</span>)
428
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">sub!</span>(<span class="ruby-regexp re">/\A\#\@ARGS (.*?)\r?\n/</span>, <span class="ruby-value str">''</span>)
429
+ <span class="ruby-identifier">template</span>.<span class="ruby-identifier">args</span> = <span class="ruby-identifier">$1</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">','</span>)
430
+ <span class="ruby-keyword kw">end</span>
431
+ <span class="ruby-identifier">template</span>.<span class="ruby-identifier">script</span> = <span class="ruby-identifier">s</span>
432
+ <span class="ruby-keyword kw">end</span>
433
+ </pre>
434
+ </div>
435
+ </div>
436
+ </div>
437
+
438
+ <div id="method-M000032" class="method-detail">
439
+ <a name="M000032"></a>
440
+
441
+ <div class="method-heading">
442
+ <a href="#M000032" class="method-signature">
443
+ <span class="method-name">read_template_file</span><span class="method-args">(filename, _context)</span>
444
+ </a>
445
+ </div>
446
+
447
+ <div class="method-description">
448
+ <p>
449
+ read template file and preprocess it
450
+ </p>
451
+ <p><a class="source-toggle" href="#"
452
+ onclick="toggleCode('M000032-source');return false;">[Source]</a></p>
453
+ <div class="method-source-code" id="M000032-source">
454
+ <pre>
455
+ <span class="ruby-comment cmt"># File lib/tenjin.rb, line 845</span>
456
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">read_template_file</span>(<span class="ruby-identifier">filename</span>, <span class="ruby-identifier">_context</span>)
457
+ <span class="ruby-keyword kw">return</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">filename</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-ivar">@preprocess</span>
458
+ <span class="ruby-identifier">_context</span> <span class="ruby-operator">||=</span> {}
459
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">_context</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">_context</span>.<span class="ruby-identifier">_engine</span>.<span class="ruby-identifier">nil?</span>
460
+ <span class="ruby-identifier">_context</span> = <span class="ruby-identifier">hook_context</span>(<span class="ruby-identifier">_context</span>)
461
+ <span class="ruby-keyword kw">end</span>
462
+ <span class="ruby-identifier">preprocessor</span> = <span class="ruby-constant">Preprocessor</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">filename</span>)
463
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">preprocessor</span>.<span class="ruby-identifier">render</span>(<span class="ruby-identifier">_context</span>)
464
+ <span class="ruby-keyword kw">end</span>
465
+ </pre>
466
+ </div>
467
+ </div>
468
+ </div>
469
+
470
+ <div id="method-M000033" class="method-detail">
471
+ <a name="M000033"></a>
472
+
473
+ <div class="method-heading">
474
+ <a href="#M000033" class="method-signature">
475
+ <span class="method-name">register_template</span><span class="method-args">(template_name, template)</span>
476
+ </a>
477
+ </div>
478
+
479
+ <div class="method-description">
480
+ <p>
481
+ register template object
482
+ </p>
483
+ <p><a class="source-toggle" href="#"
484
+ onclick="toggleCode('M000033-source');return false;">[Source]</a></p>
485
+ <div class="method-source-code" id="M000033-source">
486
+ <pre>
487
+ <span class="ruby-comment cmt"># File lib/tenjin.rb, line 856</span>
488
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">register_template</span>(<span class="ruby-identifier">template_name</span>, <span class="ruby-identifier">template</span>)
489
+ <span class="ruby-comment cmt">#template.timestamp = Time.new unless template.timestamp</span>
490
+ <span class="ruby-ivar">@templates</span>[<span class="ruby-identifier">template_name</span>] = <span class="ruby-identifier">template</span>
491
+ <span class="ruby-keyword kw">end</span>
492
+ </pre>
493
+ </div>
494
+ </div>
495
+ </div>
496
+
497
+ <div id="method-M000039" class="method-detail">
498
+ <a name="M000039"></a>
499
+
500
+ <div class="method-heading">
501
+ <a href="#M000039" class="method-signature">
502
+ <span class="method-name">render</span><span class="method-args">(template_name, context=Context.new, layout=true)</span>
503
+ </a>
504
+ </div>
505
+
506
+ <div class="method-description">
507
+ <p>
508
+ get template object and evaluate it with context object. if argument
509
+ &#8216;layout&#8217; is true then default layout file (specified at
510
+ initializer) is used as layout template, else if false then no layout
511
+ template is used. if argument &#8216;layout&#8217; is string, it is
512
+ regarded as layout template name.
513
+ </p>
514
+ <p><a class="source-toggle" href="#"
515
+ onclick="toggleCode('M000039-source');return false;">[Source]</a></p>
516
+ <div class="method-source-code" id="M000039-source">
517
+ <pre>
518
+ <span class="ruby-comment cmt"># File lib/tenjin.rb, line 924</span>
519
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">render</span>(<span class="ruby-identifier">template_name</span>, <span class="ruby-identifier">context</span>=<span class="ruby-constant">Context</span>.<span class="ruby-identifier">new</span>, <span class="ruby-identifier">layout</span>=<span class="ruby-keyword kw">true</span>)
520
+ <span class="ruby-comment cmt">#context = Context.new(context) if context.is_a?(Hash)</span>
521
+ <span class="ruby-identifier">context</span> = <span class="ruby-identifier">hook_context</span>(<span class="ruby-identifier">context</span>)
522
+ <span class="ruby-keyword kw">while</span> <span class="ruby-keyword kw">true</span>
523
+ <span class="ruby-identifier">template</span> = <span class="ruby-identifier">get_template</span>(<span class="ruby-identifier">template_name</span>, <span class="ruby-identifier">context</span>) <span class="ruby-comment cmt"># context is passed only for preprocessor</span>
524
+ <span class="ruby-identifier">_buf</span> = <span class="ruby-identifier">context</span>.<span class="ruby-identifier">_buf</span>
525
+ <span class="ruby-identifier">output</span> = <span class="ruby-identifier">template</span>.<span class="ruby-identifier">render</span>(<span class="ruby-identifier">context</span>)
526
+ <span class="ruby-identifier">context</span>.<span class="ruby-identifier">_buf</span> = <span class="ruby-identifier">_buf</span>
527
+ <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">context</span>[<span class="ruby-value str">'_layout'</span>].<span class="ruby-identifier">nil?</span>
528
+ <span class="ruby-identifier">layout</span> = <span class="ruby-identifier">context</span>[<span class="ruby-value str">'_layout'</span>]
529
+ <span class="ruby-identifier">context</span>[<span class="ruby-value str">'_layout'</span>] = <span class="ruby-keyword kw">nil</span>
530
+ <span class="ruby-keyword kw">end</span>
531
+ <span class="ruby-identifier">layout</span> = <span class="ruby-ivar">@layout</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">layout</span> <span class="ruby-operator">==</span> <span class="ruby-keyword kw">true</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">layout</span>.<span class="ruby-identifier">nil?</span>
532
+ <span class="ruby-keyword kw">break</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">layout</span>
533
+ <span class="ruby-identifier">template_name</span> = <span class="ruby-identifier">layout</span>
534
+ <span class="ruby-identifier">layout</span> = <span class="ruby-keyword kw">false</span>
535
+ <span class="ruby-identifier">context</span>[<span class="ruby-value str">'_content'</span>] = <span class="ruby-identifier">output</span>
536
+ <span class="ruby-keyword kw">end</span>
537
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">output</span>
538
+ <span class="ruby-keyword kw">end</span>
539
+ </pre>
540
+ </div>
541
+ </div>
542
+ </div>
543
+
544
+ <div id="method-M000036" class="method-detail">
545
+ <a name="M000036"></a>
546
+
547
+ <div class="method-heading">
548
+ <a href="#M000036" class="method-signature">
549
+ <span class="method-name">store_cachefile</span><span class="method-args">(cache_filename, template)</span>
550
+ </a>
551
+ </div>
552
+
553
+ <div class="method-description">
554
+ <p>
555
+ store template into cache file
556
+ </p>
557
+ <p><a class="source-toggle" href="#"
558
+ onclick="toggleCode('M000036-source');return false;">[Source]</a></p>
559
+ <div class="method-source-code" id="M000036-source">
560
+ <pre>
561
+ <span class="ruby-comment cmt"># File lib/tenjin.rb, line 888</span>
562
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">store_cachefile</span>(<span class="ruby-identifier">cache_filename</span>, <span class="ruby-identifier">template</span>)
563
+ <span class="ruby-identifier">s</span> = <span class="ruby-identifier">template</span>.<span class="ruby-identifier">script</span>
564
+ <span class="ruby-identifier">s</span> = <span class="ruby-node">&quot;\#@ARGS #{template.args.join(',')}\n#{s}&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">template</span>.<span class="ruby-identifier">args</span>
565
+ <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">cache_filename</span>, <span class="ruby-value str">'w'</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span>
566
+ <span class="ruby-identifier">f</span>.<span class="ruby-identifier">flock</span>(<span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-constant">LOCK_EX</span>)
567
+ <span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-identifier">s</span>)
568
+ <span class="ruby-comment cmt">#f.lock(FIle::LOCK_UN) # File#close() unlocks automatically</span>
569
+ <span class="ruby-keyword kw">end</span>
570
+ <span class="ruby-keyword kw">end</span>
571
+ </pre>
572
+ </div>
573
+ </div>
574
+ </div>
575
+
576
+ <div id="method-M000030" class="method-detail">
577
+ <a name="M000030"></a>
578
+
579
+ <div class="method-heading">
580
+ <a href="#M000030" class="method-signature">
581
+ <span class="method-name">to_filename</span><span class="method-args">(template_name)</span>
582
+ </a>
583
+ </div>
584
+
585
+ <div class="method-description">
586
+ <p>
587
+ convert short name into filename (ex. &#8217;:list&#8217; =&gt;
588
+ &#8216;template/list.rb.html&#8217;)
589
+ </p>
590
+ <p><a class="source-toggle" href="#"
591
+ onclick="toggleCode('M000030-source');return false;">[Source]</a></p>
592
+ <div class="method-source-code" id="M000030-source">
593
+ <pre>
594
+ <span class="ruby-comment cmt"># File lib/tenjin.rb, line 825</span>
595
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_filename</span>(<span class="ruby-identifier">template_name</span>)
596
+ <span class="ruby-identifier">name</span> = <span class="ruby-identifier">template_name</span>
597
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">name</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Symbol</span>) <span class="ruby-operator">?</span> <span class="ruby-node">&quot;#{@prefix}#{name}#{@postfix}&quot;</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">name</span>
598
+ <span class="ruby-keyword kw">end</span>
599
+ </pre>
600
+ </div>
601
+ </div>
602
+ </div>
603
+
604
+
605
+ </div>
606
+
607
+
608
+ </div>
609
+
610
+
611
+ <div id="validator-badges">
612
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
613
+ </div>
614
+
615
+ </body>
616
+ </html>