summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authormakoto kuwata <kwa@kuwata-lab.com>2008-04-29 13:26:32 +0000
committermakoto kuwata <kwa@kuwata-lab.com>2008-04-29 13:26:32 +0000
commit0b66076e57243280b715d1bed89b1dc6f0e93f80 (patch)
tree1837a056ff838862d69bce851f67335592b7a85c /lib
parentfa5be13289315103cacaef99390b0ef27f3d9e9c (diff)
downloaderubis-0b66076e57243280b715d1bed89b1dc6f0e93f80.tar.gz
- [enhance] '<%= =%>' and '<%= -%>' removed tail spaces
Diffstat (limited to 'lib')
-rw-r--r--lib/erubis/converter.rb5
-rw-r--r--lib/erubis/enhancer.rb3
2 files changed, 5 insertions, 3 deletions
diff --git a/lib/erubis/converter.rb b/lib/erubis/converter.rb
index 0781f80..2d66dba 100644
--- a/lib/erubis/converter.rb
+++ b/lib/erubis/converter.rb
@@ -114,7 +114,7 @@ module Erubis
prefix, postfix = pattern.split() # '<% %>' => '<%', '%>'
#return /(.*?)(^[ \t]*)?#{prefix}(=+|\#)?(.*?)-?#{postfix}([ \t]*\r?\n)?/m
#return /(^[ \t]*)?#{prefix}(=+|\#)?(.*?)-?#{postfix}([ \t]*\r?\n)?/m
- return /#{prefix}(=+|-|\#)?(.*?)-?#{postfix}([ \t]*\r?\n)?/m
+ return /#{prefix}(=+|-|\#)?(.*?)([-=])?#{postfix}([ \t]*\r?\n)?/m
end
module_function :pattern_regexp
@@ -130,7 +130,7 @@ module Erubis
regexp = pat.nil? || pat == '<% %>' ? DEFAULT_REGEXP : pattern_regexp(pat)
pos = 0
is_bol = true # is beginning of line
- input.scan(regexp) do |indicator, code, rspace|
+ input.scan(regexp) do |indicator, code, tailch, rspace|
match = Regexp.last_match()
len = match.begin(0) - pos
text = input[pos, len]
@@ -142,6 +142,7 @@ module Erubis
## * when '<%= %>', do nothing
## * when '<% %>' or '<%# %>', delete spaces iff only spaces are around '<% %>'
if ch == ?= # <%= %>
+ rspace = nil if tailch && !tailch.empty?
add_text(src, lspace) if lspace
add_expr(src, code, indicator)
add_text(src, rspace) if rspace
diff --git a/lib/erubis/enhancer.rb b/lib/erubis/enhancer.rb
index b129a11..48b455a 100644
--- a/lib/erubis/enhancer.rb
+++ b/lib/erubis/enhancer.rb
@@ -593,7 +593,7 @@ module Erubis
pos = 0
is_bol = true # is beginning of line
str = ''
- input.scan(regexp) do |indicator, code, rspace|
+ input.scan(regexp) do |indicator, code, tailch, rspace|
match = Regexp.last_match()
len = match.begin(0) - pos
text = input[pos, len]
@@ -605,6 +605,7 @@ module Erubis
## * when '<%= %>', do nothing
## * when '<% %>' or '<%# %>', delete spaces iff only spaces are around '<% %>'
if ch == ?= # <%= %>
+ rspace = nil if tailch && !tailch.empty?
str << lspace if lspace
add_expr(str, code, indicator)
str << rspace if rspace