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/local-setting.rb
CHANGED
data/lib/erubis/main.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
|
|
|
@@ -49,21 +49,21 @@ module Erubis
|
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
def initialize
|
|
52
|
-
@single_options = "
|
|
53
|
-
@arg_options = "
|
|
52
|
+
@single_options = "hvxztTSbeBXNUC"
|
|
53
|
+
@arg_options = "pcrfKIlaE" #C
|
|
54
54
|
@option_names = {
|
|
55
55
|
?h => :help,
|
|
56
56
|
?v => :version,
|
|
57
57
|
?x => :source,
|
|
58
58
|
?z => :syntax,
|
|
59
|
-
|
|
60
|
-
?t => :untabify,
|
|
59
|
+
?T => :unexpand,
|
|
60
|
+
?t => :untabify, # obsolete
|
|
61
61
|
?S => :intern,
|
|
62
62
|
?b => :bodyonly,
|
|
63
63
|
?B => :binding,
|
|
64
64
|
?p => :pattern,
|
|
65
65
|
?c => :context,
|
|
66
|
-
|
|
66
|
+
#?C => :class,
|
|
67
67
|
?e => :escape,
|
|
68
68
|
?r => :requires,
|
|
69
69
|
?f => :datafiles,
|
|
@@ -72,6 +72,10 @@ module Erubis
|
|
|
72
72
|
?l => :lang,
|
|
73
73
|
?a => :action,
|
|
74
74
|
?E => :enhancers,
|
|
75
|
+
?X => :notext,
|
|
76
|
+
?N => :linenum,
|
|
77
|
+
?U => :unique,
|
|
78
|
+
?C => :compact,
|
|
75
79
|
}
|
|
76
80
|
assert unless @single_options.length + @arg_options.length == @option_names.length
|
|
77
81
|
(@single_options + @arg_options).each_byte do |ch|
|
|
@@ -115,14 +119,15 @@ module Erubis
|
|
|
115
119
|
## action
|
|
116
120
|
action = opts.action
|
|
117
121
|
action ||= 'syntax' if opts.syntax
|
|
118
|
-
action ||= 'convert' if opts.source
|
|
122
|
+
action ||= 'convert' if opts.source || opts.notext
|
|
119
123
|
|
|
120
124
|
## lang
|
|
121
125
|
lang = opts.lang || 'ruby'
|
|
122
126
|
action ||= 'convert' if opts.lang
|
|
123
127
|
|
|
124
128
|
## class name of Eruby
|
|
125
|
-
classname = opts.class
|
|
129
|
+
#classname = opts.class
|
|
130
|
+
classname = nil
|
|
126
131
|
klass = get_classobj(classname, lang, properties[:pi])
|
|
127
132
|
|
|
128
133
|
## kanji code
|
|
@@ -153,6 +158,9 @@ module Erubis
|
|
|
153
158
|
engine.bipattern = properties[:bipattern] if enhancer == Erubis::BiPatternEnhancer
|
|
154
159
|
end
|
|
155
160
|
|
|
161
|
+
## no-text
|
|
162
|
+
engine.extend(Erubis::NoTextEnhancer) if opts.notext
|
|
163
|
+
|
|
156
164
|
## convert and execute
|
|
157
165
|
val = nil
|
|
158
166
|
msg = "Syntax OK\n"
|
|
@@ -179,7 +187,7 @@ module Erubis
|
|
|
179
187
|
def do_action(action, engine, context, filename, opts)
|
|
180
188
|
case action
|
|
181
189
|
when 'convert'
|
|
182
|
-
s = engine.src
|
|
190
|
+
s = manipulate_src(engine.src, opts)
|
|
183
191
|
when nil, 'exec', 'execute'
|
|
184
192
|
s = opts.binding ? engine.result(context.to_hash) : engine.evaluate(context)
|
|
185
193
|
when 'syntax'
|
|
@@ -191,36 +199,55 @@ module Erubis
|
|
|
191
199
|
return s
|
|
192
200
|
end
|
|
193
201
|
|
|
202
|
+
def manipulate_src(source, opts)
|
|
203
|
+
flag_linenum = opts.linenum
|
|
204
|
+
flag_unique = opts.unique
|
|
205
|
+
flag_compact = opts.compact
|
|
206
|
+
if flag_linenum
|
|
207
|
+
n = 0
|
|
208
|
+
source.gsub!(/^/) { n += 1; "%5d: " % n }
|
|
209
|
+
source.gsub!(/^ *\d+:\s+?\n/, '') if flag_compact
|
|
210
|
+
source.gsub!(/(^ *\d+:\s+?\n)+/, "\n") if flag_unique
|
|
211
|
+
else
|
|
212
|
+
source.gsub!(/^\s*?\n/, '') if flag_compact
|
|
213
|
+
source.gsub!(/(^\s*?\n)+/, "\n") if flag_unique
|
|
214
|
+
end
|
|
215
|
+
return source
|
|
216
|
+
end
|
|
217
|
+
|
|
194
218
|
def usage
|
|
195
219
|
command = File.basename($0)
|
|
196
|
-
|
|
197
|
-
erubis - embedded program converter for multi-language
|
|
198
|
-
Usage: #{command} [..options..] [file ...]
|
|
199
|
-
-h, --help : help
|
|
200
|
-
-v : version
|
|
201
|
-
-x : show converted code
|
|
202
|
-
-
|
|
203
|
-
-
|
|
204
|
-
-
|
|
205
|
-
-
|
|
206
|
-
-
|
|
207
|
-
-
|
|
208
|
-
-
|
|
209
|
-
-
|
|
210
|
-
-
|
|
211
|
-
-
|
|
212
|
-
-
|
|
213
|
-
-
|
|
214
|
-
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
220
|
+
buf = []
|
|
221
|
+
buf << "erubis - embedded program converter for multi-language"
|
|
222
|
+
buf << "Usage: #{command} [..options..] [file ...]"
|
|
223
|
+
buf << " -h, --help : help"
|
|
224
|
+
buf << " -v : version"
|
|
225
|
+
buf << " -x : show converted code"
|
|
226
|
+
buf << " -X : show converted code, only ruby code and no text part"
|
|
227
|
+
buf << " -N : numbering: add line numbers (for '-x/-X')"
|
|
228
|
+
buf << " -U : unique: compress empty lines to a line (for '-x/-X')"
|
|
229
|
+
buf << " -C : compact: remove empty lines (for '-x/-X')"
|
|
230
|
+
buf << " -b : body only: no preamble nor postamble (for '-x/-X')"
|
|
231
|
+
buf << " -z : syntax checking"
|
|
232
|
+
buf << " -e : escape (equal to '--E Escape')"
|
|
233
|
+
buf << " -p pattern : embedded pattern (default '<% %>')"
|
|
234
|
+
buf << " -l lang : convert but no execute (ruby/php/c/java/scheme/perl/js)"
|
|
235
|
+
buf << " -E e1,e2,... : enhancer names (Escape, PercentLine, BiPattern, ...)"
|
|
236
|
+
buf << " -I path : library include path"
|
|
237
|
+
buf << " -K kanji : kanji code (euc/sjis/utf8) (default none)"
|
|
238
|
+
buf << " -c context : context data string (yaml inline style or ruby code)"
|
|
239
|
+
buf << " -f datafile : context data file ('*.yaml', '*.yml', or '*.rb')"
|
|
240
|
+
#buf << " -t : expand tab characters in YAML file"
|
|
241
|
+
buf << " -T : don't expand tab characters in YAML file"
|
|
242
|
+
buf << " -S : convert mapping key from string to symbol in YAML file"
|
|
243
|
+
buf << " -B : invoke 'result(binding)' instead of 'evaluate(context)'"
|
|
244
|
+
buf << " --pi=name : parse '<?name ... ?>' instead of '<% ... %>'"
|
|
218
245
|
#'
|
|
219
246
|
# -T : don't trim spaces around '<% %>'
|
|
220
247
|
# -c class : class name (XmlEruby/PercentLineEruby/...) (default Eruby)
|
|
221
248
|
# -r library : require library
|
|
222
249
|
# -a : action (convert/execute)
|
|
223
|
-
return
|
|
250
|
+
return join("\n")
|
|
224
251
|
end
|
|
225
252
|
|
|
226
253
|
|
|
@@ -385,10 +412,10 @@ END
|
|
|
385
412
|
filename.strip!
|
|
386
413
|
test(?f, filename) or raise CommandOptionError.new("#{filename}: file not found.")
|
|
387
414
|
if filename =~ /\.ya?ml$/
|
|
388
|
-
if opts.
|
|
389
|
-
ydoc = YAML.load(untabify(File.read(filename)))
|
|
390
|
-
else
|
|
415
|
+
if opts.unexpand
|
|
391
416
|
ydoc = YAML.load_file(filename)
|
|
417
|
+
else
|
|
418
|
+
ydoc = YAML.load(untabify(File.read(filename)))
|
|
392
419
|
end
|
|
393
420
|
ydoc.is_a?(Hash) or raise CommandOptionError.new("#{filename}: root object is not a mapping.")
|
|
394
421
|
intern_hash_keys(ydoc) if opts.intern
|
data/lib/erubis/tiny.rb
CHANGED
data/test/assert-text-equal.rb
CHANGED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
<%
|
|
2
|
+
import java.util.*;
|
|
3
|
+
|
|
4
|
+
public class Example {
|
|
5
|
+
private String user;
|
|
6
|
+
private String[] list;
|
|
7
|
+
public example(String user, String[] list) {
|
|
8
|
+
this.user = user;
|
|
9
|
+
this.list = list;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
public String view() {
|
|
13
|
+
StringBuffer _buf = new StringBuffer();
|
|
14
|
+
%>
|
|
15
|
+
<html>
|
|
16
|
+
<body>
|
|
17
|
+
<p>Hello <%= user %>!</p>
|
|
18
|
+
<table>
|
|
19
|
+
<tbody>
|
|
20
|
+
<% for (int i = 0; i < list.length; i++) { %>
|
|
21
|
+
<tr bgcolor="<%= i % 2 == 0 ? "#FFCCCC" : "#CCCCFF" %>">
|
|
22
|
+
<td><%= i + 1 %></td>
|
|
23
|
+
<td><%== list[i] %></td>
|
|
24
|
+
</tr>
|
|
25
|
+
<% } %>
|
|
26
|
+
</tbody>
|
|
27
|
+
</table>
|
|
28
|
+
<body>
|
|
29
|
+
</html>
|
|
30
|
+
<%
|
|
31
|
+
return _buf.toString();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public static void main(String[] args) {
|
|
35
|
+
String[] list = { "<aaa>", "b&b", "\"ccc\"" };
|
|
36
|
+
Example ex = Example.new("Erubis", list);
|
|
37
|
+
System.out.print(ex.view());
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public static String escape(String s) {
|
|
41
|
+
StringBuffer sb = new StringBuffer();
|
|
42
|
+
for (int i = 0; i < s.length(); i++) {
|
|
43
|
+
char ch = s.charAt(i);
|
|
44
|
+
switch (ch) {
|
|
45
|
+
case '<': sb.append("<"); break;
|
|
46
|
+
case '>': sb.append(">"); break;
|
|
47
|
+
case '&': sb.append("&"); break;
|
|
48
|
+
case '"': sb.append("""); break;
|
|
49
|
+
default: sb.append(ch);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return sb.toString();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
%>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<%
|
|
2
|
+
#include <stdio.h>
|
|
3
|
+
|
|
4
|
+
int main(int argc, char *argv[])
|
|
5
|
+
{
|
|
6
|
+
int i;
|
|
7
|
+
|
|
8
|
+
%>
|
|
9
|
+
<html>
|
|
10
|
+
<body>
|
|
11
|
+
<p>Hello <%= "%s", argv[0] %>!</p>
|
|
12
|
+
<table>
|
|
13
|
+
<tbody>
|
|
14
|
+
<% for (i = 1; i < argc; i++) { %>
|
|
15
|
+
<tr bgcolor="<%= i % 2 == 0 ? "#FFCCCC" : "#CCCCFF" %>">
|
|
16
|
+
<td><%= "%d", i %></td>
|
|
17
|
+
<td><%= "%s", argv[i] %></td>
|
|
18
|
+
</tr>
|
|
19
|
+
<% } %>
|
|
20
|
+
</tbody>
|
|
21
|
+
</table>
|
|
22
|
+
</body>
|
|
23
|
+
</html>
|
|
24
|
+
<%
|
|
25
|
+
return 0;
|
|
26
|
+
}
|
|
27
|
+
%>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<%
|
|
2
|
+
var user = 'Erubis';
|
|
3
|
+
var list = ['<aaa>', 'b&b', '"ccc"'];
|
|
4
|
+
%>
|
|
5
|
+
<html>
|
|
6
|
+
<body>
|
|
7
|
+
<p>Hello <%= user %>!</p>
|
|
8
|
+
<table>
|
|
9
|
+
<tbody>
|
|
10
|
+
<% var i; %>
|
|
11
|
+
<% for (i = 0; i < list.length; i++) { %>
|
|
12
|
+
<tr bgcolor="<%= i % 2 == 0 ? '#FFCCCC' : '#CCCCFF' %>">
|
|
13
|
+
<td><%= i + 1 %></td>
|
|
14
|
+
<td><%= list[i] %></td>
|
|
15
|
+
</tr>
|
|
16
|
+
<% } %>
|
|
17
|
+
</tbody>
|
|
18
|
+
</table>
|
|
19
|
+
</body>
|
|
20
|
+
</html>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<%
|
|
2
|
+
my $user = 'Erubis';
|
|
3
|
+
my @list = ('<aaa>', 'b&b', '"ccc"');
|
|
4
|
+
%>
|
|
5
|
+
<html>
|
|
6
|
+
<body>
|
|
7
|
+
<p>Hello <%= $user %>!</p>
|
|
8
|
+
<table>
|
|
9
|
+
<% $i = 0; %>
|
|
10
|
+
<% for $item (@list) { %>
|
|
11
|
+
<tr bgcolor=<%= ++$i % 2 == 0 ? '#FFCCCC' : '#CCCCFF' %>">
|
|
12
|
+
<td><%= $i %></td>
|
|
13
|
+
<td><%= $item %></td>
|
|
14
|
+
</tr>
|
|
15
|
+
<% } %>
|
|
16
|
+
</table>
|
|
17
|
+
</body>
|
|
18
|
+
</html>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<?xml version="1.0"?>
|
|
2
|
+
<html>
|
|
3
|
+
<body>
|
|
4
|
+
<p>Hello <%= $user %>!</p>
|
|
5
|
+
<table>
|
|
6
|
+
<tbody>
|
|
7
|
+
<% $i = 0; %>
|
|
8
|
+
<% foreach ($list as $item) { %>
|
|
9
|
+
<% $i++; %>
|
|
10
|
+
<tr bgcolor="<%= $i % 2 == 0 ? '#FFCCCC' : '#CCCCFF' %>">
|
|
11
|
+
<td><%= $i %></td>
|
|
12
|
+
<td><%== $item %></td>
|
|
13
|
+
</tr>
|
|
14
|
+
<% } %>
|
|
15
|
+
</tbody>
|
|
16
|
+
</table>
|
|
17
|
+
</body>
|
|
18
|
+
</html>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
<html>
|
|
2
|
+
<body>
|
|
3
|
+
<%
|
|
4
|
+
(let ((user "Erubis")
|
|
5
|
+
(items '("<aaa>" "b&b" "\"ccc\""))
|
|
6
|
+
(i 0))
|
|
7
|
+
%>
|
|
8
|
+
<p>Hello <%= user %>!</p>
|
|
9
|
+
<table>
|
|
10
|
+
<%
|
|
11
|
+
(for-each
|
|
12
|
+
(lambda (item)
|
|
13
|
+
(set! i (+ i 1))
|
|
14
|
+
%>
|
|
15
|
+
<tr bgcolor="<%= (if (= (modulo i 2) 0) "#FFCCCC" "#CCCCFF") %>">
|
|
16
|
+
<td><%= i %></td>
|
|
17
|
+
<td><%= item %></td>
|
|
18
|
+
</tr>
|
|
19
|
+
<%
|
|
20
|
+
) ; lambda end
|
|
21
|
+
items) ; for-each end
|
|
22
|
+
%>
|
|
23
|
+
</table>
|
|
24
|
+
<%
|
|
25
|
+
) ; let end
|
|
26
|
+
%>
|
|
27
|
+
</body>
|
|
28
|
+
</html>
|