summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormakoto kuwata <kwa@kuwata-lab.com>2008-05-03 04:22:01 +0000
committermakoto kuwata <kwa@kuwata-lab.com>2008-05-03 04:22:01 +0000
commit5c0477bfd60ae2035ccd73c79831f35afcb0a8f8 (patch)
tree9299e7ffa02f454a298801b46b1645363d6bcc68
parent0b66076e57243280b715d1bed89b1dc6f0e93f80 (diff)
downloaderubis-5c0477bfd60ae2035ccd73c79831f35afcb0a8f8.tar.gz
- [enhance] Conerter#convert_input(): convert '<%% %>' into '<% %>'
- [enhance] test-erubis.rb: add 'doublepercent1' test - [enhance] Engine#load_file() can take :cachename property
-rw-r--r--ChangeLog.txt5
-rw-r--r--Rookbook.yaml8
-rw-r--r--lib/erubis/converter.rb11
-rw-r--r--lib/erubis/engine.rb11
-rw-r--r--test/test-erubis.rb20
5 files changed, 43 insertions, 12 deletions
diff --git a/ChangeLog.txt b/ChangeLog.txt
index ee7ceee..cdae9e3 100644
--- a/ChangeLog.txt
+++ b/ChangeLog.txt
@@ -2,6 +2,11 @@
.?lastupdate: $Date$
.?version: $Rev$
+: Rev.104 (2008-04-29)
+ .- [enhance] Conerter#convert_input(): convert '<%% %>' into '<% %>'
+ .- [enhance] test-erubis.rb: add 'doublepercent1' test
+ .- [enhance] Engine#load_file() can take :cachename property
+
: Rev.103 (2008-04-29)
.- [enhance] '<%= =%>' and '<%= -%>' removed tail spaces
diff --git a/Rookbook.yaml b/Rookbook.yaml
index facdee0..1295db5 100644
--- a/Rookbook.yaml
+++ b/Rookbook.yaml
@@ -5,7 +5,7 @@
###
properties:
- - release : 2.5.0
+ - release : 2.6.0
- copyright : copyright(c) 2006-2008 kuwata-lab all rights reserved.
@@ -47,9 +47,9 @@ recipes:
#sys "ruby test/test-notext.rb"
sys "ruby test/test.rb 2>&1 | tee test.log"
- - product: :clear
+ - product: :clean
method*: |
- rm_rf '$(project)_*.*', '$(project)-*.gem', apidocdir
+ rm_rf '$(project)_*.*', '$(project)-*.gem', 'lib/**/*.rbc', apidocdir
- product: :apidoc
desc: create api document by RDoc
@@ -126,7 +126,7 @@ recipes:
rm_rf dir if test(?d, dir)
mkdir_p dir
#
- rm_f 'test/data/**/*.cache'
+ rm_f 'test/data/**/*.cache', 'lib/**/*.rbc'
#store 'lib/**/*', 'bin/*', 'test/**/*', text_files, dir
store 'lib/**/*', 'bin/*', 'test/**/*', text_files, dir do |f|
base = File.basename(f)
diff --git a/lib/erubis/converter.rb b/lib/erubis/converter.rb
index 2d66dba..3bfb2bf 100644
--- a/lib/erubis/converter.rb
+++ b/lib/erubis/converter.rb
@@ -111,10 +111,10 @@ module Erubis
## return regexp of pattern to parse eRuby script
def pattern_regexp(pattern)
- 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
+ @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
end
module_function :pattern_regexp
@@ -155,6 +155,9 @@ module Erubis
add_stmt(src, "\n" * n)
add_text(src, rspace) if rspace
end
+ elsif ch == ?% # <%% %>
+ s = "#{lspace}#{@prefix||='<%'}#{code}#{tailch}#{@postfix||='%>'}#{rspace}"
+ add_text(src, s)
else # <% %>
if @trim && lspace && rspace
add_stmt(src, "#{lspace}#{code}#{rspace}")
diff --git a/lib/erubis/engine.rb b/lib/erubis/engine.rb
index c1e1e79..583d393 100644
--- a/lib/erubis/engine.rb
+++ b/lib/erubis/engine.rb
@@ -42,20 +42,23 @@ module Erubis
##
## load file, write cache file, and return engine object.
- ## this method create cache file (filename + '.cache') automatically.
+ ## this method create code cache file automatically.
+ ## cachefile name can be specified with properties[:cachename],
+ ## or filname + 'cache' is used as default.
##
def self.load_file(filename, properties={})
- cachename = filename + '.cache'
+ cachename = properties[:cachename] || (filename + '.cache')
properties[:filename] = filename
if test(?f, cachename) && File.mtime(filename) <= File.mtime(cachename)
engine = self.new(nil, properties)
engine.src = File.read(cachename)
else
- input = File.open(filename, 'rb') { |f| f.read }
+ input = File.open(filename, 'rb') {|f| f.read }
engine = self.new(input, properties)
- File.open(cachename, 'w') do |f|
+ File.open(cachename, 'wb') do |f|
f.flock(File::LOCK_EX)
f.write(engine.src)
+ f.flush()
end
end
engine.src.untaint # ok?
diff --git a/test/test-erubis.rb b/test/test-erubis.rb
index d173195..6f0578a 100644
--- a/test/test-erubis.rb
+++ b/test/test-erubis.rb
@@ -539,6 +539,26 @@ __END__
<>&" <>&"</p>
##
+- name: doublepercent1
+ options:
+ input: |
+ <% x1 = 10 %>
+ <%% x2 = 20 %>
+ <%= x1 %>
+ <%%= x2 %>
+ src: |
+ _buf = ''; x1 = 10
+ _buf << '<% x2 = 20 %>
+ '; _buf << ( x1 ).to_s; _buf << '
+ '; _buf << '<%= x2 %>
+ ';
+ _buf.to_s
+ output: |
+ <% x2 = 20 %>
+ 10
+ <%= x2 %>
+
+##
- name: optimized1
class: OptimizedEruby
input: &optimized1_input|