erubis 2.3.1 → 2.4.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 +69 -2
- data/README.txt +1 -1
- data/benchmark/bench.rb +1 -1
- data/bin/erubis +1 -1
- data/contrib/erubis +3295 -2
- data/contrib/inline-require +1 -1
- data/doc-api/classes/Erubis.html +1 -1
- data/doc-api/classes/Erubis/ArrayEnhancer.html +12 -12
- data/doc-api/classes/Erubis/Basic/Converter.html +4 -4
- 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 +3 -2
- data/doc-api/classes/Erubis/DeleteIndentEnhancer.html +6 -6
- data/doc-api/classes/Erubis/Engine.html +30 -30
- data/doc-api/classes/Erubis/ErboutEnhancer.html +12 -12
- data/doc-api/classes/Erubis/EscapeEnhancer.html +6 -6
- data/doc-api/classes/Erubis/HeaderFooterEnhancer.html +12 -12
- data/doc-api/classes/Erubis/Helpers/RailsHelper.html +62 -7
- data/doc-api/classes/Erubis/Helpers/RailsHelper/PreprocessingEruby.html +177 -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 +20 -20
- 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 +3 -3
- data/doc-api/classes/Erubis/PercentLineEnhancer.html +6 -6
- data/doc-api/classes/Erubis/PhpGenerator.html +54 -54
- 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 +47 -15
- 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 +79 -14
- 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 +1 -1
- data/doc-api/files/erubis/enhancer_rb.html +1 -1
- data/doc-api/files/erubis/error_rb.html +1 -1
- data/doc-api/files/erubis/evaluator_rb.html +2 -2
- data/doc-api/files/erubis/generator_rb.html +1 -1
- data/doc-api/files/erubis/helper_rb.html +2 -2
- data/doc-api/files/erubis/helpers/rails_helper_rb.html +3 -2
- data/doc-api/files/erubis/local-setting_rb.html +1 -1
- data/doc-api/files/erubis/main_rb.html +2 -2
- 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 +1 -0
- data/doc-api/fr_method_index.html +128 -120
- data/doc/users-guide.html +248 -88
- data/lib/erubis.rb +2 -2
- data/lib/erubis/context.rb +1 -1
- data/lib/erubis/converter.rb +3 -2
- data/lib/erubis/engine.rb +1 -1
- 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 +1 -1
- data/lib/erubis/error.rb +1 -1
- data/lib/erubis/evaluator.rb +15 -4
- data/lib/erubis/generator.rb +1 -1
- data/lib/erubis/helper.rb +14 -2
- data/lib/erubis/helpers/rails_helper.rb +48 -3
- data/lib/erubis/local-setting.rb +1 -1
- data/lib/erubis/main.rb +7 -8
- data/lib/erubis/tiny.rb +1 -1
- data/test/assert-text-equal.rb +1 -1
- data/test/data/users-guide/def_method.rb +14 -0
- data/test/data/users-guide/def_method.result +3 -0
- data/test/test-engines.rb +1 -1
- data/test/test-enhancers.rb +1 -1
- data/test/test-erubis.rb +40 -2
- data/test/test-main.rb +17 -4
- data/test/test-users-guide.rb +1 -1
- data/test/test.rb +1 -1
- data/test/testutil.rb +1 -1
- metadata +15 -11
- data/test/data/users-guide/stderr.log +0 -3
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: 2007-
|
|
17
|
+
last update: $Date: 2007-07-19 13:13:21 +0900 (Thu, 19 Jul 2007) $<br>
|
|
18
18
|
</div>
|
|
19
19
|
|
|
20
|
-
<p>release: 2.
|
|
20
|
+
<p>release: 2.4.0
|
|
21
21
|
</p>
|
|
22
22
|
<a name="preface"></a>
|
|
23
23
|
<h2 class="section1">Preface</h2>
|
|
@@ -25,29 +25,29 @@
|
|
|
25
25
|
It has the following features.
|
|
26
26
|
</p>
|
|
27
27
|
<ul type="disc">
|
|
28
|
-
<li
|
|
28
|
+
<li>Very fast, almost three times faster than ERB and about ten percent faster than eruby (implemented in C)
|
|
29
29
|
</li>
|
|
30
|
-
<li
|
|
30
|
+
<li>File caching of converted Ruby script support
|
|
31
31
|
</li>
|
|
32
|
-
<li
|
|
32
|
+
<li>Auto escaping support
|
|
33
33
|
</li>
|
|
34
|
-
<li
|
|
34
|
+
<li>Auto trimming spaces around '<% %>'
|
|
35
35
|
</li>
|
|
36
|
-
<li
|
|
36
|
+
<li>Embedded pattern changeable (default '<% %>')
|
|
37
37
|
</li>
|
|
38
|
-
<li
|
|
38
|
+
<li>Enable to handle Processing Instructions (PI) as embedded pattern (ex. '<?rb ... ?>')
|
|
39
39
|
</li>
|
|
40
|
-
<li
|
|
40
|
+
<li>Multi-language support (Ruby/PHP/C/Java/Scheme/Perl/Javascript)
|
|
41
41
|
</li>
|
|
42
|
-
<li
|
|
42
|
+
<li>Context object available and easy to combine eRuby template with YAML datafile
|
|
43
43
|
</li>
|
|
44
|
-
<li
|
|
44
|
+
<li>Print statement available
|
|
45
45
|
</li>
|
|
46
|
-
<li
|
|
46
|
+
<li>Easy to expand and customize in subclass
|
|
47
47
|
</li>
|
|
48
|
-
<li><a href="#
|
|
48
|
+
<li><a href="#rails">Ruby on Rails support</a>
|
|
49
49
|
</li>
|
|
50
|
-
<li
|
|
50
|
+
<li>mod_ruby support|#topcs-modruby
|
|
51
51
|
</li>
|
|
52
52
|
</ul>
|
|
53
53
|
<p>Erubis is implemented in pure Ruby. It requires Ruby 1.8 or higher.
|
|
@@ -139,6 +139,16 @@ It has the following features.
|
|
|
139
139
|
</li>
|
|
140
140
|
</ul>
|
|
141
141
|
</li>
|
|
142
|
+
<li><a href="#rails">Ruby on Rails Support</a>
|
|
143
|
+
<ul>
|
|
144
|
+
<li><a href="#rails-settings">Settings</a>
|
|
145
|
+
</li>
|
|
146
|
+
<li><a href="#rails-preprocessing">Preprosessing</a>
|
|
147
|
+
</li>
|
|
148
|
+
<li><a href="#rails-others">Others</a>
|
|
149
|
+
</li>
|
|
150
|
+
</ul>
|
|
151
|
+
</li>
|
|
142
152
|
<li><a href="#topics">Other Topics</a>
|
|
143
153
|
<ul>
|
|
144
154
|
<li><a href="#topics-fasteruby">Class Erubis::FastEruby</a>
|
|
@@ -149,12 +159,12 @@ It has the following features.
|
|
|
149
159
|
</li>
|
|
150
160
|
<li><a href="#topics-tinyeruby">Erubis::TinyEruby class</a>
|
|
151
161
|
</li>
|
|
152
|
-
<li><a href="#topics-rails">Ruby on Rails Support</a>
|
|
153
|
-
</li>
|
|
154
162
|
<li><a href="#topics-php">NoTextEnhancer and NoCodeEnhancer in PHP</a>
|
|
155
163
|
</li>
|
|
156
164
|
<li><a href="#topcs-modruby">Helper Class for mod_ruby</a>
|
|
157
165
|
</li>
|
|
166
|
+
<li><a href="#topics-defmethod">Define method</a>
|
|
167
|
+
</li>
|
|
158
168
|
<li><a href="#topics-benchmark">Benchmark</a>
|
|
159
169
|
</li>
|
|
160
170
|
</ul>
|
|
@@ -2281,6 +2291,200 @@ document.write(_buf.join(""));
|
|
|
2281
2291
|
<br>
|
|
2282
2292
|
|
|
2283
2293
|
|
|
2294
|
+
<a name="rails"></a>
|
|
2295
|
+
<h2 class="section1">Ruby on Rails Support</h2>
|
|
2296
|
+
<p>Erubis supports Ruby on Rails.
|
|
2297
|
+
This section describes how to use Erubis with Ruby on Rails.
|
|
2298
|
+
</p>
|
|
2299
|
+
<a name="rails-settings"></a>
|
|
2300
|
+
<h3 class="section2">Settings</h3>
|
|
2301
|
+
<ol type="1">
|
|
2302
|
+
<li>Add the following code to your 'config/environment.rb'.
|
|
2303
|
+
<div class="program_caption">
|
|
2304
|
+
config/environment.rb</div>
|
|
2305
|
+
<pre class="program">require 'erubis/helpers/rails_helper'
|
|
2306
|
+
#Erubis::Helpers::RailsHelper.engine_class = Erubis::Eruby # or Erubis::FastEruby
|
|
2307
|
+
#Erubis::Helpers::RailsHelper.init_properties = {}
|
|
2308
|
+
#Erubis::Helpers::RailsHelper.show_src = false
|
|
2309
|
+
#Erubis::Helpers::RailsHelper.preprocessing = true
|
|
2310
|
+
</pre>
|
|
2311
|
+
<p> This will replace ERB in Rails by Erubis entirely.
|
|
2312
|
+
</p>
|
|
2313
|
+
</li>
|
|
2314
|
+
<li>(Optional) apply the following patch to 'action_pack/lib/action_view/base.rb'.
|
|
2315
|
+
<div class="program_caption">
|
|
2316
|
+
action_view_base_rb.patch</div>
|
|
2317
|
+
<pre class="program">--- lib/action_view/base.rb (original)
|
|
2318
|
+
+++ lib/action_view/base.rb (working copy)
|
|
2319
|
+
@@ -445,6 +445,11 @@
|
|
2320
|
+
end
|
|
2321
|
+
end
|
|
2322
|
+
|
|
2323
|
+
+ # convert template into ruby code
|
|
2324
|
+
+ def convert_template_into_ruby_code(template)
|
|
2325
|
+
+ ERB.new(template, nil, @@erb_trim_mode).src
|
|
2326
|
+
+ end
|
|
2327
|
+
+
|
|
2328
|
+
# Create source code for given template
|
|
2329
|
+
def create_template_source(extension, template, render_symbol, locals)
|
|
2330
|
+
if template_requires_setup?(extension)
|
|
2331
|
+
@@ -458,7 +463,7 @@
|
|
2332
|
+
"update_page do |page|\n#{template}\nend"
|
|
2333
|
+
end
|
|
2334
|
+
else
|
|
2335
|
+
- body = ERB.new(template, nil, @@erb_trim_mode).src
|
|
2336
|
+
+ body = convert_template_into_ruby_code(template)
|
|
2337
|
+
end
|
|
2338
|
+
|
|
2339
|
+
@@template_args[render_symbol] ||= {}
|
|
2340
|
+
</pre>
|
|
2341
|
+
<p> This patch is included in erubis_2.X.X/contrib directory and the following is an
|
|
2342
|
+
example to apply this patch.
|
|
2343
|
+
</p>
|
|
2344
|
+
<div class="terminal_caption">
|
|
2345
|
+
how to apply patch:</div>
|
|
2346
|
+
<pre class="terminal">$ cd /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_view/
|
|
2347
|
+
$ sudo patch -p1 < /tmp/erubis_2.X.X/contrib/action_view_base_rb.patch
|
|
2348
|
+
</pre>
|
|
2349
|
+
<p> Notice that this patch is not necessary if you are using Ruby on Rails ver 1.1 or 1.2, but it is recommended.
|
|
2350
|
+
</p>
|
|
2351
|
+
</li>
|
|
2352
|
+
<li>Restart web server.
|
|
2353
|
+
<pre class="terminal">$ ruby script/server
|
|
2354
|
+
</pre>
|
|
2355
|
+
</li>
|
|
2356
|
+
</ol>
|
|
2357
|
+
<p>The setting is above all.
|
|
2358
|
+
</p>
|
|
2359
|
+
<br>
|
|
2360
|
+
|
|
2361
|
+
|
|
2362
|
+
<a name="rails-preprocessing"></a>
|
|
2363
|
+
<h3 class="section2">Preprosessing</h3>
|
|
2364
|
+
<p><strong>(Experimental)</strong>
|
|
2365
|
+
Erubis supports preprocessing of template files.
|
|
2366
|
+
Preprocessing make your Ruby on Rails application about 20-40 percent faster.
|
|
2367
|
+
To enable preprocessing, set Erubis::Helpers::RailsHelper.preprocessing to true in your 'environment.rb' file.
|
|
2368
|
+
</p>
|
|
2369
|
+
<p>For example, assume the following template.
|
|
2370
|
+
This is slow because link_to() method is called every time when template is rendered.
|
|
2371
|
+
</p>
|
|
2372
|
+
<pre class="program"><%= link_to 'Create', :action=>'create' %>
|
|
2373
|
+
</pre>
|
|
2374
|
+
<p>The following is faster than the above, but not flexible because url is fixed.
|
|
2375
|
+
</p>
|
|
2376
|
+
<pre class="program"><a href="/users/create">Create</a>
|
|
2377
|
+
</pre>
|
|
2378
|
+
<p>Preprocessing solves this problem.
|
|
2379
|
+
If you use '[%= %]' instead of '<%= %>', preprocessor evaluate it only once when template is loaded.
|
|
2380
|
+
</p>
|
|
2381
|
+
<pre class="program"><strong>[%= link_to 'Create', :action=>'create'%]</strong>
|
|
2382
|
+
</pre>
|
|
2383
|
+
<p>The above is evaluated by preprocessor and replaced to the following code automatically.
|
|
2384
|
+
</p>
|
|
2385
|
+
<pre class="program"><a href="/users/create">Create</a>
|
|
2386
|
+
</pre>
|
|
2387
|
+
<p>Notice that this is done only once when template file is loaded.
|
|
2388
|
+
It means that link_to() method is not called when template is rendered.
|
|
2389
|
+
</p>
|
|
2390
|
+
<p>If link_to() method have variable arguments, use <code>_?()</code> helper method.
|
|
2391
|
+
</p>
|
|
2392
|
+
<pre class="program"><% for user in @users %>
|
|
2393
|
+
[%= link_to <strong>_?('user.name')</strong>, :action=>'show', :id=><strong>_?('user.id')</strong> %]
|
|
2394
|
+
<% end %>
|
|
2395
|
+
</pre>
|
|
2396
|
+
<p>The above is evaluated by preprocessor when template is loaded and expanded into the following code.
|
|
2397
|
+
This will be much faster because link_to() method is not called when rendering.
|
|
2398
|
+
</p>
|
|
2399
|
+
<pre class="program"><% for user in @users %>
|
|
2400
|
+
<a href="/users/show/<strong><%=user.id%></strong>"><strong><%=user.name%></strong></a>
|
|
2401
|
+
<% end %>
|
|
2402
|
+
</pre>
|
|
2403
|
+
<p>Preprocessing statement (<code>[% %]</code>) is also available as well as preprocessing expression (<code>[%= %]</code>).
|
|
2404
|
+
</p>
|
|
2405
|
+
<pre class="program"><select name="state">
|
|
2406
|
+
<option value="">-</option>
|
|
2407
|
+
<strong>[% for code in states.keys.sort %]</strong>
|
|
2408
|
+
<option value="<strong>[%= code %]</strong>"><strong>[%= states[code] %]</strong></option>
|
|
2409
|
+
<strong>[% end %]</strong>
|
|
2410
|
+
</select>
|
|
2411
|
+
</pre>
|
|
2412
|
+
<p>The above will be evaluated by preprocessor and expanded into the following when template is loaded.
|
|
2413
|
+
In the result, rendering speed will be much faster because for-loop is not executed when rendering.
|
|
2414
|
+
</p>
|
|
2415
|
+
<pre class="program"><select name="state">
|
|
2416
|
+
<option value="">-</option>
|
|
2417
|
+
<option value="AK">Alaska</option>
|
|
2418
|
+
<option value="AL">Alabama</option>
|
|
2419
|
+
<option value="AR">Arkansas</option>
|
|
2420
|
+
<option value="AS">American Samoa</option>
|
|
2421
|
+
<option value="AZ">Arizona</option>
|
|
2422
|
+
<option value="CA">California</option>
|
|
2423
|
+
<option value="CO">Colorado</option>
|
|
2424
|
+
....
|
|
2425
|
+
</select>
|
|
2426
|
+
</pre>
|
|
2427
|
+
<p>Notice that it is not recommended to use preprocessing with tag helpers,
|
|
2428
|
+
because tag helpers generate different html code when form parameter has errors or not.
|
|
2429
|
+
</p>
|
|
2430
|
+
<p>Helper methods of Ruby on Rails are divided into two groups.
|
|
2431
|
+
</p>
|
|
2432
|
+
<ul type="disc">
|
|
2433
|
+
<li>link_to() or _() (method of gettext package) are not need to call for every time
|
|
2434
|
+
as template is rendered because it returns same value when same arguments are passed.
|
|
2435
|
+
These methods can be got faster by preprocessing.
|
|
2436
|
+
</li>
|
|
2437
|
+
<li>Tag helper methods should be called for every time as template is rendered
|
|
2438
|
+
because it may return differrent value even if the same arguments are passed.
|
|
2439
|
+
Preprocessing is not available with these methods.
|
|
2440
|
+
</li>
|
|
2441
|
+
</ul>
|
|
2442
|
+
<br>
|
|
2443
|
+
|
|
2444
|
+
|
|
2445
|
+
<a name="rails-others"></a>
|
|
2446
|
+
<h3 class="section2">Others</h3>
|
|
2447
|
+
<ul type="disc">
|
|
2448
|
+
<li>ActionView::Helpers::CaptureHelper#capture() and ActionView::Helpers::Texthelper#concat() are available.
|
|
2449
|
+
</li>
|
|
2450
|
+
</ul>
|
|
2451
|
+
<ul type="disc">
|
|
2452
|
+
<li>If Erubis::Helper::Rails.show_src is ture, Erubis prints converted Ruby code into log file (ex. 'log/development.log').
|
|
2453
|
+
</li>
|
|
2454
|
+
</ul>
|
|
2455
|
+
<p>If it is nil (default), Erubis prints converted Ruby code into log file only when development mode.
|
|
2456
|
+
It is useful for debugging.
|
|
2457
|
+
</p>
|
|
2458
|
+
<ul type="disc">
|
|
2459
|
+
<li>ERB::Util.h() is redefined if you require 'erubis/helpers/rails_helper.rb'.
|
|
2460
|
+
Original definition of ERB::Util.h() is the following and it is slow
|
|
2461
|
+
because it scans string four times.
|
|
2462
|
+
<pre class="program"> def html_escape(s)
|
|
2463
|
+
s.to_s.gsub(/&/, "&amp;").gsub(/\"/, "&quot;").gsub(/>/, "&gt;").gsub(/</, "&lt;")
|
|
2464
|
+
end
|
|
2465
|
+
alias h html_escape
|
|
2466
|
+
</pre>
|
|
2467
|
+
</li>
|
|
2468
|
+
</ul>
|
|
2469
|
+
<p> New definition in 'erubis/helpers/rails_helper.rb' is faster than the above
|
|
2470
|
+
because it scans string only once.
|
|
2471
|
+
</p>
|
|
2472
|
+
<pre class="program"> ESCAPE_TABLE = { '&'=>'&amp;', '<'=>'&lt;', '>'=>'&gt;', '"'=>'&quot;', "'"=>'&#039;', }
|
|
2473
|
+
def h(value)
|
|
2474
|
+
value.to_s.gsub(/[&<>"]/) { |s| ESCAPE_TABLE[s] }
|
|
2475
|
+
end
|
|
2476
|
+
</pre>
|
|
2477
|
+
<p> Notice that the new definition may be slow if string contains
|
|
2478
|
+
many '< > & "' characters because block is call many time.
|
|
2479
|
+
You should use ERB::Util.html_hscape() if string contains a lot of '< > & "'
|
|
2480
|
+
characters.
|
|
2481
|
+
</p>
|
|
2482
|
+
<br>
|
|
2483
|
+
|
|
2484
|
+
|
|
2485
|
+
<br>
|
|
2486
|
+
|
|
2487
|
+
|
|
2284
2488
|
<a name="topics"></a>
|
|
2285
2489
|
<h2 class="section1">Other Topics</h2>
|
|
2286
2490
|
<a name="topics-fasteruby"></a>
|
|
@@ -2412,73 +2616,6 @@ try Erubis::TinyEruby class.
|
|
|
2412
2616
|
<br>
|
|
2413
2617
|
|
|
2414
2618
|
|
|
2415
|
-
<a name="topics-rails"></a>
|
|
2416
|
-
<h3 class="section2">Ruby on Rails Support</h3>
|
|
2417
|
-
<p>Erubis supports Ruby on Rails.
|
|
2418
|
-
</p>
|
|
2419
|
-
<ol type="1">
|
|
2420
|
-
<li>Add the following code to your 'config/environment.rb'.
|
|
2421
|
-
<div class="program_caption">
|
|
2422
|
-
config/environment.rb</div>
|
|
2423
|
-
<pre class="program">require 'erubis/helpers/rails_helper'
|
|
2424
|
-
#Erubis::Helpers::RailsHelper.engine_class = Erubis::Eruby # or Erubis::FastEruby
|
|
2425
|
-
#Erubis::Helpers::RailsHelper.init_properties = {}
|
|
2426
|
-
#Erubis::Helpers::RailsHelper.show_src = false
|
|
2427
|
-
</pre>
|
|
2428
|
-
<p> This will replace ERB in Rails by Erubis entirely.
|
|
2429
|
-
</p>
|
|
2430
|
-
</li>
|
|
2431
|
-
<li>(Optional) apply the following patch to 'action_pack/lib/action_view/base.rb'.
|
|
2432
|
-
<div class="program_caption">
|
|
2433
|
-
action_view_base_rb.patch</div>
|
|
2434
|
-
<pre class="program">--- lib/action_view/base.rb (original)
|
|
2435
|
-
+++ lib/action_view/base.rb (working copy)
|
|
2436
|
-
@@ -445,6 +445,11 @@
|
|
2437
|
-
end
|
|
2438
|
-
end
|
|
2439
|
-
|
|
2440
|
-
+ # convert template into ruby code
|
|
2441
|
-
+ def convert_template_into_ruby_code(template)
|
|
2442
|
-
+ ERB.new(template, nil, @@erb_trim_mode).src
|
|
2443
|
-
+ end
|
|
2444
|
-
+
|
|
2445
|
-
# Create source code for given template
|
|
2446
|
-
def create_template_source(extension, template, render_symbol, locals)
|
|
2447
|
-
if template_requires_setup?(extension)
|
|
2448
|
-
@@ -458,7 +463,7 @@
|
|
2449
|
-
"update_page do |page|\n#{template}\nend"
|
|
2450
|
-
end
|
|
2451
|
-
else
|
|
2452
|
-
- body = ERB.new(template, nil, @@erb_trim_mode).src
|
|
2453
|
-
+ body = convert_template_into_ruby_code(template)
|
|
2454
|
-
end
|
|
2455
|
-
|
|
2456
|
-
@@template_args[render_symbol] ||= {}
|
|
2457
|
-
</pre>
|
|
2458
|
-
<p> This patch is included in erubis_2.X.X/contrib directory and the following is an
|
|
2459
|
-
example to apply this patch.
|
|
2460
|
-
</p>
|
|
2461
|
-
<div class="terminal_caption">
|
|
2462
|
-
how to apply patch:</div>
|
|
2463
|
-
<pre class="terminal">$ cd /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_view/
|
|
2464
|
-
$ sudo patch -p1 < /tmp/erubis_2.X.X/contrib/action_view_base_rb.patch
|
|
2465
|
-
</pre>
|
|
2466
|
-
<p> Notice that this patch is not necessary if you are using Ruby on Rails ver 1.1 or 1.2, but it is recommended.
|
|
2467
|
-
</p>
|
|
2468
|
-
</li>
|
|
2469
|
-
<li>Restart web server.
|
|
2470
|
-
<pre class="terminal">$ ruby script/server
|
|
2471
|
-
</pre>
|
|
2472
|
-
</li>
|
|
2473
|
-
</ol>
|
|
2474
|
-
<p>ActionView::Helpers::CaptureHelper#capture() and ActionView::Helpers::Texthelper#concat() are available.
|
|
2475
|
-
</p>
|
|
2476
|
-
<p>If Erubis::Helper::Rails.show_src is ture, Erubis prints converted Ruby code into log file (ex. 'log/development.log').
|
|
2477
|
-
It is useful for debugging.
|
|
2478
|
-
</p>
|
|
2479
|
-
<br>
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
2619
|
<a name="topics-php"></a>
|
|
2483
2620
|
<h3 class="section2">NoTextEnhancer and NoCodeEnhancer in PHP</h3>
|
|
2484
2621
|
<p>NoTextEnhancer and NoCodEnahncer are quite useful not only for eRuby but also for PHP.
|
|
@@ -2571,8 +2708,8 @@ example of using NoCodeEnhancer with PHP file</div>
|
|
|
2571
2708
|
<p>Thanks Andrew R Jackson, he developed 'erubis-run.rb' which enables you to use Erubis with mod_ruby.
|
|
2572
2709
|
</p>
|
|
2573
2710
|
<ol type="1">
|
|
2574
|
-
<li>Copy 'erubis-2.
|
|
2575
|
-
<pre class="terminal">$ cd erubis-2.
|
|
2711
|
+
<li>Copy 'erubis-2.4.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.
|
|
2712
|
+
<pre class="terminal">$ cd erubis-2.4.0/
|
|
2576
2713
|
$ sudo copy contrib/erubis-run.rb /usr/local/lib/ruby/1.8/apache/
|
|
2577
2714
|
</pre>
|
|
2578
2715
|
</li>
|
|
@@ -2618,19 +2755,42 @@ $ sudo chmod 775 .
|
|
|
2618
2755
|
</ol>
|
|
2619
2756
|
<p>You must set your directories to be writable by web server process, because
|
|
2620
2757
|
Apache::ErubisRun calls Erubis::Eruby.load_file() internally which creates cache files
|
|
2621
|
-
in the same directory
|
|
2758
|
+
in the same directory in which '*.rhtml' file exists.
|
|
2622
2759
|
</p>
|
|
2623
2760
|
<br>
|
|
2624
2761
|
|
|
2625
2762
|
|
|
2763
|
+
<a name="topics-defmethod"></a>
|
|
2764
|
+
<h3 class="section2">Define method</h3>
|
|
2765
|
+
<p>Erubis::Eruby#def_method() defines instance method or singleton method.
|
|
2766
|
+
</p>
|
|
2767
|
+
<a name="def_method.rb"></a>
|
|
2768
|
+
<pre class="program">require 'erubis'
|
|
2769
|
+
s = "hello <%= name %>"
|
|
2770
|
+
eruby = Erubis::Eruby.new(s)
|
|
2771
|
+
filename = 'hello.rhtml'
|
|
2772
|
+
|
|
2773
|
+
## define instance method to Dummy class (or module)
|
|
2774
|
+
class Dummy; end
|
|
2775
|
+
<strong>eruby.def_method(Dummy, 'render(name)', filename)</strong> # filename is optional
|
|
2776
|
+
p Dummy.new.render('world') #=> "hello world"
|
|
2777
|
+
|
|
2778
|
+
## define singleton method to dummy object
|
|
2779
|
+
obj = Object.new
|
|
2780
|
+
<strong>eruby.def_method(obj, 'render(name)', filename)</strong> # filename is optional
|
|
2781
|
+
p obj.render('world') #=> "hello world"
|
|
2782
|
+
</pre>
|
|
2783
|
+
<br>
|
|
2784
|
+
|
|
2785
|
+
|
|
2626
2786
|
<a name="topics-benchmark"></a>
|
|
2627
2787
|
<h3 class="section2">Benchmark</h3>
|
|
2628
|
-
<p>A benchmark script is included in Erubis package at 'erubis-2.
|
|
2788
|
+
<p>A benchmark script is included in Erubis package at 'erubis-2.4.0/benchark/' directory.
|
|
2629
2789
|
Here is an example result of benchmark.
|
|
2630
2790
|
</p>
|
|
2631
2791
|
<div class="terminal_caption">
|
|
2632
2792
|
MacOS X 10.4 Tiger, Intel CoreDuo 1.83GHz, Ruby1.8.6, eruby1.0.5, gcc4.0.1</div>
|
|
2633
|
-
<pre class="terminal">$ cd erubis-2.
|
|
2793
|
+
<pre class="terminal">$ cd erubis-2.4.0/benchmark/
|
|
2634
2794
|
$ ruby bench.rb -n 10000 -m execute
|
|
2635
2795
|
*** ntimes=10000, testmode=execute
|
|
2636
2796
|
user system total real
|
data/lib/erubis.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
##
|
|
2
2
|
## $Rev: 59 $
|
|
3
|
-
## 2.
|
|
3
|
+
## 2.4.0
|
|
4
4
|
## copyright(c) 2006-2007 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.4.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: 89 $
|
|
3
|
+
## $Release: 2.4.0 $
|
|
4
4
|
## copyright(c) 2006-2007 kuwata-lab.com all rights reserved.
|
|
5
5
|
##
|
|
6
6
|
|
|
@@ -36,6 +36,7 @@ module Erubis
|
|
|
36
36
|
@preamble.nil? ? add_preamble(codebuf) : (@preamble && (codebuf << @preamble))
|
|
37
37
|
convert_input(codebuf, input)
|
|
38
38
|
@postamble.nil? ? add_postamble(codebuf) : (@postamble && (codebuf << @postamble))
|
|
39
|
+
@_proc = nil # clear cached proc object
|
|
39
40
|
return codebuf # or codebuf.join()
|
|
40
41
|
end
|
|
41
42
|
|