erbse 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGES.txt +828 -0
- data/MIT-LICENSE +20 -0
- data/README.md +51 -0
- data/benchmark/Makefile +6 -0
- data/benchmark/bench.rb +313 -0
- data/benchmark/bench_context.yaml +141 -0
- data/benchmark/templates/_footer.html +4 -0
- data/benchmark/templates/_header.html +52 -0
- 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 +10 -0
- data/erbse.gemspec +24 -0
- data/lib/erbse.rb +52 -0
- data/lib/erbse/context.rb +83 -0
- data/lib/erbse/converter.rb +357 -0
- data/lib/erbse/engine.rb +114 -0
- data/lib/erbse/engine/ec.rb +117 -0
- data/lib/erbse/engine/ecpp.rb +113 -0
- data/lib/erbse/engine/ejava.rb +110 -0
- data/lib/erbse/engine/ejavascript.rb +119 -0
- data/lib/erbse/engine/enhanced.rb +126 -0
- data/lib/erbse/engine/eperl.rb +95 -0
- data/lib/erbse/engine/ephp.rb +99 -0
- data/lib/erbse/engine/eruby.rb +119 -0
- data/lib/erbse/engine/escheme.rb +114 -0
- data/lib/erbse/engine/optimized.rb +127 -0
- data/lib/erbse/enhancer.rb +723 -0
- data/lib/erbse/error.rb +23 -0
- data/lib/erbse/evaluator.rb +88 -0
- data/lib/erbse/generator.rb +85 -0
- data/lib/erbse/helper.rb +47 -0
- data/lib/erbse/helpers/rails_form_helper.rb +197 -0
- data/lib/erbse/helpers/rails_helper.rb +353 -0
- data/lib/erbse/main.rb +516 -0
- data/lib/erbse/preprocessing.rb +58 -0
- data/lib/erbse/tiny.rb +144 -0
- data/lib/erbse/util.rb +22 -0
- data/lib/erbse/version.rb +3 -0
- data/test/assert-text-equal.rb +44 -0
- 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/bufvar-example.rb +10 -0
- data/test/data/users-guide/bufvar-example.result +17 -0
- data/test/data/users-guide/context.rb +6 -0
- data/test/data/users-guide/context.yaml +8 -0
- data/test/data/users-guide/def_method.rb +14 -0
- data/test/data/users-guide/def_method.result +3 -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.ecpp +30 -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 +17 -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 +32 -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-example.rb +8 -0
- data/test/data/users-guide/fasteruby-example.result +18 -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/main_program1.rb +8 -0
- data/test/data/users-guide/main_program1.result +6 -0
- data/test/data/users-guide/main_program2.rb +8 -0
- data/test/data/users-guide/main_program2.result +6 -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 +6 -0
- data/test/data/users-guide/percentline_example.result +9 -0
- 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/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/stderr.log +3 -0
- data/test/data/users-guide/stdout_exmple.result +9 -0
- data/test/data/users-guide/stringbuffer_example.result +9 -0
- data/test/data/users-guide/tail_260.result +4 -0
- data/test/data/users-guide/tailnewline.rhtml +3 -0
- data/test/data/users-guide/template1.rhtml +4 -0
- data/test/data/users-guide/template2.rhtml +4 -0
- data/test/test-engines.rb +425 -0
- data/test/test-enhancers.rb +646 -0
- data/test/test-erubis.rb +887 -0
- data/test/test-index-cgi.rb +191 -0
- data/test/test-main.rb +752 -0
- data/test/test-users-guide.rb +73 -0
- data/test/test.rb +45 -0
- data/test/testutil.rb +111 -0
- metadata +233 -0
@@ -0,0 +1,119 @@
|
|
1
|
+
##
|
2
|
+
## $Release: 2.7.0 $
|
3
|
+
## copyright(c) 2006-2011 kuwata-lab.com all rights reserved.
|
4
|
+
##
|
5
|
+
|
6
|
+
require 'erubis/engine'
|
7
|
+
require 'erubis/enhancer'
|
8
|
+
|
9
|
+
|
10
|
+
module Erubis
|
11
|
+
|
12
|
+
|
13
|
+
module JavascriptGenerator
|
14
|
+
include Generator
|
15
|
+
|
16
|
+
def self.supported_properties() # :nodoc:
|
17
|
+
list = []
|
18
|
+
#list << [:indent, '', "indent spaces (ex. ' ')"]
|
19
|
+
#list << [:bufvar, '_buf', "output buffer variable name"]
|
20
|
+
list << [:docwrite, true, "use 'document.write()' when true"]
|
21
|
+
return list
|
22
|
+
end
|
23
|
+
|
24
|
+
def init_generator(properties={})
|
25
|
+
super
|
26
|
+
@escapefunc ||= 'escape'
|
27
|
+
@indent = properties[:indent] || ''
|
28
|
+
@bufvar = properties[:bufvar] || '_buf'
|
29
|
+
@docwrite = properties[:docwrite] != false # '!= false' will be removed in the next release
|
30
|
+
end
|
31
|
+
|
32
|
+
def add_preamble(src)
|
33
|
+
src << "#{@indent}var #{@bufvar} = [];"
|
34
|
+
end
|
35
|
+
|
36
|
+
def escape_text(text)
|
37
|
+
@@table_ ||= { "\r"=>"\\r", "\n"=>"\\n\\\n", "\t"=>"\\t", '"'=>'\\"', "\\"=>"\\\\" }
|
38
|
+
return text.gsub!(/[\r\n\t"\\]/) { |m| @@table_[m] } || text
|
39
|
+
end
|
40
|
+
|
41
|
+
def add_indent(src, indent)
|
42
|
+
src << (src.empty? || src[-1] == ?\n ? indent : ' ')
|
43
|
+
end
|
44
|
+
|
45
|
+
def add_text(src, text)
|
46
|
+
return if text.empty?
|
47
|
+
add_indent(src, @indent)
|
48
|
+
src << @bufvar << '.push("'
|
49
|
+
s = escape_text(text)
|
50
|
+
if s[-1] == ?\n
|
51
|
+
s[-2, 2] = ''
|
52
|
+
src << s << "\");\n"
|
53
|
+
else
|
54
|
+
src << s << "\");"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def add_stmt(src, code)
|
59
|
+
src << code
|
60
|
+
end
|
61
|
+
|
62
|
+
def add_expr_literal(src, code)
|
63
|
+
add_indent(src, @indent)
|
64
|
+
code.strip!
|
65
|
+
src << "#{@bufvar}.push(#{code});"
|
66
|
+
end
|
67
|
+
|
68
|
+
def add_expr_escaped(src, code)
|
69
|
+
add_expr_literal(src, escaped_expr(code))
|
70
|
+
end
|
71
|
+
|
72
|
+
def add_expr_debug(src, code)
|
73
|
+
add_indent(src, @indent)
|
74
|
+
code.strip!
|
75
|
+
src << "alert(\"*** debug: #{code}=\"+(#{code}));"
|
76
|
+
end
|
77
|
+
|
78
|
+
def add_postamble(src)
|
79
|
+
src << "\n" if src[-1] == ?;
|
80
|
+
if @docwrite
|
81
|
+
src << @indent << 'document.write(' << @bufvar << ".join(\"\"));\n"
|
82
|
+
else
|
83
|
+
src << @indent << @bufvar << ".join(\"\");\n"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
##
|
91
|
+
## engine for JavaScript
|
92
|
+
##
|
93
|
+
class Ejavascript < Basic::Engine
|
94
|
+
include JavascriptGenerator
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
class EscapedEjavascript < Ejavascript
|
99
|
+
include EscapeEnhancer
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
#class XmlEjavascript < Ejavascript
|
104
|
+
# include EscapeEnhancer
|
105
|
+
#end
|
106
|
+
|
107
|
+
|
108
|
+
class PI::Ejavascript < PI::Engine
|
109
|
+
include JavascriptGenerator
|
110
|
+
|
111
|
+
def init_converter(properties={})
|
112
|
+
@pi = 'js'
|
113
|
+
super(properties)
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
|
119
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
##
|
2
|
+
## $Release: 2.7.0 $
|
3
|
+
## copyright(c) 2006-2011 kuwata-lab.com all rights reserved.
|
4
|
+
##
|
5
|
+
|
6
|
+
require 'erubis/enhancer'
|
7
|
+
require 'erubis/engine/eruby'
|
8
|
+
|
9
|
+
|
10
|
+
module Erubis
|
11
|
+
|
12
|
+
|
13
|
+
#--
|
14
|
+
## moved to engine/ruby.rb
|
15
|
+
#class EscapedEruby < Eruby
|
16
|
+
# include EscapeEnhancer
|
17
|
+
#end
|
18
|
+
#++
|
19
|
+
|
20
|
+
|
21
|
+
#--
|
22
|
+
### (obsolete)
|
23
|
+
#class FastEruby < Eruby
|
24
|
+
# include FastEnhancer
|
25
|
+
#end
|
26
|
+
#++
|
27
|
+
|
28
|
+
|
29
|
+
class StdoutEruby < Eruby
|
30
|
+
include StdoutEnhancer
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
class PrintOutEruby < Eruby
|
35
|
+
include PrintOutEnhancer
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
class PrintEnabledEruby < Eruby
|
40
|
+
include PrintEnabledEnhancer
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
class ArrayEruby < Eruby
|
45
|
+
include ArrayEnhancer
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
class ArrayBufferEruby < Eruby
|
50
|
+
include ArrayBufferEnhancer
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
class StringBufferEruby < Eruby
|
55
|
+
include StringBufferEnhancer
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
class StringIOEruby < Eruby
|
60
|
+
include StringIOEnhancer
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
class ErboutEruby < Eruby
|
65
|
+
include ErboutEnhancer
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
class NoTextEruby < Eruby
|
70
|
+
include NoTextEnhancer
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
class NoCodeEruby < Eruby
|
75
|
+
include NoCodeEnhancer
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
class SimplifiedEruby < Eruby
|
80
|
+
include SimplifyEnhancer
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
class StdoutSimplifiedEruby < Eruby
|
85
|
+
include StdoutEnhancer
|
86
|
+
include SimplifyEnhancer
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
class PrintOutSimplifiedEruby < Eruby
|
91
|
+
include PrintOutEnhancer
|
92
|
+
include SimplifyEnhancer
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
class BiPatternEruby < Eruby
|
97
|
+
include BiPatternEnhancer
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
class PercentLineEruby < Eruby
|
102
|
+
include PercentLineEnhancer
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
class PrefixedLineEruby < Eruby
|
107
|
+
include PrefixedLineEnhancer
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
class HeaderFooterEruby < Eruby
|
112
|
+
include HeaderFooterEnhancer
|
113
|
+
end
|
114
|
+
|
115
|
+
|
116
|
+
class DeleteIndentEruby < Eruby
|
117
|
+
include DeleteIndentEnhancer
|
118
|
+
end
|
119
|
+
|
120
|
+
|
121
|
+
class InterpolationEruby < Eruby
|
122
|
+
include InterpolationEnhancer
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
##
|
2
|
+
## $Release: 2.7.0 $
|
3
|
+
## copyright(c) 2006-2011 kuwata-lab.com all rights reserved.
|
4
|
+
##
|
5
|
+
|
6
|
+
require 'erubis/engine'
|
7
|
+
require 'erubis/enhancer'
|
8
|
+
|
9
|
+
|
10
|
+
module Erubis
|
11
|
+
|
12
|
+
|
13
|
+
module PerlGenerator
|
14
|
+
include Generator
|
15
|
+
|
16
|
+
def self.supported_properties() # :nodoc:
|
17
|
+
return [
|
18
|
+
[:func, 'print', "function name"],
|
19
|
+
]
|
20
|
+
end
|
21
|
+
|
22
|
+
def init_generator(properties={})
|
23
|
+
super
|
24
|
+
@escapefunc ||= 'encode_entities'
|
25
|
+
@func = properties[:func] || 'print'
|
26
|
+
end
|
27
|
+
|
28
|
+
def add_preamble(src)
|
29
|
+
src << "use HTML::Entities; ";
|
30
|
+
end
|
31
|
+
|
32
|
+
def escape_text(text)
|
33
|
+
return text.gsub!(/['\\]/, '\\\\\&') || text
|
34
|
+
end
|
35
|
+
|
36
|
+
def add_text(src, text)
|
37
|
+
src << @func << "('" << escape_text(text) << "'); " unless text.empty?
|
38
|
+
end
|
39
|
+
|
40
|
+
def add_expr_literal(src, code)
|
41
|
+
code.strip!
|
42
|
+
src << @func << "(" << code << "); "
|
43
|
+
end
|
44
|
+
|
45
|
+
def add_expr_escaped(src, code)
|
46
|
+
add_expr_literal(src, escaped_expr(code))
|
47
|
+
end
|
48
|
+
|
49
|
+
def add_expr_debug(src, code)
|
50
|
+
code.strip!
|
51
|
+
s = code.gsub(/\'/, "\\'")
|
52
|
+
src << @func << "('*** debug: #{code}=', #{code}, \"\\n\");"
|
53
|
+
end
|
54
|
+
|
55
|
+
def add_stmt(src, code)
|
56
|
+
src << code
|
57
|
+
end
|
58
|
+
|
59
|
+
def add_postamble(src)
|
60
|
+
src << "\n" unless src[-1] == ?\n
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
##
|
67
|
+
## engine for Perl
|
68
|
+
##
|
69
|
+
class Eperl < Basic::Engine
|
70
|
+
include PerlGenerator
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
class EscapedEperl < Eperl
|
75
|
+
include EscapeEnhancer
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
#class XmlEperl < Eperl
|
80
|
+
# include EscapeEnhancer
|
81
|
+
#end
|
82
|
+
|
83
|
+
|
84
|
+
class PI::Eperl < PI::Engine
|
85
|
+
include PerlGenerator
|
86
|
+
|
87
|
+
def init_converter(properties={})
|
88
|
+
@pi = 'perl'
|
89
|
+
super(properties)
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
##
|
2
|
+
## $Release: 2.7.0 $
|
3
|
+
## copyright(c) 2006-2011 kuwata-lab.com all rights reserved.
|
4
|
+
##
|
5
|
+
|
6
|
+
require 'erubis/engine'
|
7
|
+
require 'erubis/enhancer'
|
8
|
+
|
9
|
+
|
10
|
+
module Erubis
|
11
|
+
|
12
|
+
|
13
|
+
module PhpGenerator
|
14
|
+
include Generator
|
15
|
+
|
16
|
+
def self.supported_properties() # :nodoc:
|
17
|
+
return []
|
18
|
+
end
|
19
|
+
|
20
|
+
def init_generator(properties={})
|
21
|
+
super
|
22
|
+
@escapefunc ||= 'htmlspecialchars'
|
23
|
+
end
|
24
|
+
|
25
|
+
def add_preamble(src)
|
26
|
+
# empty
|
27
|
+
end
|
28
|
+
|
29
|
+
def escape_text(text)
|
30
|
+
return text.gsub!(/<\?xml\b/, '<<?php ?>?xml') || text
|
31
|
+
end
|
32
|
+
|
33
|
+
def add_text(src, text)
|
34
|
+
src << escape_text(text)
|
35
|
+
end
|
36
|
+
|
37
|
+
def add_expr_literal(src, code)
|
38
|
+
code.strip!
|
39
|
+
src << "<?php echo #{code}; ?>"
|
40
|
+
end
|
41
|
+
|
42
|
+
def add_expr_escaped(src, code)
|
43
|
+
add_expr_literal(src, escaped_expr(code))
|
44
|
+
end
|
45
|
+
|
46
|
+
def add_expr_debug(src, code)
|
47
|
+
code.strip!
|
48
|
+
s = code.gsub(/\'/, "\\'")
|
49
|
+
src << "<?php error_log('*** debug: #{s}='.(#{code}), 0); ?>"
|
50
|
+
end
|
51
|
+
|
52
|
+
def add_stmt(src, code)
|
53
|
+
src << "<?php"
|
54
|
+
src << " " if code[0] != ?\ #
|
55
|
+
if code[-1] == ?\n
|
56
|
+
code.chomp!
|
57
|
+
src << code << "?>\n"
|
58
|
+
else
|
59
|
+
src << code << "?>"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def add_postamble(src)
|
64
|
+
# empty
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
##
|
71
|
+
## engine for PHP
|
72
|
+
##
|
73
|
+
class Ephp < Basic::Engine
|
74
|
+
include PhpGenerator
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
class EscapedEphp < Ephp
|
79
|
+
include EscapeEnhancer
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
#class XmlEphp < Ephp
|
84
|
+
# include EscapeEnhancer
|
85
|
+
#end
|
86
|
+
|
87
|
+
|
88
|
+
class PI::Ephp < PI::Engine
|
89
|
+
include PhpGenerator
|
90
|
+
|
91
|
+
def init_converter(properties={})
|
92
|
+
@pi = 'php'
|
93
|
+
super(properties)
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
require 'erbse/enhancer'
|
2
|
+
|
3
|
+
|
4
|
+
module Erbse
|
5
|
+
|
6
|
+
|
7
|
+
##
|
8
|
+
## code generator for Ruby
|
9
|
+
##
|
10
|
+
module RubyGenerator
|
11
|
+
include Generator
|
12
|
+
#include ArrayBufferEnhancer
|
13
|
+
include StringBufferEnhancer
|
14
|
+
|
15
|
+
def init_generator(properties={})
|
16
|
+
super
|
17
|
+
@escapefunc ||= "Erubis::XmlHelper.escape_xml"
|
18
|
+
@bufvar = properties[:bufvar] || "_buf"
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.supported_properties() # :nodoc:
|
22
|
+
return []
|
23
|
+
end
|
24
|
+
|
25
|
+
def escape_text(text)
|
26
|
+
text.gsub(/['\\]/, '\\\\\&') # "'" => "\\'", '\\' => '\\\\'
|
27
|
+
end
|
28
|
+
|
29
|
+
def escaped_expr(code)
|
30
|
+
return "#{@escapefunc}(#{code})"
|
31
|
+
end
|
32
|
+
|
33
|
+
#--
|
34
|
+
#def add_preamble(src)
|
35
|
+
# src << "#{@bufvar} = [];"
|
36
|
+
#end
|
37
|
+
#++
|
38
|
+
|
39
|
+
def add_text(src, text)
|
40
|
+
src << " #{@bufvar} << '" << escape_text(text) << "';" unless text.empty?
|
41
|
+
end
|
42
|
+
|
43
|
+
def add_stmt(src, code)
|
44
|
+
#src << code << ';'
|
45
|
+
src << code
|
46
|
+
src << ';' unless code[-1] == ?\n
|
47
|
+
end
|
48
|
+
|
49
|
+
def add_expr_literal(src, code)
|
50
|
+
src << " #{@bufvar} << (" << code << ').to_s;'
|
51
|
+
end
|
52
|
+
|
53
|
+
def add_expr_escaped(src, code)
|
54
|
+
src << " #{@bufvar} << " << escaped_expr(code) << ';'
|
55
|
+
end
|
56
|
+
|
57
|
+
def add_expr_debug(src, code)
|
58
|
+
code.strip!
|
59
|
+
s = (code.dump =~ /\A"(.*)"\z/) && $1
|
60
|
+
src << ' $stderr.puts("*** debug: ' << s << '=#{(' << code << ').inspect}");'
|
61
|
+
end
|
62
|
+
|
63
|
+
#--
|
64
|
+
#def add_postamble(src)
|
65
|
+
# src << "\n#{@bufvar}.join\n"
|
66
|
+
#end
|
67
|
+
#++
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
##
|
73
|
+
## engine for Ruby
|
74
|
+
##
|
75
|
+
class Eruby < Basic::Engine
|
76
|
+
include RubyEvaluator
|
77
|
+
include RubyGenerator
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
##
|
82
|
+
## fast engine for Ruby
|
83
|
+
##
|
84
|
+
class FastEruby < Eruby
|
85
|
+
include InterpolationEnhancer
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
##
|
90
|
+
## swtich '<%= %>' to escaped and '<%== %>' to not escaped
|
91
|
+
##
|
92
|
+
class EscapedEruby < Eruby
|
93
|
+
include EscapeEnhancer
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
##
|
98
|
+
## sanitize expression (<%= ... %>) by default
|
99
|
+
##
|
100
|
+
## this is equivalent to EscapedEruby and is prepared only for compatibility.
|
101
|
+
##
|
102
|
+
class XmlEruby < Eruby
|
103
|
+
include EscapeEnhancer
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
class PI::Eruby < PI::Engine
|
108
|
+
include RubyEvaluator
|
109
|
+
include RubyGenerator
|
110
|
+
|
111
|
+
def init_converter(properties={})
|
112
|
+
@pi = 'rb'
|
113
|
+
super(properties)
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
|
119
|
+
end
|