erubis 2.2.0 → 2.3.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 +120 -3
- data/README.txt +1 -1
- data/benchmark/Makefile +6 -0
- data/benchmark/bench.rb +306 -0
- data/benchmark/{erubybench.yaml → bench_context.yaml} +20 -20
- data/benchmark/templates/_footer.html +4 -0
- data/benchmark/{erubybench.rhtml → templates/_header.html} +1 -34
- data/benchmark/templates/bench_erb.rhtml +29 -0
- data/benchmark/templates/bench_erubis.rhtml +29 -0
- data/benchmark/templates/bench_eruby.rhtml +29 -0
- data/bin/erubis +2 -2
- data/contrib/erubis +3 -3114
- data/contrib/erubis-run.rb +132 -0
- data/contrib/inline-require +1 -1
- data/doc-api/classes/{ERB.html → ActionView/Base/ERB.html} +3 -3
- data/doc-api/classes/Erubis.html +8 -1
- data/doc-api/classes/Erubis/ArrayEnhancer.html +12 -12
- data/doc-api/classes/Erubis/Basic/Converter.html +24 -24
- data/doc-api/classes/Erubis/BiPatternEnhancer.html +14 -14
- 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 +150 -0
- data/doc-api/classes/Erubis/DeleteIndentEruby.html +120 -0
- data/doc-api/classes/Erubis/Engine.html +31 -31
- data/doc-api/classes/Erubis/ErboutEnhancer.html +175 -0
- data/doc-api/classes/Erubis/ErboutEruby.html +120 -0
- data/doc-api/classes/Erubis/Eruby.html +5 -0
- data/doc-api/classes/Erubis/EscapeEnhancer.html +6 -6
- data/doc-api/classes/Erubis/Evaluator.html +19 -19
- data/doc-api/classes/Erubis/FastEruby.html +131 -0
- data/doc-api/classes/Erubis/HeaderFooterEnhancer.html +14 -14
- data/doc-api/classes/Erubis/Helpers/RailsHelper.html +49 -45
- data/doc-api/classes/Erubis/InterpolationEnhancer.html +304 -0
- data/doc-api/classes/Erubis/InterpolationEruby.html +120 -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 +35 -27
- data/doc-api/classes/Erubis/NoCodeEnhancer.html +5 -5
- data/doc-api/classes/Erubis/NoTextEnhancer.html +7 -7
- 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 +18 -18
- 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 +7 -7
- 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 +8 -8
- data/doc-api/classes/Erubis/PerlGenerator.html +54 -54
- 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 +12 -12
- 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 +8 -8
- 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 +14 -14
- data/doc-api/created.rid +1 -1
- data/doc-api/files/README_txt.html +4 -4
- data/doc-api/files/erubis/context_rb.html +2 -2
- data/doc-api/files/erubis/converter_rb.html +2 -2
- data/doc-api/files/erubis/engine/ec_rb.html +2 -2
- data/doc-api/files/erubis/engine/ejava_rb.html +2 -2
- data/doc-api/files/erubis/engine/ejavascript_rb.html +2 -2
- data/doc-api/files/erubis/engine/enhanced_rb.html +2 -2
- data/doc-api/files/erubis/engine/eperl_rb.html +2 -2
- data/doc-api/files/erubis/engine/ephp_rb.html +2 -2
- data/doc-api/files/erubis/engine/eruby_rb.html +2 -2
- data/doc-api/files/erubis/engine/escheme_rb.html +2 -2
- data/doc-api/files/erubis/engine/optimized_rb.html +2 -2
- 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 +2 -2
- data/doc-api/files/erubis/evaluator_rb.html +2 -2
- data/doc-api/files/erubis/generator_rb.html +2 -2
- data/doc-api/files/erubis/helper_rb.html +2 -2
- data/doc-api/files/erubis/helpers/rails_helper_rb.html +2 -2
- data/doc-api/files/erubis/local-setting_rb.html +2 -2
- data/doc-api/files/erubis/main_rb.html +2 -2
- data/doc-api/files/erubis/tiny_rb.html +2 -2
- data/doc-api/files/erubis_rb.html +1 -1
- data/doc-api/fr_class_index.html +8 -1
- data/doc-api/fr_method_index.html +166 -158
- data/doc/users-guide.html +623 -215
- data/lib/erubis.rb +2 -2
- data/lib/erubis/context.rb +2 -2
- data/lib/erubis/converter.rb +2 -2
- data/lib/erubis/engine.rb +3 -3
- data/lib/erubis/engine/ec.rb +2 -2
- data/lib/erubis/engine/ejava.rb +2 -2
- data/lib/erubis/engine/ejavascript.rb +2 -2
- data/lib/erubis/engine/enhanced.rb +17 -2
- data/lib/erubis/engine/eperl.rb +2 -2
- data/lib/erubis/engine/ephp.rb +2 -2
- data/lib/erubis/engine/eruby.rb +10 -2
- data/lib/erubis/engine/escheme.rb +2 -2
- data/lib/erubis/engine/optimized.rb +2 -2
- data/lib/erubis/enhancer.rb +134 -25
- data/lib/erubis/error.rb +2 -2
- data/lib/erubis/evaluator.rb +2 -2
- data/lib/erubis/generator.rb +2 -2
- data/lib/erubis/helper.rb +2 -2
- data/lib/erubis/helpers/rails_helper.rb +19 -75
- data/lib/erubis/local-setting.rb +2 -2
- data/lib/erubis/main.rb +63 -36
- data/lib/erubis/tiny.rb +2 -2
- data/test/assert-text-equal.rb +2 -2
- data/test/data/users-guide/Example.ejava +55 -0
- data/test/data/users-guide/array_example.result +9 -0
- data/test/data/users-guide/arraybuffer_example.result +9 -0
- data/test/data/users-guide/bipattern-example.rhtml +4 -0
- data/test/data/users-guide/bipattern_example.result +6 -0
- data/test/data/users-guide/context.rb +6 -0
- data/test/data/users-guide/context.yaml +8 -0
- data/test/data/users-guide/escape_example.result +9 -0
- data/test/data/users-guide/example.ec +27 -0
- data/test/data/users-guide/example.ejs +20 -0
- data/test/data/users-guide/example.eperl +18 -0
- data/test/data/users-guide/example.ephp +18 -0
- data/test/data/users-guide/example.eruby +6 -0
- data/test/data/users-guide/example.escheme +28 -0
- data/test/data/users-guide/example1.eruby +6 -0
- data/test/data/users-guide/example1.rb +16 -0
- data/test/data/users-guide/example1.result +16 -0
- data/test/data/users-guide/example10.rb +4 -0
- data/test/data/users-guide/example10.result +17 -0
- data/test/data/users-guide/example10.xhtml +14 -0
- data/test/data/users-guide/example10_x.result +17 -0
- data/test/data/users-guide/example11.php +20 -0
- data/test/data/users-guide/example11.result +23 -0
- data/test/data/users-guide/example11.rhtml +21 -0
- data/test/data/users-guide/example11_C.result +10 -0
- data/test/data/users-guide/example11_N.result +16 -0
- data/test/data/users-guide/example11_U.result +16 -0
- data/test/data/users-guide/example11_php.result +15 -0
- data/test/data/users-guide/example1_x.result +9 -0
- data/test/data/users-guide/example2.eruby +7 -0
- data/test/data/users-guide/example2.rb +10 -0
- data/test/data/users-guide/example2.result +27 -0
- data/test/data/users-guide/example2_trim.result +10 -0
- data/test/data/users-guide/example2_x.result +10 -0
- data/test/data/users-guide/example3.eruby +6 -0
- data/test/data/users-guide/example3.rb +10 -0
- data/test/data/users-guide/example31.result +22 -0
- data/test/data/users-guide/example32.result +4 -0
- data/test/data/users-guide/example3_e.result +8 -0
- data/test/data/users-guide/example4.eruby +3 -0
- data/test/data/users-guide/example4.rb +11 -0
- data/test/data/users-guide/example4.result +10 -0
- data/test/data/users-guide/example4_x.result +5 -0
- data/test/data/users-guide/example5.eruby +6 -0
- data/test/data/users-guide/example5.rb +16 -0
- data/test/data/users-guide/example5.result +7 -0
- data/test/data/users-guide/example6.rb +12 -0
- data/test/data/users-guide/example6.result +7 -0
- data/test/data/users-guide/example7.eruby +8 -0
- data/test/data/users-guide/example71.result +13 -0
- data/test/data/users-guide/example72.result +13 -0
- data/test/data/users-guide/example8.eruby +6 -0
- data/test/data/users-guide/example8_ruby.result +7 -0
- data/test/data/users-guide/example8_yaml.result +7 -0
- data/test/data/users-guide/example9.eruby +3 -0
- data/test/data/users-guide/example9.rb +8 -0
- data/test/data/users-guide/example9.result +9 -0
- data/test/data/users-guide/example91.result +5 -0
- data/test/data/users-guide/example92.result +4 -0
- data/test/data/users-guide/example_c.result +29 -0
- data/test/data/users-guide/example_java.result +56 -0
- data/test/data/users-guide/example_js.result +22 -0
- data/test/data/users-guide/example_perl.result +20 -0
- data/test/data/users-guide/example_php.result +19 -0
- data/test/data/users-guide/example_scheme.result +30 -0
- data/test/data/users-guide/example_scheme_display.result +29 -0
- data/test/data/users-guide/fasteruby.rb +11 -0
- data/test/data/users-guide/fasteruby.result +38 -0
- data/test/data/users-guide/fasteruby.rhtml +15 -0
- data/test/data/users-guide/headerfooter-example.eruby +9 -0
- data/test/data/users-guide/headerfooter-example2.rb +8 -0
- data/test/data/users-guide/headerfooter-example2.rhtml +10 -0
- data/test/data/users-guide/headerfooter_example.result +11 -0
- data/test/data/users-guide/headerfooter_example2.result +13 -0
- data/test/data/users-guide/interpolation_example.result +9 -0
- data/test/data/users-guide/nocode-example.eruby +14 -0
- data/test/data/users-guide/nocode-php.result +20 -0
- data/test/data/users-guide/nocode_example.result +15 -0
- data/test/data/users-guide/normal-eruby-test.eruby +9 -0
- data/test/data/users-guide/normal_eruby_test.result +11 -0
- data/test/data/users-guide/notext-example.eruby +14 -0
- data/test/data/users-guide/notext-example.php +19 -0
- data/test/data/users-guide/notext-php.result +20 -0
- data/test/data/users-guide/notext_example.result +16 -0
- data/test/data/users-guide/percentline-example.rhtml +4 -0
- data/test/data/users-guide/percentline_example.result +7 -0
- data/test/data/users-guide/printenable_example.result +4 -0
- data/test/data/users-guide/printenabled-example.eruby +3 -0
- data/test/data/users-guide/printenabled-example.rb +8 -0
- data/test/data/users-guide/printstatement_example.result +8 -0
- data/test/data/users-guide/simplify_example.result +9 -0
- data/test/data/users-guide/stdout_exmple.result +9 -0
- data/test/data/users-guide/stringbuffer_example.result +9 -0
- data/test/test-engines.rb +2 -2
- data/test/test-enhancers.rb +569 -0
- data/test/test-erubis.rb +3 -380
- data/test/test-main.rb +39 -15
- data/test/test-users-guide.rb +56 -0
- data/test/test.rb +4 -3
- data/test/testutil.rb +2 -2
- metadata +166 -57
- data/benchmark/erubybench-lib.rb +0 -189
- data/benchmark/erubybench.rb +0 -600
- data/bin/notext +0 -154
- data/test/test-notext.rb +0 -27
data/lib/erubis.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
##
|
|
2
2
|
## $Rev: 59 $
|
|
3
|
-
##
|
|
3
|
+
## 2.3.0
|
|
4
4
|
## copyright(c) 2006-2007 kuwata-lab 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.3.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
data/lib/erubis/engine.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
##
|
|
2
|
-
## $Rev:
|
|
3
|
-
## $Release: 2.
|
|
2
|
+
## $Rev: 77 $
|
|
3
|
+
## $Release: 2.3.0 $
|
|
4
4
|
## copyright(c) 2006-2007 kuwata-lab all rights reserved.
|
|
5
5
|
##
|
|
6
6
|
|
|
@@ -80,7 +80,7 @@ module Erubis
|
|
|
80
80
|
|
|
81
81
|
|
|
82
82
|
##
|
|
83
|
-
## helper method evaluate Proc object
|
|
83
|
+
## helper method evaluate Proc object with contect object.
|
|
84
84
|
## context may be Binding, Hash, or Object.
|
|
85
85
|
##
|
|
86
86
|
def process_proc(proc_obj, context=nil, filename=nil)
|
data/lib/erubis/engine/ec.rb
CHANGED
data/lib/erubis/engine/ejava.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
##
|
|
2
|
-
## $Rev:
|
|
3
|
-
## $Release: 2.
|
|
2
|
+
## $Rev: 77 $
|
|
3
|
+
## $Release: 2.3.0 $
|
|
4
4
|
## copyright(c) 2006-2007 kuwata-lab all rights reserved.
|
|
5
5
|
##
|
|
6
6
|
|
|
@@ -62,6 +62,11 @@ module Erubis
|
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
|
|
65
|
+
class ErboutEruby < Eruby
|
|
66
|
+
include ErboutEnhancer
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
|
|
65
70
|
class NoTextEruby < Eruby
|
|
66
71
|
include NoTextEnhancer
|
|
67
72
|
end
|
|
@@ -104,4 +109,14 @@ module Erubis
|
|
|
104
109
|
end
|
|
105
110
|
|
|
106
111
|
|
|
112
|
+
class DeleteIndentEruby < Eruby
|
|
113
|
+
include DeleteIndentEnhancer
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
class InterpolationEruby < Eruby
|
|
118
|
+
include InterpolationEnhancer
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
|
|
107
122
|
end
|
data/lib/erubis/engine/eperl.rb
CHANGED
data/lib/erubis/engine/ephp.rb
CHANGED
data/lib/erubis/engine/eruby.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
##
|
|
2
|
-
## $Rev:
|
|
3
|
-
## $Release: 2.
|
|
2
|
+
## $Rev: 77 $
|
|
3
|
+
## $Release: 2.3.0 $
|
|
4
4
|
## copyright(c) 2006-2007 kuwata-lab all rights reserved.
|
|
5
5
|
##
|
|
6
6
|
|
|
@@ -84,6 +84,14 @@ module Erubis
|
|
|
84
84
|
end
|
|
85
85
|
|
|
86
86
|
|
|
87
|
+
##
|
|
88
|
+
## fast engine for Ruby
|
|
89
|
+
##
|
|
90
|
+
class FastEruby < Eruby
|
|
91
|
+
include InterpolationEnhancer
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
|
|
87
95
|
##
|
|
88
96
|
## swtich '<%= %>' to escaped and '<%== %>' to not escaped
|
|
89
97
|
##
|
data/lib/erubis/enhancer.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
##
|
|
2
|
-
## $Rev:
|
|
3
|
-
## $Release: 2.
|
|
2
|
+
## $Rev: 77 $
|
|
3
|
+
## $Release: 2.3.0 $
|
|
4
4
|
## copyright(c) 2006-2007 kuwata-lab all rights reserved.
|
|
5
5
|
##
|
|
6
6
|
|
|
@@ -243,29 +243,27 @@ module Erubis
|
|
|
243
243
|
end
|
|
244
244
|
|
|
245
245
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
#end
|
|
268
|
-
#++
|
|
246
|
+
##
|
|
247
|
+
## set buffer variable name to '_erbout' as well as '_buf'
|
|
248
|
+
##
|
|
249
|
+
## this is only for Eruby.
|
|
250
|
+
##
|
|
251
|
+
module ErboutEnhancer
|
|
252
|
+
|
|
253
|
+
def self.desc # :nodoc:
|
|
254
|
+
"set '_erbout = _buf = \"\";' to be compatible with ERB."
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
def add_preamble(src)
|
|
258
|
+
src << "_erbout = _buf = '';"
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
def add_postamble(src)
|
|
262
|
+
src << "\n" unless src[-1] == ?\n
|
|
263
|
+
src << "_buf.to_s\n"
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
end
|
|
269
267
|
|
|
270
268
|
|
|
271
269
|
##
|
|
@@ -544,4 +542,115 @@ module Erubis
|
|
|
544
542
|
end
|
|
545
543
|
|
|
546
544
|
|
|
545
|
+
##
|
|
546
|
+
## delete indentation of HTML.
|
|
547
|
+
##
|
|
548
|
+
## this is language-independent.
|
|
549
|
+
##
|
|
550
|
+
module DeleteIndentEnhancer
|
|
551
|
+
|
|
552
|
+
def self.desc # :nodoc:
|
|
553
|
+
"delete indentation of HTML."
|
|
554
|
+
end
|
|
555
|
+
|
|
556
|
+
def convert_input(src, input)
|
|
557
|
+
input = input.gsub(/^[ \t]+</, '<')
|
|
558
|
+
super(src, input)
|
|
559
|
+
end
|
|
560
|
+
|
|
561
|
+
end
|
|
562
|
+
|
|
563
|
+
|
|
564
|
+
##
|
|
565
|
+
## convert "<h1><%=title%></h1>" into "_buf << %Q`<h1>#{title}</h1>`"
|
|
566
|
+
##
|
|
567
|
+
## this is only for Eruby.
|
|
568
|
+
##
|
|
569
|
+
module InterpolationEnhancer
|
|
570
|
+
|
|
571
|
+
def self.desc # :nodoc:
|
|
572
|
+
"convert '<p><%=text%></p>' into '_buf << %Q`<p>\#{text}</p>`'"
|
|
573
|
+
end
|
|
574
|
+
|
|
575
|
+
def convert_input(src, input)
|
|
576
|
+
pat = @pattern
|
|
577
|
+
regexp = pat.nil? || pat == '<% %>' ? Basic::Converter::DEFAULT_REGEXP : pattern_regexp(pat)
|
|
578
|
+
pos = 0
|
|
579
|
+
is_bol = true # is beginning of line
|
|
580
|
+
str = ''
|
|
581
|
+
input.scan(regexp) do |indicator, code, rspace|
|
|
582
|
+
match = Regexp.last_match()
|
|
583
|
+
len = match.begin(0) - pos
|
|
584
|
+
text = input[pos, len]
|
|
585
|
+
pos = match.end(0)
|
|
586
|
+
ch = indicator ? indicator[0] : nil
|
|
587
|
+
lspace = ch == ?= ? nil : detect_spaces_at_bol(text, is_bol)
|
|
588
|
+
is_bol = rspace ? true : false
|
|
589
|
+
_add_text_to_str(str, text)
|
|
590
|
+
## * when '<%= %>', do nothing
|
|
591
|
+
## * when '<% %>' or '<%# %>', delete spaces iff only spaces are around '<% %>'
|
|
592
|
+
if ch == ?= # <%= %>
|
|
593
|
+
str << lspace if lspace
|
|
594
|
+
add_expr(str, code, indicator)
|
|
595
|
+
str << rspace if rspace
|
|
596
|
+
elsif ch == ?\# # <%# %>
|
|
597
|
+
n = code.count("\n") + (rspace ? 1 : 0)
|
|
598
|
+
if @trim && lspace && rspace
|
|
599
|
+
add_text(src, str)
|
|
600
|
+
str = ''
|
|
601
|
+
add_stmt(src, "\n" * n)
|
|
602
|
+
else
|
|
603
|
+
str << lspace if lspace
|
|
604
|
+
add_text(src, str)
|
|
605
|
+
str = ''
|
|
606
|
+
add_stmt(src, "\n" * n)
|
|
607
|
+
str << rspace if rspace
|
|
608
|
+
end
|
|
609
|
+
else # <% %>
|
|
610
|
+
if @trim && lspace && rspace
|
|
611
|
+
add_text(src, str)
|
|
612
|
+
str = ''
|
|
613
|
+
add_stmt(src, "#{lspace}#{code}#{rspace}")
|
|
614
|
+
else
|
|
615
|
+
str << lspace if lspace
|
|
616
|
+
add_text(src, str)
|
|
617
|
+
str = ''
|
|
618
|
+
add_stmt(src, code)
|
|
619
|
+
str << rspace if rspace
|
|
620
|
+
end
|
|
621
|
+
end
|
|
622
|
+
end
|
|
623
|
+
rest = $' || input # add input when no matched
|
|
624
|
+
_add_text_to_str(str, rest)
|
|
625
|
+
add_text(src, str)
|
|
626
|
+
end
|
|
627
|
+
|
|
628
|
+
def add_text(src, text)
|
|
629
|
+
return if !text || text.empty?
|
|
630
|
+
#src << " _buf << %Q`" << text << "`;"
|
|
631
|
+
if text[-1] == ?\n
|
|
632
|
+
text[-1] = "\\n"
|
|
633
|
+
src << " _buf << %Q`" << text << "`\n"
|
|
634
|
+
else
|
|
635
|
+
src << " _buf << %Q`" << text << "`;"
|
|
636
|
+
end
|
|
637
|
+
end
|
|
638
|
+
|
|
639
|
+
def _add_text_to_str(str, text)
|
|
640
|
+
return if !text || text.empty?
|
|
641
|
+
text.gsub!(/['\#\\]/, '\\\\\&')
|
|
642
|
+
str << text
|
|
643
|
+
end
|
|
644
|
+
|
|
645
|
+
def add_expr_escaped(str, code)
|
|
646
|
+
str << "\#{#{escaped_expr(code)}}"
|
|
647
|
+
end
|
|
648
|
+
|
|
649
|
+
def add_expr_literal(str, code)
|
|
650
|
+
str << "\#{#{code}}"
|
|
651
|
+
end
|
|
652
|
+
|
|
653
|
+
end
|
|
654
|
+
|
|
655
|
+
|
|
547
656
|
end
|
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: 78 $
|
|
3
|
+
### $Release: 2.3.0 $
|
|
4
4
|
### copyright(c) 2006-2007 kuwata-lab all rights reserved.
|
|
5
5
|
###
|
|
6
6
|
|
|
@@ -10,6 +10,14 @@ require 'erubis'
|
|
|
10
10
|
|
|
11
11
|
module Erubis
|
|
12
12
|
|
|
13
|
+
class Eruby
|
|
14
|
+
include ErboutEnhancer # will generate '_erbout = _buf = ""; '
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
class FastEruby
|
|
18
|
+
include ErboutEnhancer # will generate '_erbout = _buf = ""; '
|
|
19
|
+
end
|
|
20
|
+
|
|
13
21
|
module Helpers
|
|
14
22
|
|
|
15
23
|
##
|
|
@@ -20,13 +28,13 @@ module Erubis
|
|
|
20
28
|
## 1. add the folliwng code in your 'config/environment.rb'
|
|
21
29
|
##
|
|
22
30
|
## require 'erubis/helpers/rails_helper'
|
|
23
|
-
## #Erubis::Helpers::RailsHelper.engine_class = Erubis::Eruby
|
|
31
|
+
## #Erubis::Helpers::RailsHelper.engine_class = Erubis::Eruby # or Erubis::FastEruby
|
|
24
32
|
## #Erubis::Helpers::RailsHelper.init_properties = {}
|
|
25
|
-
## #Erubis::Helpers::RailsHelper.show_src = false
|
|
33
|
+
## #Erubis::Helpers::RailsHelper.show_src = false # set true for debugging
|
|
26
34
|
##
|
|
27
35
|
## 2. (optional) apply the patch for 'action_view/base.rb'
|
|
28
36
|
##
|
|
29
|
-
## $ cd /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.
|
|
37
|
+
## $ cd /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/
|
|
30
38
|
## $ sudo patch -p1 < /tmp/erubis_2.X.X/contrib/action_view_base_rb.patch
|
|
31
39
|
##
|
|
32
40
|
## 3. restart web server.
|
|
@@ -38,6 +46,7 @@ module Erubis
|
|
|
38
46
|
|
|
39
47
|
#cattr_accessor :init_properties
|
|
40
48
|
@@engine_class = Erubis::Eruby
|
|
49
|
+
#@@engine_class = Erubis::FastEruby
|
|
41
50
|
|
|
42
51
|
def self.engine_class
|
|
43
52
|
@@engine_class
|
|
@@ -104,82 +113,17 @@ if ActionPack::VERSION::MINOR <= 12 ### Rails 1.1
|
|
|
104
113
|
when :rxml
|
|
105
114
|
"xml = Builder::XmlMarkup.new(:indent => 2)\n" +
|
|
106
115
|
"@controller.headers['Content-Type'] ||= 'application/xml'\n" +
|
|
107
|
-
template
|
|
108
|
-
when :rjs
|
|
109
|
-
"@controller.headers['Content-Type'] ||= 'text/javascript'\n" +
|
|
110
|
-
"update_page do |page|\n#{template}\nend"
|
|
111
|
-
end
|
|
112
|
-
else
|
|
113
|
-
#body = ERB.new(template, nil, @@erb_trim_mode).src
|
|
114
|
-
body = convert_template_into_ruby_code(template)
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
@@template_args[render_symbol] ||= {}
|
|
118
|
-
locals_keys = @@template_args[render_symbol].keys | locals
|
|
119
|
-
@@template_args[render_symbol] = locals_keys.inject({}) { |h, k| h[k] = true; h }
|
|
120
|
-
|
|
121
|
-
locals_code = ""
|
|
122
|
-
locals_keys.each do |key|
|
|
123
|
-
locals_code << "#{key} = local_assigns[:#{key}] if local_assigns.has_key?(:#{key})\n"
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
"def #{render_symbol}(local_assigns)\n#{locals_code}#{body}\nend"
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
else ### Rails 1.2 or later
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
# Create source code for given template
|
|
134
|
-
def create_template_source(extension, template, render_symbol, locals)
|
|
135
|
-
if template_requires_setup?(extension)
|
|
136
|
-
body = case extension.to_sym
|
|
137
|
-
when :rxml
|
|
138
|
-
"controller.response.content_type ||= 'application/xml'\n" +
|
|
139
|
-
"xml = Builder::XmlMarkup.new(:indent => 2)\n" +
|
|
140
|
-
template
|
|
141
|
-
when :rjs
|
|
142
|
-
"controller.response.content_type ||= 'text/javascript'\n" +
|
|
143
|
-
"update_page do |page|\n#{template}\nend"
|
|
144
|
-
end
|
|
145
|
-
else
|
|
146
|
-
#body = ERB.new(template, nil, @@erb_trim_mode).src
|
|
147
|
-
body = convert_template_into_ruby_code(template)
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
@@template_args[render_symbol] ||= {}
|
|
151
|
-
locals_keys = @@template_args[render_symbol].keys | locals
|
|
152
|
-
@@template_args[render_symbol] = locals_keys.inject({}) { |h, k| h[k] = true; h }
|
|
153
|
-
|
|
154
|
-
locals_code = ""
|
|
155
|
-
locals_keys.each do |key|
|
|
156
|
-
locals_code << "#{key} = local_assigns[:#{key}]\n"
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
"def #{render_symbol}(local_assigns)\n#{locals_code}#{body}\nend"
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
end ###
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
end
|
|
171
|
-
|
|
172
|
-
|
|
173
116
|
## set Erubis as eRuby compiler in Ruby on Rails instead of ERB
|
|
174
117
|
class ActionView::Base # :nodoc:
|
|
175
118
|
private
|
|
176
119
|
def convert_template_into_ruby_code(template)
|
|
177
120
|
#src = Erubis::Eruby.new(template).src
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
121
|
+
rails_helper = Erubis::Helpers::RailsHelper
|
|
122
|
+
klass = rails_helper.engine_class
|
|
123
|
+
properties = rails_helper.init_properties
|
|
124
|
+
show_src = rails_helper.show_src
|
|
181
125
|
src = klass.new(template, properties).src
|
|
182
|
-
src.insert(0, '_erbout = ')
|
|
126
|
+
#src.insert(0, '_erbout = ')
|
|
183
127
|
logger.debug "** Erubis: src==<<'END'\n#{src}END\n" if show_src
|
|
184
128
|
src
|
|
185
129
|
end
|