erubis 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
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,20 +1,13 @@
1
1
  ##
2
- ## $Rev: 36 $
3
- ## $Release: 2.1.0 $
4
- ## copyright(c) 2006 kuwata-lab all rights reserved.
2
+ ## $Rev: 59 $
3
+ ## $Release: 2.2.0 $
4
+ ## copyright(c) 2006-2007 kuwata-lab all rights reserved.
5
5
  ##
6
6
 
7
7
  ##
8
8
  ## an implementation of eRuby
9
9
  ##
10
- ## * class Eruby - normal eRuby class
11
- ## * class XmlEruby - eRuby class which escape '&<>"' into '&amp;&lt;&gt;&quot;'
12
- ## * module StdoutEnhancer - use $stdout instead of String as output
13
- ## * module PrintEnhancer - enable to write print statement in <% ... %>
14
- ## * class OptimizedEruby - optimized Eruby class faster than FastEruby
15
- ## * class OptimizedXmlEruby - optimized XmlEruby class faster than FastXmlEruby
16
- ##
17
- ## example:
10
+ ## ex.
18
11
  ## input = <<'END'
19
12
  ## <ul>
20
13
  ## <% for item in @list %>
@@ -24,25 +17,24 @@
24
17
  ## </ul>
25
18
  ## END
26
19
  ## list = ['<aaa>', 'b&b', '"ccc"']
27
- ## eruby = Erubis::Eruby.new()
28
- ## code = eruby.convert(input)
20
+ ## eruby = Erubis::Eruby.new(input)
29
21
  ## puts "--- code ---"
30
- ## puts code
22
+ ## puts eruby.src
31
23
  ## puts "--- result ---"
32
- ## context = Object.new
33
- ## context.instance_variable_set("@list", list)
34
- ## puts context.instance_eval(code)
35
- ## # or @list = list; puts eval(code, binding())
24
+ ## context = Erubis::Context.new() # or new(:list=>list)
25
+ ## context[:list] = list
26
+ ## puts eruby.evaluate(context)
36
27
  ##
37
28
  ## result:
38
29
  ## --- source ---
39
- ## _buf = ""; _buf << " <ul>\n"
40
- ## for item in list
41
- ## _buf << " <li>"; _buf << ( item ).to_s; _buf << "\n"
42
- ## _buf << " "; _buf << Erubis::XmlEruby.escape( item ); _buf << "</li>\n"
43
- ## end
44
- ## _buf << " </ul>\n"
45
- ## _buf
30
+ ## _buf = ''; _buf << '<ul>
31
+ ## '; for item in @list
32
+ ## _buf << ' <li>'; _buf << ( item ).to_s; _buf << '
33
+ ## '; _buf << ' '; _buf << Erubis::XmlHelper.escape_xml( item ); _buf << '</li>
34
+ ## '; end
35
+ ## _buf << '</ul>
36
+ ## ';
37
+ ## _buf.to_s
46
38
  ## --- result ---
47
39
  ## <ul>
48
40
  ## <li><aaa>
@@ -55,6 +47,10 @@
55
47
  ##
56
48
 
57
49
 
50
+ module Erubis
51
+ VERSION = ('$Release: 2.2.0 $' =~ /([.\d]+)/) && $1
52
+ end
53
+
58
54
  require 'erubis/engine'
59
55
  #require 'erubis/generator'
60
56
  #require 'erubis/converter'
@@ -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: 59 $
3
+ ## $Release: 2.2.0 $
4
+ ## copyright(c) 2006-2007 kuwata-lab all rights reserved.
5
5
  ##
6
6
 
7
7
 
@@ -29,6 +29,7 @@ module Erubis
29
29
  ## print eruby.evaluate(context)
30
30
  ##
31
31
  class Context
32
+ include Enumerable
32
33
 
33
34
  def initialize(hash=nil)
34
35
  hash.each do |name, value|
@@ -45,7 +46,36 @@ module Erubis
45
46
  end
46
47
 
47
48
  def keys
48
- return instance_variables.collect { |name| name[1,name.length-1] }
49
+ return instance_variables.collect { |name| name[1..-1] }
50
+ end
51
+
52
+ def each
53
+ instance_variables.each do |name|
54
+ key = name[1..-1]
55
+ value = instance_variable_get(name)
56
+ yield(key, value)
57
+ end
58
+ end
59
+
60
+ def to_hash
61
+ hash = {}
62
+ self.keys.each { |key| hash[key] = self[key] }
63
+ return hash
64
+ end
65
+
66
+ def update(context_or_hash)
67
+ arg = context_or_hash
68
+ if arg.is_a?(Hash)
69
+ arg.each do |key, val|
70
+ self[key] = val
71
+ end
72
+ else
73
+ arg.instance_variables.each do |varname|
74
+ key = varname[1..-1]
75
+ val = arg.instance_variable_get(varname)
76
+ self[key] = val
77
+ end
78
+ end
49
79
  end
50
80
 
51
81
  end
@@ -1,7 +1,7 @@
1
1
  ##
2
- ## $Rev: 37 $
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
  require 'abstract'
@@ -41,6 +41,36 @@ module Erubis
41
41
 
42
42
  protected
43
43
 
44
+ ##
45
+ ## detect spaces at beginning of line
46
+ ##
47
+ def detect_spaces_at_bol(text, is_bol)
48
+ lspace = nil
49
+ if text.empty?
50
+ lspace = "" if is_bol
51
+ elsif text[-1] == ?\n
52
+ lspace = ""
53
+ else
54
+ rindex = text.rindex(?\n)
55
+ if rindex
56
+ s = text[rindex+1..-1]
57
+ if s =~ /\A[ \t]*\z/
58
+ lspace = s
59
+ #text = text[0..rindex]
60
+ text[rindex+1..-1] = ''
61
+ end
62
+ else
63
+ if is_bol && text =~ /\A[ \t]*\z/
64
+ #lspace = text
65
+ #text = nil
66
+ lspace = text.dup
67
+ text[0..-1] = ''
68
+ end
69
+ end
70
+ end
71
+ return lspace
72
+ end
73
+
44
74
  ##
45
75
  ## (abstract) convert input to code
46
76
  ##
@@ -72,57 +102,65 @@ module Erubis
72
102
 
73
103
  def init_converter(properties={})
74
104
  super(properties)
75
- @pattern = properties[:pattern]
76
- @trim = properties[:trim] != false
105
+ @pattern = properties[:pattern]
106
+ @trim = properties[:trim] != false
77
107
  end
78
108
 
79
- #DEFAULT_REGEXP = /(.*?)(^[ \t]*)?<%(=+|\#)?(.*?)-?%>([ \t]*\r?\n)?/m
80
- DEFAULT_REGEXP = /(^[ \t]*)?<%(=+|\#)?(.*?)-?%>([ \t]*\r?\n)?/m
109
+ protected
81
110
 
82
111
  ## return regexp of pattern to parse eRuby script
83
- def pattern_regexp(pattern=@pattern)
84
- if pattern.nil? || pattern == '<% %>'
85
- return DEFAULT_REGEXP
86
- else
87
- prefix, postfix = pattern.split()
88
- #return /(.*?)(^[ \t]*)?#{prefix}(=+|\#)?(.*?)-?#{postfix}([ \t]*\r?\n)?/m
89
- return /(^[ \t]*)?#{prefix}(=+|\#)?(.*?)-?#{postfix}([ \t]*\r?\n)?/m
90
- end
112
+ def pattern_regexp(pattern)
113
+ prefix, postfix = pattern.split() # '<% %>' => '<%', '%>'
114
+ #return /(.*?)(^[ \t]*)?#{prefix}(=+|\#)?(.*?)-?#{postfix}([ \t]*\r?\n)?/m
115
+ #return /(^[ \t]*)?#{prefix}(=+|\#)?(.*?)-?#{postfix}([ \t]*\r?\n)?/m
116
+ return /#{prefix}(=+|-|\#)?(.*?)-?#{postfix}([ \t]*\r?\n)?/m
91
117
  end
92
- protected :pattern_regexp
118
+ module_function :pattern_regexp
119
+
120
+ #DEFAULT_REGEXP = /(.*?)(^[ \t]*)?<%(=+|\#)?(.*?)-?%>([ \t]*\r?\n)?/m
121
+ #DEFAULT_REGEXP = /(^[ \t]*)?<%(=+|\#)?(.*?)-?%>([ \t]*\r?\n)?/m
122
+ #DEFAULT_REGEXP = /<%(=+|\#)?(.*?)-?%>([ \t]*\r?\n)?/m
123
+ DEFAULT_REGEXP = pattern_regexp('<% %>')
124
+
125
+ public
93
126
 
94
127
  def convert_input(src, input)
95
- regexp = pattern_regexp(@pattern)
128
+ pat = @pattern
129
+ regexp = pat.nil? || pat == '<% %>' ? DEFAULT_REGEXP : pattern_regexp(pat)
96
130
  pos = 0
97
- input.scan(regexp) do |lspace, indicator, code, rspace|
131
+ is_bol = true # is beginning of line
132
+ input.scan(regexp) do |indicator, code, rspace|
98
133
  match = Regexp.last_match()
99
- index = match.begin(0)
100
- text = input[pos, index - pos]
101
- pos = match.end(0)
102
- add_text(src, text)
134
+ len = match.begin(0) - pos
135
+ text = input[pos, len]
136
+ pos = match.end(0)
137
+ ch = indicator ? indicator[0] : nil
138
+ lspace = ch == ?= ? nil : detect_spaces_at_bol(text, is_bol)
139
+ is_bol = rspace ? true : false
140
+ add_text(src, text) if text && !text.empty?
103
141
  ## * when '<%= %>', do nothing
104
142
  ## * when '<% %>' or '<%# %>', delete spaces iff only spaces are around '<% %>'
105
- if !indicator # <% %>
143
+ if ch == ?= # <%= %>
144
+ add_text(src, lspace) if lspace
145
+ add_expr(src, code, indicator)
146
+ add_text(src, rspace) if rspace
147
+ elsif ch == ?\# # <%# %>
148
+ n = code.count("\n") + (rspace ? 1 : 0)
106
149
  if @trim && lspace && rspace
107
- add_stmt(src, "#{lspace}#{code}#{rspace}")
150
+ add_stmt(src, "\n" * n)
108
151
  else
109
152
  add_text(src, lspace) if lspace
110
- add_stmt(src, code)
153
+ add_stmt(src, "\n" * n)
111
154
  add_text(src, rspace) if rspace
112
155
  end
113
- elsif indicator[0] == ?\# # <%# %>
114
- n = code.count("\n") + (rspace ? 1 : 0)
156
+ else # <% %>
115
157
  if @trim && lspace && rspace
116
- add_stmt(src, "\n" * n)
158
+ add_stmt(src, "#{lspace}#{code}#{rspace}")
117
159
  else
118
160
  add_text(src, lspace) if lspace
119
- add_stmt(src, "\n" * n)
161
+ add_stmt(src, code)
120
162
  add_text(src, rspace) if rspace
121
163
  end
122
- else # <%= %>
123
- add_text(src, lspace) if lspace
124
- add_expr(src, code, indicator)
125
- add_text(src, rspace) if rspace
126
164
  end
127
165
  end
128
166
  rest = $' || input # add input when no matched
@@ -171,9 +209,9 @@ module Erubis
171
209
 
172
210
  def init_converter(properties={})
173
211
  super(properties)
174
- @trim = !(properties[:trim] == false)
212
+ @trim = properties.fetch(:trim, true)
175
213
  @pi = properties[:pi] if properties[:pi]
176
- @embchar = properties[:embchar] || '@'
214
+ @embchar = properties[:embchar] || '@'
177
215
  @pattern = properties[:pattern]
178
216
  @pattern = '<% %>' if @pattern.nil? #|| @pattern == true
179
217
  end
@@ -186,60 +224,106 @@ module Erubis
186
224
  protected
187
225
 
188
226
  def convert_input(codebuf, input)
189
- parse_stmts(codebuf, input)
190
- #parse_stmts2(codebuf, input)
191
- end
192
-
193
- def parse_stmts(codebuf, input)
194
- #regexp = pattern_regexp(@pattern)
195
- @pi ||= 'e'
196
- @stmt_pattern ||= /(^[ \t]*)?<\?#{@pi}(?:-(\w+))?(\s.*?)\?>([ \t]*\r?\n)?/m
197
- pos = 0
198
- input.scan(@stmt_pattern) do |lspace, pi_arg, code, rspace|
199
- match = Regexp.last_match
200
- index = match.begin(0)
201
- text = input[pos, index - pos]
202
- pos = match.end(0)
203
- parse_exprs(codebuf, text) # unless text.empty?
204
- if @trim && lspace && rspace
205
- add_pi_stmt(codebuf, "#{lspace}#{code}#{rspace}", pi_arg)
206
- else
207
- add_text(codebuf, lspace)
208
- add_pi_stmt(codebuf, code, pi_arg)
209
- add_text(codebuf, rspace)
210
- end
211
- end
212
- rest = $' || input
213
- parse_exprs(codebuf, rest)
214
- end
215
-
216
- def parse_exprs(codebuf, input)
217
- unless @expr_pattern
227
+ unless @regexp
228
+ @pi ||= 'e'
218
229
  ch = Regexp.escape(@embchar)
219
230
  if @pattern
220
231
  left, right = @pattern.split(' ')
221
- @expr_pattern = /#{ch}(!*)?\{(.*?)\}#{ch}|#{left}(=+)(.*?)#{right}/
232
+ @regexp = /<\?#{@pi}(?:-(\w+))?(\s.*?)\?>([ \t]*\r?\n)?|#{ch}(!*)?\{(.*?)\}#{ch}|#{left}(=+)(.*?)#{right}/m
222
233
  else
223
- @expr_pattern = /#{ch}(!*)?\{(.*?)\}#{ch}/
234
+ @regexp = /<\?#{@pi}(?:-(\w+))?(\s.*?)\?>([ \t]*\r?\n)?|#{ch}(!*)?\{(.*?)\}#{ch}/m
224
235
  end
225
236
  end
237
+ #
238
+ is_bol = true
226
239
  pos = 0
227
- input.scan(@expr_pattern) do |indicator1, code1, indicator2, code2|
228
- indicator = indicator1 || indicator2
229
- code = code1 || code2
240
+ input.scan(@regexp) do |pi_arg, stmt, rspace,
241
+ indicator1, expr1, indicator2, expr2|
230
242
  match = Regexp.last_match
231
- index = match.begin(0)
232
- text = input[pos, index - pos]
243
+ len = match.begin(0) - pos
244
+ text = input[pos, len]
233
245
  pos = match.end(0)
246
+ lspace = stmt ? detect_spaces_at_bol(text, is_bol) : nil
247
+ is_bol = stmt && rspace ? true : false
234
248
  add_text(codebuf, text) # unless text.empty?
235
- add_pi_expr(codebuf, code, indicator)
249
+ #
250
+ if stmt
251
+ if @trim && lspace && rspace
252
+ add_pi_stmt(codebuf, "#{lspace}#{stmt}#{rspace}", pi_arg)
253
+ else
254
+ add_text(codebuf, lspace) if lspace
255
+ add_pi_stmt(codebuf, stmt, pi_arg)
256
+ add_text(codebuf, rspace) if rspace
257
+ end
258
+ else
259
+ add_pi_expr(codebuf, expr1 || expr2, indicator1 || indicator2)
260
+ end
236
261
  end
237
262
  rest = $' || input
238
263
  add_text(codebuf, rest)
239
264
  end
240
265
 
266
+ #--
267
+ #def convert_input(codebuf, input)
268
+ # parse_stmts(codebuf, input)
269
+ # #parse_stmts2(codebuf, input)
270
+ #end
271
+ #
272
+ #def parse_stmts(codebuf, input)
273
+ # #regexp = pattern_regexp(@pattern)
274
+ # @pi ||= 'e'
275
+ # @stmt_pattern ||= /<\?#{@pi}(?:-(\w+))?(\s.*?)\?>([ \t]*\r?\n)?/m
276
+ # is_bol = true
277
+ # pos = 0
278
+ # input.scan(@stmt_pattern) do |pi_arg, code, rspace|
279
+ # match = Regexp.last_match
280
+ # len = match.begin(0) - pos
281
+ # text = input[pos, len]
282
+ # pos = match.end(0)
283
+ # lspace = detect_spaces_at_bol(text, is_bol)
284
+ # is_bol = rspace ? true : false
285
+ # parse_exprs(codebuf, text) # unless text.empty?
286
+ # if @trim && lspace && rspace
287
+ # add_pi_stmt(codebuf, "#{lspace}#{code}#{rspace}", pi_arg)
288
+ # else
289
+ # add_text(codebuf, lspace)
290
+ # add_pi_stmt(codebuf, code, pi_arg)
291
+ # add_text(codebuf, rspace)
292
+ # end
293
+ # end
294
+ # rest = $' || input
295
+ # parse_exprs(codebuf, rest)
296
+ #end
297
+ #
298
+ #def parse_exprs(codebuf, input)
299
+ # unless @expr_pattern
300
+ # ch = Regexp.escape(@embchar)
301
+ # if @pattern
302
+ # left, right = @pattern.split(' ')
303
+ # @expr_pattern = /#{ch}(!*)?\{(.*?)\}#{ch}|#{left}(=+)(.*?)#{right}/
304
+ # else
305
+ # @expr_pattern = /#{ch}(!*)?\{(.*?)\}#{ch}/
306
+ # end
307
+ # end
308
+ # pos = 0
309
+ # input.scan(@expr_pattern) do |indicator1, code1, indicator2, code2|
310
+ # indicator = indicator1 || indicator2
311
+ # code = code1 || code2
312
+ # match = Regexp.last_match
313
+ # len = match.begin(0) - pos
314
+ # text = input[pos, len]
315
+ # pos = match.end(0)
316
+ # add_text(codebuf, text) # unless text.empty?
317
+ # add_pi_expr(codebuf, code, indicator)
318
+ # end
319
+ # rest = $' || input
320
+ # add_text(codebuf, rest)
321
+ #end
322
+ #++
323
+
241
324
  def add_pi_stmt(codebuf, code, pi_arg) # :nodoc:
242
325
  case pi_arg
326
+ when nil ; add_stmt(codebuf, code)
243
327
  when 'header' ; @header = code
244
328
  when 'footer' ; @footer = code
245
329
  when 'comment'; add_stmt(codebuf, "\n" * code.count("\n"))
@@ -250,57 +334,17 @@ module Erubis
250
334
 
251
335
  def add_pi_expr(codebuf, code, indicator) # :nodoc:
252
336
  case indicator
253
- when nil, '', '==' # @{...}@ or <%== ... %>
337
+ when nil, '', '==' # @{...}@ or <%== ... %>
254
338
  @escape == false ? add_expr_literal(codebuf, code) : add_expr_escaped(codebuf, code)
255
- when '!', '=' # @!{...}@ or <%= ... %>
339
+ when '!', '=' # @!{...}@ or <%= ... %>
256
340
  @escape == false ? add_expr_escaped(codebuf, code) : add_expr_literal(codebuf, code)
257
- when '!!', '===' # @!!{...}@ or <%=== ... %>
341
+ when '!!', '===' # @!!{...}@ or <%=== ... %>
258
342
  add_expr_debug(codebuf, code)
259
343
  else
260
344
  # ignore
261
345
  end
262
346
  end
263
347
 
264
- ## (obsolete) equivarent to parse_stmts(), but a little slower than it.
265
- def parse_stmts2(codebuf, input) # :nodoc:
266
- #regexp = pattern_regexp(@pattern)
267
- @pi ||= 'e'
268
- unless @embedded_pattern
269
- ch = Regexp.escape(@embchar)
270
- if @pattern
271
- left, right = @pattern.split(' ')
272
- @embedded_pattern = /(^[ \t]*)?<\?#{@pi}(?:-(\w+))?(\s.*?)\?>([ \t]*\r?\n)?|#{ch}(!*)?\{(.*?)\}#{ch}|#{left}(=+)(.*?)#{right}/m
273
- else
274
- @embedded_pattern = /(^[ \t]*)?<\?#{@pi}(?:-(\w+))?(\s.*?)\?>([ \t]*\r?\n)?|#{ch}(!*)?\{(.*?)\}#{ch}/m
275
- end
276
- end
277
- pos = 0
278
- input.scan(@embedded_pattern) do |lspace, pi_arg, stmt, rspace,
279
- indicator1, expr1, indicator2, expr2|
280
- match = Regexp.last_match
281
- index = match.begin(0)
282
- text = input[pos, index - pos]
283
- pos = match.end(0)
284
- add_text(codebuf, text) # unless text.empty?
285
- if stmt
286
- code = stmt
287
- if @trim && lspace && rspace
288
- add_pi_stmt(codebuf, "#{lspace}#{code}#{rspace}", pi_arg)
289
- else
290
- add_text(codebuf, lspace)
291
- add_pi_stmt(codebuf, code, pi_arg)
292
- add_text(codebuf, rspace)
293
- end
294
- else
295
- code = expr1 || expr2
296
- indicator = indicator1 || indicator2
297
- add_pi_expr(codebuf, code, indicator)
298
- end
299
- end
300
- rest = $' || input
301
- add_text(codebuf, rest)
302
- end
303
-
304
348
  end
305
349
 
306
350