erubis 2.6.6 → 2.7.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 +79 -3
- data/MIT-LICENSE +1 -1
- data/README.txt +2 -2
- data/benchmark/bench.rb +2 -2
- data/bin/erubis +2 -2
- data/contrib/erubis +293 -155
- data/contrib/inline-require +2 -2
- data/doc-api/classes/Erubis.html +10 -1
- data/doc-api/classes/Erubis/ArrayBufferEnhancer.html +12 -12
- data/doc-api/classes/Erubis/ArrayEnhancer.html +14 -14
- data/doc-api/classes/Erubis/Basic/Converter.html +24 -24
- 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/CppGenerator.html +382 -0
- data/doc-api/classes/Erubis/DeleteIndentEnhancer.html +7 -7
- data/doc-api/classes/Erubis/Ecpp.html +126 -0
- data/doc-api/classes/Erubis/Engine.html +36 -36
- data/doc-api/classes/Erubis/ErboutEnhancer.html +14 -14
- data/doc-api/classes/Erubis/EscapeEnhancer.html +6 -6
- data/doc-api/classes/Erubis/EscapedEcpp.html +120 -0
- 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 +14 -14
- data/doc-api/classes/Erubis/Helpers/RailsFormHelper.html +150 -150
- data/doc-api/classes/Erubis/Helpers/RailsHelper.html +49 -49
- data/doc-api/classes/Erubis/Helpers/RailsHelper/TemplateConverter.html +24 -24
- data/doc-api/classes/Erubis/InterpolationEnhancer.html +38 -39
- data/doc-api/classes/Erubis/JavaGenerator.html +60 -60
- data/doc-api/classes/Erubis/JavascriptGenerator.html +66 -66
- data/doc-api/classes/Erubis/Main.html +22 -22
- 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.html +1 -0
- 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/Ecpp.html +166 -0
- 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 +18 -34
- data/doc-api/classes/Erubis/PerlGenerator.html +54 -54
- data/doc-api/classes/Erubis/PhpGenerator.html +54 -54
- data/doc-api/classes/Erubis/PrefixedLineEnhancer.html +210 -0
- data/doc-api/classes/Erubis/PrefixedLineEruby.html +120 -0
- data/doc-api/classes/Erubis/PreprocessingEruby.html +12 -12
- data/doc-api/classes/Erubis/PreprocessingHelper.html +22 -22
- data/doc-api/classes/Erubis/PrintEnabledEnhancer.html +20 -20
- data/doc-api/classes/Erubis/PrintOutEnhancer.html +33 -33
- data/doc-api/classes/Erubis/RubyEvaluator.html +18 -18
- data/doc-api/classes/Erubis/RubyGenerator.html +59 -58
- 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 +13 -13
- data/doc-api/classes/Erubis/StringBufferEnhancer.html +14 -14
- data/doc-api/classes/Erubis/TinyEruby.html +24 -24
- data/doc-api/classes/Erubis/XmlHelper.html +30 -30
- data/doc-api/classes/Kernel.html +155 -0
- data/doc-api/created.rid +1 -1
- data/doc-api/files/README_txt.html +3 -3
- data/doc-api/files/erubis/context_rb.html +1 -1
- data/doc-api/files/erubis/converter_rb.html +3 -3
- data/doc-api/files/erubis/engine/ec_rb.html +1 -1
- data/doc-api/files/erubis/engine/ecpp_rb.html +115 -0
- 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 +1 -1
- data/doc-api/files/erubis/engine/ephp_rb.html +1 -1
- data/doc-api/files/erubis/engine/eruby_rb.html +2 -2
- 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 +3 -3
- data/doc-api/files/erubis/helper_rb.html +1 -1
- data/doc-api/files/erubis/helpers/rails_form_helper_rb.html +1 -1
- data/doc-api/files/erubis/helpers/rails_helper_rb.html +1 -1
- data/doc-api/files/erubis/local-setting_rb.html +1 -1
- data/doc-api/files/erubis/main_rb.html +4 -2
- data/doc-api/files/erubis/preprocessing_rb.html +1 -1
- data/doc-api/files/erubis/tiny_rb.html +1 -1
- data/doc-api/files/erubis/util_rb.html +107 -0
- data/doc-api/files/erubis_rb.html +2 -2
- data/doc-api/fr_class_index.html +7 -0
- data/doc-api/fr_file_index.html +2 -0
- data/doc-api/fr_method_index.html +237 -223
- data/doc/docstyle.css +25 -4
- data/doc/users-guide.html +286 -21
- data/examples/basic/Makefile +7 -2
- data/examples/basic/example.ecpp +33 -0
- data/lib/erubis.rb +4 -3
- data/lib/erubis/context.rb +2 -2
- data/lib/erubis/converter.rb +3 -3
- data/lib/erubis/engine.rb +8 -8
- data/lib/erubis/engine/ec.rb +2 -2
- data/lib/erubis/engine/ecpp.rb +113 -0
- data/lib/erubis/engine/ejava.rb +9 -9
- data/lib/erubis/engine/ejavascript.rb +9 -9
- data/lib/erubis/engine/enhanced.rb +7 -2
- data/lib/erubis/engine/eperl.rb +2 -2
- data/lib/erubis/engine/ephp.rb +2 -2
- data/lib/erubis/engine/eruby.rb +8 -7
- data/lib/erubis/engine/escheme.rb +2 -2
- data/lib/erubis/engine/optimized.rb +2 -2
- data/lib/erubis/enhancer.rb +70 -27
- data/lib/erubis/error.rb +2 -2
- data/lib/erubis/evaluator.rb +2 -2
- data/lib/erubis/generator.rb +3 -3
- data/lib/erubis/helper.rb +2 -2
- data/lib/erubis/helpers/rails_form_helper.rb +2 -2
- data/lib/erubis/helpers/rails_helper.rb +2 -2
- data/lib/erubis/local-setting.rb +2 -2
- data/lib/erubis/main.rb +31 -4
- data/lib/erubis/preprocessing.rb +2 -2
- data/lib/erubis/tiny.rb +2 -2
- data/lib/erubis/util.rb +22 -0
- data/test/assert-text-equal.rb +2 -2
- data/test/data/users-guide/bufvar-example.rb +10 -0
- data/test/data/users-guide/bufvar-example.result +17 -0
- data/test/data/users-guide/example.ecpp +30 -0
- data/test/data/users-guide/example_c.result +22 -19
- data/test/data/users-guide/fasteruby-example.rb +8 -0
- data/test/data/users-guide/fasteruby-example.result +18 -0
- data/test/data/users-guide/percentline-example.rhtml +3 -1
- data/test/data/users-guide/percentline_example.result +5 -3
- data/test/data/users-guide/prefixedline-example.rb +9 -0
- data/test/data/users-guide/prefixedline-example.rhtml +6 -0
- data/test/data/users-guide/prefixedline_example.result +9 -0
- data/test/test-engines.rb +58 -2
- data/test/test-enhancers.rb +51 -2
- data/test/test-erubis.rb +14 -10
- data/test/test-index-cgi.rb +191 -0
- data/test/test-main.rb +35 -4
- data/test/test-users-guide.rb +18 -2
- data/test/test.rb +18 -2
- data/test/testutil.rb +22 -7
- metadata +30 -24
data/CHANGES.txt
CHANGED
@@ -1,7 +1,83 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
-
# $Release: 2.
|
3
|
-
# copyright(c) 2006-
|
2
|
+
# $Release: 2.7.0 $
|
3
|
+
# copyright(c) 2006-2011 kuwata-lab.com all rights reserved.
|
4
4
|
|
5
|
+
- release: 2.7.0
|
6
|
+
date: 2011-04-01
|
7
|
+
enhancements:
|
8
|
+
|
9
|
+
- |
|
10
|
+
New option ':bufvar' supported to specify buffer variable name.
|
11
|
+
|
12
|
+
ex:
|
13
|
+
input = "Hello <%= name %>!"
|
14
|
+
eruby = Erubis::Eruby.new(input)
|
15
|
+
puts eruby.src
|
16
|
+
#=> _buf = ''; _buf << "Hello "; _buf << ( name ).to_s; _buf << '!';
|
17
|
+
|
18
|
+
eruby = Erubis::Eruby.new(input, :bufvar=>'@_out')
|
19
|
+
puts eruby.src
|
20
|
+
#=> @_out = ''; @_out << 'Hello '; @_out << ( name ).to_s; @_out << '!';
|
21
|
+
|
22
|
+
- |
|
23
|
+
New enhancer 'PrefixedLineEnhancer' which is a customizable version
|
24
|
+
of PercentLineEnhancer.
|
25
|
+
The difference between PrefixedLineEnhancer and PercentLineEnhancer is:
|
26
|
+
* You can indent Ruby statetment lines starting with '%'
|
27
|
+
* You can specify prefix character by :prefixchar option.
|
28
|
+
|
29
|
+
ex:
|
30
|
+
class MyEruby < Erubis::Eruby
|
31
|
+
include Erubis::PrefixedLineEnhancer
|
32
|
+
end
|
33
|
+
input = <<END
|
34
|
+
<ul>
|
35
|
+
% for item in @items
|
36
|
+
<li><%= item %></li>
|
37
|
+
% end
|
38
|
+
%% you can indent '%' lines
|
39
|
+
</ul>
|
40
|
+
END
|
41
|
+
eruby = MyEruby.new(input, :prefixchar=>'%') # default '%'
|
42
|
+
puts eruby.src
|
43
|
+
|
44
|
+
output:
|
45
|
+
_buf = ''; _buf << '<ul>
|
46
|
+
'; for item in @items
|
47
|
+
_buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li>
|
48
|
+
'; end
|
49
|
+
% you can indent '%' lines
|
50
|
+
_buf << '</ul>
|
51
|
+
';
|
52
|
+
_buf.to_s
|
53
|
+
|
54
|
+
- |
|
55
|
+
Add helper CGI script. See 'public_html/README.txt' for details.
|
56
|
+
|
57
|
+
- |
|
58
|
+
Rubinius is supported as first-class Ruby implementation.
|
59
|
+
|
60
|
+
- |
|
61
|
+
C++ support. Try '-l cpp' command-line option.
|
62
|
+
|
63
|
+
|
64
|
+
changes:
|
65
|
+
|
66
|
+
- |
|
67
|
+
Remove dependency to 'abstract' library.
|
68
|
+
You don't need to install 'abstract' gem.
|
69
|
+
|
70
|
+
- |
|
71
|
+
Erubis::Eruby#load_file() now sets cache file timestamp to the same
|
72
|
+
value as original eRuby file. For example, if you restore eRuby files
|
73
|
+
from backup, Erubis::Eruby#load_file() can detect it and generate
|
74
|
+
cache file again.
|
75
|
+
|
76
|
+
## generates cache file (A.rhtml.cache).
|
77
|
+
eruby = Erubis::Eruby.load_file('A.rhtml')
|
78
|
+
p File.mtime('A.rhtml') == File.mtime('A.rhtml.cache') #=> true
|
79
|
+
|
80
|
+
|
5
81
|
|
6
82
|
- release: 2.6.6
|
7
83
|
date: 2010-06-27
|
@@ -21,7 +97,7 @@
|
|
21
97
|
|
22
98
|
- release: 2.6.4
|
23
99
|
date: 2009-02-18
|
24
|
-
|
100
|
+
enhancements:
|
25
101
|
|
26
102
|
- |
|
27
103
|
Rails 2.2 and 2.3 support.
|
data/MIT-LICENSE
CHANGED
data/README.txt
CHANGED
data/benchmark/bench.rb
CHANGED
data/bin/erubis
CHANGED
data/contrib/erubis
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
###
|
4
|
-
### $Release: 2.
|
5
|
-
### copyright(c) 2006-
|
4
|
+
### $Release: 2.7.0 $
|
5
|
+
### copyright(c) 2006-2011 kuwata-lab.com all rights reserved.
|
6
6
|
###
|
7
7
|
|
8
8
|
#--begin of require 'erubis/main'
|
9
9
|
###
|
10
|
-
### $Release: 2.
|
11
|
-
### copyright(c) 2006-
|
10
|
+
### $Release: 2.7.0 $
|
11
|
+
### copyright(c) 2006-2011 kuwata-lab.com all rights reserved.
|
12
12
|
###
|
13
13
|
|
14
14
|
require 'yaml'
|
15
15
|
#--begin of require 'erubis'
|
16
16
|
##
|
17
|
-
## $Release: 2.
|
18
|
-
## copyright(c) 2006-
|
17
|
+
## $Release: 2.7.0 $
|
18
|
+
## copyright(c) 2006-2011 kuwata-lab.com all rights reserved.
|
19
19
|
##
|
20
20
|
|
21
21
|
##
|
@@ -62,81 +62,28 @@ require 'yaml'
|
|
62
62
|
|
63
63
|
|
64
64
|
module Erubis
|
65
|
-
VERSION = ('$Release: 2.
|
65
|
+
VERSION = ('$Release: 2.7.0 $' =~ /([.\d]+)/) && $1
|
66
66
|
end
|
67
67
|
|
68
68
|
#--begin of require 'erubis/engine'
|
69
69
|
##
|
70
|
-
## $Release: 2.
|
71
|
-
## copyright(c) 2006-
|
70
|
+
## $Release: 2.7.0 $
|
71
|
+
## copyright(c) 2006-2011 kuwata-lab.com all rights reserved.
|
72
72
|
##
|
73
73
|
|
74
74
|
|
75
75
|
#--begin of require 'erubis/generator'
|
76
76
|
##
|
77
|
-
## $Release: 2.
|
78
|
-
## copyright(c) 2006-
|
77
|
+
## $Release: 2.7.0 $
|
78
|
+
## copyright(c) 2006-2011 kuwata-lab.com all rights reserved.
|
79
79
|
##
|
80
80
|
|
81
|
-
#--begin of require '
|
81
|
+
#--begin of require 'erubis/util'
|
82
82
|
##
|
83
|
-
## $
|
84
|
-
##
|
85
|
-
## copyright(c) 2006 kuwata-lab.com all rights reserved.
|
83
|
+
## $Release: 2.7.0 $
|
84
|
+
## copyright(c) 2006-2011 kuwata-lab.com all rights reserved.
|
86
85
|
##
|
87
|
-
##
|
88
|
-
## helper to define abstract method in Ruby.
|
89
|
-
##
|
90
|
-
##
|
91
|
-
## example1. (shorter notation)
|
92
|
-
##
|
93
|
-
## require 'abstract'
|
94
|
-
## class Foo
|
95
|
-
## abstract_method 'arg1, arg2=""', :method1, :method2, :method3
|
96
|
-
## end
|
97
|
-
##
|
98
|
-
##
|
99
|
-
## example2. (RDoc friendly notation)
|
100
|
-
##
|
101
|
-
## require 'abstract'
|
102
|
-
## class Bar
|
103
|
-
## # ... method1 description ...
|
104
|
-
## def method1(arg1, arg2="")
|
105
|
-
## not_implemented
|
106
|
-
## end
|
107
|
-
##
|
108
|
-
## # ... method2 description ...
|
109
|
-
## def method2(arg1, arg2="")
|
110
|
-
## not_implemented
|
111
|
-
## end
|
112
|
-
## end
|
113
|
-
##
|
114
|
-
|
115
|
-
|
116
|
-
##
|
117
|
-
class Module
|
118
|
-
|
119
|
-
##
|
120
|
-
## define abstract methods
|
121
|
-
##
|
122
|
-
def abstract_method args_str, *method_names
|
123
|
-
method_names.each do |name|
|
124
|
-
module_eval <<-END
|
125
|
-
def #{name}(#{args_str})
|
126
|
-
mesg = "class \#{self.class.name} must implement abstract method `#{self.name}##{name}()'."
|
127
|
-
#mesg = "\#{self.class.name}##{name}() is not implemented."
|
128
|
-
err = NotImplementedError.new mesg
|
129
|
-
err.set_backtrace caller()
|
130
|
-
raise err
|
131
|
-
end
|
132
|
-
END
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
end
|
137
86
|
|
138
|
-
|
139
|
-
##
|
140
87
|
module Kernel
|
141
88
|
|
142
89
|
##
|
@@ -154,7 +101,7 @@ module Kernel
|
|
154
101
|
private :not_implemented
|
155
102
|
|
156
103
|
end
|
157
|
-
#--end of require '
|
104
|
+
#--end of require 'erubis/util'
|
158
105
|
|
159
106
|
module Erubis
|
160
107
|
|
@@ -237,11 +184,11 @@ end
|
|
237
184
|
#--end of require 'erubis/generator'
|
238
185
|
#--begin of require 'erubis/converter'
|
239
186
|
##
|
240
|
-
## $Release: 2.
|
241
|
-
## copyright(c) 2006-
|
187
|
+
## $Release: 2.7.0 $
|
188
|
+
## copyright(c) 2006-2011 kuwata-lab.com all rights reserved.
|
242
189
|
##
|
243
190
|
|
244
|
-
#--already included require '
|
191
|
+
#--already included require 'erubis/util'
|
245
192
|
|
246
193
|
module Erubis
|
247
194
|
|
@@ -596,14 +543,14 @@ end
|
|
596
543
|
#--end of require 'erubis/converter'
|
597
544
|
#--begin of require 'erubis/evaluator'
|
598
545
|
##
|
599
|
-
## $Release: 2.
|
600
|
-
## copyright(c) 2006-
|
546
|
+
## $Release: 2.7.0 $
|
547
|
+
## copyright(c) 2006-2011 kuwata-lab.com all rights reserved.
|
601
548
|
##
|
602
549
|
|
603
550
|
#--begin of require 'erubis/error'
|
604
551
|
##
|
605
|
-
## $Release: 2.
|
606
|
-
## copyright(c) 2006-
|
552
|
+
## $Release: 2.7.0 $
|
553
|
+
## copyright(c) 2006-2011 kuwata-lab.com all rights reserved.
|
607
554
|
##
|
608
555
|
|
609
556
|
module Erubis
|
@@ -627,8 +574,8 @@ end
|
|
627
574
|
#--end of require 'erubis/error'
|
628
575
|
#--begin of require 'erubis/context'
|
629
576
|
##
|
630
|
-
## $Release: 2.
|
631
|
-
## copyright(c) 2006-
|
577
|
+
## $Release: 2.7.0 $
|
578
|
+
## copyright(c) 2006-2011 kuwata-lab.com all rights reserved.
|
632
579
|
##
|
633
580
|
|
634
581
|
|
@@ -833,17 +780,17 @@ module Erubis
|
|
833
780
|
def self.load_file(filename, properties={})
|
834
781
|
cachename = properties[:cachename] || (filename + '.cache')
|
835
782
|
properties[:filename] = filename
|
836
|
-
|
783
|
+
timestamp = File.mtime(filename)
|
784
|
+
if test(?f, cachename) && timestamp == File.mtime(cachename)
|
837
785
|
engine = self.new(nil, properties)
|
838
786
|
engine.src = File.read(cachename)
|
839
787
|
else
|
840
788
|
input = File.open(filename, 'rb') {|f| f.read }
|
841
789
|
engine = self.new(input, properties)
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
end
|
790
|
+
tmpname = cachename + rand().to_s[1,8]
|
791
|
+
File.open(tmpname, 'wb') {|f| f.write(engine.src) }
|
792
|
+
File.rename(tmpname, cachename)
|
793
|
+
File.utime(timestamp, timestamp, cachename)
|
847
794
|
end
|
848
795
|
engine.src.untaint # ok?
|
849
796
|
return engine
|
@@ -909,10 +856,11 @@ end
|
|
909
856
|
#require 'erubis/evaluator'
|
910
857
|
#require 'erubis/error'
|
911
858
|
#require 'erubis/context'
|
859
|
+
#requier 'erubis/util'
|
912
860
|
#--begin of require 'erubis/helper'
|
913
861
|
##
|
914
|
-
## $Release: 2.
|
915
|
-
## copyright(c) 2006-
|
862
|
+
## $Release: 2.7.0 $
|
863
|
+
## copyright(c) 2006-2011 kuwata-lab.com all rights reserved.
|
916
864
|
##
|
917
865
|
|
918
866
|
|
@@ -960,8 +908,8 @@ end
|
|
960
908
|
#--end of require 'erubis/helper'
|
961
909
|
#--begin of require 'erubis/enhancer'
|
962
910
|
##
|
963
|
-
## $Release: 2.
|
964
|
-
## copyright(c) 2006-
|
911
|
+
## $Release: 2.7.0 $
|
912
|
+
## copyright(c) 2006-2011 kuwata-lab.com all rights reserved.
|
965
913
|
##
|
966
914
|
|
967
915
|
|
@@ -1028,7 +976,7 @@ module Erubis
|
|
1028
976
|
end
|
1029
977
|
|
1030
978
|
def add_preamble(src)
|
1031
|
-
src << "
|
979
|
+
src << "#{@bufvar} = $stdout;"
|
1032
980
|
end
|
1033
981
|
|
1034
982
|
def add_postamble(src)
|
@@ -1053,15 +1001,15 @@ module Erubis
|
|
1053
1001
|
end
|
1054
1002
|
|
1055
1003
|
def add_text(src, text)
|
1056
|
-
src << " print '
|
1004
|
+
src << " print '#{escape_text(text)}';" unless text.empty?
|
1057
1005
|
end
|
1058
1006
|
|
1059
1007
|
def add_expr_literal(src, code)
|
1060
|
-
src <<
|
1008
|
+
src << " print((#{code}).to_s);"
|
1061
1009
|
end
|
1062
1010
|
|
1063
1011
|
def add_expr_escaped(src, code)
|
1064
|
-
src <<
|
1012
|
+
src << " print #{escaped_expr(code)};"
|
1065
1013
|
end
|
1066
1014
|
|
1067
1015
|
def add_postamble(src)
|
@@ -1123,12 +1071,12 @@ module Erubis
|
|
1123
1071
|
end
|
1124
1072
|
|
1125
1073
|
def add_preamble(src)
|
1126
|
-
src << "
|
1074
|
+
src << "#{@bufvar} = [];"
|
1127
1075
|
end
|
1128
1076
|
|
1129
1077
|
def add_postamble(src)
|
1130
1078
|
src << "\n" unless src[-1] == ?\n
|
1131
|
-
src << "
|
1079
|
+
src << "#{@bufvar}\n"
|
1132
1080
|
end
|
1133
1081
|
|
1134
1082
|
end
|
@@ -1169,12 +1117,12 @@ module Erubis
|
|
1169
1117
|
end
|
1170
1118
|
|
1171
1119
|
def add_preamble(src)
|
1172
|
-
src << "
|
1120
|
+
src << "#{@bufvar} = '';"
|
1173
1121
|
end
|
1174
1122
|
|
1175
1123
|
def add_postamble(src)
|
1176
1124
|
src << "\n" unless src[-1] == ?\n
|
1177
|
-
src << "
|
1125
|
+
src << "#{@bufvar}.to_s\n"
|
1178
1126
|
end
|
1179
1127
|
|
1180
1128
|
end
|
@@ -1192,12 +1140,12 @@ module Erubis
|
|
1192
1140
|
end
|
1193
1141
|
|
1194
1142
|
def add_preamble(src)
|
1195
|
-
src << "
|
1143
|
+
src << "#{@bufvar} = StringIO.new;"
|
1196
1144
|
end
|
1197
1145
|
|
1198
1146
|
def add_postamble(src)
|
1199
1147
|
src << "\n" unless src[-1] == ?\n
|
1200
|
-
src << "
|
1148
|
+
src << "#{@bufvar}.string\n"
|
1201
1149
|
end
|
1202
1150
|
|
1203
1151
|
end
|
@@ -1215,12 +1163,12 @@ module Erubis
|
|
1215
1163
|
end
|
1216
1164
|
|
1217
1165
|
def add_preamble(src)
|
1218
|
-
src << "_erbout =
|
1166
|
+
src << "_erbout = #{@bufvar} = '';"
|
1219
1167
|
end
|
1220
1168
|
|
1221
1169
|
def add_postamble(src)
|
1222
1170
|
src << "\n" unless src[-1] == ?\n
|
1223
|
-
src << "
|
1171
|
+
src << "#{@bufvar}.to_s\n"
|
1224
1172
|
end
|
1225
1173
|
|
1226
1174
|
end
|
@@ -1395,23 +1343,34 @@ module Erubis
|
|
1395
1343
|
|
1396
1344
|
|
1397
1345
|
##
|
1398
|
-
## regards lines starting with '
|
1346
|
+
## regards lines starting with '^[ \t]*%' as program code
|
1399
1347
|
##
|
1400
|
-
##
|
1348
|
+
## in addition you can specify prefix character (default '%')
|
1401
1349
|
##
|
1402
1350
|
## this is language-independent.
|
1403
1351
|
##
|
1404
|
-
module
|
1352
|
+
module PrefixedLineEnhancer
|
1405
1353
|
|
1406
1354
|
def self.desc # :nodoc:
|
1407
|
-
"regard lines
|
1355
|
+
"regard lines matched to '^[ \t]*%' as program code"
|
1356
|
+
end
|
1357
|
+
|
1358
|
+
def init_generator(properties={})
|
1359
|
+
super
|
1360
|
+
@prefixchar = properties[:prefixchar]
|
1408
1361
|
end
|
1409
1362
|
|
1410
1363
|
def add_text(src, text)
|
1364
|
+
unless @prefixrexp
|
1365
|
+
@prefixchar ||= '%'
|
1366
|
+
@prefixrexp = Regexp.compile("^([ \\t]*)\\#{@prefixchar}(.*?\\r?\\n)")
|
1367
|
+
end
|
1411
1368
|
pos = 0
|
1412
1369
|
text2 = ''
|
1413
|
-
text.scan(
|
1414
|
-
|
1370
|
+
text.scan(@prefixrexp) do
|
1371
|
+
space = $1
|
1372
|
+
line = $2
|
1373
|
+
space, line = '', $1 unless $2
|
1415
1374
|
match = Regexp.last_match
|
1416
1375
|
len = match.begin(0) - pos
|
1417
1376
|
str = text[pos, len]
|
@@ -1421,12 +1380,12 @@ module Erubis
|
|
1421
1380
|
else
|
1422
1381
|
text2 << str
|
1423
1382
|
end
|
1424
|
-
if line[0] ==
|
1425
|
-
text2 << line
|
1383
|
+
if line[0, 1] == @prefixchar
|
1384
|
+
text2 << space << line
|
1426
1385
|
else
|
1427
1386
|
super(src, text2)
|
1428
1387
|
text2 = ''
|
1429
|
-
add_stmt(src, line)
|
1388
|
+
add_stmt(src, space + line)
|
1430
1389
|
end
|
1431
1390
|
end
|
1432
1391
|
#rest = pos == 0 ? text : $' # ruby1.8
|
@@ -1441,6 +1400,39 @@ module Erubis
|
|
1441
1400
|
end
|
1442
1401
|
|
1443
1402
|
|
1403
|
+
##
|
1404
|
+
## regards lines starting with '%' as program code
|
1405
|
+
##
|
1406
|
+
## this is for compatibility to eruby and ERB.
|
1407
|
+
##
|
1408
|
+
## this is language-independent.
|
1409
|
+
##
|
1410
|
+
module PercentLineEnhancer
|
1411
|
+
include PrefixedLineEnhancer
|
1412
|
+
|
1413
|
+
def self.desc # :nodoc:
|
1414
|
+
"regard lines starting with '%' as program code"
|
1415
|
+
end
|
1416
|
+
|
1417
|
+
#--
|
1418
|
+
#def init_generator(properties={})
|
1419
|
+
# super
|
1420
|
+
# @prefixchar = '%'
|
1421
|
+
# @prefixrexp = /^\%(.*?\r?\n)/
|
1422
|
+
#end
|
1423
|
+
#++
|
1424
|
+
|
1425
|
+
def add_text(src, text)
|
1426
|
+
unless @prefixrexp
|
1427
|
+
@prefixchar = '%'
|
1428
|
+
@prefixrexp = /^\%(.*?\r?\n)/
|
1429
|
+
end
|
1430
|
+
super(src, text)
|
1431
|
+
end
|
1432
|
+
|
1433
|
+
end
|
1434
|
+
|
1435
|
+
|
1444
1436
|
##
|
1445
1437
|
## [experimental] allow header and footer in eRuby script
|
1446
1438
|
##
|
@@ -1615,16 +1607,15 @@ module Erubis
|
|
1615
1607
|
#src << " _buf << %Q`" << text << "`;"
|
1616
1608
|
if text[-1] == ?\n
|
1617
1609
|
text[-1] = "\\n"
|
1618
|
-
src << "
|
1610
|
+
src << " #{@bufvar} << %Q`#{text}`\n"
|
1619
1611
|
else
|
1620
|
-
src << "
|
1612
|
+
src << " #{@bufvar} << %Q`#{text}`;"
|
1621
1613
|
end
|
1622
1614
|
end
|
1623
1615
|
|
1624
1616
|
def _add_text_to_str(str, text)
|
1625
1617
|
return if !text || text.empty?
|
1626
|
-
text.gsub
|
1627
|
-
str << text
|
1618
|
+
str << text.gsub(/[`\#\\]/, '\\\\\&')
|
1628
1619
|
end
|
1629
1620
|
|
1630
1621
|
def add_expr_escaped(str, code)
|
@@ -1643,8 +1634,8 @@ end
|
|
1643
1634
|
#require 'erubis/tiny'
|
1644
1635
|
#--begin of require 'erubis/engine/eruby'
|
1645
1636
|
##
|
1646
|
-
## $Release: 2.
|
1647
|
-
## copyright(c) 2006-
|
1637
|
+
## $Release: 2.7.0 $
|
1638
|
+
## copyright(c) 2006-2011 kuwata-lab.com all rights reserved.
|
1648
1639
|
##
|
1649
1640
|
|
1650
1641
|
#--already included require 'erubis/engine'
|
@@ -1665,6 +1656,7 @@ module Erubis
|
|
1665
1656
|
def init_generator(properties={})
|
1666
1657
|
super
|
1667
1658
|
@escapefunc ||= "Erubis::XmlHelper.escape_xml"
|
1659
|
+
@bufvar = properties[:bufvar] || "_buf"
|
1668
1660
|
end
|
1669
1661
|
|
1670
1662
|
def self.supported_properties() # :nodoc:
|
@@ -1681,12 +1673,12 @@ module Erubis
|
|
1681
1673
|
|
1682
1674
|
#--
|
1683
1675
|
#def add_preamble(src)
|
1684
|
-
# src << "
|
1676
|
+
# src << "#{@bufvar} = [];"
|
1685
1677
|
#end
|
1686
1678
|
#++
|
1687
1679
|
|
1688
1680
|
def add_text(src, text)
|
1689
|
-
src << "
|
1681
|
+
src << " #{@bufvar} << '" << escape_text(text) << "';" unless text.empty?
|
1690
1682
|
end
|
1691
1683
|
|
1692
1684
|
def add_stmt(src, code)
|
@@ -1696,11 +1688,11 @@ module Erubis
|
|
1696
1688
|
end
|
1697
1689
|
|
1698
1690
|
def add_expr_literal(src, code)
|
1699
|
-
src <<
|
1691
|
+
src << " #{@bufvar} << (" << code << ').to_s;'
|
1700
1692
|
end
|
1701
1693
|
|
1702
1694
|
def add_expr_escaped(src, code)
|
1703
|
-
src <<
|
1695
|
+
src << " #{@bufvar} << " << escaped_expr(code) << ';'
|
1704
1696
|
end
|
1705
1697
|
|
1706
1698
|
def add_expr_debug(src, code)
|
@@ -1711,7 +1703,7 @@ module Erubis
|
|
1711
1703
|
|
1712
1704
|
#--
|
1713
1705
|
#def add_postamble(src)
|
1714
|
-
# src << "\
|
1706
|
+
# src << "\n#{@bufvar}.join\n"
|
1715
1707
|
#end
|
1716
1708
|
#++
|
1717
1709
|
|
@@ -1778,8 +1770,8 @@ end
|
|
1778
1770
|
|
1779
1771
|
#--begin of require 'erubis/local-setting'
|
1780
1772
|
##
|
1781
|
-
## $Release: 2.
|
1782
|
-
## copyright(c) 2006-
|
1773
|
+
## $Release: 2.7.0 $
|
1774
|
+
## copyright(c) 2006-2011 kuwata-lab.com all rights reserved.
|
1783
1775
|
##
|
1784
1776
|
|
1785
1777
|
##
|
@@ -1790,8 +1782,8 @@ end
|
|
1790
1782
|
#--end of require 'erubis'
|
1791
1783
|
#--begin of require 'erubis/tiny'
|
1792
1784
|
##
|
1793
|
-
## $Release: 2.
|
1794
|
-
## copyright(c) 2006-
|
1785
|
+
## $Release: 2.7.0 $
|
1786
|
+
## copyright(c) 2006-2011 kuwata-lab.com all rights reserved.
|
1795
1787
|
##
|
1796
1788
|
|
1797
1789
|
module Erubis
|
@@ -1936,8 +1928,8 @@ end
|
|
1936
1928
|
#--end of require 'erubis/tiny'
|
1937
1929
|
#--begin of require 'erubis/engine/enhanced'
|
1938
1930
|
##
|
1939
|
-
## $Release: 2.
|
1940
|
-
## copyright(c) 2006-
|
1931
|
+
## $Release: 2.7.0 $
|
1932
|
+
## copyright(c) 2006-2011 kuwata-lab.com all rights reserved.
|
1941
1933
|
##
|
1942
1934
|
|
1943
1935
|
#--already included require 'erubis/enhancer'
|
@@ -2040,6 +2032,11 @@ module Erubis
|
|
2040
2032
|
end
|
2041
2033
|
|
2042
2034
|
|
2035
|
+
class PrefixedLineEruby < Eruby
|
2036
|
+
include PrefixedLineEnhancer
|
2037
|
+
end
|
2038
|
+
|
2039
|
+
|
2043
2040
|
class HeaderFooterEruby < Eruby
|
2044
2041
|
include HeaderFooterEnhancer
|
2045
2042
|
end
|
@@ -2059,8 +2056,8 @@ end
|
|
2059
2056
|
#--end of require 'erubis/engine/enhanced'
|
2060
2057
|
#--begin of require 'erubis/engine/optimized'
|
2061
2058
|
##
|
2062
|
-
## $Release: 2.
|
2063
|
-
## copyright(c) 2006-
|
2059
|
+
## $Release: 2.7.0 $
|
2060
|
+
## copyright(c) 2006-2011 kuwata-lab.com all rights reserved.
|
2064
2061
|
##
|
2065
2062
|
|
2066
2063
|
|
@@ -2189,8 +2186,8 @@ end
|
|
2189
2186
|
#--already included require 'erubis/engine/eruby'
|
2190
2187
|
#--begin of require 'erubis/engine/ephp'
|
2191
2188
|
##
|
2192
|
-
## $Release: 2.
|
2193
|
-
## copyright(c) 2006-
|
2189
|
+
## $Release: 2.7.0 $
|
2190
|
+
## copyright(c) 2006-2011 kuwata-lab.com all rights reserved.
|
2194
2191
|
##
|
2195
2192
|
|
2196
2193
|
#--already included require 'erubis/engine'
|
@@ -2290,8 +2287,8 @@ end
|
|
2290
2287
|
#--end of require 'erubis/engine/ephp'
|
2291
2288
|
#--begin of require 'erubis/engine/ec'
|
2292
2289
|
##
|
2293
|
-
## $Release: 2.
|
2294
|
-
## copyright(c) 2006-
|
2290
|
+
## $Release: 2.7.0 $
|
2291
|
+
## copyright(c) 2006-2011 kuwata-lab.com all rights reserved.
|
2295
2292
|
##
|
2296
2293
|
|
2297
2294
|
#--already included require 'erubis/engine'
|
@@ -2407,10 +2404,125 @@ module Erubis
|
|
2407
2404
|
|
2408
2405
|
end
|
2409
2406
|
#--end of require 'erubis/engine/ec'
|
2407
|
+
#--begin of require 'erubis/engine/ecpp'
|
2408
|
+
##
|
2409
|
+
## $Release: 2.7.0 $
|
2410
|
+
## copyright(c) 2006-2011 kuwata-lab.com all rights reserved.
|
2411
|
+
##
|
2412
|
+
|
2413
|
+
#--already included require 'erubis/engine'
|
2414
|
+
#--already included require 'erubis/enhancer'
|
2415
|
+
|
2416
|
+
|
2417
|
+
module Erubis
|
2418
|
+
|
2419
|
+
|
2420
|
+
module CppGenerator
|
2421
|
+
include Generator
|
2422
|
+
|
2423
|
+
def self.supported_properties() # :nodoc:
|
2424
|
+
return [
|
2425
|
+
[:indent, '', "indent spaces (ex. ' ')"],
|
2426
|
+
[:bufvar, '_buf', "buffer variable name"],
|
2427
|
+
]
|
2428
|
+
end
|
2429
|
+
|
2430
|
+
def init_generator(properties={})
|
2431
|
+
super
|
2432
|
+
@escapefunc ||= "escape"
|
2433
|
+
@indent = properties[:indent] || ''
|
2434
|
+
@bufvar = properties[:bufvar] || '_buf'
|
2435
|
+
end
|
2436
|
+
|
2437
|
+
def add_preamble(src)
|
2438
|
+
src << "#line 1 \"#{self.filename}\"\n" if self.filename
|
2439
|
+
end
|
2440
|
+
|
2441
|
+
def escape_text(text)
|
2442
|
+
@@table_ ||= { "\r"=>"\\r", "\n"=>"\\n", "\t"=>"\\t", '"'=>'\\"', "\\"=>"\\\\" }
|
2443
|
+
text.gsub!(/[\r\n\t"\\]/) { |m| @@table_[m] }
|
2444
|
+
return text
|
2445
|
+
end
|
2446
|
+
|
2447
|
+
def escaped_expr(code)
|
2448
|
+
return "#{@escapefunc}(#{code.strip})"
|
2449
|
+
end
|
2450
|
+
|
2451
|
+
def add_text(src, text)
|
2452
|
+
return if text.empty?
|
2453
|
+
src << (src.empty? || src[-1] == ?\n ? @indent : ' ')
|
2454
|
+
src << "_buf << "
|
2455
|
+
i = 0
|
2456
|
+
text.each_line do |line|
|
2457
|
+
src << "\n" << @indent << " " if i > 0
|
2458
|
+
i += 1
|
2459
|
+
src << '"' << escape_text(line) << '"'
|
2460
|
+
end
|
2461
|
+
src << ";" #<< (text[-1] == ?\n ? "\n" : "")
|
2462
|
+
src << "\n" if text[-1] == ?\n
|
2463
|
+
end
|
2464
|
+
|
2465
|
+
def add_stmt(src, code)
|
2466
|
+
src << code
|
2467
|
+
end
|
2468
|
+
|
2469
|
+
def add_expr_literal(src, code)
|
2470
|
+
src << @indent if src.empty? || src[-1] == ?\n
|
2471
|
+
src << " _buf << (" << code.strip << ");"
|
2472
|
+
end
|
2473
|
+
|
2474
|
+
def add_expr_escaped(src, code)
|
2475
|
+
src << @indent if src.empty? || src[-1] == ?\n
|
2476
|
+
src << ' ' << escaped_expr(code) << ';'
|
2477
|
+
end
|
2478
|
+
|
2479
|
+
def add_expr_debug(src, code)
|
2480
|
+
code.strip!
|
2481
|
+
src << @indent if src.empty? || src[-1] == ?\n
|
2482
|
+
src << " std::cerr << \"*** debug: #{code.gsub(/(")/, '\\\&')}=\" << (#{code});"
|
2483
|
+
end
|
2484
|
+
|
2485
|
+
def add_postamble(src)
|
2486
|
+
# empty
|
2487
|
+
end
|
2488
|
+
|
2489
|
+
end
|
2490
|
+
|
2491
|
+
|
2492
|
+
##
|
2493
|
+
## engine for C
|
2494
|
+
##
|
2495
|
+
class Ecpp < Basic::Engine
|
2496
|
+
include CppGenerator
|
2497
|
+
end
|
2498
|
+
|
2499
|
+
|
2500
|
+
class EscapedEcpp < Ecpp
|
2501
|
+
include EscapeEnhancer
|
2502
|
+
end
|
2503
|
+
|
2504
|
+
|
2505
|
+
#class XmlEcpp < Ecpp
|
2506
|
+
# include EscapeEnhancer
|
2507
|
+
#end
|
2508
|
+
|
2509
|
+
class PI::Ecpp < PI::Engine
|
2510
|
+
include CppGenerator
|
2511
|
+
|
2512
|
+
def init_converter(properties={})
|
2513
|
+
@pi = 'cpp'
|
2514
|
+
super(properties)
|
2515
|
+
end
|
2516
|
+
|
2517
|
+
end
|
2518
|
+
|
2519
|
+
|
2520
|
+
end
|
2521
|
+
#--end of require 'erubis/engine/ecpp'
|
2410
2522
|
#--begin of require 'erubis/engine/ejava'
|
2411
2523
|
##
|
2412
|
-
## $Release: 2.
|
2413
|
-
## copyright(c) 2006-
|
2524
|
+
## $Release: 2.7.0 $
|
2525
|
+
## copyright(c) 2006-2011 kuwata-lab.com all rights reserved.
|
2414
2526
|
##
|
2415
2527
|
|
2416
2528
|
#--already included require 'erubis/engine'
|
@@ -2426,7 +2538,7 @@ module Erubis
|
|
2426
2538
|
def self.supported_properties() # :nodoc:
|
2427
2539
|
return [
|
2428
2540
|
[:indent, '', "indent spaces (ex. ' ')"],
|
2429
|
-
[:
|
2541
|
+
[:bufvar, '_buf', "output buffer variable name"],
|
2430
2542
|
[:bufclass, 'StringBuffer', "output buffer class (ex. 'StringBuilder')"],
|
2431
2543
|
]
|
2432
2544
|
end
|
@@ -2435,12 +2547,12 @@ module Erubis
|
|
2435
2547
|
super
|
2436
2548
|
@escapefunc ||= 'escape'
|
2437
2549
|
@indent = properties[:indent] || ''
|
2438
|
-
@
|
2550
|
+
@bufvar = properties[:bufvar] || '_buf'
|
2439
2551
|
@bufclass = properties[:bufclass] || 'StringBuffer'
|
2440
2552
|
end
|
2441
2553
|
|
2442
2554
|
def add_preamble(src)
|
2443
|
-
src << "#{@indent}#{@bufclass} #{@
|
2555
|
+
src << "#{@indent}#{@bufclass} #{@bufvar} = new #{@bufclass}();"
|
2444
2556
|
end
|
2445
2557
|
|
2446
2558
|
def escape_text(text)
|
@@ -2451,7 +2563,7 @@ module Erubis
|
|
2451
2563
|
def add_text(src, text)
|
2452
2564
|
return if text.empty?
|
2453
2565
|
src << (src.empty? || src[-1] == ?\n ? @indent : ' ')
|
2454
|
-
src << @
|
2566
|
+
src << @bufvar << ".append("
|
2455
2567
|
i = 0
|
2456
2568
|
text.each_line do |line|
|
2457
2569
|
src << "\n" << @indent << ' + ' if i > 0
|
@@ -2468,7 +2580,7 @@ module Erubis
|
|
2468
2580
|
def add_expr_literal(src, code)
|
2469
2581
|
src << @indent if src.empty? || src[-1] == ?\n
|
2470
2582
|
code.strip!
|
2471
|
-
src << " #{@
|
2583
|
+
src << " #{@bufvar}.append(#{code});"
|
2472
2584
|
end
|
2473
2585
|
|
2474
2586
|
def add_expr_escaped(src, code)
|
@@ -2483,8 +2595,8 @@ module Erubis
|
|
2483
2595
|
|
2484
2596
|
def add_postamble(src)
|
2485
2597
|
src << "\n" if src[-1] == ?;
|
2486
|
-
src << @indent << "return " << @
|
2487
|
-
#src << @indent << "System.out.print(" << @
|
2598
|
+
src << @indent << "return " << @bufvar << ".toString();\n"
|
2599
|
+
#src << @indent << "System.out.print(" << @bufvar << ".toString());\n"
|
2488
2600
|
end
|
2489
2601
|
|
2490
2602
|
end
|
@@ -2521,8 +2633,8 @@ end
|
|
2521
2633
|
#--end of require 'erubis/engine/ejava'
|
2522
2634
|
#--begin of require 'erubis/engine/escheme'
|
2523
2635
|
##
|
2524
|
-
## $Release: 2.
|
2525
|
-
## copyright(c) 2006-
|
2636
|
+
## $Release: 2.7.0 $
|
2637
|
+
## copyright(c) 2006-2011 kuwata-lab.com all rights reserved.
|
2526
2638
|
##
|
2527
2639
|
|
2528
2640
|
#--already included require 'erubis/engine'
|
@@ -2637,8 +2749,8 @@ end
|
|
2637
2749
|
#--end of require 'erubis/engine/escheme'
|
2638
2750
|
#--begin of require 'erubis/engine/eperl'
|
2639
2751
|
##
|
2640
|
-
## $Release: 2.
|
2641
|
-
## copyright(c) 2006-
|
2752
|
+
## $Release: 2.7.0 $
|
2753
|
+
## copyright(c) 2006-2011 kuwata-lab.com all rights reserved.
|
2642
2754
|
##
|
2643
2755
|
|
2644
2756
|
#--already included require 'erubis/engine'
|
@@ -2734,8 +2846,8 @@ end
|
|
2734
2846
|
#--end of require 'erubis/engine/eperl'
|
2735
2847
|
#--begin of require 'erubis/engine/ejavascript'
|
2736
2848
|
##
|
2737
|
-
## $Release: 2.
|
2738
|
-
## copyright(c) 2006-
|
2849
|
+
## $Release: 2.7.0 $
|
2850
|
+
## copyright(c) 2006-2011 kuwata-lab.com all rights reserved.
|
2739
2851
|
##
|
2740
2852
|
|
2741
2853
|
#--already included require 'erubis/engine'
|
@@ -2751,7 +2863,7 @@ module Erubis
|
|
2751
2863
|
def self.supported_properties() # :nodoc:
|
2752
2864
|
list = []
|
2753
2865
|
#list << [:indent, '', "indent spaces (ex. ' ')"]
|
2754
|
-
#list << [:
|
2866
|
+
#list << [:bufvar, '_buf', "output buffer variable name"]
|
2755
2867
|
list << [:docwrite, true, "use 'document.write()' when true"]
|
2756
2868
|
return list
|
2757
2869
|
end
|
@@ -2760,12 +2872,12 @@ module Erubis
|
|
2760
2872
|
super
|
2761
2873
|
@escapefunc ||= 'escape'
|
2762
2874
|
@indent = properties[:indent] || ''
|
2763
|
-
@
|
2875
|
+
@bufvar = properties[:bufvar] || '_buf'
|
2764
2876
|
@docwrite = properties[:docwrite] != false # '!= false' will be removed in the next release
|
2765
2877
|
end
|
2766
2878
|
|
2767
2879
|
def add_preamble(src)
|
2768
|
-
src << "#{@indent}var #{@
|
2880
|
+
src << "#{@indent}var #{@bufvar} = [];"
|
2769
2881
|
end
|
2770
2882
|
|
2771
2883
|
def escape_text(text)
|
@@ -2780,7 +2892,7 @@ module Erubis
|
|
2780
2892
|
def add_text(src, text)
|
2781
2893
|
return if text.empty?
|
2782
2894
|
add_indent(src, @indent)
|
2783
|
-
src << @
|
2895
|
+
src << @bufvar << '.push("'
|
2784
2896
|
s = escape_text(text)
|
2785
2897
|
if s[-1] == ?\n
|
2786
2898
|
s[-2, 2] = ''
|
@@ -2797,7 +2909,7 @@ module Erubis
|
|
2797
2909
|
def add_expr_literal(src, code)
|
2798
2910
|
add_indent(src, @indent)
|
2799
2911
|
code.strip!
|
2800
|
-
src << "#{@
|
2912
|
+
src << "#{@bufvar}.push(#{code});"
|
2801
2913
|
end
|
2802
2914
|
|
2803
2915
|
def add_expr_escaped(src, code)
|
@@ -2813,9 +2925,9 @@ module Erubis
|
|
2813
2925
|
def add_postamble(src)
|
2814
2926
|
src << "\n" if src[-1] == ?;
|
2815
2927
|
if @docwrite
|
2816
|
-
src << @indent << 'document.write(' << @
|
2928
|
+
src << @indent << 'document.write(' << @bufvar << ".join(\"\"));\n"
|
2817
2929
|
else
|
2818
|
-
src << @indent << @
|
2930
|
+
src << @indent << @bufvar << ".join(\"\");\n"
|
2819
2931
|
end
|
2820
2932
|
end
|
2821
2933
|
|
@@ -3069,7 +3181,7 @@ module Erubis
|
|
3069
3181
|
buf << " -z : syntax checking"
|
3070
3182
|
buf << " -e : escape (equal to '--E Escape')"
|
3071
3183
|
buf << " -p pattern : embedded pattern (default '<% %>')"
|
3072
|
-
buf << " -l lang : convert but no execute (ruby/php/c/java/scheme/perl/js)"
|
3184
|
+
buf << " -l lang : convert but no execute (ruby/php/c/cpp/java/scheme/perl/js)"
|
3073
3185
|
buf << " -E e1,e2,... : enhancer names (Escape, PercentLine, BiPattern, ...)"
|
3074
3186
|
buf << " -I path : library include path"
|
3075
3187
|
buf << " -K kanji : kanji code (euc/sjis/utf8) (default none)"
|
@@ -3107,7 +3219,7 @@ module Erubis
|
|
3107
3219
|
list << ['(common)', common_props]
|
3108
3220
|
list << ['(basic)', basic_props - common_props]
|
3109
3221
|
list << ['(pi)', pi_props - common_props]
|
3110
|
-
%w[ruby php c java scheme perl javascript].each do |lang|
|
3222
|
+
%w[ruby php c cpp java scheme perl javascript].each do |lang|
|
3111
3223
|
klass = Erubis.const_get("E#{lang}")
|
3112
3224
|
list << [lang, collect_supported_properties(klass) - basic_props]
|
3113
3225
|
end
|
@@ -3322,6 +3434,32 @@ module Erubis
|
|
3322
3434
|
return "#{filename}:#{linenum}: #{message}"
|
3323
3435
|
end
|
3324
3436
|
|
3437
|
+
if defined?(RUBY_ENGINE) && RUBY_ENGINE == "rbx"
|
3438
|
+
def check_syntax(filename, src)
|
3439
|
+
require 'compiler'
|
3440
|
+
verbose = $VERBOSE
|
3441
|
+
msg = nil
|
3442
|
+
begin
|
3443
|
+
$VERBOSE = true
|
3444
|
+
Rubinius::Compiler.compile_string(src, filename)
|
3445
|
+
rescue SyntaxError => ex
|
3446
|
+
ex_linenum = ex.line
|
3447
|
+
linenum = 0
|
3448
|
+
srcline = src.each_line do |line|
|
3449
|
+
linenum += 1
|
3450
|
+
break line if linenum == ex_linenum
|
3451
|
+
end
|
3452
|
+
msg = "#{ex.message}\n"
|
3453
|
+
msg << srcline
|
3454
|
+
msg << "\n" unless srcline =~ /\n\z/
|
3455
|
+
msg << (" " * (ex.column-1)) << "^\n"
|
3456
|
+
ensure
|
3457
|
+
$VERBOSE = verbose
|
3458
|
+
end
|
3459
|
+
return msg
|
3460
|
+
end
|
3461
|
+
end
|
3462
|
+
|
3325
3463
|
end
|
3326
3464
|
|
3327
3465
|
end
|