erubis 2.5.0 → 2.6.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/CHANGES.txt +62 -2
- data/README.txt +1 -1
- data/benchmark/bench.rb +18 -10
- data/bin/erubis +1 -1
- data/contrib/erubis +2 -3318
- data/contrib/inline-require +1 -1
- data/doc-api/classes/ActionView.html +105 -0
- data/doc-api/classes/ActionView/TemplateHandlers/Erubis.html +202 -0
- data/doc-api/classes/Erubis.html +7 -1
- data/doc-api/classes/Erubis/ArrayBufferEnhancer.html +12 -12
- data/doc-api/classes/Erubis/ArrayEnhancer.html +12 -12
- data/doc-api/classes/Erubis/Basic/Converter.html +34 -30
- data/doc-api/classes/Erubis/BiPatternEnhancer.html +12 -12
- data/doc-api/classes/Erubis/CGenerator.html +60 -60
- data/doc-api/classes/Erubis/Context.html +42 -42
- data/doc-api/classes/Erubis/Converter.html +27 -27
- data/doc-api/classes/Erubis/DeleteIndentEnhancer.html +6 -6
- data/doc-api/classes/Erubis/Engine.html +40 -37
- data/doc-api/classes/Erubis/ErboutEnhancer.html +12 -12
- 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 +60 -60
- data/doc-api/classes/Erubis/HeaderFooterEnhancer.html +12 -12
- data/doc-api/classes/Erubis/Helpers/RailsFormHelper.html +201 -176
- data/doc-api/classes/Erubis/Helpers/RailsHelper.html +58 -58
- data/doc-api/classes/Erubis/Helpers/RailsHelper/{PreprocessingEruby.html → TemplateConverter.html} +24 -37
- data/doc-api/classes/Erubis/InterpolationEnhancer.html +36 -35
- 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 +19 -19
- data/doc-api/classes/Erubis/NoCodeEnhancer.html +30 -30
- data/doc-api/classes/Erubis/NoTextEnhancer.html +6 -6
- 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 +21 -21
- 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 +6 -6
- data/doc-api/classes/Erubis/PI/Escheme.html +6 -6
- data/doc-api/classes/Erubis/PI/TinyEruby.html +24 -24
- data/doc-api/classes/Erubis/PercentLineEnhancer.html +6 -6
- data/doc-api/classes/Erubis/PerlGenerator.html +54 -54
- data/doc-api/classes/Erubis/PhpGenerator.html +54 -54
- data/doc-api/classes/Erubis/PreprocessingEruby.html +183 -0
- data/doc-api/classes/Erubis/PreprocessingHelper.html +212 -0
- data/doc-api/classes/Erubis/PrintEnabledEnhancer.html +20 -20
- data/doc-api/classes/Erubis/PrintOutEnhancer.html +30 -30
- data/doc-api/classes/Erubis/RubyEvaluator.html +18 -18
- data/doc-api/classes/Erubis/RubyGenerator.html +48 -48
- data/doc-api/classes/Erubis/SchemeGenerator.html +60 -60
- data/doc-api/classes/Erubis/SimplifyEnhancer.html +7 -7
- data/doc-api/classes/Erubis/StdoutEnhancer.html +12 -12
- data/doc-api/classes/Erubis/StringBufferEnhancer.html +12 -12
- data/doc-api/classes/Erubis/TinyEruby.html +24 -24
- data/doc-api/classes/Erubis/XmlHelper.html +30 -30
- data/doc-api/created.rid +1 -1
- data/doc-api/files/README_txt.html +2 -2
- data/doc-api/files/erubis/context_rb.html +1 -1
- data/doc-api/files/erubis/converter_rb.html +2 -2
- data/doc-api/files/erubis/engine/ec_rb.html +1 -1
- data/doc-api/files/erubis/engine/ejava_rb.html +1 -1
- data/doc-api/files/erubis/engine/ejavascript_rb.html +1 -1
- data/doc-api/files/erubis/engine/enhanced_rb.html +1 -1
- data/doc-api/files/erubis/engine/eperl_rb.html +1 -1
- data/doc-api/files/erubis/engine/ephp_rb.html +1 -1
- data/doc-api/files/erubis/engine/eruby_rb.html +1 -1
- data/doc-api/files/erubis/engine/escheme_rb.html +1 -1
- data/doc-api/files/erubis/engine/optimized_rb.html +1 -1
- 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 +1 -1
- data/doc-api/files/erubis/evaluator_rb.html +1 -1
- data/doc-api/files/erubis/generator_rb.html +1 -1
- data/doc-api/files/erubis/helper_rb.html +1 -1
- data/doc-api/files/erubis/helpers/rails_form_helper_rb.html +2 -2
- data/doc-api/files/erubis/helpers/rails_helper_rb.html +3 -3
- data/doc-api/files/erubis/local-setting_rb.html +1 -1
- data/doc-api/files/erubis/main_rb.html +1 -1
- data/doc-api/files/erubis/preprocessing_rb.html +114 -0
- data/doc-api/files/erubis/tiny_rb.html +1 -1
- data/doc-api/files/erubis_rb.html +1 -1
- data/doc-api/fr_class_index.html +5 -1
- data/doc-api/fr_file_index.html +1 -0
- data/doc-api/fr_method_index.html +223 -213
- data/doc/users-guide.html +75 -6
- data/lib/erubis.rb +2 -2
- data/lib/erubis/context.rb +1 -1
- data/lib/erubis/converter.rb +11 -7
- data/lib/erubis/engine.rb +9 -6
- data/lib/erubis/engine/ec.rb +1 -1
- data/lib/erubis/engine/ejava.rb +1 -1
- data/lib/erubis/engine/ejavascript.rb +1 -1
- data/lib/erubis/engine/enhanced.rb +1 -1
- data/lib/erubis/engine/eperl.rb +1 -1
- data/lib/erubis/engine/ephp.rb +1 -1
- data/lib/erubis/engine/eruby.rb +1 -1
- data/lib/erubis/engine/escheme.rb +1 -1
- data/lib/erubis/engine/optimized.rb +1 -1
- data/lib/erubis/enhancer.rb +4 -3
- data/lib/erubis/error.rb +1 -1
- data/lib/erubis/evaluator.rb +1 -1
- data/lib/erubis/generator.rb +1 -1
- data/lib/erubis/helper.rb +1 -1
- data/lib/erubis/helpers/rails_form_helper.rb +18 -10
- data/lib/erubis/helpers/rails_helper.rb +100 -98
- data/lib/erubis/local-setting.rb +1 -1
- data/lib/erubis/main.rb +1 -1
- data/lib/erubis/preprocessing.rb +59 -0
- data/lib/erubis/tiny.rb +1 -1
- data/test/assert-text-equal.rb +1 -1
- data/test/data/users-guide/stderr.log +3 -0
- data/test/data/users-guide/tail_260.result +4 -0
- data/test/data/users-guide/tailnewline.rhtml +3 -0
- data/test/test-engines.rb +1 -1
- data/test/test-enhancers.rb +1 -1
- data/test/test-erubis.rb +44 -2
- data/test/test-main.rb +2 -2
- data/test/test-users-guide.rb +1 -1
- data/test/test.rb +1 -1
- data/test/testutil.rb +1 -1
- metadata +15 -5
- data/contrib/action_view_base_rb.patch +0 -23
data/doc/users-guide.html
CHANGED
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
|
|
15
15
|
<div align="left"><h1>Erubis Users' Guide</h1></div>
|
|
16
16
|
<div align="left">
|
|
17
|
-
last update: $Date: 2008-
|
|
17
|
+
last update: $Date: 2008-05-05 18:47:05 +0900 (Mon, 05 May 2008) $<br>
|
|
18
18
|
</div>
|
|
19
19
|
|
|
20
|
-
<p>release: 2.
|
|
20
|
+
<p>release: 2.6.0
|
|
21
21
|
</p>
|
|
22
22
|
<a name="preface"></a>
|
|
23
23
|
<h2 class="section1">Preface</h2>
|
|
@@ -153,6 +153,10 @@ It has the following features.
|
|
|
153
153
|
</li>
|
|
154
154
|
<li><a href="#topics">Other Topics</a>
|
|
155
155
|
<ul>
|
|
156
|
+
<li><a href="#'<%= =%>' and '<%= -%>'">'<%= =%>' and '<%= -%>'</a>
|
|
157
|
+
</li>
|
|
158
|
+
<li><a href="#'<%% %>' and '<%%= %>'">'<%% %>' and '<%%= %>'</a>
|
|
159
|
+
</li>
|
|
156
160
|
<li><a href="#topics-context-vs-binding">evaluate(context) v.s. result(binding)</a>
|
|
157
161
|
</li>
|
|
158
162
|
<li><a href="#topics-fasteruby">Class Erubis::FastEruby</a>
|
|
@@ -2606,6 +2610,64 @@ This means that pp_text_field() with preprocessing makes view layer very fast.
|
|
|
2606
2610
|
|
|
2607
2611
|
<a name="topics"></a>
|
|
2608
2612
|
<h2 class="section1">Other Topics</h2>
|
|
2613
|
+
<a name="'<%= =%>' and '<%= -%>'"></a>
|
|
2614
|
+
<h3 class="section2">'<%= =%>' and '<%= -%>'</h3>
|
|
2615
|
+
<p>Since 2.6.0, '<%= -%>' remove tail spaces and newline.
|
|
2616
|
+
This is for compatibiliy with ERB when trim mode is '-'.
|
|
2617
|
+
'<%= =%>' also removes tail spaces and newlines, and this is
|
|
2618
|
+
Erubis-original enhancement (cooler than '<%= -%>', isn't it?).
|
|
2619
|
+
</p>
|
|
2620
|
+
<a name="tailnewline.rhtml.comment_filter"></a>
|
|
2621
|
+
<div class="program_caption">
|
|
2622
|
+
tailnewline.rhtml</div>
|
|
2623
|
+
<pre class="program"><div>
|
|
2624
|
+
<%= @var -%> # or <%= @var =%>
|
|
2625
|
+
</div>
|
|
2626
|
+
</pre>
|
|
2627
|
+
<div class="terminal_caption">
|
|
2628
|
+
result (version 2.5.0):</div>
|
|
2629
|
+
<pre class="terminal">$ erubis -c '{var: "AAA\n"}' tailnewline.rhtml
|
|
2630
|
+
<div>
|
|
2631
|
+
AAA
|
|
2632
|
+
|
|
2633
|
+
</div>
|
|
2634
|
+
</pre>
|
|
2635
|
+
<a name="tail_260.result"></a>
|
|
2636
|
+
<div class="terminal_caption">
|
|
2637
|
+
result (version 2.6.0):</div>
|
|
2638
|
+
<pre class="terminal">$ erubis -c '{var: "AAA\n"}' tailnewline.rhtml
|
|
2639
|
+
<div>
|
|
2640
|
+
AAA
|
|
2641
|
+
</div>
|
|
2642
|
+
</pre>
|
|
2643
|
+
<br>
|
|
2644
|
+
|
|
2645
|
+
|
|
2646
|
+
<a name="'<%% %>' and '<%%= %>'"></a>
|
|
2647
|
+
<h3 class="section2">'<%% %>' and '<%%= %>'</h3>
|
|
2648
|
+
<p>Since 2.6.0, '<%% %>' and '<%%= %>' are converted into '<% %>' and '<%= %>' respectively.
|
|
2649
|
+
This is for compatibility with ERB.
|
|
2650
|
+
</p>
|
|
2651
|
+
<div class="program_caption">
|
|
2652
|
+
doublepercent.rhtml:</div>
|
|
2653
|
+
<pre class="program"><ul>
|
|
2654
|
+
<%% for item in @list %>
|
|
2655
|
+
<li><%%= item %></li>
|
|
2656
|
+
<%% end %>
|
|
2657
|
+
</ul>
|
|
2658
|
+
</pre>
|
|
2659
|
+
<div class="terminal_caption">
|
|
2660
|
+
result:</div>
|
|
2661
|
+
<pre class="terminal">$ erubis doublepercent.rhtml
|
|
2662
|
+
<ul>
|
|
2663
|
+
<% for item in @list %>
|
|
2664
|
+
<li><%= item %></li>
|
|
2665
|
+
<% end %>
|
|
2666
|
+
</ul>
|
|
2667
|
+
</pre>
|
|
2668
|
+
<br>
|
|
2669
|
+
|
|
2670
|
+
|
|
2609
2671
|
<a name="topics-context-vs-binding"></a>
|
|
2610
2672
|
<h3 class="section2">evaluate(context) v.s. result(binding)</h3>
|
|
2611
2673
|
<p>It is recommended to use 'Erubis::Eruby#evaluate(context)' instead of 'Erubis::Eruby#result(binding)' because Ruby's Binding object has some problems.
|
|
@@ -2808,6 +2870,13 @@ if test(?f, cachename)
|
|
|
2808
2870
|
puts "*** cache file '#{cachename}' created."
|
|
2809
2871
|
end
|
|
2810
2872
|
</pre>
|
|
2873
|
+
<p>Since 2.6.0, it is able to specify cache filename.
|
|
2874
|
+
</p>
|
|
2875
|
+
<div class="program_caption">
|
|
2876
|
+
specify cache filename.</div>
|
|
2877
|
+
<pre class="program">filename = 'example.rhtml'
|
|
2878
|
+
eruby = Erubis::Eruby.load_file(filename, :cachename=>filename+'.cache')
|
|
2879
|
+
</pre>
|
|
2811
2880
|
<p>Caching makes Erubis about 40-50 percent faster than no-caching.
|
|
2812
2881
|
See <a href="#topics-benchmark">benchmark</a> for details.
|
|
2813
2882
|
</p>
|
|
@@ -2915,8 +2984,8 @@ example of using NoCodeEnhancer with PHP file</div>
|
|
|
2915
2984
|
<p>Thanks Andrew R Jackson, he developed 'erubis-run.rb' which enables you to use Erubis with mod_ruby.
|
|
2916
2985
|
</p>
|
|
2917
2986
|
<ol type="1">
|
|
2918
|
-
<li>Copy 'erubis-2.
|
|
2919
|
-
<pre class="terminal">$ cd erubis-2.
|
|
2987
|
+
<li>Copy 'erubis-2.6.0/contrib/erubis-run.rb' to the 'RUBYLIBDIR/apache' directory (for example '/usr/local/lib/ruby/1.8/apache') which contains 'ruby-run.rb', 'eruby-run.rb', and so on.
|
|
2988
|
+
<pre class="terminal">$ cd erubis-2.6.0/
|
|
2920
2989
|
$ sudo copy contrib/erubis-run.rb /usr/local/lib/ruby/1.8/apache/
|
|
2921
2990
|
</pre>
|
|
2922
2991
|
</li>
|
|
@@ -2992,12 +3061,12 @@ p obj.render('world') #=> "hello world"
|
|
|
2992
3061
|
|
|
2993
3062
|
<a name="topics-benchmark"></a>
|
|
2994
3063
|
<h3 class="section2">Benchmark</h3>
|
|
2995
|
-
<p>A benchmark script is included in Erubis package at 'erubis-2.
|
|
3064
|
+
<p>A benchmark script is included in Erubis package at 'erubis-2.6.0/benchark/' directory.
|
|
2996
3065
|
Here is an example result of benchmark.
|
|
2997
3066
|
</p>
|
|
2998
3067
|
<div class="terminal_caption">
|
|
2999
3068
|
MacOS X 10.4 Tiger, Intel CoreDuo 1.83GHz, Ruby1.8.6, eruby1.0.5, gcc4.0.1</div>
|
|
3000
|
-
<pre class="terminal">$ cd erubis-2.
|
|
3069
|
+
<pre class="terminal">$ cd erubis-2.6.0/benchmark/
|
|
3001
3070
|
$ ruby bench.rb -n 10000 -m execute
|
|
3002
3071
|
*** ntimes=10000, testmode=execute
|
|
3003
3072
|
user system total real
|
data/lib/erubis.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
##
|
|
2
2
|
## $Rev: 99 $
|
|
3
|
-
## $Release: 2.
|
|
3
|
+
## $Release: 2.6.0 $
|
|
4
4
|
## copyright(c) 2006-2008 kuwata-lab.com all rights reserved.
|
|
5
5
|
##
|
|
6
6
|
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
|
|
49
49
|
|
|
50
50
|
module Erubis
|
|
51
|
-
VERSION = ('$Release: 2.
|
|
51
|
+
VERSION = ('$Release: 2.6.0 $' =~ /([.\d]+)/) && $1
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
require 'erubis/engine'
|
data/lib/erubis/context.rb
CHANGED
data/lib/erubis/converter.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
##
|
|
2
|
-
## $Rev:
|
|
3
|
-
## $Release: 2.
|
|
2
|
+
## $Rev: 104 $
|
|
3
|
+
## $Release: 2.6.0 $
|
|
4
4
|
## copyright(c) 2006-2008 kuwata-lab.com all rights reserved.
|
|
5
5
|
##
|
|
6
6
|
|
|
@@ -111,10 +111,10 @@ module Erubis
|
|
|
111
111
|
|
|
112
112
|
## return regexp of pattern to parse eRuby script
|
|
113
113
|
def pattern_regexp(pattern)
|
|
114
|
-
prefix, postfix = pattern.split() # '<% %>' => '<%', '%>'
|
|
115
|
-
#return /(.*?)(^[ \t]*)?#{prefix}(=+|\#)?(.*?)-?#{postfix}([ \t]*\r?\n)?/m
|
|
116
|
-
#return /(^[ \t]*)?#{prefix}(=+|\#)?(.*?)-?#{postfix}([ \t]*\r?\n)?/m
|
|
117
|
-
return /#{prefix}(
|
|
114
|
+
@prefix, @postfix = pattern.split() # '<% %>' => '<%', '%>'
|
|
115
|
+
#return /(.*?)(^[ \t]*)?#{@prefix}(=+|\#)?(.*?)-?#{@postfix}([ \t]*\r?\n)?/m
|
|
116
|
+
#return /(^[ \t]*)?#{@prefix}(=+|\#)?(.*?)-?#{@postfix}([ \t]*\r?\n)?/m
|
|
117
|
+
return /#{@prefix}(=+|-|\#|%)?(.*?)([-=])?#{@postfix}([ \t]*\r?\n)?/m
|
|
118
118
|
end
|
|
119
119
|
module_function :pattern_regexp
|
|
120
120
|
|
|
@@ -130,7 +130,7 @@ module Erubis
|
|
|
130
130
|
regexp = pat.nil? || pat == '<% %>' ? DEFAULT_REGEXP : pattern_regexp(pat)
|
|
131
131
|
pos = 0
|
|
132
132
|
is_bol = true # is beginning of line
|
|
133
|
-
input.scan(regexp) do |indicator, code, rspace|
|
|
133
|
+
input.scan(regexp) do |indicator, code, tailch, rspace|
|
|
134
134
|
match = Regexp.last_match()
|
|
135
135
|
len = match.begin(0) - pos
|
|
136
136
|
text = input[pos, len]
|
|
@@ -142,6 +142,7 @@ module Erubis
|
|
|
142
142
|
## * when '<%= %>', do nothing
|
|
143
143
|
## * when '<% %>' or '<%# %>', delete spaces iff only spaces are around '<% %>'
|
|
144
144
|
if ch == ?= # <%= %>
|
|
145
|
+
rspace = nil if tailch && !tailch.empty?
|
|
145
146
|
add_text(src, lspace) if lspace
|
|
146
147
|
add_expr(src, code, indicator)
|
|
147
148
|
add_text(src, rspace) if rspace
|
|
@@ -154,6 +155,9 @@ module Erubis
|
|
|
154
155
|
add_stmt(src, "\n" * n)
|
|
155
156
|
add_text(src, rspace) if rspace
|
|
156
157
|
end
|
|
158
|
+
elsif ch == ?% # <%% %>
|
|
159
|
+
s = "#{lspace}#{@prefix||='<%'}#{code}#{tailch}#{@postfix||='%>'}#{rspace}"
|
|
160
|
+
add_text(src, s)
|
|
157
161
|
else # <% %>
|
|
158
162
|
if @trim && lspace && rspace
|
|
159
163
|
add_stmt(src, "#{lspace}#{code}#{rspace}")
|
data/lib/erubis/engine.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
##
|
|
2
|
-
## $Rev:
|
|
3
|
-
## $Release: 2.
|
|
2
|
+
## $Rev: 104 $
|
|
3
|
+
## $Release: 2.6.0 $
|
|
4
4
|
## copyright(c) 2006-2008 kuwata-lab.com all rights reserved.
|
|
5
5
|
##
|
|
6
6
|
|
|
@@ -42,20 +42,23 @@ module Erubis
|
|
|
42
42
|
|
|
43
43
|
##
|
|
44
44
|
## load file, write cache file, and return engine object.
|
|
45
|
-
## this method create cache file
|
|
45
|
+
## this method create code cache file automatically.
|
|
46
|
+
## cachefile name can be specified with properties[:cachename],
|
|
47
|
+
## or filname + 'cache' is used as default.
|
|
46
48
|
##
|
|
47
49
|
def self.load_file(filename, properties={})
|
|
48
|
-
cachename = filename + '.cache'
|
|
50
|
+
cachename = properties[:cachename] || (filename + '.cache')
|
|
49
51
|
properties[:filename] = filename
|
|
50
52
|
if test(?f, cachename) && File.mtime(filename) <= File.mtime(cachename)
|
|
51
53
|
engine = self.new(nil, properties)
|
|
52
54
|
engine.src = File.read(cachename)
|
|
53
55
|
else
|
|
54
|
-
input = File.open(filename, 'rb') {
|
|
56
|
+
input = File.open(filename, 'rb') {|f| f.read }
|
|
55
57
|
engine = self.new(input, properties)
|
|
56
|
-
File.open(cachename, '
|
|
58
|
+
File.open(cachename, 'wb') do |f|
|
|
57
59
|
f.flock(File::LOCK_EX)
|
|
58
60
|
f.write(engine.src)
|
|
61
|
+
f.flush()
|
|
59
62
|
end
|
|
60
63
|
end
|
|
61
64
|
engine.src.untaint # ok?
|
data/lib/erubis/engine/ec.rb
CHANGED
data/lib/erubis/engine/ejava.rb
CHANGED
data/lib/erubis/engine/eperl.rb
CHANGED
data/lib/erubis/engine/ephp.rb
CHANGED
data/lib/erubis/engine/eruby.rb
CHANGED
data/lib/erubis/enhancer.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
##
|
|
2
|
-
## $Rev:
|
|
3
|
-
## $Release: 2.
|
|
2
|
+
## $Rev: 103 $
|
|
3
|
+
## $Release: 2.6.0 $
|
|
4
4
|
## copyright(c) 2006-2008 kuwata-lab.com all rights reserved.
|
|
5
5
|
##
|
|
6
6
|
|
|
@@ -593,7 +593,7 @@ module Erubis
|
|
|
593
593
|
pos = 0
|
|
594
594
|
is_bol = true # is beginning of line
|
|
595
595
|
str = ''
|
|
596
|
-
input.scan(regexp) do |indicator, code, rspace|
|
|
596
|
+
input.scan(regexp) do |indicator, code, tailch, rspace|
|
|
597
597
|
match = Regexp.last_match()
|
|
598
598
|
len = match.begin(0) - pos
|
|
599
599
|
text = input[pos, len]
|
|
@@ -605,6 +605,7 @@ module Erubis
|
|
|
605
605
|
## * when '<%= %>', do nothing
|
|
606
606
|
## * when '<% %>' or '<%# %>', delete spaces iff only spaces are around '<% %>'
|
|
607
607
|
if ch == ?= # <%= %>
|
|
608
|
+
rspace = nil if tailch && !tailch.empty?
|
|
608
609
|
str << lspace if lspace
|
|
609
610
|
add_expr(str, code, indicator)
|
|
610
611
|
str << rspace if rspace
|
data/lib/erubis/error.rb
CHANGED
data/lib/erubis/evaluator.rb
CHANGED
data/lib/erubis/generator.rb
CHANGED
data/lib/erubis/helper.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
###
|
|
2
|
-
### $Rev:
|
|
3
|
-
### $Release: 2.
|
|
2
|
+
### $Rev: 109 $
|
|
3
|
+
### $Release: 2.6.0 $
|
|
4
4
|
### copyright(c) 2006-2008 kuwata-lab.com all rights reserved.
|
|
5
5
|
###
|
|
6
6
|
|
|
@@ -15,24 +15,32 @@ end
|
|
|
15
15
|
|
|
16
16
|
module Erubis::Helpers::RailsFormHelper
|
|
17
17
|
|
|
18
|
+
|
|
19
|
+
if ActionPack::VERSION::MAJOR == 1 ### Rails 1.X
|
|
18
20
|
def pp_template_filename(basename)
|
|
19
21
|
return "#{RAILS_ROOT}/app/views/#{controller.controller_name}/#{basename}.rhtml"
|
|
20
22
|
end
|
|
23
|
+
else ### Rails 2.X
|
|
24
|
+
def pp_template_filename(basename)
|
|
25
|
+
fname = "#{RAILS_ROOT}/app/views/#{controller.controller_name}/#{basename}.html.erb"
|
|
26
|
+
return fname if test(?f, fname)
|
|
27
|
+
return "#{RAILS_ROOT}/app/views/#{controller.controller_name}/#{basename}.rhtml"
|
|
28
|
+
end
|
|
29
|
+
end
|
|
21
30
|
|
|
22
31
|
def pp_render_partial(basename)
|
|
23
32
|
basename = "_#{basename}" unless basename[0] == ?_
|
|
24
33
|
filename = pp_template_filename(basename)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return eruby.evaluate(self)
|
|
34
|
+
preprocessor = _create_preprocessor(File.read(filename))
|
|
35
|
+
return preprocessor.evaluate(_preprocessing_context_object())
|
|
28
36
|
end
|
|
29
37
|
|
|
30
|
-
def pp_error_on(object_name, method
|
|
38
|
+
def pp_error_on(object_name, method)
|
|
31
39
|
s = ''
|
|
32
|
-
s << "<% _stag, _etag = _pp_error_tags(@#{object_name}.errors.on('#{method}'))%>"
|
|
33
|
-
s << "<%=_stag%>"
|
|
40
|
+
s << "<% _stag, _etag = _pp_error_tags(@#{object_name}.errors.on('#{method}')) %>"
|
|
41
|
+
s << "<%= _stag %>"
|
|
34
42
|
s << yield(object_name, method)
|
|
35
|
-
s << "<%=_etag%>"
|
|
43
|
+
s << "<%= _etag %>"
|
|
36
44
|
return s
|
|
37
45
|
end
|
|
38
46
|
|
|
@@ -52,7 +60,7 @@ module Erubis::Helpers::RailsFormHelper
|
|
|
52
60
|
unless options.key?(:value) || options.key?('value')
|
|
53
61
|
options['value'] = _?("h @#{object_name}.#{method}")
|
|
54
62
|
end
|
|
55
|
-
|
|
63
|
+
#$stderr.puts "*** debug: pp_tag_helper(): options=#{options.inspect}"
|
|
56
64
|
return pp_error_on(object_name, method) {
|
|
57
65
|
s = __send__(helper, object_name, method, options)
|
|
58
66
|
_pp_remove_error_div(s)
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
###
|
|
2
|
-
### $Rev:
|
|
3
|
-
### $Release: 2.
|
|
2
|
+
### $Rev: 109 $
|
|
3
|
+
### $Release: 2.6.0 $
|
|
4
4
|
### copyright(c) 2006-2008 kuwata-lab.com all rights reserved.
|
|
5
5
|
###
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
require 'erubis'
|
|
9
|
-
require '
|
|
9
|
+
require 'erubis/preprocessing'
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
module Erubis
|
|
@@ -43,40 +43,34 @@ module Erubis
|
|
|
43
43
|
module RailsHelper
|
|
44
44
|
|
|
45
45
|
#cattr_accessor :init_properties
|
|
46
|
-
@@engine_class = Erubis::Eruby
|
|
47
|
-
#@@engine_class = Erubis::FastEruby
|
|
48
|
-
|
|
46
|
+
@@engine_class = ::Erubis::Eruby
|
|
47
|
+
#@@engine_class = ::Erubis::FastEruby
|
|
49
48
|
def self.engine_class
|
|
50
49
|
@@engine_class
|
|
51
50
|
end
|
|
52
|
-
|
|
53
51
|
def self.engine_class=(klass)
|
|
54
52
|
@@engine_class = klass
|
|
55
53
|
end
|
|
56
54
|
|
|
57
55
|
#cattr_accessor :init_properties
|
|
58
56
|
@@init_properties = {}
|
|
59
|
-
|
|
60
57
|
def self.init_properties
|
|
61
58
|
@@init_properties
|
|
62
59
|
end
|
|
63
|
-
|
|
64
60
|
def self.init_properties=(hash)
|
|
65
61
|
@@init_properties = hash
|
|
66
62
|
end
|
|
67
63
|
|
|
68
64
|
#cattr_accessor :show_src
|
|
69
65
|
@@show_src = nil
|
|
70
|
-
|
|
71
66
|
def self.show_src
|
|
72
67
|
@@show_src
|
|
73
68
|
end
|
|
74
|
-
|
|
75
69
|
def self.show_src=(flag)
|
|
76
70
|
@@show_src = flag
|
|
77
71
|
end
|
|
78
72
|
|
|
79
|
-
|
|
73
|
+
#cattr_accessor :preprocessing
|
|
80
74
|
@@preprocessing = false
|
|
81
75
|
def self.preprocessing
|
|
82
76
|
@@preprocessing
|
|
@@ -84,18 +78,40 @@ module Erubis
|
|
|
84
78
|
def self.preprocessing=(flag)
|
|
85
79
|
@@preprocessing = flag
|
|
86
80
|
end
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
## define class for backward-compatibility
|
|
84
|
+
class PreprocessingEruby < Erubis::PreprocessingEruby # :nodoc:
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
module TemplateConverter
|
|
89
|
+
## covert eRuby string into ruby code
|
|
90
|
+
def _convert_template(template) # :nodoc:
|
|
91
|
+
#src = ::Erubis::Eruby.new(template).src
|
|
92
|
+
klass = ::Erubis::Helpers::RailsHelper.engine_class
|
|
93
|
+
properties = ::Erubis::Helpers::RailsHelper.init_properties
|
|
94
|
+
show_src = ::Erubis::Helpers::RailsHelper.show_src
|
|
95
|
+
show_src = ENV['RAILS_ENV'] == 'development' if show_src.nil?
|
|
96
|
+
## preprocessing
|
|
97
|
+
if ::Erubis::Helpers::RailsHelper.preprocessing
|
|
98
|
+
preprocessor = _create_preprocessor(template)
|
|
99
|
+
template = preprocessor.evaluate(_preprocessing_context_object())
|
|
100
|
+
logger.info "** Erubis: preprocessed==<<'END'\n#{template}END\n" if show_src
|
|
101
|
+
end
|
|
102
|
+
## convert into ruby code
|
|
103
|
+
src = klass.new(template, properties).src
|
|
104
|
+
#src.insert(0, '_erbout = ')
|
|
105
|
+
logger.info "** Erubis: src==<<'END'\n#{src}END\n" if show_src
|
|
106
|
+
return src
|
|
93
107
|
end
|
|
94
|
-
def
|
|
95
|
-
|
|
108
|
+
def _create_preprocessor(template)
|
|
109
|
+
return PreprocessingEruby.new(template, :escape=>true)
|
|
110
|
+
end
|
|
111
|
+
def _preprocessing_context_object
|
|
112
|
+
return self
|
|
96
113
|
end
|
|
97
114
|
end
|
|
98
|
-
##----------------------------------------
|
|
99
115
|
|
|
100
116
|
end
|
|
101
117
|
|
|
@@ -104,27 +120,52 @@ module Erubis
|
|
|
104
120
|
end
|
|
105
121
|
|
|
106
122
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
123
|
+
class ActionView::Base # :nodoc:
|
|
124
|
+
include ::Erubis::Helpers::RailsHelper::TemplateConverter
|
|
125
|
+
include ::Erubis::PreprocessingHelper
|
|
126
|
+
private
|
|
127
|
+
# convert template into ruby code
|
|
128
|
+
def convert_template_into_ruby_code(template)
|
|
129
|
+
#ERB.new(template, nil, @@erb_trim_mode).src
|
|
130
|
+
return _convert_template(template)
|
|
131
|
+
end
|
|
132
|
+
end
|
|
110
133
|
|
|
111
|
-
require 'action_pack/version'
|
|
112
134
|
|
|
113
|
-
|
|
135
|
+
require 'action_pack/version'
|
|
114
136
|
|
|
115
|
-
class Base # :nodoc:
|
|
116
137
|
|
|
117
|
-
|
|
138
|
+
if ActionPack::VERSION::MAJOR >= 2 ### Rails 2.X
|
|
118
139
|
|
|
119
|
-
# convert template into ruby code
|
|
120
|
-
def convert_template_into_ruby_code(template)
|
|
121
|
-
ERB.new(template, nil, @@erb_trim_mode).src
|
|
122
|
-
end
|
|
123
140
|
|
|
141
|
+
if ActionPack::VERSION::MINOR > 0 || ActionPack::VERSION::TINY >= 2 ### Rails 2.0.2 or higher
|
|
124
142
|
|
|
125
|
-
|
|
143
|
+
module ActionView
|
|
144
|
+
module TemplateHandlers # :nodoc:
|
|
145
|
+
class Erubis < TemplateHandler
|
|
146
|
+
include ::Erubis::Helpers::RailsHelper::TemplateConverter
|
|
147
|
+
include ::Erubis::PreprocessingHelper
|
|
148
|
+
def compile(template)
|
|
149
|
+
return _convert_template(template)
|
|
150
|
+
end
|
|
151
|
+
def logger
|
|
152
|
+
return @view.controller.logger
|
|
153
|
+
end
|
|
154
|
+
def _preprocessing_context_object
|
|
155
|
+
return @view.controller.instance_variable_get('@template')
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
Base.class_eval do
|
|
160
|
+
register_default_template_handler :erb, TemplateHandlers::Erubis
|
|
161
|
+
register_template_handler :rhtml, TemplateHandlers::Erubis
|
|
162
|
+
end
|
|
163
|
+
end
|
|
126
164
|
|
|
165
|
+
else ### Rails 2.0.0 or 2.0.1
|
|
127
166
|
|
|
167
|
+
class ActionView::Base # :nodoc:
|
|
168
|
+
private
|
|
128
169
|
# Method to create the source code for a given template.
|
|
129
170
|
def create_template_source(extension, template, render_symbol, locals)
|
|
130
171
|
if template_requires_setup?(extension)
|
|
@@ -143,23 +184,30 @@ if ActionPack::VERSION::MAJOR >= 2 ### Rails 2.X
|
|
|
143
184
|
#body = ERB.new(template, nil, @@erb_trim_mode).src
|
|
144
185
|
body = convert_template_into_ruby_code(template)
|
|
145
186
|
end
|
|
146
|
-
|
|
187
|
+
#
|
|
147
188
|
@@template_args[render_symbol] ||= {}
|
|
148
189
|
locals_keys = @@template_args[render_symbol].keys | locals
|
|
149
190
|
@@template_args[render_symbol] = locals_keys.inject({}) { |h, k| h[k] = true; h }
|
|
150
|
-
|
|
191
|
+
#
|
|
151
192
|
locals_code = ""
|
|
152
193
|
locals_keys.each do |key|
|
|
153
194
|
locals_code << "#{key} = local_assigns[:#{key}]\n"
|
|
154
195
|
end
|
|
155
|
-
|
|
196
|
+
#
|
|
156
197
|
"def #{render_symbol}(local_assigns)\n#{locals_code}#{body}\nend"
|
|
157
198
|
end
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
end #if
|
|
158
202
|
|
|
159
203
|
|
|
160
|
-
|
|
204
|
+
else ### Rails 1.X
|
|
161
205
|
|
|
162
206
|
|
|
207
|
+
if ActionPack::VERSION::MINOR > 12 ### Rails 1.2
|
|
208
|
+
|
|
209
|
+
class ActionView::Base # :nodoc:
|
|
210
|
+
private
|
|
163
211
|
# Create source code for given template
|
|
164
212
|
def create_template_source(extension, template, render_symbol, locals)
|
|
165
213
|
if template_requires_setup?(extension)
|
|
@@ -176,23 +224,24 @@ elsif ActionPack::VERSION::MINOR > 12 ### Rails 1.2
|
|
|
176
224
|
#body = ERB.new(template, nil, @@erb_trim_mode).src
|
|
177
225
|
body = convert_template_into_ruby_code(template)
|
|
178
226
|
end
|
|
179
|
-
|
|
227
|
+
#
|
|
180
228
|
@@template_args[render_symbol] ||= {}
|
|
181
229
|
locals_keys = @@template_args[render_symbol].keys | locals
|
|
182
230
|
@@template_args[render_symbol] = locals_keys.inject({}) { |h, k| h[k] = true; h }
|
|
183
|
-
|
|
231
|
+
#
|
|
184
232
|
locals_code = ""
|
|
185
233
|
locals_keys.each do |key|
|
|
186
234
|
locals_code << "#{key} = local_assigns[:#{key}]\n"
|
|
187
235
|
end
|
|
188
|
-
|
|
236
|
+
#
|
|
189
237
|
"def #{render_symbol}(local_assigns)\n#{locals_code}#{body}\nend"
|
|
190
238
|
end
|
|
239
|
+
end
|
|
191
240
|
|
|
241
|
+
else ### Rails 1.1
|
|
192
242
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
243
|
+
class ActionView::Base # :nodoc:
|
|
244
|
+
private
|
|
196
245
|
# Create source code for given template
|
|
197
246
|
def create_template_source(extension, template, render_symbol, locals)
|
|
198
247
|
if template_requires_setup?(extension)
|
|
@@ -209,77 +258,30 @@ elsif ActionPack::VERSION::MINOR <= 12 ### Rails 1.1
|
|
|
209
258
|
#body = ERB.new(template, nil, @@erb_trim_mode).src
|
|
210
259
|
body = convert_template_into_ruby_code(template)
|
|
211
260
|
end
|
|
212
|
-
|
|
261
|
+
#
|
|
213
262
|
@@template_args[render_symbol] ||= {}
|
|
214
263
|
locals_keys = @@template_args[render_symbol].keys | locals
|
|
215
264
|
@@template_args[render_symbol] = locals_keys.inject({}) { |h, k| h[k] = true; h }
|
|
216
|
-
|
|
265
|
+
#
|
|
217
266
|
locals_code = ""
|
|
218
267
|
locals_keys.each do |key|
|
|
219
268
|
locals_code << "#{key} = local_assigns[:#{key}] if local_assigns.has_key?(:#{key})\n"
|
|
220
269
|
end
|
|
221
|
-
|
|
270
|
+
#
|
|
222
271
|
"def #{render_symbol}(local_assigns)\n#{locals_code}#{body}\nend"
|
|
223
272
|
end
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
end ###
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
end
|
|
230
|
-
|
|
231
|
-
end
|
|
232
|
-
|
|
233
|
-
end
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
## set Erubis as eRuby compiler in Ruby on Rails instead of ERB
|
|
237
|
-
class ActionView::Base # :nodoc:
|
|
238
|
-
private
|
|
239
|
-
def convert_template_into_ruby_code(template)
|
|
240
|
-
#src = Erubis::Eruby.new(template).src
|
|
241
|
-
klass = Erubis::Helpers::RailsHelper.engine_class
|
|
242
|
-
properties = Erubis::Helpers::RailsHelper.init_properties
|
|
243
|
-
show_src = Erubis::Helpers::RailsHelper.show_src
|
|
244
|
-
show_src = ENV['RAILS_ENV'] == 'development' if show_src.nil?
|
|
245
|
-
##----- preprocessing -------------------
|
|
246
|
-
if Erubis::Helpers::RailsHelper.preprocessing
|
|
247
|
-
preprocessor = Erubis::Helpers::RailsHelper::PreprocessingEruby.new(template)
|
|
248
|
-
#template = self.instance_eval(preprocessor.src)
|
|
249
|
-
template = preprocessor.evaluate(self)
|
|
250
|
-
logger.debug "** Erubis: preprocessed==<<'END'\n#{template}END\n" if show_src
|
|
251
273
|
end
|
|
252
|
-
##----------------------------------------
|
|
253
|
-
src = klass.new(template, properties).src
|
|
254
|
-
#src.insert(0, '_erbout = ')
|
|
255
|
-
logger.debug "** Erubis: src==<<'END'\n#{src}END\n" if show_src
|
|
256
|
-
src
|
|
257
|
-
end
|
|
258
274
|
|
|
259
|
-
|
|
260
|
-
def _p(arg)
|
|
261
|
-
return "<%=#{arg}%>"
|
|
262
|
-
end
|
|
263
|
-
def _P(arg)
|
|
264
|
-
return "<%=h(#{arg})%>"
|
|
265
|
-
end
|
|
266
|
-
alias _? _p
|
|
267
|
-
def _decode(arg)
|
|
268
|
-
arg = arg.to_s
|
|
269
|
-
arg.gsub!(/%3C%25(?:=|%3D)(.*?)%25%3E/) { "<%=#{CGI.unescape($1)}%>" }
|
|
270
|
-
arg.gsub!(/<%=(.*?)%>/) { "<%=#{CGI.unescapeHTML($1)}%>" }
|
|
271
|
-
return arg
|
|
272
|
-
end
|
|
273
|
-
##----------------------------------------
|
|
275
|
+
end #if
|
|
274
276
|
|
|
275
|
-
end
|
|
277
|
+
end ###
|
|
276
278
|
|
|
277
279
|
|
|
278
280
|
## make h() method faster
|
|
279
281
|
module ERB::Util # :nodoc:
|
|
280
282
|
ESCAPE_TABLE = { '&'=>'&', '<'=>'<', '>'=>'>', '"'=>'"', "'"=>''', }
|
|
281
283
|
def h(value)
|
|
282
|
-
value.to_s.gsub(/[&<>"]/) {
|
|
284
|
+
value.to_s.gsub(/[&<>"]/) {|s| ESCAPE_TABLE[s] }
|
|
283
285
|
end
|
|
284
286
|
module_function :h
|
|
285
287
|
end
|
|
@@ -287,5 +289,5 @@ end
|
|
|
287
289
|
|
|
288
290
|
## finish
|
|
289
291
|
ac = ActionController::Base.new
|
|
290
|
-
ac.logger.info "** Erubis #{Erubis::VERSION}"
|
|
291
|
-
#$stdout.puts "** Erubis #{Erubis::VERSION}"
|
|
292
|
+
ac.logger.info "** Erubis #{::Erubis::VERSION}"
|
|
293
|
+
#$stdout.puts "** Erubis #{::Erubis::VERSION}"
|