erubis 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. data/{ChangeLog → CHANGES} +139 -6
  2. data/MIT-LICENSE +20 -0
  3. data/README.txt +20 -5
  4. data/benchmark/erubybench.rb +465 -229
  5. data/benchmark/erubybench.rhtml +39 -15
  6. data/benchmark/erubybench.yaml +126 -46
  7. data/bin/erubis +2 -2
  8. data/bin/notext +3 -3
  9. data/contrib/action_view_base_rb.patch +23 -0
  10. data/contrib/erubis +466 -308
  11. data/contrib/inline-require +2 -2
  12. data/doc-api/classes/ERB.html +101 -0
  13. data/doc-api/classes/Erubis.html +59 -6
  14. data/doc-api/classes/Erubis/ArrayEnhancer.html +12 -12
  15. data/doc-api/classes/Erubis/Basic/Converter.html +61 -57
  16. data/doc-api/classes/Erubis/BiPatternEnhancer.html +14 -14
  17. data/doc-api/classes/Erubis/CGenerator.html +60 -60
  18. data/doc-api/classes/Erubis/Context.html +125 -29
  19. data/doc-api/classes/Erubis/Converter.html +73 -22
  20. data/doc-api/classes/Erubis/Engine.html +55 -39
  21. data/doc-api/classes/Erubis/EscapeEnhancer.html +6 -6
  22. data/doc-api/classes/Erubis/Evaluator.html +19 -19
  23. data/doc-api/classes/Erubis/Generator.html +16 -10
  24. data/doc-api/classes/Erubis/HeaderFooterEnhancer.html +14 -14
  25. data/doc-api/classes/Erubis/{Helper.html → Helpers.html} +5 -6
  26. data/doc-api/classes/Erubis/Helpers/RailsHelper.html +296 -0
  27. data/doc-api/classes/Erubis/JavaGenerator.html +54 -54
  28. data/doc-api/classes/Erubis/JavascriptGenerator.html +60 -60
  29. data/doc-api/classes/Erubis/Main.html +42 -30
  30. data/doc-api/classes/Erubis/NoCodeEnhancer.html +5 -5
  31. data/doc-api/classes/Erubis/NoTextEnhancer.html +7 -7
  32. data/doc-api/classes/Erubis/OptimizedEruby.html +6 -6
  33. data/doc-api/classes/Erubis/OptimizedGenerator.html +72 -72
  34. data/doc-api/classes/Erubis/OptimizedXmlEruby.html +6 -6
  35. data/doc-api/classes/Erubis/PI/Converter.html +28 -81
  36. data/doc-api/classes/Erubis/PI/Ec.html +6 -6
  37. data/doc-api/classes/Erubis/PI/Ejava.html +6 -6
  38. data/doc-api/classes/Erubis/PI/Ejavascript.html +6 -6
  39. data/doc-api/classes/Erubis/PI/Eperl.html +6 -6
  40. data/doc-api/classes/Erubis/PI/Ephp.html +6 -6
  41. data/doc-api/classes/Erubis/PI/Eruby.html +7 -7
  42. data/doc-api/classes/Erubis/PI/Escheme.html +6 -6
  43. data/doc-api/classes/Erubis/PI/TinyEruby.html +66 -79
  44. data/doc-api/classes/Erubis/PercentLineEnhancer.html +8 -8
  45. data/doc-api/classes/Erubis/PerlGenerator.html +54 -54
  46. data/doc-api/classes/Erubis/PhpGenerator.html +54 -54
  47. data/doc-api/classes/Erubis/PrintEnabledEnhancer.html +21 -21
  48. data/doc-api/classes/Erubis/PrintOutEnhancer.html +30 -30
  49. data/doc-api/classes/Erubis/RubyEvaluator.html +12 -12
  50. data/doc-api/classes/Erubis/RubyGenerator.html +9 -9
  51. data/doc-api/classes/Erubis/SimplifyEnhancer.html +7 -6
  52. data/doc-api/classes/Erubis/StdoutEnhancer.html +12 -12
  53. data/doc-api/classes/Erubis/StringBufferEnhancer.html +13 -13
  54. data/doc-api/classes/Erubis/TinyEruby.html +56 -68
  55. data/doc-api/classes/Erubis/XmlHelper.html +20 -23
  56. data/doc-api/created.rid +1 -1
  57. data/doc-api/files/{__/README_txt.html → README_txt.html} +35 -20
  58. data/doc-api/files/erubis/context_rb.html +2 -2
  59. data/doc-api/files/erubis/converter_rb.html +2 -2
  60. data/doc-api/files/erubis/engine/ec_rb.html +2 -2
  61. data/doc-api/files/erubis/engine/ejava_rb.html +2 -2
  62. data/doc-api/files/erubis/engine/ejavascript_rb.html +2 -2
  63. data/doc-api/files/erubis/engine/enhanced_rb.html +2 -2
  64. data/doc-api/files/erubis/engine/eperl_rb.html +2 -2
  65. data/doc-api/files/erubis/engine/ephp_rb.html +2 -2
  66. data/doc-api/files/erubis/engine/eruby_rb.html +2 -3
  67. data/doc-api/files/erubis/engine/escheme_rb.html +2 -2
  68. data/doc-api/files/erubis/engine/optimized_rb.html +2 -2
  69. data/doc-api/files/erubis/engine_rb.html +2 -2
  70. data/doc-api/files/erubis/enhancer_rb.html +2 -2
  71. data/doc-api/files/erubis/error_rb.html +2 -2
  72. data/doc-api/files/erubis/evaluator_rb.html +2 -2
  73. data/doc-api/files/erubis/generator_rb.html +2 -2
  74. data/doc-api/files/erubis/helper_rb.html +2 -2
  75. data/doc-api/files/erubis/{helper/rails_rb.html → helpers/rails_helper_rb.html} +6 -31
  76. data/doc-api/files/erubis/local-setting_rb.html +2 -2
  77. data/doc-api/files/erubis/main_rb.html +4 -2
  78. data/doc-api/files/erubis/tiny_rb.html +2 -2
  79. data/doc-api/files/erubis_rb.html +2 -2
  80. data/doc-api/fr_class_index.html +3 -3
  81. data/doc-api/fr_file_index.html +2 -2
  82. data/doc-api/fr_method_index.html +142 -147
  83. data/doc-api/index.html +1 -1
  84. data/doc/users-guide.html +387 -218
  85. data/lib/erubis.rb +21 -25
  86. data/lib/erubis/context.rb +34 -4
  87. data/lib/erubis/converter.rb +159 -115
  88. data/lib/erubis/engine.rb +29 -12
  89. data/lib/erubis/engine/ec.rb +2 -2
  90. data/lib/erubis/engine/ejava.rb +2 -2
  91. data/lib/erubis/engine/ejavascript.rb +2 -2
  92. data/lib/erubis/engine/enhanced.rb +2 -2
  93. data/lib/erubis/engine/eperl.rb +2 -2
  94. data/lib/erubis/engine/ephp.rb +2 -2
  95. data/lib/erubis/engine/eruby.rb +5 -6
  96. data/lib/erubis/engine/escheme.rb +2 -2
  97. data/lib/erubis/engine/optimized.rb +2 -2
  98. data/lib/erubis/enhancer.rb +33 -7
  99. data/lib/erubis/error.rb +2 -2
  100. data/lib/erubis/evaluator.rb +2 -2
  101. data/lib/erubis/generator.rb +6 -3
  102. data/lib/erubis/helper.rb +6 -23
  103. data/lib/erubis/helpers/rails_helper.rb +202 -0
  104. data/lib/erubis/local-setting.rb +4 -4
  105. data/lib/erubis/main.rb +90 -35
  106. data/lib/erubis/tiny.rb +57 -52
  107. data/test/assert-text-equal.rb +2 -2
  108. data/test/test-engines.rb +5 -5
  109. data/test/test-erubis.rb +173 -63
  110. data/test/test-main.rb +135 -27
  111. data/test/test-notext.rb +2 -2
  112. data/test/test.rb +2 -2
  113. data/test/testutil.rb +2 -2
  114. metadata +16 -16
  115. data/LGPL +0 -504
  116. data/doc-api/classes/Erubis/Helper/CachedRailsTemplate.html +0 -198
  117. data/doc-api/classes/Erubis/Helper/RailsTemplate.html +0 -366
  118. data/lib/erubis/helper/rails.rb +0 -159
@@ -1,7 +1,7 @@
1
1
  ##
2
- ## $Rev: 32 $
3
- ## $Release: 2.1.0 $
4
- ## copyright(c) 2006 kuwata-lab all rights reserved.
2
+ ## $Rev: 55 $
3
+ ## $Release: 2.2.0 $
4
+ ## copyright(c) 2006-2007 kuwata-lab all rights reserved.
5
5
  ##
6
6
 
7
7
 
@@ -23,11 +23,6 @@ module Erubis
23
23
  #include Converter
24
24
  #include Generator
25
25
 
26
- # convert input string and set it to @src
27
- def convert!(input)
28
- @src = convert(input)
29
- end
30
-
31
26
  def initialize(input=nil, properties={})
32
27
  #@input = input
33
28
  init_generator(properties)
@@ -36,12 +31,34 @@ module Erubis
36
31
  @src = convert(input) if input
37
32
  end
38
33
 
39
- ## load file and create engine object
34
+
35
+ ##
36
+ ## convert input string and set it to @src
37
+ ##
38
+ def convert!(input)
39
+ @src = convert(input)
40
+ end
41
+
42
+
43
+ ##
44
+ ## load file, write cache file, and return engine object.
45
+ ## this method create cache file (filename + '.cache') automatically.
46
+ ##
40
47
  def self.load_file(filename, properties={})
41
- input = File.open(filename, 'rb') { |f| f.read }
42
- input.untaint # is it ok?
48
+ cachename = filename + '.cache'
43
49
  properties[:filename] = filename
44
- engine = self.new(input, properties)
50
+ if test(?f, cachename) && File.mtime(filename) <= File.mtime(cachename)
51
+ engine = self.new(nil, properties)
52
+ engine.src = File.read(cachename)
53
+ else
54
+ input = File.open(filename, 'rb') { |f| f.read }
55
+ engine = self.new(input, properties)
56
+ File.open(cachename, 'w') do |f|
57
+ f.flock(File::LOCK_EX)
58
+ f.write(engine.src)
59
+ end
60
+ end
61
+ engine.src.untaint # ok?
45
62
  return engine
46
63
  end
47
64
 
@@ -1,7 +1,7 @@
1
1
  ##
2
2
  ## $Rev: 33 $
3
- ## $Release: 2.1.0 $
4
- ## copyright(c) 2006 kuwata-lab all rights reserved.
3
+ ## $Release: 2.2.0 $
4
+ ## copyright(c) 2006-2007 kuwata-lab all rights reserved.
5
5
  ##
6
6
 
7
7
  require 'erubis/engine'
@@ -1,7 +1,7 @@
1
1
  ##
2
2
  ## $Rev: 31 $
3
- ## $Release: 2.1.0 $
4
- ## copyright(c) 2006 kuwata-lab all rights reserved.
3
+ ## $Release: 2.2.0 $
4
+ ## copyright(c) 2006-2007 kuwata-lab all rights reserved.
5
5
  ##
6
6
 
7
7
  require 'erubis/engine'
@@ -1,7 +1,7 @@
1
1
  ##
2
2
  ## $Rev: 31 $
3
- ## $Release: 2.1.0 $
4
- ## copyright(c) 2006 kuwata-lab all rights reserved.
3
+ ## $Release: 2.2.0 $
4
+ ## copyright(c) 2006-2007 kuwata-lab all rights reserved.
5
5
  ##
6
6
 
7
7
  require 'erubis/engine'
@@ -1,7 +1,7 @@
1
1
  ##
2
2
  ## $Rev: 27 $
3
- ## $Release: 2.1.0 $
4
- ## copyright(c) 2006 kuwata-lab all rights reserved.
3
+ ## $Release: 2.2.0 $
4
+ ## copyright(c) 2006-2007 kuwata-lab all rights reserved.
5
5
  ##
6
6
 
7
7
  require 'erubis/enhancer'
@@ -1,7 +1,7 @@
1
1
  ##
2
2
  ## $Rev: 40 $
3
- ## $Release: 2.1.0 $
4
- ## copyright(c) 2006 kuwata-lab all rights reserved.
3
+ ## $Release: 2.2.0 $
4
+ ## copyright(c) 2006-2007 kuwata-lab all rights reserved.
5
5
  ##
6
6
 
7
7
  require 'erubis/engine'
@@ -1,7 +1,7 @@
1
1
  ##
2
2
  ## $Rev: 31 $
3
- ## $Release: 2.1.0 $
4
- ## copyright(c) 2006 kuwata-lab all rights reserved.
3
+ ## $Release: 2.2.0 $
4
+ ## copyright(c) 2006-2007 kuwata-lab all rights reserved.
5
5
  ##
6
6
 
7
7
  require 'erubis/engine'
@@ -1,12 +1,11 @@
1
1
  ##
2
- ## $Rev: 33 $
3
- ## $Release: 2.1.0 $
4
- ## copyright(c) 2006 kuwata-lab all rights reserved.
2
+ ## $Rev: 54 $
3
+ ## $Release: 2.2.0 $
4
+ ## copyright(c) 2006-2007 kuwata-lab all rights reserved.
5
5
  ##
6
6
 
7
7
  require 'erubis/engine'
8
8
  require 'erubis/enhancer'
9
- require 'abstract'
10
9
 
11
10
 
12
11
  module Erubis
@@ -17,8 +16,8 @@ module Erubis
17
16
  ##
18
17
  module RubyGenerator
19
18
  include Generator
20
- #include StringBufferEnhancer
21
- include ArrayBufferEnhancer
19
+ #include ArrayBufferEnhancer
20
+ include StringBufferEnhancer
22
21
 
23
22
  def init_generator(properties={})
24
23
  super
@@ -1,7 +1,7 @@
1
1
  ##
2
2
  ## $Rev: 33 $
3
- ## $Release: 2.1.0 $
4
- ## copyright(c) 2006 kuwata-lab all rights reserved.
3
+ ## $Release: 2.2.0 $
4
+ ## copyright(c) 2006-2007 kuwata-lab all rights reserved.
5
5
  ##
6
6
 
7
7
  require 'erubis/engine'
@@ -1,7 +1,7 @@
1
1
  ##
2
2
  ## $Rev: 31 $
3
- ## $Release: 2.1.0 $
4
- ## copyright(c) 2006 kuwata-lab all rights reserved.
3
+ ## $Release: 2.2.0 $
4
+ ## copyright(c) 2006-2007 kuwata-lab all rights reserved.
5
5
  ##
6
6
 
7
7
 
@@ -1,7 +1,7 @@
1
1
  ##
2
- ## $Rev: 32 $
3
- ## $Release: 2.1.0 $
4
- ## copyright(c) 2006 kuwata-lab all rights reserved.
2
+ ## $Rev: 60 $
3
+ ## $Release: 2.2.0 $
4
+ ## copyright(c) 2006-2007 kuwata-lab all rights reserved.
5
5
  ##
6
6
 
7
7
 
@@ -214,7 +214,7 @@ module Erubis
214
214
 
215
215
  def add_postamble(src)
216
216
  src << "\n" unless src[-1] == ?\n
217
- src << "_buf\n"
217
+ src << "_buf.to_s\n"
218
218
  end
219
219
 
220
220
  end
@@ -243,6 +243,31 @@ module Erubis
243
243
  end
244
244
 
245
245
 
246
+ #--
247
+ ###
248
+ ### set buffer variable name to '_erbout' as well as '_buf'
249
+ ###
250
+ ### this is only for Eruby.
251
+ ###
252
+ #module ErboutEnhancer
253
+ #
254
+ # def self.desc # :nodoc:
255
+ # "set buffer name '_erbout' as well as '_buf'"
256
+ # end
257
+ #
258
+ # def add_preamble(src)
259
+ # src << "_erbout = _buf = '';"
260
+ # end
261
+ #
262
+ # def add_postamble(src)
263
+ # src << "\n" unless src[-1] == ?\n
264
+ # src << "_buf.to_s\n"
265
+ # end
266
+ #
267
+ #end
268
+ #++
269
+
270
+
246
271
  ##
247
272
  ## remove text and leave code, especially useful when debugging.
248
273
  ##
@@ -323,9 +348,10 @@ module Erubis
323
348
  #regexp = pattern_regexp(@pattern)
324
349
  pos = 0
325
350
  input.scan(SIMPLE_REGEXP) do |indicator, code|
326
- index = Regexp.last_match.begin(0)
327
- text = input[pos, index - pos]
328
- pos = index + $&.length()
351
+ match = Regexp.last_match
352
+ index = match.begin(0)
353
+ text = input[pos, index - pos]
354
+ pos = match.end(0)
329
355
  add_text(src, text)
330
356
  if !indicator # <% %>
331
357
  add_stmt(src, code)
@@ -1,7 +1,7 @@
1
1
  ##
2
2
  ## $Rev: 32 $
3
- ## $Release: 2.1.0 $
4
- ## copyright(c) 2006 kuwata-lab all rights reserved.
3
+ ## $Release: 2.2.0 $
4
+ ## copyright(c) 2006-2007 kuwata-lab all rights reserved.
5
5
  ##
6
6
 
7
7
  module Erubis
@@ -1,7 +1,7 @@
1
1
  ##
2
2
  ## $Rev: 32 $
3
- ## $Release: 2.1.0 $
4
- ## copyright(c) 2006 kuwata-lab all rights reserved.
3
+ ## $Release: 2.2.0 $
4
+ ## copyright(c) 2006-2007 kuwata-lab all rights reserved.
5
5
  ##
6
6
 
7
7
  require 'erubis/error'
@@ -1,7 +1,7 @@
1
1
  ##
2
- ## $Rev: 32 $
3
- ## $Release: 2.1.0 $
4
- ## copyright(c) 2006 kuwata-lab all rights reserved.
2
+ ## $Rev: 42 $
3
+ ## $Release: 2.2.0 $
4
+ ## copyright(c) 2006-2007 kuwata-lab all rights reserved.
5
5
  ##
6
6
 
7
7
  require 'abstract'
@@ -9,6 +9,9 @@ require 'abstract'
9
9
  module Erubis
10
10
 
11
11
 
12
+ ##
13
+ ## code generator, called by Converter module
14
+ ##
12
15
  module Generator
13
16
 
14
17
  def self.supported_properties() # :nodoc:
@@ -1,7 +1,7 @@
1
1
  ##
2
- ## $Rev: 21 $
3
- ## $Release: 2.1.0 $
4
- ## copyright(c) 2006 kuwata-lab all rights reserved.
2
+ ## $Rev: 64 $
3
+ ## $Release: 2.2.0 $
4
+ ## copyright(c) 2006-2007 kuwata-lab all rights reserved.
5
5
  ##
6
6
 
7
7
 
@@ -22,28 +22,11 @@ module Erubis
22
22
  "'" => '&#039;',
23
23
  }
24
24
 
25
- def escape_xml(obj)
26
- #table = ESCAPE_TABLE
27
- #obj.to_s.gsub(/[&<>"]/) { |s| table[s] } # or /[&<>"']/
28
- obj.to_s.gsub(/[&<>"]/) { |s| ESCAPE_TABLE[s] } # or /[&<>"']/
29
- #obj.to_s.gsub(SCAN_REGEXP) { |s| ESCAPE_TABLE[s] }
30
- #obj.to_s.gsub(/[&<>"]/) { ESCAPE_TABLE[$&] }
25
+ def escape_xml(value)
26
+ value.to_s.gsub(/[&<>"]/) { |s| ESCAPE_TABLE[s] } # or /[&<>"']/
27
+ #value.to_s.gsub(/[&<>"]/) { ESCAPE_TABLE[$&] }
31
28
  end
32
29
 
33
- #--
34
- #def escape_xml(obj)
35
- # str = obj.to_s.dup
36
- # #str = obj.to_s
37
- # #str = str.dup if obj.__id__ == str.__id__
38
- # str.gsub!(/&/, '&amp;')
39
- # str.gsub!(/</, '&lt;')
40
- # str.gsub!(/>/, '&gt;')
41
- # str.gsub!(/"/, '&quot;')
42
- # str.gsub!(/'/, '&#039;')
43
- # return str
44
- #end
45
- #++
46
-
47
30
  alias h escape_xml
48
31
  alias html_escape escape_xml
49
32
 
@@ -0,0 +1,202 @@
1
+ ###
2
+ ### $Rev: 64 $
3
+ ### $Release: 2.2.0 $
4
+ ### copyright(c) 2006-2007 kuwata-lab all rights reserved.
5
+ ###
6
+
7
+
8
+ require 'erubis'
9
+
10
+
11
+ module Erubis
12
+
13
+ module Helpers
14
+
15
+ ##
16
+ ## helper module for Ruby on Rails
17
+ ##
18
+ ## howto:
19
+ ##
20
+ ## 1. add the folliwng code in your 'config/environment.rb'
21
+ ##
22
+ ## require 'erubis/helpers/rails_helper'
23
+ ## #Erubis::Helpers::RailsHelper.engine_class = Erubis::Eruby
24
+ ## #Erubis::Helpers::RailsHelper.init_properties = {}
25
+ ## #Erubis::Helpers::RailsHelper.show_src = false
26
+ ##
27
+ ## 2. (optional) apply the patch for 'action_view/base.rb'
28
+ ##
29
+ ## $ cd /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_view/
30
+ ## $ sudo patch -p1 < /tmp/erubis_2.X.X/contrib/action_view_base_rb.patch
31
+ ##
32
+ ## 3. restart web server.
33
+ ##
34
+ ## if Erubis::Helper::Rails.show_src is ture, Erubis prints converted Ruby code
35
+ ## into log file ('log/development.log' or so). This may be useful for debug.
36
+ ##
37
+ module RailsHelper
38
+
39
+ #cattr_accessor :init_properties
40
+ @@engine_class = Erubis::Eruby
41
+
42
+ def self.engine_class
43
+ @@engine_class
44
+ end
45
+
46
+ def self.engine_class=(klass)
47
+ @@engine_class = klass
48
+ end
49
+
50
+ #cattr_accessor :init_properties
51
+ @@init_properties = {}
52
+
53
+ def self.init_properties
54
+ @@init_properties
55
+ end
56
+
57
+ def self.init_properties=(hash)
58
+ @@init_properties = hash
59
+ end
60
+
61
+ #cattr_accessor :show_src
62
+ @@show_src = false
63
+
64
+ def self.show_src
65
+ @@show_src
66
+ end
67
+
68
+ def self.show_src=(flag)
69
+ @@show_src = flag
70
+ end
71
+
72
+ end
73
+
74
+ end
75
+
76
+ end
77
+
78
+
79
+ method_name = 'convert_template_into_ruby_code'
80
+ unless ActionView::Base.private_instance_methods.include?(method_name) ||
81
+ ActionView::Base.instance_methods.include?(method_name)
82
+
83
+ require 'action_pack/version'
84
+
85
+ module ActionView # :nodoc:
86
+
87
+ class Base # :nodoc:
88
+
89
+ private
90
+
91
+ # convert template into ruby code
92
+ def convert_template_into_ruby_code(template)
93
+ ERB.new(template, nil, @@erb_trim_mode).src
94
+ end
95
+
96
+
97
+ if ActionPack::VERSION::MINOR <= 12 ### Rails 1.1
98
+
99
+
100
+ # Create source code for given template
101
+ def create_template_source(extension, template, render_symbol, locals)
102
+ if template_requires_setup?(extension)
103
+ body = case extension.to_sym
104
+ when :rxml
105
+ "xml = Builder::XmlMarkup.new(:indent => 2)\n" +
106
+ "@controller.headers['Content-Type'] ||= 'application/xml'\n" +
107
+ template
108
+ when :rjs
109
+ "@controller.headers['Content-Type'] ||= 'text/javascript'\n" +
110
+ "update_page do |page|\n#{template}\nend"
111
+ end
112
+ else
113
+ #body = ERB.new(template, nil, @@erb_trim_mode).src
114
+ body = convert_template_into_ruby_code(template)
115
+ end
116
+
117
+ @@template_args[render_symbol] ||= {}
118
+ locals_keys = @@template_args[render_symbol].keys | locals
119
+ @@template_args[render_symbol] = locals_keys.inject({}) { |h, k| h[k] = true; h }
120
+
121
+ locals_code = ""
122
+ locals_keys.each do |key|
123
+ locals_code << "#{key} = local_assigns[:#{key}] if local_assigns.has_key?(:#{key})\n"
124
+ end
125
+
126
+ "def #{render_symbol}(local_assigns)\n#{locals_code}#{body}\nend"
127
+ end
128
+
129
+
130
+ else ### Rails 1.2 or later
131
+
132
+
133
+ # Create source code for given template
134
+ def create_template_source(extension, template, render_symbol, locals)
135
+ if template_requires_setup?(extension)
136
+ body = case extension.to_sym
137
+ when :rxml
138
+ "controller.response.content_type ||= 'application/xml'\n" +
139
+ "xml = Builder::XmlMarkup.new(:indent => 2)\n" +
140
+ template
141
+ when :rjs
142
+ "controller.response.content_type ||= 'text/javascript'\n" +
143
+ "update_page do |page|\n#{template}\nend"
144
+ end
145
+ else
146
+ #body = ERB.new(template, nil, @@erb_trim_mode).src
147
+ body = convert_template_into_ruby_code(template)
148
+ end
149
+
150
+ @@template_args[render_symbol] ||= {}
151
+ locals_keys = @@template_args[render_symbol].keys | locals
152
+ @@template_args[render_symbol] = locals_keys.inject({}) { |h, k| h[k] = true; h }
153
+
154
+ locals_code = ""
155
+ locals_keys.each do |key|
156
+ locals_code << "#{key} = local_assigns[:#{key}]\n"
157
+ end
158
+
159
+ "def #{render_symbol}(local_assigns)\n#{locals_code}#{body}\nend"
160
+ end
161
+
162
+
163
+ end ###
164
+
165
+
166
+ end
167
+
168
+ end
169
+
170
+ end
171
+
172
+
173
+ ## set Erubis as eRuby compiler in Ruby on Rails instead of ERB
174
+ class ActionView::Base # :nodoc:
175
+ private
176
+ def convert_template_into_ruby_code(template)
177
+ #src = Erubis::Eruby.new(template).src
178
+ klass = Erubis::Helpers::RailsHelper.engine_class
179
+ properties = Erubis::Helpers::RailsHelper.init_properties
180
+ show_src = Erubis::Helpers::RailsHelper.show_src
181
+ src = klass.new(template, properties).src
182
+ src.insert(0, '_erbout = ')
183
+ logger.debug "** Erubis: src==<<'END'\n#{src}END\n" if show_src
184
+ src
185
+ end
186
+ end
187
+
188
+
189
+ ## make h() method faster
190
+ module ERB::Util # :nodoc:
191
+ ESCAPE_TABLE = { '&'=>'&amp;', '<'=>'&lt;', '>'=>'&gt;', '"'=>'&quot;', "'"=>'&#039;', }
192
+ def h(value)
193
+ value.to_s.gsub(/[&<>"]/) { |s| ESCAPE_TABLE[s] }
194
+ end
195
+ module_function :h
196
+ end
197
+
198
+
199
+ ## finish
200
+ ac = ActionController::Base.new
201
+ ac.logger.info "** Erubis #{Erubis::VERSION}"
202
+ #$stdout.puts "** Erubis #{Erubis::VERSION}"