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.
- data/{ChangeLog → CHANGES} +139 -6
- data/MIT-LICENSE +20 -0
- data/README.txt +20 -5
- data/benchmark/erubybench.rb +465 -229
- data/benchmark/erubybench.rhtml +39 -15
- data/benchmark/erubybench.yaml +126 -46
- data/bin/erubis +2 -2
- data/bin/notext +3 -3
- data/contrib/action_view_base_rb.patch +23 -0
- data/contrib/erubis +466 -308
- data/contrib/inline-require +2 -2
- data/doc-api/classes/ERB.html +101 -0
- data/doc-api/classes/Erubis.html +59 -6
- data/doc-api/classes/Erubis/ArrayEnhancer.html +12 -12
- data/doc-api/classes/Erubis/Basic/Converter.html +61 -57
- data/doc-api/classes/Erubis/BiPatternEnhancer.html +14 -14
- data/doc-api/classes/Erubis/CGenerator.html +60 -60
- data/doc-api/classes/Erubis/Context.html +125 -29
- data/doc-api/classes/Erubis/Converter.html +73 -22
- data/doc-api/classes/Erubis/Engine.html +55 -39
- data/doc-api/classes/Erubis/EscapeEnhancer.html +6 -6
- data/doc-api/classes/Erubis/Evaluator.html +19 -19
- data/doc-api/classes/Erubis/Generator.html +16 -10
- data/doc-api/classes/Erubis/HeaderFooterEnhancer.html +14 -14
- data/doc-api/classes/Erubis/{Helper.html → Helpers.html} +5 -6
- data/doc-api/classes/Erubis/Helpers/RailsHelper.html +296 -0
- data/doc-api/classes/Erubis/JavaGenerator.html +54 -54
- data/doc-api/classes/Erubis/JavascriptGenerator.html +60 -60
- data/doc-api/classes/Erubis/Main.html +42 -30
- data/doc-api/classes/Erubis/NoCodeEnhancer.html +5 -5
- data/doc-api/classes/Erubis/NoTextEnhancer.html +7 -7
- data/doc-api/classes/Erubis/OptimizedEruby.html +6 -6
- data/doc-api/classes/Erubis/OptimizedGenerator.html +72 -72
- data/doc-api/classes/Erubis/OptimizedXmlEruby.html +6 -6
- data/doc-api/classes/Erubis/PI/Converter.html +28 -81
- data/doc-api/classes/Erubis/PI/Ec.html +6 -6
- data/doc-api/classes/Erubis/PI/Ejava.html +6 -6
- data/doc-api/classes/Erubis/PI/Ejavascript.html +6 -6
- data/doc-api/classes/Erubis/PI/Eperl.html +6 -6
- data/doc-api/classes/Erubis/PI/Ephp.html +6 -6
- data/doc-api/classes/Erubis/PI/Eruby.html +7 -7
- data/doc-api/classes/Erubis/PI/Escheme.html +6 -6
- data/doc-api/classes/Erubis/PI/TinyEruby.html +66 -79
- data/doc-api/classes/Erubis/PercentLineEnhancer.html +8 -8
- data/doc-api/classes/Erubis/PerlGenerator.html +54 -54
- data/doc-api/classes/Erubis/PhpGenerator.html +54 -54
- data/doc-api/classes/Erubis/PrintEnabledEnhancer.html +21 -21
- data/doc-api/classes/Erubis/PrintOutEnhancer.html +30 -30
- data/doc-api/classes/Erubis/RubyEvaluator.html +12 -12
- data/doc-api/classes/Erubis/RubyGenerator.html +9 -9
- data/doc-api/classes/Erubis/SimplifyEnhancer.html +7 -6
- data/doc-api/classes/Erubis/StdoutEnhancer.html +12 -12
- data/doc-api/classes/Erubis/StringBufferEnhancer.html +13 -13
- data/doc-api/classes/Erubis/TinyEruby.html +56 -68
- data/doc-api/classes/Erubis/XmlHelper.html +20 -23
- data/doc-api/created.rid +1 -1
- data/doc-api/files/{__/README_txt.html → README_txt.html} +35 -20
- data/doc-api/files/erubis/context_rb.html +2 -2
- data/doc-api/files/erubis/converter_rb.html +2 -2
- data/doc-api/files/erubis/engine/ec_rb.html +2 -2
- data/doc-api/files/erubis/engine/ejava_rb.html +2 -2
- data/doc-api/files/erubis/engine/ejavascript_rb.html +2 -2
- data/doc-api/files/erubis/engine/enhanced_rb.html +2 -2
- data/doc-api/files/erubis/engine/eperl_rb.html +2 -2
- data/doc-api/files/erubis/engine/ephp_rb.html +2 -2
- data/doc-api/files/erubis/engine/eruby_rb.html +2 -3
- data/doc-api/files/erubis/engine/escheme_rb.html +2 -2
- data/doc-api/files/erubis/engine/optimized_rb.html +2 -2
- data/doc-api/files/erubis/engine_rb.html +2 -2
- data/doc-api/files/erubis/enhancer_rb.html +2 -2
- data/doc-api/files/erubis/error_rb.html +2 -2
- data/doc-api/files/erubis/evaluator_rb.html +2 -2
- data/doc-api/files/erubis/generator_rb.html +2 -2
- data/doc-api/files/erubis/helper_rb.html +2 -2
- data/doc-api/files/erubis/{helper/rails_rb.html → helpers/rails_helper_rb.html} +6 -31
- data/doc-api/files/erubis/local-setting_rb.html +2 -2
- data/doc-api/files/erubis/main_rb.html +4 -2
- data/doc-api/files/erubis/tiny_rb.html +2 -2
- data/doc-api/files/erubis_rb.html +2 -2
- data/doc-api/fr_class_index.html +3 -3
- data/doc-api/fr_file_index.html +2 -2
- data/doc-api/fr_method_index.html +142 -147
- data/doc-api/index.html +1 -1
- data/doc/users-guide.html +387 -218
- data/lib/erubis.rb +21 -25
- data/lib/erubis/context.rb +34 -4
- data/lib/erubis/converter.rb +159 -115
- data/lib/erubis/engine.rb +29 -12
- data/lib/erubis/engine/ec.rb +2 -2
- data/lib/erubis/engine/ejava.rb +2 -2
- data/lib/erubis/engine/ejavascript.rb +2 -2
- data/lib/erubis/engine/enhanced.rb +2 -2
- data/lib/erubis/engine/eperl.rb +2 -2
- data/lib/erubis/engine/ephp.rb +2 -2
- data/lib/erubis/engine/eruby.rb +5 -6
- data/lib/erubis/engine/escheme.rb +2 -2
- data/lib/erubis/engine/optimized.rb +2 -2
- data/lib/erubis/enhancer.rb +33 -7
- data/lib/erubis/error.rb +2 -2
- data/lib/erubis/evaluator.rb +2 -2
- data/lib/erubis/generator.rb +6 -3
- data/lib/erubis/helper.rb +6 -23
- data/lib/erubis/helpers/rails_helper.rb +202 -0
- data/lib/erubis/local-setting.rb +4 -4
- data/lib/erubis/main.rb +90 -35
- data/lib/erubis/tiny.rb +57 -52
- data/test/assert-text-equal.rb +2 -2
- data/test/test-engines.rb +5 -5
- data/test/test-erubis.rb +173 -63
- data/test/test-main.rb +135 -27
- data/test/test-notext.rb +2 -2
- data/test/test.rb +2 -2
- data/test/testutil.rb +2 -2
- metadata +16 -16
- data/LGPL +0 -504
- data/doc-api/classes/Erubis/Helper/CachedRailsTemplate.html +0 -198
- data/doc-api/classes/Erubis/Helper/RailsTemplate.html +0 -366
- data/lib/erubis/helper/rails.rb +0 -159
data/lib/erubis.rb
CHANGED
|
@@ -1,20 +1,13 @@
|
|
|
1
1
|
##
|
|
2
|
-
## $Rev:
|
|
3
|
-
## $Release: 2.
|
|
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
|
-
##
|
|
11
|
-
## * class XmlEruby - eRuby class which escape '&<>"' into '&<>"'
|
|
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
|
|
22
|
+
## puts eruby.src
|
|
31
23
|
## puts "--- result ---"
|
|
32
|
-
## context =
|
|
33
|
-
## context
|
|
34
|
-
## puts
|
|
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 =
|
|
40
|
-
##
|
|
41
|
-
##
|
|
42
|
-
## _buf <<
|
|
43
|
-
##
|
|
44
|
-
##
|
|
45
|
-
##
|
|
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'
|
data/lib/erubis/context.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
##
|
|
2
|
-
## $Rev:
|
|
3
|
-
## $Release: 2.
|
|
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
|
|
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
|
data/lib/erubis/converter.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
##
|
|
2
|
-
## $Rev:
|
|
3
|
-
## $Release: 2.
|
|
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
|
|
76
|
-
@trim
|
|
105
|
+
@pattern = properties[:pattern]
|
|
106
|
+
@trim = properties[:trim] != false
|
|
77
107
|
end
|
|
78
108
|
|
|
79
|
-
|
|
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
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
-
|
|
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
|
-
|
|
128
|
+
pat = @pattern
|
|
129
|
+
regexp = pat.nil? || pat == '<% %>' ? DEFAULT_REGEXP : pattern_regexp(pat)
|
|
96
130
|
pos = 0
|
|
97
|
-
|
|
131
|
+
is_bol = true # is beginning of line
|
|
132
|
+
input.scan(regexp) do |indicator, code, rspace|
|
|
98
133
|
match = Regexp.last_match()
|
|
99
|
-
|
|
100
|
-
text
|
|
101
|
-
pos
|
|
102
|
-
|
|
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
|
|
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, "
|
|
150
|
+
add_stmt(src, "\n" * n)
|
|
108
151
|
else
|
|
109
152
|
add_text(src, lspace) if lspace
|
|
110
|
-
add_stmt(src,
|
|
153
|
+
add_stmt(src, "\n" * n)
|
|
111
154
|
add_text(src, rspace) if rspace
|
|
112
155
|
end
|
|
113
|
-
|
|
114
|
-
n = code.count("\n") + (rspace ? 1 : 0)
|
|
156
|
+
else # <% %>
|
|
115
157
|
if @trim && lspace && rspace
|
|
116
|
-
add_stmt(src, "
|
|
158
|
+
add_stmt(src, "#{lspace}#{code}#{rspace}")
|
|
117
159
|
else
|
|
118
160
|
add_text(src, lspace) if lspace
|
|
119
|
-
add_stmt(src,
|
|
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 =
|
|
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
|
-
|
|
190
|
-
|
|
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
|
-
@
|
|
232
|
+
@regexp = /<\?#{@pi}(?:-(\w+))?(\s.*?)\?>([ \t]*\r?\n)?|#{ch}(!*)?\{(.*?)\}#{ch}|#{left}(=+)(.*?)#{right}/m
|
|
222
233
|
else
|
|
223
|
-
@
|
|
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(@
|
|
228
|
-
|
|
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
|
-
|
|
232
|
-
text = input[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
|
-
|
|
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
|
|
337
|
+
when nil, '', '==' # @{...}@ or <%== ... %>
|
|
254
338
|
@escape == false ? add_expr_literal(codebuf, code) : add_expr_escaped(codebuf, code)
|
|
255
|
-
when
|
|
339
|
+
when '!', '=' # @!{...}@ or <%= ... %>
|
|
256
340
|
@escape == false ? add_expr_escaped(codebuf, code) : add_expr_literal(codebuf, code)
|
|
257
|
-
when
|
|
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
|
|