ghazel-erubis 2.6.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (298) hide show
  1. data/CHANGES.txt +744 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.txt +102 -0
  4. data/benchmark/Makefile +6 -0
  5. data/benchmark/bench.rb +313 -0
  6. data/benchmark/bench_context.yaml +141 -0
  7. data/benchmark/templates/_footer.html +4 -0
  8. data/benchmark/templates/_header.html +52 -0
  9. data/benchmark/templates/bench_erb.rhtml +29 -0
  10. data/benchmark/templates/bench_erubis.rhtml +29 -0
  11. data/benchmark/templates/bench_eruby.rhtml +29 -0
  12. data/bin/erubis +10 -0
  13. data/contrib/erubis +3330 -0
  14. data/contrib/erubis-run.rb +132 -0
  15. data/contrib/inline-require +179 -0
  16. data/doc/docstyle.css +188 -0
  17. data/doc/users-guide.html +3285 -0
  18. data/doc-api/classes/ActionView/TemplateHandlers/ErubisHandler.html +209 -0
  19. data/doc-api/classes/ActionView.html +105 -0
  20. data/doc-api/classes/ERB.html +101 -0
  21. data/doc-api/classes/Erubis/ArrayBufferEnhancer.html +175 -0
  22. data/doc-api/classes/Erubis/ArrayBufferEruby.html +120 -0
  23. data/doc-api/classes/Erubis/ArrayEnhancer.html +174 -0
  24. data/doc-api/classes/Erubis/ArrayEruby.html +120 -0
  25. data/doc-api/classes/Erubis/Basic/Converter.html +327 -0
  26. data/doc-api/classes/Erubis/Basic/Engine.html +130 -0
  27. data/doc-api/classes/Erubis/Basic.html +112 -0
  28. data/doc-api/classes/Erubis/BiPatternEnhancer.html +215 -0
  29. data/doc-api/classes/Erubis/BiPatternEruby.html +120 -0
  30. data/doc-api/classes/Erubis/CGenerator.html +386 -0
  31. data/doc-api/classes/Erubis/CommandOptionError.html +113 -0
  32. data/doc-api/classes/Erubis/Context.html +344 -0
  33. data/doc-api/classes/Erubis/Converter.html +283 -0
  34. data/doc-api/classes/Erubis/DeleteIndentEnhancer.html +150 -0
  35. data/doc-api/classes/Erubis/DeleteIndentEruby.html +120 -0
  36. data/doc-api/classes/Erubis/Ec.html +126 -0
  37. data/doc-api/classes/Erubis/Ejava.html +126 -0
  38. data/doc-api/classes/Erubis/Ejavascript.html +126 -0
  39. data/doc-api/classes/Erubis/Engine.html +305 -0
  40. data/doc-api/classes/Erubis/Eperl.html +126 -0
  41. data/doc-api/classes/Erubis/Ephp.html +126 -0
  42. data/doc-api/classes/Erubis/ErboutEnhancer.html +175 -0
  43. data/doc-api/classes/Erubis/ErboutEruby.html +120 -0
  44. data/doc-api/classes/Erubis/ErubisError.html +117 -0
  45. data/doc-api/classes/Erubis/Eruby.html +132 -0
  46. data/doc-api/classes/Erubis/EscapeEnhancer.html +165 -0
  47. data/doc-api/classes/Erubis/EscapedEc.html +120 -0
  48. data/doc-api/classes/Erubis/EscapedEjava.html +120 -0
  49. data/doc-api/classes/Erubis/EscapedEjavascript.html +120 -0
  50. data/doc-api/classes/Erubis/EscapedEperl.html +120 -0
  51. data/doc-api/classes/Erubis/EscapedEphp.html +120 -0
  52. data/doc-api/classes/Erubis/EscapedEruby.html +127 -0
  53. data/doc-api/classes/Erubis/EscapedEscheme.html +120 -0
  54. data/doc-api/classes/Erubis/Escheme.html +126 -0
  55. data/doc-api/classes/Erubis/Evaluator.html +212 -0
  56. data/doc-api/classes/Erubis/FastEruby.html +131 -0
  57. data/doc-api/classes/Erubis/Generator.html +416 -0
  58. data/doc-api/classes/Erubis/HeaderFooterEnhancer.html +267 -0
  59. data/doc-api/classes/Erubis/HeaderFooterEruby.html +120 -0
  60. data/doc-api/classes/Erubis/Helpers/RailsFormHelper.html +787 -0
  61. data/doc-api/classes/Erubis/Helpers/RailsHelper/TemplateConverter.html +213 -0
  62. data/doc-api/classes/Erubis/Helpers/RailsHelper.html +349 -0
  63. data/doc-api/classes/Erubis/Helpers.html +116 -0
  64. data/doc-api/classes/Erubis/InterpolationEnhancer.html +306 -0
  65. data/doc-api/classes/Erubis/InterpolationEruby.html +120 -0
  66. data/doc-api/classes/Erubis/JavaGenerator.html +359 -0
  67. data/doc-api/classes/Erubis/JavascriptGenerator.html +386 -0
  68. data/doc-api/classes/Erubis/Main.html +341 -0
  69. data/doc-api/classes/Erubis/NoCodeEnhancer.html +249 -0
  70. data/doc-api/classes/Erubis/NoCodeEruby.html +120 -0
  71. data/doc-api/classes/Erubis/NoTextEnhancer.html +159 -0
  72. data/doc-api/classes/Erubis/NoTextEruby.html +120 -0
  73. data/doc-api/classes/Erubis/NotSupportedError.html +119 -0
  74. data/doc-api/classes/Erubis/OptimizedEruby.html +163 -0
  75. data/doc-api/classes/Erubis/OptimizedGenerator.html +439 -0
  76. data/doc-api/classes/Erubis/OptimizedXmlEruby.html +163 -0
  77. data/doc-api/classes/Erubis/PI/Converter.html +266 -0
  78. data/doc-api/classes/Erubis/PI/Ec.html +166 -0
  79. data/doc-api/classes/Erubis/PI/Ejava.html +166 -0
  80. data/doc-api/classes/Erubis/PI/Ejavascript.html +166 -0
  81. data/doc-api/classes/Erubis/PI/Engine.html +122 -0
  82. data/doc-api/classes/Erubis/PI/Eperl.html +166 -0
  83. data/doc-api/classes/Erubis/PI/Ephp.html +166 -0
  84. data/doc-api/classes/Erubis/PI/Eruby.html +155 -0
  85. data/doc-api/classes/Erubis/PI/Escheme.html +166 -0
  86. data/doc-api/classes/Erubis/PI/TinyEruby.html +293 -0
  87. data/doc-api/classes/Erubis/PI.html +124 -0
  88. data/doc-api/classes/Erubis/PercentLineEnhancer.html +179 -0
  89. data/doc-api/classes/Erubis/PercentLineEruby.html +120 -0
  90. data/doc-api/classes/Erubis/PerlGenerator.html +344 -0
  91. data/doc-api/classes/Erubis/PhpGenerator.html +350 -0
  92. data/doc-api/classes/Erubis/PreprocessingEruby.html +183 -0
  93. data/doc-api/classes/Erubis/PreprocessingHelper.html +212 -0
  94. data/doc-api/classes/Erubis/PrintEnabledEnhancer.html +212 -0
  95. data/doc-api/classes/Erubis/PrintEnabledEruby.html +120 -0
  96. data/doc-api/classes/Erubis/PrintOutEnhancer.html +244 -0
  97. data/doc-api/classes/Erubis/PrintOutEruby.html +120 -0
  98. data/doc-api/classes/Erubis/PrintOutSimplifiedEruby.html +121 -0
  99. data/doc-api/classes/Erubis/RubyEvaluator.html +227 -0
  100. data/doc-api/classes/Erubis/RubyGenerator.html +327 -0
  101. data/doc-api/classes/Erubis/SchemeGenerator.html +382 -0
  102. data/doc-api/classes/Erubis/SimplifiedEruby.html +120 -0
  103. data/doc-api/classes/Erubis/SimplifyEnhancer.html +191 -0
  104. data/doc-api/classes/Erubis/StdoutEnhancer.html +173 -0
  105. data/doc-api/classes/Erubis/StdoutEruby.html +120 -0
  106. data/doc-api/classes/Erubis/StdoutSimplifiedEruby.html +121 -0
  107. data/doc-api/classes/Erubis/StringBufferEnhancer.html +174 -0
  108. data/doc-api/classes/Erubis/StringBufferEruby.html +120 -0
  109. data/doc-api/classes/Erubis/StringIOEruby.html +120 -0
  110. data/doc-api/classes/Erubis/TinyEruby.html +298 -0
  111. data/doc-api/classes/Erubis/XmlEruby.html +130 -0
  112. data/doc-api/classes/Erubis/XmlHelper.html +255 -0
  113. data/doc-api/classes/Erubis.html +353 -0
  114. data/doc-api/created.rid +1 -0
  115. data/doc-api/files/README_txt.html +247 -0
  116. data/doc-api/files/erubis/context_rb.html +107 -0
  117. data/doc-api/files/erubis/converter_rb.html +114 -0
  118. data/doc-api/files/erubis/engine/ec_rb.html +115 -0
  119. data/doc-api/files/erubis/engine/ejava_rb.html +115 -0
  120. data/doc-api/files/erubis/engine/ejavascript_rb.html +115 -0
  121. data/doc-api/files/erubis/engine/enhanced_rb.html +115 -0
  122. data/doc-api/files/erubis/engine/eperl_rb.html +115 -0
  123. data/doc-api/files/erubis/engine/ephp_rb.html +115 -0
  124. data/doc-api/files/erubis/engine/eruby_rb.html +115 -0
  125. data/doc-api/files/erubis/engine/escheme_rb.html +115 -0
  126. data/doc-api/files/erubis/engine/optimized_rb.html +114 -0
  127. data/doc-api/files/erubis/engine_rb.html +117 -0
  128. data/doc-api/files/erubis/enhancer_rb.html +107 -0
  129. data/doc-api/files/erubis/error_rb.html +107 -0
  130. data/doc-api/files/erubis/evaluator_rb.html +115 -0
  131. data/doc-api/files/erubis/generator_rb.html +114 -0
  132. data/doc-api/files/erubis/helper_rb.html +107 -0
  133. data/doc-api/files/erubis/helpers/rails_form_helper_rb.html +107 -0
  134. data/doc-api/files/erubis/helpers/rails_helper_rb.html +116 -0
  135. data/doc-api/files/erubis/local-setting_rb.html +107 -0
  136. data/doc-api/files/erubis/main_rb.html +127 -0
  137. data/doc-api/files/erubis/preprocessing_rb.html +114 -0
  138. data/doc-api/files/erubis/tiny_rb.html +107 -0
  139. data/doc-api/files/erubis_rb.html +118 -0
  140. data/doc-api/fr_class_index.html +122 -0
  141. data/doc-api/fr_file_index.html +51 -0
  142. data/doc-api/fr_method_index.html +251 -0
  143. data/doc-api/index.html +24 -0
  144. data/doc-api/rdoc-style.css +208 -0
  145. data/examples/basic/Makefile +53 -0
  146. data/examples/basic/example.ec +42 -0
  147. data/examples/basic/example.ejava +45 -0
  148. data/examples/basic/example.ejs +16 -0
  149. data/examples/basic/example.eperl +16 -0
  150. data/examples/basic/example.ephp +17 -0
  151. data/examples/basic/example.eruby +15 -0
  152. data/examples/basic/example.escheme +26 -0
  153. data/examples/pi/Makefile +54 -0
  154. data/examples/pi/example.ec +42 -0
  155. data/examples/pi/example.ejava +45 -0
  156. data/examples/pi/example.ejs +16 -0
  157. data/examples/pi/example.eperl +16 -0
  158. data/examples/pi/example.ephp +17 -0
  159. data/examples/pi/example.eruby +15 -0
  160. data/examples/pi/example.escheme +26 -0
  161. data/lib/erubis/context.rb +83 -0
  162. data/lib/erubis/converter.rb +357 -0
  163. data/lib/erubis/engine/ec.rb +117 -0
  164. data/lib/erubis/engine/ejava.rb +110 -0
  165. data/lib/erubis/engine/ejavascript.rb +119 -0
  166. data/lib/erubis/engine/enhanced.rb +121 -0
  167. data/lib/erubis/engine/eperl.rb +95 -0
  168. data/lib/erubis/engine/ephp.rb +99 -0
  169. data/lib/erubis/engine/eruby.rb +124 -0
  170. data/lib/erubis/engine/escheme.rb +114 -0
  171. data/lib/erubis/engine/optimized.rb +127 -0
  172. data/lib/erubis/engine.rb +120 -0
  173. data/lib/erubis/enhancer.rb +680 -0
  174. data/lib/erubis/error.rb +23 -0
  175. data/lib/erubis/evaluator.rb +88 -0
  176. data/lib/erubis/generator.rb +85 -0
  177. data/lib/erubis/helper.rb +47 -0
  178. data/lib/erubis/helpers/rails_form_helper.rb +197 -0
  179. data/lib/erubis/helpers/rails_helper.rb +353 -0
  180. data/lib/erubis/local-setting.rb +9 -0
  181. data/lib/erubis/main.rb +489 -0
  182. data/lib/erubis/preprocessing.rb +58 -0
  183. data/lib/erubis/tiny.rb +144 -0
  184. data/lib/erubis.rb +72 -0
  185. data/setup.rb +1331 -0
  186. data/test/assert-text-equal.rb +44 -0
  187. data/test/data/users-guide/Example.ejava +55 -0
  188. data/test/data/users-guide/array_example.result +9 -0
  189. data/test/data/users-guide/arraybuffer_example.result +9 -0
  190. data/test/data/users-guide/bipattern-example.rhtml +4 -0
  191. data/test/data/users-guide/bipattern_example.result +6 -0
  192. data/test/data/users-guide/context.rb +6 -0
  193. data/test/data/users-guide/context.yaml +8 -0
  194. data/test/data/users-guide/def_method.rb +14 -0
  195. data/test/data/users-guide/def_method.result +3 -0
  196. data/test/data/users-guide/escape_example.result +9 -0
  197. data/test/data/users-guide/example.ec +27 -0
  198. data/test/data/users-guide/example.ejs +20 -0
  199. data/test/data/users-guide/example.eperl +18 -0
  200. data/test/data/users-guide/example.ephp +18 -0
  201. data/test/data/users-guide/example.eruby +6 -0
  202. data/test/data/users-guide/example.escheme +28 -0
  203. data/test/data/users-guide/example1.eruby +6 -0
  204. data/test/data/users-guide/example1.rb +17 -0
  205. data/test/data/users-guide/example1.result +16 -0
  206. data/test/data/users-guide/example10.rb +4 -0
  207. data/test/data/users-guide/example10.result +17 -0
  208. data/test/data/users-guide/example10.xhtml +14 -0
  209. data/test/data/users-guide/example10_x.result +17 -0
  210. data/test/data/users-guide/example11.php +20 -0
  211. data/test/data/users-guide/example11.result +23 -0
  212. data/test/data/users-guide/example11.rhtml +21 -0
  213. data/test/data/users-guide/example11_C.result +10 -0
  214. data/test/data/users-guide/example11_N.result +16 -0
  215. data/test/data/users-guide/example11_U.result +16 -0
  216. data/test/data/users-guide/example11_php.result +15 -0
  217. data/test/data/users-guide/example1_x.result +9 -0
  218. data/test/data/users-guide/example2.eruby +7 -0
  219. data/test/data/users-guide/example2.rb +10 -0
  220. data/test/data/users-guide/example2.result +27 -0
  221. data/test/data/users-guide/example2_trim.result +10 -0
  222. data/test/data/users-guide/example2_x.result +10 -0
  223. data/test/data/users-guide/example3.eruby +6 -0
  224. data/test/data/users-guide/example3.rb +10 -0
  225. data/test/data/users-guide/example31.result +22 -0
  226. data/test/data/users-guide/example32.result +4 -0
  227. data/test/data/users-guide/example3_e.result +8 -0
  228. data/test/data/users-guide/example4.eruby +3 -0
  229. data/test/data/users-guide/example4.rb +11 -0
  230. data/test/data/users-guide/example4.result +10 -0
  231. data/test/data/users-guide/example4_x.result +5 -0
  232. data/test/data/users-guide/example5.eruby +6 -0
  233. data/test/data/users-guide/example5.rb +16 -0
  234. data/test/data/users-guide/example5.result +7 -0
  235. data/test/data/users-guide/example6.rb +12 -0
  236. data/test/data/users-guide/example6.result +7 -0
  237. data/test/data/users-guide/example7.eruby +8 -0
  238. data/test/data/users-guide/example71.result +13 -0
  239. data/test/data/users-guide/example72.result +13 -0
  240. data/test/data/users-guide/example8.eruby +6 -0
  241. data/test/data/users-guide/example8_ruby.result +7 -0
  242. data/test/data/users-guide/example8_yaml.result +7 -0
  243. data/test/data/users-guide/example9.eruby +3 -0
  244. data/test/data/users-guide/example9.rb +8 -0
  245. data/test/data/users-guide/example9.result +9 -0
  246. data/test/data/users-guide/example91.result +5 -0
  247. data/test/data/users-guide/example92.result +4 -0
  248. data/test/data/users-guide/example_c.result +29 -0
  249. data/test/data/users-guide/example_java.result +56 -0
  250. data/test/data/users-guide/example_js.result +22 -0
  251. data/test/data/users-guide/example_perl.result +20 -0
  252. data/test/data/users-guide/example_php.result +19 -0
  253. data/test/data/users-guide/example_scheme.result +30 -0
  254. data/test/data/users-guide/example_scheme_display.result +29 -0
  255. data/test/data/users-guide/fasteruby.rb +11 -0
  256. data/test/data/users-guide/fasteruby.result +38 -0
  257. data/test/data/users-guide/fasteruby.rhtml +15 -0
  258. data/test/data/users-guide/headerfooter-example.eruby +9 -0
  259. data/test/data/users-guide/headerfooter-example2.rb +8 -0
  260. data/test/data/users-guide/headerfooter-example2.rhtml +10 -0
  261. data/test/data/users-guide/headerfooter_example.result +11 -0
  262. data/test/data/users-guide/headerfooter_example2.result +13 -0
  263. data/test/data/users-guide/interpolation_example.result +9 -0
  264. data/test/data/users-guide/main_program1.rb +8 -0
  265. data/test/data/users-guide/main_program1.result +6 -0
  266. data/test/data/users-guide/main_program2.rb +8 -0
  267. data/test/data/users-guide/main_program2.result +6 -0
  268. data/test/data/users-guide/nocode-example.eruby +14 -0
  269. data/test/data/users-guide/nocode-php.result +20 -0
  270. data/test/data/users-guide/nocode_example.result +15 -0
  271. data/test/data/users-guide/normal-eruby-test.eruby +9 -0
  272. data/test/data/users-guide/normal_eruby_test.result +11 -0
  273. data/test/data/users-guide/notext-example.eruby +14 -0
  274. data/test/data/users-guide/notext-example.php +19 -0
  275. data/test/data/users-guide/notext-php.result +20 -0
  276. data/test/data/users-guide/notext_example.result +16 -0
  277. data/test/data/users-guide/percentline-example.rhtml +4 -0
  278. data/test/data/users-guide/percentline_example.result +7 -0
  279. data/test/data/users-guide/printenable_example.result +4 -0
  280. data/test/data/users-guide/printenabled-example.eruby +3 -0
  281. data/test/data/users-guide/printenabled-example.rb +8 -0
  282. data/test/data/users-guide/printstatement_example.result +8 -0
  283. data/test/data/users-guide/simplify_example.result +9 -0
  284. data/test/data/users-guide/stderr.log +3 -0
  285. data/test/data/users-guide/stdout_exmple.result +9 -0
  286. data/test/data/users-guide/stringbuffer_example.result +9 -0
  287. data/test/data/users-guide/tail_260.result +4 -0
  288. data/test/data/users-guide/tailnewline.rhtml +3 -0
  289. data/test/data/users-guide/template1.rhtml +4 -0
  290. data/test/data/users-guide/template2.rhtml +4 -0
  291. data/test/test-engines.rb +369 -0
  292. data/test/test-enhancers.rb +570 -0
  293. data/test/test-erubis.rb +883 -0
  294. data/test/test-main.rb +721 -0
  295. data/test/test-users-guide.rb +57 -0
  296. data/test/test.rb +29 -0
  297. data/test/testutil.rb +96 -0
  298. metadata +360 -0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ copyright(c) 2006-2009 kuwata-lab.com 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,102 @@
1
+ = README
2
+
3
+ release:: 2.6.5
4
+ copyright:: copyright(c) 2006-2009 kuwata-lab.com all rights reserved.
5
+
6
+
7
+
8
+ == About Erubis
9
+
10
+ Erubis is an implementation of eRuby. It has the following features.
11
+ * Very fast, almost three times faster than ERB and even 10% faster than eruby
12
+ * Multi-language support (Ruby/PHP/C/Java/Scheme/Perl/Javascript)
13
+ * Auto escaping support
14
+ * Auto trimming spaces around '<% %>'
15
+ * Embedded pattern changeable (default '<% %>')
16
+ * Enable to handle Processing Instructions (PI) as embedded pattern (ex. '<?rb ... ?>')
17
+ * Context object available and easy to combine eRuby template with YAML datafile
18
+ * Print statement available
19
+ * Easy to extend and customize in subclass
20
+ * Ruby on Rails support
21
+
22
+ Erubis is implemented in pure Ruby. It requires Ruby 1.8 or higher.
23
+ Erubis now supports Ruby 1.9.
24
+
25
+ See doc/users-guide.html for details.
26
+
27
+
28
+
29
+ == Installation
30
+
31
+ * If you have installed RubyGems, just type <tt>gem install erubis</tt>.
32
+
33
+ $ sudo gem install erubis
34
+
35
+ * Else install abstract[http://rubyforge.org/projects/abstract/] at first,
36
+ and download erubis_X.X.X.tar.bz2 and install it by setup.rb.
37
+
38
+ $ tar xjf abstract_X.X.X.tar.bz2
39
+ $ cd abstract_X.X.X/
40
+ $ sudo ruby setup.rb
41
+ $ cd ..
42
+ $ tar xjf erubis_X.X.X.tar.bz2
43
+ $ cd erubis_X.X.X/
44
+ $ sudo ruby setup.rb
45
+
46
+ * (Optional) It is able to merge 'lib/**/*.rb' into 'bin/erubis' by
47
+ 'contrib/inline-require' script.
48
+
49
+ $ tar xjf erubis_X.X.X.tar.bz2
50
+ $ cd erubis_X.X.X/
51
+ $ cp /tmp/abstract_X.X.X/lib/abstract.rb lib
52
+ $ unset RUBYLIB
53
+ $ contrib/inline-require -I lib bin/erubis > contrib/erubis
54
+
55
+
56
+
57
+ == Ruby on Rails Support
58
+
59
+ Erubis supports Ruby on Rails.
60
+ All you have to do is to add the following code into your 'config/environment.rb'
61
+ and restart web server.
62
+
63
+ require 'erubis/helpers/rails_helper'
64
+ #Erubis::Helpers::RailsHelper.engine_class = Erubis::Eruby
65
+ #Erubis::Helpers::RailsHelper.init_properties = {}
66
+ #Erubis::Helpers::RailsHelper.show_src = nil
67
+
68
+ If Erubis::Helpers::RailsHelper.show_src is ture, Erubis prints converted Ruby code
69
+ into log file ('log/development.log' or so). It is useful for debug.
70
+
71
+
72
+
73
+ == Exploring Guide
74
+
75
+ If you are exploring Eruby, see the following class at first.
76
+ * Erubis::TinyEruby (erubis/tiny.rb) --
77
+ the most simple eRuby implementation.
78
+ * Erubis::Engine (erubis/engine.rb) --
79
+ base class of Eruby, Ephp, Ejava, and so on.
80
+ * Erubis::Eruby (erubis/engine/eruby.rb) --
81
+ engine class for eRuby.
82
+ * Erubis::Converter (erubis/converter.rb) --
83
+ convert eRuby script into Ruby code.
84
+
85
+
86
+
87
+ == Benchmark
88
+
89
+ 'benchmark/erubybenchmark.rb' is a benchmark script of Erubis.
90
+ Try 'ruby erubybenchmark.rb' in benchmark directory.
91
+
92
+
93
+
94
+ == License
95
+
96
+ MIT License
97
+
98
+
99
+
100
+ == Author
101
+
102
+ makoto kuwata <kwa(at)kuwata-lab.com>
@@ -0,0 +1,6 @@
1
+
2
+ bench:
3
+ ruby bench.rb -n 10000
4
+
5
+ clean:
6
+ rm -rf bench_*.rhtml*
@@ -0,0 +1,313 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ###
4
+ ### $Release: 2.6.5 $
5
+ ### copyright(c) 2006-2009 kuwata-lab.com all rights reserved.
6
+ ###
7
+
8
+ require 'erb'
9
+ require 'erubis'
10
+ require 'erubis/tiny'
11
+ require 'erubis/engine/enhanced'
12
+ require 'yaml'
13
+ require 'cgi'
14
+ include ERB::Util
15
+
16
+ begin
17
+ require 'eruby'
18
+ rescue LoadError
19
+ ERuby = nil
20
+ end
21
+
22
+ def File.write(filename, content)
23
+ File.open(filename, 'w') { |f| f.write(content) }
24
+ end
25
+
26
+
27
+ ## change benchmark library to use $stderr instead of $stdout
28
+ require 'benchmark'
29
+ module Benchmark
30
+ class Report
31
+ def print(*args)
32
+ $stderr.print(*args)
33
+ end
34
+ end
35
+ module_function
36
+ def print(*args)
37
+ $stderr.print(*args)
38
+ end
39
+ end
40
+
41
+
42
+ class BenchmarkApplication
43
+
44
+ TARGETS = %w[eruby
45
+ ERB ERB(cached)
46
+ Erubis::Eruby Erubis::Eruby(cached)
47
+ Erubis::FastEruby Erubis::FastEruby(cached)
48
+ Erubis::TinyEruby
49
+ Erubis::ArrayBufferEruby
50
+ Erubis::PrintOutEruby
51
+ Erubis::StdoutEruby
52
+ ]
53
+
54
+ def initialize(ntimes, context, targets=nil, params={})
55
+ @ntimes = ntimes
56
+ @context = context
57
+ @targets = targets && !targets.empty? ? targets : TARGETS.dup
58
+ @testmode = params[:testmode] || 'execute'
59
+ @erubyfile = params[:erubyfile] || 'erubybench.rhtml'
60
+ @printout = params[:printout] || false
61
+ end
62
+
63
+ attr_accessor :ntimes, :targets
64
+ attr_accessor :testmode, :erubyfile, :contextfile, :printout
65
+
66
+ def context2code(context, varname='context')
67
+ s = ''
68
+ context.each { |k, | s << "#{k} = #{varname}[#{k.inspect}]; " }
69
+ return s
70
+ end
71
+
72
+ def perform_benchmark
73
+ width = 30
74
+ $stderr.puts "*** ntimes=#{@ntimes}, testmode=#{@testmode}"
75
+ Benchmark.bm(width) do |job|
76
+ for target in @targets do
77
+ method = "#{@testmode}_#{target.gsub(/::|-|\(/, '_').gsub(/\)/, '').downcase}"
78
+ #$stderr.puts "*** debug: method=#{method.inspect}"
79
+ next unless self.respond_to?(method)
80
+ filename = "bench_#{(target =~ /^(\w+)/) && $1.downcase}.rhtml"
81
+ title = target
82
+ output = nil
83
+ job.report(title) do
84
+ output = self.__send__(method, filename, @context)
85
+ end
86
+ File.write("output.#{target.gsub(/[^\w]/,'')}", output) if @printout && output && !output.empty?
87
+ end
88
+ end
89
+ end
90
+
91
+ ##
92
+
93
+ def execute_eruby(filename, context)
94
+ return unless ERuby
95
+ #eval context2code(context)
96
+ list = context['list']
97
+ @ntimes.times do
98
+ ERuby.import(filename)
99
+ end
100
+ return nil
101
+ end
102
+
103
+ def execute_erb(filename, context)
104
+ #eval context2code(context)
105
+ list = context['list']
106
+ output = nil
107
+ @ntimes.times do
108
+ eruby = ERB.new(File.read(filename))
109
+ output = eruby.result(binding())
110
+ print output
111
+ end
112
+ return output
113
+ end
114
+
115
+ def execute_erb_cached(filename, context)
116
+ #eval context2code(context)
117
+ list = context['list']
118
+ output = nil
119
+ cachefile = filename + '.cache'
120
+ File.unlink(cachefile) if test(?f, cachefile)
121
+ @ntimes.times do
122
+ if !test(?f, cachefile) || File.mtime(filename) > File.mtime(cachefile)
123
+ eruby = ERB.new(File.read(filename))
124
+ File.write(cachefile, eruby.src)
125
+ else
126
+ eruby = ERB.new('')
127
+ #eruby.src = File.read(cachefile)
128
+ eruby.instance_variable_set("@src", File.read(cachefile))
129
+ end
130
+ output = eruby.result(binding())
131
+ print output
132
+ end
133
+ return output
134
+ end
135
+
136
+ ## no cached
137
+ for klass in %w[Eruby FastEruby TinyEruby ArrayBufferEruby PrintOutEruby StdoutEruby] do
138
+ s = <<-END
139
+ def execute_erubis_#{klass.downcase}(filename, context)
140
+ #eval context2code(context)
141
+ list = context['list']
142
+ output = nil
143
+ @ntimes.times do
144
+ eruby = Erubis::#{klass}.new(File.read(filename))
145
+ output = eruby.result(binding())
146
+ print output
147
+ end
148
+ return output
149
+ end
150
+ END
151
+ eval s
152
+ end
153
+
154
+ ## cached
155
+ for klass in %w[Eruby FastEruby] do
156
+ s = <<-END
157
+ def execute_erubis_#{klass.downcase}_cached(filename, context)
158
+ #eval context2code(context)
159
+ list = context['list']
160
+ cachefile = filename + '.cache'
161
+ File.unlink(cachefile) if test(?f, cachefile)
162
+ output = nil
163
+ @ntimes.times do
164
+ eruby = Erubis::#{klass}.load_file(filename)
165
+ output = eruby.result(binding())
166
+ print output
167
+ end
168
+ savefile = cachefile.sub(/\\.cache$/, '.#{klass.downcase}.cache')
169
+ File.rename(cachefile, savefile)
170
+ return output
171
+ end
172
+ END
173
+ eval s
174
+ end
175
+
176
+ ##
177
+
178
+ def convert_eruby(filename, context)
179
+ return unless ERuby
180
+ #eval context2code(context)
181
+ list = context['list']
182
+ output = nil
183
+ @ntimes.times do
184
+ output = ERuby::Compiler.new.compile_string(File.read(filename))
185
+ end
186
+ return output
187
+ end
188
+
189
+ def convert_erb(filename, context)
190
+ #eval context2code(context)
191
+ list = context['list']
192
+ output = nil
193
+ @ntimes.times do
194
+ eruby = ERB.new(File.read(filename))
195
+ output = eruby.src
196
+ end
197
+ return output
198
+ end
199
+
200
+ for klass in %w[Eruby FastEruby TinyEruby]
201
+ s = <<-END
202
+ def convert_erubis_#{klass.downcase}(filename, context)
203
+ #eval context2code(context)
204
+ list = context['list']
205
+ output = nil
206
+ @ntimes.times do
207
+ eruby = Erubis::#{klass}.new(File.read(filename))
208
+ output = eruby.src
209
+ end
210
+ return output
211
+ end
212
+ END
213
+ eval s
214
+ end
215
+
216
+ end
217
+
218
+
219
+ require 'optparse'
220
+
221
+ class MainApplication
222
+
223
+ def parse_argv(argv=ARGV)
224
+ optparser = OptionParser.new
225
+ options = {}
226
+ ['-h', '-n N', '-t erubyfile', '-f contextfile', '-A', '-e',
227
+ '-x exclude', '-m testmode', '-X', '-p', '-D'].each do |opt|
228
+ optparser.on(opt) { |val| options[opt[1].chr] = val }
229
+ end
230
+ begin
231
+ targets = optparser.parse!(argv)
232
+ rescue => ex
233
+ $stderr.puts "#{@script}: #{ex.to_s}"
234
+ exit(1)
235
+ end
236
+ return options, targets
237
+ end
238
+
239
+ def execute
240
+ @script = File.basename($0)
241
+ ntimes = 1000
242
+ targets = BenchmarkApplication::TARGETS.dup
243
+ testmode = 'execute'
244
+ contextfile = 'bench_context.yaml'
245
+ #
246
+ options, args = parse_argv(ARGV)
247
+ ntimes = options['n'].to_i if options['n']
248
+ targets = args if args && !args.empty?
249
+ targets = targets - options['x'].split(/,/) if options['x']
250
+ testmode = options['m'] if options['m']
251
+ contextfile = options['f'] if options['f']
252
+ erubyfile = options['t'] if options['t']
253
+ #
254
+ if options['h']
255
+ $stderr.puts "Usage: ruby #{@script} [..options..] [..targets..]"
256
+ $stderr.puts " -h : help"
257
+ $stderr.puts " -n N : loop N times"
258
+ $stderr.puts " -f datafile : context data filename (*.yaml)"
259
+ $stderr.puts " -x exclude : exclude target name"
260
+ $stdout.puts " -m testmode : 'execute' or 'convert' (default 'execute')"
261
+ $stderr.puts " -p : print output to file (filename: 'output.TARGETNAME')"
262
+ return
263
+ end
264
+ #
265
+ #if ! options['t']
266
+ for item in %w[eruby erb erubis]
267
+ fname = "bench_#{item}.rhtml"
268
+ header = File.read("templates/_header.html")
269
+ #body = File.read("templates/#{erubyfile}")
270
+ body = File.read("templates/#{fname}")
271
+ footer = File.read("templates/_footer.html")
272
+ content = header + body + footer
273
+ File.write(fname, content)
274
+ end
275
+ #
276
+ if options['e'] # escape
277
+ tuples = [
278
+ [ 'bench_eruby.rhtml', '<%= CGI.escapeHTML((\1).to_s) %>' ],
279
+ [ 'bench_erb.rhtml', '<%=h \1 %>' ],
280
+ [ 'bench_erubis.rhtml', '<%== \1 %>' ],
281
+ ]
282
+ for fname, replace in tuples
283
+ content = File.read(fname).gsub(/<%= ?(.*?) ?%>/, replace)
284
+ File.write(fname, content)
285
+ end
286
+ targets.delete('Erubis::TinyEruby') ## because TinyEruby doesn't support '<%== =>'
287
+ end
288
+ #
289
+ context = YAML.load_file(contextfile)
290
+ #
291
+ params = {
292
+ :printout=>options['p'],
293
+ :testmode=>testmode,
294
+ }
295
+ app = BenchmarkApplication.new(ntimes, context, targets, params)
296
+ app.perform_benchmark()
297
+ end
298
+
299
+ end
300
+
301
+
302
+ if __FILE__ == $0
303
+
304
+ ## open /dev/null
305
+ $stdout = File.open('/dev/null', 'w')
306
+ at_exit do
307
+ $stdout.close()
308
+ end
309
+
310
+ ## start benchmark
311
+ MainApplication.new().execute()
312
+
313
+ end
@@ -0,0 +1,141 @@
1
+ list:
2
+ - name: Adobe Systems
3
+ name2: Adobe Systems Inc.
4
+ url: http://www.adobe.com
5
+ symbol: ADBE
6
+ price: 39.26
7
+ change: 0.13
8
+ ratio: 0.33
9
+ - name: Advanced Micro Devices
10
+ name2: Advanced Micro Devices Inc.
11
+ url: http://www.amd.com
12
+ symbol: AMD
13
+ price: 16.22
14
+ change: 0.17
15
+ ratio: 1.06
16
+ - name: Amazon.com
17
+ name2: Amazon.com Inc
18
+ url: http://www.amazon.com
19
+ symbol: AMZN
20
+ price: 36.85
21
+ change: -0.23
22
+ ratio: -0.62
23
+ - name: Apple
24
+ name2: Apple Inc.
25
+ url: http://www.apple.com
26
+ symbol: AAPL
27
+ price: 85.38
28
+ change: -0.87
29
+ ratio: -1.01
30
+ - name: BEA Systems
31
+ name2: BEA Systems Inc.
32
+ url: http://www.bea.com
33
+ symbol: BEAS
34
+ price: 12.46
35
+ change: 0.09
36
+ ratio: 0.73
37
+ - name: CA
38
+ name2: CA, Inc.
39
+ url: http://www.ca.com
40
+ symbol: CA
41
+ price: 24.66
42
+ change: 0.38
43
+ ratio: 1.57
44
+ - name: Cisco Systems
45
+ name2: Cisco Systems Inc.
46
+ url: http://www.cisco.com
47
+ symbol: CSCO
48
+ price: 26.35
49
+ change: 0.13
50
+ ratio: 0.5
51
+ - name: Dell
52
+ name2: Dell Corp.
53
+ url: http://www.dell.com/
54
+ symbol: DELL
55
+ price: 23.73
56
+ change: -0.42
57
+ ratio: -1.74
58
+ - name: eBay
59
+ name2: eBay Inc.
60
+ url: http://www.ebay.com
61
+ symbol: EBAY
62
+ price: 31.65
63
+ change: -0.8
64
+ ratio: -2.47
65
+ - name: Google
66
+ name2: Google Inc.
67
+ url: http://www.google.com
68
+ symbol: GOOG
69
+ price: 495.84
70
+ change: 7.75
71
+ ratio: 1.59
72
+ - name: Hewlett-Packard
73
+ name2: Hewlett-Packard Co.
74
+ url: http://www.hp.com
75
+ symbol: HPQ
76
+ price: 41.69
77
+ change: -0.02
78
+ ratio: -0.05
79
+ - name: IBM
80
+ name2: International Business Machines Corp.
81
+ url: http://www.ibm.com
82
+ symbol: IBM
83
+ price: 97.45
84
+ change: -0.06
85
+ ratio: -0.06
86
+ - name: Intel
87
+ name2: Intel Corp.
88
+ url: http://www.intel.com
89
+ symbol: INTC
90
+ price: 20.53
91
+ change: -0.07
92
+ ratio: -0.34
93
+ - name: Juniper Networks
94
+ name2: Juniper Networks, Inc
95
+ url: http://www.juniper.net/
96
+ symbol: JNPR
97
+ price: 18.96
98
+ change: 0.5
99
+ ratio: 2.71
100
+ - name: Microsoft
101
+ name2: Microsoft Corp
102
+ url: http://www.microsoft.com
103
+ symbol: MSFT
104
+ price: 30.6
105
+ change: 0.15
106
+ ratio: 0.49
107
+ - name: Oracle
108
+ name2: Oracle Corp.
109
+ url: http://www.oracle.com
110
+ symbol: ORCL
111
+ price: 17.15
112
+ change: 0.17
113
+ ratio: 1.0
114
+ - name: SAP
115
+ name2: SAP AG
116
+ url: http://www.sap.com
117
+ symbol: SAP
118
+ price: 46.2
119
+ change: -0.16
120
+ ratio: -0.35
121
+ - name: Seagate Technology
122
+ name2: Seagate Technology
123
+ url: http://www.seagate.com/
124
+ symbol: STX
125
+ price: 27.35
126
+ change: -0.36
127
+ ratio: -1.3
128
+ - name: Sun Microsystems
129
+ name2: Sun Microsystems Inc.
130
+ url: http://www.sun.com
131
+ symbol: SUNW
132
+ price: 6.33
133
+ change: -0.01
134
+ ratio: -0.16
135
+ - name: Yahoo
136
+ name2: Yahoo! Inc.
137
+ url: http://www.yahoo.com
138
+ symbol: YHOO
139
+ price: 28.04
140
+ change: -0.17
141
+ ratio: -0.6
@@ -0,0 +1,4 @@
1
+ </table>
2
+
3
+ </body>
4
+ </html>
@@ -0,0 +1,52 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
3
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+ <head>
6
+ <title>Stock Prices</title>
7
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
8
+ <meta http-equiv="Content-Style-Type" content="text/css" />
9
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
10
+ <link rel="shortcut icon" href="/images/favicon.ico" />
11
+ <link rel="stylesheet" type="text/css" href="/css/style.css" media="all" />
12
+ <script type="text/javascript" src="/js/util.js"></script>
13
+ <style type="text/css">
14
+ /*<![CDATA[*/
15
+
16
+ body {
17
+ color: #333333;
18
+ line-height: 150%;
19
+ }
20
+
21
+ thead {
22
+ font-weight: bold;
23
+ background-color: #CCCCCC;
24
+ }
25
+
26
+ .odd {
27
+ background-color: #FFCCCC;
28
+ }
29
+
30
+ .even {
31
+ background-color: #CCCCFF;
32
+ }
33
+
34
+ .minus {
35
+ color: #FF0000;
36
+ }
37
+
38
+ /*]]>*/
39
+ </style>
40
+
41
+ </head>
42
+
43
+ <body>
44
+
45
+ <h1>Stock Prices</h1>
46
+
47
+ <table>
48
+ <thead>
49
+ <tr>
50
+ <th>#</th><th>symbol</th><th>name</th><th>price</th><th>change</th><th>ratio</th>
51
+ </tr>
52
+ </thead>
@@ -0,0 +1,29 @@
1
+ <tbody>
2
+ <%
3
+ n = 0
4
+ for item in list
5
+ n += 1
6
+ %>
7
+ <tr class="<%= n % 2 == 0 ? 'even' : 'odd' %>">
8
+ <td style="text-align: center"><%= n %></td>
9
+ <td>
10
+ <a href="/stocks/<%= item['symbol'] %>"><%= item['symbol'] %></a>
11
+ </td>
12
+ <td>
13
+ <a href="<%= item['url'] %>"><%= item['name'] %></a>
14
+ </td>
15
+ <td>
16
+ <strong><%= item['price'] %></strong>
17
+ </td>
18
+ <% if item['change'] < 0.0 %>
19
+ <td class="minus"><%= item['change'] %></td>
20
+ <td class="minus"><%= item['ratio'] %></td>
21
+ <% else %>
22
+ <td><%= item['change'] %></td>
23
+ <td><%= item['ratio'] %></td>
24
+ <% end %>
25
+ </tr>
26
+ <%
27
+ end
28
+ %>
29
+ </tbody>
@@ -0,0 +1,29 @@
1
+ <tbody>
2
+ <%
3
+ n = 0
4
+ for item in list
5
+ n += 1
6
+ %>
7
+ <tr class="<%= n % 2 == 0 ? 'even' : 'odd' %>">
8
+ <td style="text-align: center"><%= n %></td>
9
+ <td>
10
+ <a href="/stocks/<%= item['symbol'] %>"><%= item['symbol'] %></a>
11
+ </td>
12
+ <td>
13
+ <a href="<%= item['url'] %>"><%= item['name'] %></a>
14
+ </td>
15
+ <td>
16
+ <strong><%= item['price'] %></strong>
17
+ </td>
18
+ <% if item['change'] < 0.0 %>
19
+ <td class="minus"><%= item['change'] %></td>
20
+ <td class="minus"><%= item['ratio'] %></td>
21
+ <% else %>
22
+ <td><%= item['change'] %></td>
23
+ <td><%= item['ratio'] %></td>
24
+ <% end %>
25
+ </tr>
26
+ <%
27
+ end
28
+ %>
29
+ </tbody>