summaryrefslogtreecommitdiff
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
parentfa5be13289315103cacaef99390b0ef27f3d9e9c (diff)
downloaderubis-0b66076e57243280b715d1bed89b1dc6f0e93f80.tar.gz
- [enhance] '<%= =%>' and '<%= -%>' removed tail spaces
-rw-r--r--ChangeLog.txt3
-rw-r--r--lib/erubis/converter.rb5
-rw-r--r--lib/erubis/enhancer.rb3
-rw-r--r--test/test-erubis.rb22
4 files changed, 30 insertions, 3 deletions
diff --git a/ChangeLog.txt b/ChangeLog.txt
index 768b9cd..ee7ceee 100644
--- a/ChangeLog.txt
+++ b/ChangeLog.txt
@@ -2,6 +2,9 @@
.?lastupdate: $Date$
.?version: $Rev$
+: Rev.103 (2008-04-29)
+ .- [enhance] '<%= =%>' and '<%= -%>' removed tail spaces
+
: Rev.102 (2008-04-29)
.- [add] preprocessing.rb
.- [change] rails_helper.rb: move Preprocessing class and helper methods into preprocessing.rb
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
diff --git a/test/test-erubis.rb b/test/test-erubis.rb
index 4505b48..d173195 100644
--- a/test/test-erubis.rb
+++ b/test/test-erubis.rb
@@ -517,6 +517,28 @@ __END__
<>&"
##
+- name: tailch1
+ options:
+ input: |
+ <p>
+ <% str = '<>&"' %>
+ <%= str %>
+ <%= str =%>
+ <%= str -%>
+ </p>
+ src: |
+ _buf = ''; _buf << '<p>
+ '; str = '<>&"'
+ _buf << ' '; _buf << ( str ).to_s; _buf << '
+ '; _buf << ' '; _buf << ( str ).to_s; _buf << ' '; _buf << ( str ).to_s; _buf << '</p>
+ ';
+ _buf.to_s
+ output: |
+ <p>
+ <>&"
+ <>&" <>&"</p>
+
+##
- name: optimized1
class: OptimizedEruby
input: &optimized1_input|