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
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ copyright(c) 2007 kuwata-lab all rights reserved.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.txt ADDED
@@ -0,0 +1,54 @@
1
+ = README
2
+
3
+ release:: 0.6.0
4
+ copyright:: copyright(c) 2007 kuwata-lab all rights reserved.
5
+
6
+
7
+ == About
8
+
9
+ rbTenjin is a very fast and full-featured template engine based on embedded Ruby.
10
+ You can embed Ruby statements and expressions into your text file.
11
+ rbTenjin converts it into Ruby program and evaluate it.
12
+
13
+
14
+ == Features
15
+
16
+ * Very fast (twice faster than eruby and three times faster than ERB)
17
+ * Lightweight (only one file which contains about 1000 lines)
18
+ * Not break HTML design because it uses XML Processing
19
+ Instructions (PI) as embedded notation for Python statements.
20
+ * Secure because it supports escaping expression value by default.
21
+ * Auto caching of converted Python code.
22
+ * Nestable layout template
23
+ * Inlucde other templates
24
+ * Capture part of template
25
+ * Load YAML file as context data
26
+ * Preprocessing support
27
+
28
+ See doc/*.html for details.
29
+
30
+
31
+ == Installation
32
+
33
+ * If you have installed RubyGems, just type <tt>gem install tenjin</tt>.
34
+
35
+ $ sudo gem install tenjin
36
+
37
+ * Else download rbtenjin-X.X.X.tar.bz2 and just copy 'lib/tenjin.rb' and
38
+ 'bin/rbtenjin' into proper directory.
39
+
40
+ $ tar xjf rbtenjin-X.X.X.tar.bz2
41
+ $ cd rbtenjin-X.X.X/
42
+ $ sudo copy lib/tenjin.rb /usr/local/lib/ruby/1.8/site_ruby/1.8/
43
+ $ sudo copy bin/rbtenjin /usr/local/bin/
44
+
45
+
46
+ == Attention
47
+
48
+ rbTenjin is beta released. It means that API or specification may change
49
+ in the future.
50
+
51
+
52
+ == License
53
+
54
+ MIT License
@@ -0,0 +1,502 @@
1
+ ## parse options
2
+ require 'optparse'
3
+ optparser = OptionParser.new()
4
+ options = {}
5
+ ['-h', '-p', '-n N', '-e', '-q', '-A', '-f file', '-m mode', '-x exclude'].each do |opt|
6
+ optparser.on(opt) { |val| options[opt[1].chr] = val }
7
+ end
8
+ begin
9
+ filenames = optparser.parse!(ARGV)
10
+ rescue => ex
11
+ command = File.basename($0)
12
+ $stderr.puts "#{command}: #{ex.to_s}"
13
+ exit(1)
14
+ end
15
+
16
+
17
+ ## defaults
18
+ ntimes = 1000
19
+ mode = 'class' # 'class' or 'hash'
20
+ escape = options['e']
21
+ targets = %w[eruby eruby-cache erb erb-cache erb-reuse erb-defmethod erubis erubis-cache erubis-reuse tenjin tenjin-nocache tenjin-reuse]
22
+ #targets_all = targets + %w[tenjin-tmpl tenjin-defun tenjin-defun-reuse] + %w[eruby-convert erb-convert erubis-convert tenjin-convert]
23
+ targets_all = targets + %w[tenjin-arrbuf tenjin-arrbuf-nocache tenjin-arrbuf-reuse]
24
+
25
+
26
+ ## help
27
+ if options['h']
28
+ command = File.basename($0)
29
+ puts "Usage: ruby %s [-h] [-n N] [targets] " % command
30
+ puts " -h : help"
31
+ #puts " -p : print output"
32
+ puts " -n N : loop N times (default %d)" % ntimes
33
+ puts " -f file : context data file"
34
+ puts " -x exclude : excluded target name"
35
+ puts " -q : quiet mode"
36
+ puts " -m mode : 'class' or 'hash' (default '%s')" % mode
37
+ puts " -e : escape html"
38
+ exit(0)
39
+ end
40
+
41
+
42
+ ## set parameters
43
+ ntimes = options.fetch('n', ntimes).to_i
44
+ mode = options.fetch('m', mode)
45
+ $quiet = options['q']
46
+ datafile = options['f']
47
+ unless datafile
48
+ if mode == 'class'
49
+ datafile = 'bench_context.rb'
50
+ elsif mode == 'hash'
51
+ datafile = 'bench_context.yaml'
52
+ else
53
+ assert unreachable
54
+ end
55
+ end
56
+ if options['A']
57
+ targets = targets_all
58
+ elsif filenames && !filenames.empty?
59
+ if filenames[0] =~ /^\/.*\/$/
60
+ regexp = eval filenames[0]
61
+ targets = targets_all.select { |t| t =~ regexp }
62
+ else
63
+ targets = filenames
64
+ end
65
+ end
66
+ exclude = options['x']
67
+ targets.delete(exclude) if exclude
68
+
69
+
70
+ ## require libraries
71
+ require 'erb'
72
+ require 'tenjin'
73
+ begin
74
+ require 'eruby'
75
+ rescue LoadError
76
+ ERuby = nil
77
+ end
78
+ begin
79
+ require 'erubis'
80
+ rescue LoadError
81
+ Erubis = nil
82
+ end
83
+ require 'cgi'
84
+ include ERB::Util
85
+
86
+
87
+ ## context data
88
+ if datafile =~ /\.rb$/
89
+ context = Tenjin::Context.new
90
+ context.instance_eval(File.read(datafile), datafile)
91
+ elsif datafile =~ /\.ya?ml$/
92
+ require 'yaml'
93
+ ydoc = YAML.load_file(datafile)
94
+ context = Tenjin::Context.new(ydoc)
95
+ end
96
+ if escape
97
+ context[:list].each do |item|
98
+ if item.name =~ / /
99
+ item.name = "<#{item.name.gsub(/ /, '&')}>"
100
+ else
101
+ item.name = "\"#{item.name}\""
102
+ end
103
+ end
104
+ end
105
+ s = ''
106
+ context.instance_variables.each do |varname|
107
+ name = varname[1..-1]
108
+ s << "#{name} = context[#{name.inspect}]\n"
109
+ end
110
+ bindobj = nil
111
+ s << "bindobj = binding()\n"
112
+ eval s
113
+ #eval "puts '** title='+title\n" # error on 1.9
114
+ #eval "puts '** title='+title\n", bindobj # ok
115
+
116
+
117
+ ## helper methods
118
+ def msg(message)
119
+ unless $quiet
120
+ $stdout.write(message)
121
+ $stdout.flush()
122
+ end
123
+ end
124
+
125
+
126
+ def defun_code(rbcode)
127
+ return <<-END
128
+ def tmpl_tenjin_view()
129
+ _buf = ''
130
+ _tmpl_tenjin_view(_buf)
131
+ return _buf
132
+ end
133
+ def _tmpl_tenjin_view(_buf)
134
+ #{rbcode}
135
+ end
136
+ END
137
+ end
138
+
139
+
140
+ def read_and_convert(filename, &block)
141
+ cachename = filename + '.cache'
142
+ if !test(?f, cachename) || File.mtime(cachename) < File.mtime(filename)
143
+ rbcode = yield(filename)
144
+ File.open(cachename, 'w') { |f| f.write(rbcode) }
145
+ else
146
+ rbcode = File.read(cachename)
147
+ end
148
+ return rbcode
149
+ end
150
+
151
+
152
+ ## preparation
153
+ #msg('----- start benchmark preparations.\n')
154
+ #msg('----- end benchmark preparations.\n\n')
155
+
156
+
157
+ ## generate templates
158
+ template_filenames = [
159
+ tmpl_eruby = 'bench_eruby.rhtml',
160
+ tmpl_erb = 'bench_erb.rhtml',
161
+ tmpl_erubis = 'bench_erubis.rhtml',
162
+ tmpl_tenjin = 'bench_tenjin.rbhtml',
163
+ tmpl_tenjin2 = 'bench_tenjin2.rbhtml',
164
+ ]
165
+ header = File.read("templates/_header.html")
166
+ footer = File.read("templates/_footer.html")
167
+ template_filenames.uniq.each do |fname|
168
+ begin
169
+ body = File.read("templates/#{fname}")
170
+ rescue
171
+ if fname =~ /tenjin/
172
+ body = File.read("templates/#{tmpl_tenjin}")
173
+ else
174
+ body = File.read("templates/#{tmpl_eruby}")
175
+ body = body.gsub(/list/, '@list') if fname =~ /erubis/
176
+ end
177
+ end
178
+ ## item['key'] ==> item.key
179
+ if mode == 'class'
180
+ body.gsub!(/(\w+)\['(\w+)'\]/, '\1.\2')
181
+ end
182
+ ## escape
183
+ if escape
184
+ case fname
185
+ when /_eruby/
186
+ body.gsub!(/<%= (.*?) %>/, '<%= CGI.escapeHTML((\1).to_s) %>')
187
+ when /_erb/
188
+ body.gsub!(/<%= (.*?) %>/, '<%=h \1 %>')
189
+ when /_erubis/
190
+ body.gsub!(/<%= (.*?) %>/, '<%== \1 %>')
191
+ when /_tenjin/
192
+ body.gsub!(/\#\{(.*?)\}/, '${\1}')
193
+ end
194
+ end
195
+ #
196
+ s = header + body + footer
197
+ File.open(fname, 'w') { |f| f.write(s) }
198
+ end
199
+
200
+
201
+
202
+ ## change benchmark library to use $stderr instead of $stdout
203
+ require 'benchmark'
204
+ module Benchmark
205
+ class Report
206
+ def print(*args)
207
+ $stderr.print(*args)
208
+ end
209
+ end
210
+ module_function
211
+ def print(*args)
212
+ $stderr.print(*args)
213
+ end
214
+ end
215
+
216
+
217
+ ## open /dev/null
218
+ $stdout = File.open('/dev/null', 'w')
219
+ at_exit do
220
+ $stdout.close()
221
+ end
222
+
223
+
224
+ ##
225
+ def delete_caches()
226
+ Dir.glob('*.cache').each { |fname| File.unlink(fname) }
227
+ end
228
+
229
+
230
+ ## do benchmark
231
+ if options['p']
232
+ ntimes = 1
233
+ end
234
+ output = nil
235
+ Benchmark.bm(20) do |job|
236
+
237
+ for target in targets
238
+ delete_caches()
239
+ GC.start()
240
+ case target
241
+
242
+ when 'eruby'
243
+ job.report(target) do
244
+ ntimes.times do
245
+ ERuby.import(tmpl_eruby)
246
+ end
247
+ end if ERuby
248
+
249
+ when 'eruby-cache'
250
+ job.report(target) do
251
+ ntimes.times do
252
+ rbcode = read_and_convert(tmpl_eruby) do |fname|
253
+ ERuby::Compiler.new.compile_string(File.read(fname))
254
+ end
255
+ eval rbcode, bindobj
256
+ end
257
+ end if ERuby
258
+
259
+ when 'eruby-convert'
260
+ s = File.read(tmpl_eruby)
261
+ job.report(target) do
262
+ ntimes.times do
263
+ compiler = ERuby::Compiler.new
264
+ output = compiler.compile_string(s)
265
+ end
266
+ end if ERuby
267
+
268
+ when 'erb'
269
+ job.report(target) do
270
+ ntimes.times do
271
+ erb = ERB.new(File.read(tmpl_erb))
272
+ output = erb.result(bindobj)
273
+ print output
274
+ end
275
+ end if ERB
276
+
277
+ when 'erb-cache'
278
+ job.report(target) do
279
+ ntimes.times do
280
+ rbcode = read_and_convert(tmpl_erb) do |fname|
281
+ ERB.new(File.read(fname)).src
282
+ end
283
+ output = eval rbcode, bindobj
284
+ print output
285
+ end
286
+ end if ERB
287
+
288
+ when 'erb-reuse'
289
+ job.report(target) do
290
+ erb = ERB.new(File.read(tmpl_erb))
291
+ ntimes.times do
292
+ output = erb.result(bindobj)
293
+ print output
294
+ end
295
+ end if ERB
296
+
297
+ when 'erb-defmethod'
298
+ job.report(target) do
299
+ erb = ERB.new(File.read(tmpl_erb))
300
+ class Dummy; end
301
+ erb.def_method(Dummy, 'render(list)')
302
+ dummy = Dummy.new
303
+ ntimes.times do
304
+ output = dummy.render(context[:list])
305
+ print output
306
+ end
307
+ end if ERB
308
+
309
+ when 'erb-convert'
310
+ s = File.read(tmpl_erb)
311
+ job.report(target) do
312
+ ntimes.times do
313
+ erb = ERB.new(s)
314
+ output = erb.src
315
+ end
316
+ end if ERB
317
+
318
+ when 'erubis'
319
+ job.report(target) do
320
+ ntimes.times do
321
+ eruby = Erubis::Eruby.new(File.read(tmpl_erubis))
322
+ #output = eruby.result(bindobj)
323
+ output = eruby.evaluate(context)
324
+ print output
325
+ end
326
+ end if Erubis
327
+
328
+ when 'erubis-cache'
329
+ job.report(target) do
330
+ ntimes.times do
331
+ erubis = Erubis::Eruby.load_file(tmpl_erubis)
332
+ #output = erubis.result(bindobj)
333
+ output = erubis.evaluate(context)
334
+ print output
335
+ end
336
+ end if Erubis
337
+
338
+ when 'erubis-reuse'
339
+ job.report(target) do
340
+ erubis = Erubis::Eruby.new(File.read(tmpl_erubis))
341
+ ntimes.times do
342
+ #output = erubis.result(bindobj)
343
+ output = erubis.evaluate(context)
344
+ print output
345
+ end
346
+ end if Erubis
347
+
348
+ when 'erubis-convert'
349
+ s = File.read(tmpl_erubis)
350
+ job.report(target) do
351
+ ntimes.times do
352
+ erubis = Erubis::Eruby.new()
353
+ output = erubis.convert(s)
354
+ end
355
+ end if Erubis
356
+
357
+ when 'tenjin-tmpl'
358
+ job.report(target) do
359
+ ntimes.times do
360
+ template = Tenjin::Template.new(tmpl_tenjin)
361
+ output = template.render(context)
362
+ print output
363
+ end
364
+ end if Tenjin
365
+
366
+ when 'tenjin-tmpl-reuse'
367
+ job.report(target) do
368
+ template = Tenjin::Template.new(tmpl_tenjin)
369
+ ntimes.times do
370
+ output = template.render(context)
371
+ print output
372
+ end
373
+ end if Tenjin
374
+
375
+ when 'tenjin'
376
+ job.report(target) do
377
+ ntimes.times do
378
+ engine = Tenjin::Engine.new(:cache=>true)
379
+ output = engine.render(tmpl_tenjin, context)
380
+ print output
381
+ end
382
+ end if Tenjin
383
+
384
+ when 'tenjin-nocache'
385
+ job.report(target) do
386
+ ntimes.times do
387
+ engine = Tenjin::Engine.new(:cache=>false)
388
+ output = engine.render(tmpl_tenjin, context)
389
+ print output
390
+ end
391
+ end if Tenjin
392
+
393
+ when 'tenjin-reuse'
394
+ job.report(target) do
395
+ engine = Tenjin::Engine.new()
396
+ ntimes.times do
397
+ output = engine.render(tmpl_tenjin, context)
398
+ print output
399
+ end
400
+ end if Tenjin
401
+
402
+ when 'tenjin-convert'
403
+ s = File.read(tmpl_tenjin)
404
+ job.report(target) do
405
+ ntimes.times do
406
+ tenjin = Tenjin::Template.new(:preamble=>true, :postamble=>true)
407
+ output = tenjin.convert(s)
408
+ end
409
+ end if Erubis
410
+
411
+ when 'tenjin-defun'
412
+ job.report(target) do
413
+ template = Tenjin::Template.new(tmpl_tenjin)
414
+ defun = defun_code(template.rbcode)
415
+ ntimes.times do
416
+ context.instance_eval(defun)
417
+ output = context.tmpl_tenjin_view()
418
+ print output
419
+ end
420
+ end if Tenjin
421
+
422
+ when 'tenjin-defun-reuse'
423
+ job.report(target) do
424
+ template = Tenjin::Template.new(tmpl_tenjin)
425
+ defun = defun_code(template.rbcode)
426
+ context.instance_eval(defun)
427
+ ntimes.times do
428
+ output = context.tmpl_tenjin_view()
429
+ print output
430
+ end
431
+ end if Tenjin
432
+
433
+ ##
434
+
435
+ when 'tenjin-arrbuftmpl'
436
+ job.report(target) do
437
+ ntimes.times do
438
+ template = Tenjin::ArrayBufferTemplate.new(tmpl_tenjin2)
439
+ output = template.render(context)
440
+ print output
441
+ end
442
+ end if Tenjin::ArrayBufferTemplate
443
+
444
+ when 'tenjin-arrbuftmpl-reuse'
445
+ job.report(target) do
446
+ template = Tenjin::ArrayBufferTemplate.new(tmpl_tenjin2)
447
+ ntimes.times do
448
+ output = template.render(context)
449
+ print output
450
+ end
451
+ end if Tenjin::ArrayBufferTemplate
452
+
453
+ when 'tenjin-arrbuf'
454
+ job.report(target) do
455
+ ntimes.times do
456
+ engine = Tenjin::Engine.new(:cache=>true, :templateclass=>Tenjin::ArrayBufferTemplate)
457
+ output = engine.render(tmpl_tenjin2, context)
458
+ print output
459
+ end
460
+ end if Tenjin::ArrayBufferTemplate
461
+
462
+ when 'tenjin-arrbuf-nocache'
463
+ job.report(target) do
464
+ ntimes.times do
465
+ engine = Tenjin::Engine.new(:cache=>false, :templateclass=>Tenjin::ArrayBufferTemplate)
466
+ output = engine.render(tmpl_tenjin2, context)
467
+ print output
468
+ end
469
+ end if Tenjin::ArrayBufferTemplate
470
+
471
+ when 'tenjin-arrbuf-reuse'
472
+ job.report(target) do
473
+ engine = Tenjin::Engine.new(:templateclass=>Tenjin::ArrayBufferTemplate)
474
+ ntimes.times do
475
+ output = engine.render(tmpl_tenjin2, context)
476
+ print output
477
+ end
478
+ end if Tenjin::ArrayBufferTemplate
479
+
480
+ when 'tenjin-arrbuf-convert'
481
+ s = File.read(tmpl_tenjin2)
482
+ job.report(target) do
483
+ ntimes.times do
484
+ tenjin = Tenjin::ArrayBufferTemplate.new(:preamble=>true, :postamble=>true)
485
+ output = tenjin.convert(s)
486
+ end
487
+ end if Erubis
488
+
489
+ else
490
+ $stderr.puts("*** %s: invalid target.\n" % target)
491
+ exit(1)
492
+ end
493
+
494
+ if options['p']
495
+ File.open('%s.result' % target, 'w') { |f| f.write(output) } unless target =~ /^eruby/ && target !~ /-convert$/
496
+ puts 'created: %s.result' % target
497
+ #next
498
+ end
499
+
500
+ end
501
+
502
+ end