erubis 2.0.1 → 2.1.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/ChangeLog +150 -2
- data/LGPL +504 -0
- data/README.txt +14 -8
- data/benchmark/erubybench.rb +1 -1
- data/benchmark/erubybench.rhtml +3 -3
- data/bin/erubis +1 -1
- data/bin/notext +154 -0
- data/contrib/erubis +1036 -374
- data/contrib/inline-require +5 -3
- data/doc-api/classes/Erubis.html +43 -1
- data/doc-api/classes/Erubis/ArrayBufferEnhancer.html +14 -14
- data/doc-api/classes/Erubis/ArrayEnhancer.html +14 -14
- data/doc-api/classes/Erubis/Basic.html +112 -0
- data/doc-api/classes/Erubis/Basic/Converter.html +318 -0
- data/doc-api/classes/Erubis/Basic/Engine.html +130 -0
- data/doc-api/classes/Erubis/BiPatternEnhancer.html +14 -14
- data/doc-api/classes/Erubis/CGenerator.html +386 -0
- data/doc-api/classes/Erubis/Context.html +31 -32
- data/doc-api/classes/Erubis/Converter.html +231 -0
- data/doc-api/classes/Erubis/Ec.html +9 -283
- data/doc-api/classes/Erubis/Ejava.html +9 -274
- data/doc-api/classes/Erubis/Ejavascript.html +9 -298
- data/doc-api/classes/Erubis/Engine.html +68 -508
- data/doc-api/classes/Erubis/Eperl.html +9 -259
- data/doc-api/classes/Erubis/Ephp.html +9 -239
- data/doc-api/classes/Erubis/ErubisError.html +2 -2
- data/doc-api/classes/Erubis/Eruby.html +4 -187
- data/doc-api/classes/Erubis/EscapeEnhancer.html +9 -11
- data/doc-api/classes/Erubis/Escheme.html +9 -272
- data/doc-api/classes/Erubis/Evaluator.html +212 -0
- data/doc-api/classes/Erubis/Generator.html +410 -0
- data/doc-api/classes/Erubis/HeaderFooterEnhancer.html +16 -16
- data/doc-api/classes/Erubis/Helper.html +112 -0
- data/doc-api/classes/Erubis/Helper/CachedRailsTemplate.html +198 -0
- data/doc-api/classes/Erubis/Helper/RailsTemplate.html +366 -0
- data/doc-api/classes/Erubis/JavaGenerator.html +359 -0
- data/doc-api/classes/Erubis/JavascriptGenerator.html +381 -0
- data/doc-api/classes/Erubis/Main.html +27 -25
- data/doc-api/classes/Erubis/NoCodeEnhancer.html +249 -0
- data/doc-api/classes/Erubis/NoCodeEruby.html +120 -0
- data/doc-api/classes/Erubis/NoTextEnhancer.html +8 -8
- data/doc-api/classes/Erubis/NotSupportedError.html +119 -0
- data/doc-api/classes/Erubis/OptimizedEruby.html +22 -304
- data/doc-api/classes/Erubis/OptimizedGenerator.html +439 -0
- data/doc-api/classes/Erubis/OptimizedXmlEruby.html +7 -7
- data/doc-api/classes/Erubis/PI.html +124 -0
- data/doc-api/classes/Erubis/PI/Converter.html +318 -0
- data/doc-api/classes/Erubis/PI/Ec.html +166 -0
- data/doc-api/classes/Erubis/PI/Ejava.html +166 -0
- data/doc-api/classes/Erubis/PI/Ejavascript.html +166 -0
- data/doc-api/classes/Erubis/PI/Engine.html +122 -0
- data/doc-api/classes/Erubis/PI/Eperl.html +166 -0
- data/doc-api/classes/Erubis/PI/Ephp.html +166 -0
- data/doc-api/classes/Erubis/PI/Eruby.html +155 -0
- data/doc-api/classes/Erubis/PI/Escheme.html +166 -0
- data/doc-api/classes/Erubis/PI/TinyEruby.html +305 -0
- data/doc-api/classes/Erubis/PercentLineEnhancer.html +7 -7
- data/doc-api/classes/Erubis/PerlGenerator.html +344 -0
- data/doc-api/classes/Erubis/PhpGenerator.html +350 -0
- data/doc-api/classes/Erubis/PrintEnabledEnhancer.html +24 -24
- data/doc-api/classes/Erubis/PrintOutEnhancer.html +35 -35
- data/doc-api/classes/Erubis/RubyEvaluator.html +190 -0
- data/doc-api/classes/Erubis/RubyGenerator.html +327 -0
- data/doc-api/classes/Erubis/SchemeGenerator.html +382 -0
- data/doc-api/classes/Erubis/SimplifyEnhancer.html +17 -13
- data/doc-api/classes/Erubis/StdoutEnhancer.html +14 -14
- data/doc-api/classes/Erubis/StringBufferEnhancer.html +14 -14
- data/doc-api/classes/Erubis/TinyEruby.html +45 -40
- data/doc-api/classes/Erubis/XmlHelper.html +14 -14
- data/doc-api/created.rid +1 -1
- data/doc-api/files/__/README_txt.html +27 -9
- data/doc-api/files/erubis/context_rb.html +107 -0
- data/doc-api/files/erubis/converter_rb.html +114 -0
- 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 +3 -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 +6 -3
- data/doc-api/files/erubis/enhancer_rb.html +2 -9
- data/doc-api/files/erubis/error_rb.html +107 -0
- data/doc-api/files/erubis/evaluator_rb.html +115 -0
- data/doc-api/files/erubis/generator_rb.html +114 -0
- data/doc-api/files/erubis/helper/rails_rb.html +140 -0
- data/doc-api/files/erubis/helper_rb.html +1 -1
- data/doc-api/files/erubis/local-setting_rb.html +1 -1
- data/doc-api/files/erubis/main_rb.html +2 -2
- data/doc-api/files/erubis/tiny_rb.html +2 -2
- data/doc-api/files/erubis_rb.html +2 -2
- data/doc-api/fr_class_index.html +32 -0
- data/doc-api/fr_file_index.html +6 -0
- data/doc-api/fr_method_index.html +178 -136
- data/doc/users-guide.html +538 -199
- data/examples/{Makefile → basic/Makefile} +11 -11
- data/examples/basic/example.ec +42 -0
- data/examples/{example.ejava → basic/example.ejava} +5 -1
- data/examples/{example.ejavascript → basic/example.ejs} +0 -0
- data/examples/{example.eperl → basic/example.eperl} +2 -2
- data/examples/{example.ephp → basic/example.ephp} +0 -0
- data/examples/{example.eruby → basic/example.eruby} +0 -0
- data/examples/{example.escheme → basic/example.escheme} +0 -0
- data/examples/pi/Makefile +54 -0
- data/examples/pi/example.ec +42 -0
- data/examples/pi/example.ejava +45 -0
- data/examples/pi/example.ejs +16 -0
- data/examples/pi/example.eperl +16 -0
- data/examples/pi/example.ephp +17 -0
- data/examples/pi/example.eruby +15 -0
- data/examples/pi/example.escheme +26 -0
- data/lib/erubis.rb +15 -8
- data/lib/erubis/context.rb +54 -0
- data/lib/erubis/converter.rb +307 -0
- data/lib/erubis/engine.rb +57 -227
- data/lib/erubis/engine/ec.rb +31 -20
- data/lib/erubis/engine/ejava.rb +33 -21
- data/lib/erubis/engine/ejavascript.rb +30 -18
- data/lib/erubis/engine/enhanced.rb +7 -2
- data/lib/erubis/engine/eperl.rb +33 -19
- data/lib/erubis/engine/ephp.rb +32 -14
- data/lib/erubis/engine/eruby.rb +34 -7
- data/lib/erubis/engine/escheme.rb +34 -15
- data/lib/erubis/engine/optimized.rb +25 -11
- data/lib/erubis/enhancer.rb +53 -19
- data/lib/erubis/error.rb +24 -0
- data/lib/erubis/evaluator.rb +71 -0
- data/lib/erubis/generator.rb +83 -0
- data/lib/erubis/helper.rb +1 -1
- data/lib/erubis/helper/rails.rb +159 -0
- data/lib/erubis/local-setting.rb +1 -1
- data/lib/erubis/main.rb +87 -46
- data/lib/erubis/tiny.rb +81 -7
- data/test/assert-text-equal.rb +1 -1
- data/test/test-engines.rb +8 -9
- data/test/test-erubis.rb +196 -18
- data/test/{test-bin.rb → test-main.rb} +123 -21
- data/test/test-notext.rb +27 -0
- data/test/test.rb +5 -3
- data/test/testutil.rb +25 -36
- metadata +75 -13
- data/COPYING +0 -340
- data/examples/example.ec +0 -24
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
##
|
|
2
|
+
## $Rev: 32 $
|
|
3
|
+
## $Release: 2.1.0 $
|
|
4
|
+
## copyright(c) 2006 kuwata-lab all rights reserved.
|
|
5
|
+
##
|
|
6
|
+
|
|
7
|
+
require 'abstract'
|
|
8
|
+
|
|
9
|
+
module Erubis
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
module Generator
|
|
13
|
+
|
|
14
|
+
def self.supported_properties() # :nodoc:
|
|
15
|
+
return [
|
|
16
|
+
[:escapefunc, nil, "escape function name"],
|
|
17
|
+
]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
attr_accessor :escapefunc
|
|
21
|
+
|
|
22
|
+
def init_generator(properties={})
|
|
23
|
+
@escapefunc = properties[:escapefunc]
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
## (abstract) escape text string
|
|
28
|
+
##
|
|
29
|
+
## ex.
|
|
30
|
+
## def escape_text(text)
|
|
31
|
+
## return text.dump
|
|
32
|
+
## # or return "'" + text.gsub(/['\\]/, '\\\\\&') + "'"
|
|
33
|
+
## end
|
|
34
|
+
def escape_text(text)
|
|
35
|
+
not_implemented
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
## return escaped expression code (ex. 'h(...)' or 'htmlspecialchars(...)')
|
|
39
|
+
def escaped_expr(code)
|
|
40
|
+
code.strip!
|
|
41
|
+
return "#{@escapefunc}(#{code})"
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
## (abstract) add @preamble to src
|
|
45
|
+
def add_preamble(src)
|
|
46
|
+
not_implemented
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
## (abstract) add text string to src
|
|
50
|
+
def add_text(src, text)
|
|
51
|
+
not_implemented
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
## (abstract) add statement code to src
|
|
55
|
+
def add_stmt(src, code)
|
|
56
|
+
not_implemented
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
## (abstract) add expression literal code to src. this is called by add_expr().
|
|
60
|
+
def add_expr_literal(src, code)
|
|
61
|
+
not_implemented
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
## (abstract) add escaped expression code to src. this is called by add_expr().
|
|
65
|
+
def add_expr_escaped(src, code)
|
|
66
|
+
not_implemented
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
## (abstract) add expression code to src for debug. this is called by add_expr().
|
|
70
|
+
def add_expr_debug(src, code)
|
|
71
|
+
not_implemented
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
## (abstract) add @postamble to src
|
|
75
|
+
def add_postamble(src)
|
|
76
|
+
not_implemented
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
end
|
data/lib/erubis/helper.rb
CHANGED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
###
|
|
2
|
+
### $Rev: 38 $
|
|
3
|
+
### $Release: 2.1.0 $
|
|
4
|
+
### copyright(c) 2006 kuwata-lab all rights reserved.
|
|
5
|
+
###
|
|
6
|
+
### = How to use Erubis in Rails
|
|
7
|
+
###
|
|
8
|
+
### 1. add the folliwng code in your 'app/controllers/application.rb'.
|
|
9
|
+
### --------------------
|
|
10
|
+
### require 'erubis/helper/rails'
|
|
11
|
+
### suffix = 'erubis'
|
|
12
|
+
### ActionView::Base.register_template_handler(suffix, Erubis::Helper::RailsTemplate)
|
|
13
|
+
### #Erubis::Helper::RailsTemplate.engine_class = Erubis::EscapedEruby ## if you want
|
|
14
|
+
### #Erubis::Helper::RailsTemplate.default_class = { :escape=>true, :escapefunc='h' }
|
|
15
|
+
### --------------------
|
|
16
|
+
### 2. restart web server.
|
|
17
|
+
### 3. change view template filename from 'file.rhtml' to 'file.erubis'.
|
|
18
|
+
### (suffix '.rhtml' is not recommended because error page of Rails is
|
|
19
|
+
### assumed to use ERB.)
|
|
20
|
+
###
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
require 'erubis'
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
module Erubis
|
|
27
|
+
|
|
28
|
+
module Helper
|
|
29
|
+
|
|
30
|
+
class RailsTemplate
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@@engine_class = Erubis::Eruby
|
|
34
|
+
|
|
35
|
+
def self.engine_class
|
|
36
|
+
@@engine_class
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def self.engine_class=(klass)
|
|
40
|
+
@@engine_class = klass
|
|
41
|
+
@@engine_instance = klass.new
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
#cattr_accessor :engine_class
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@@default_properties = { }
|
|
48
|
+
|
|
49
|
+
def self.default_properties
|
|
50
|
+
return @@default_properties
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def self.default_properties=(properties)
|
|
54
|
+
@@default_properties = properties
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
#cattr_accessor :default_properties
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def initialize(view)
|
|
61
|
+
@view = view
|
|
62
|
+
#@@engine_instance ||= @@engine_class.new(nil, @@default_properties)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def convert(template)
|
|
67
|
+
#code = @@engine_instance.convert(template)
|
|
68
|
+
#return code
|
|
69
|
+
engine = @@engine_class.new(nil, @@default_properties)
|
|
70
|
+
code = engine.convert(template)
|
|
71
|
+
return code
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def render(template, assigns)
|
|
76
|
+
## get ruby code
|
|
77
|
+
code = convert(template)
|
|
78
|
+
|
|
79
|
+
## use @view as context object
|
|
80
|
+
@view.__send__(:evaluate_assigns) #or @view.instance_eval("evaluate_assigns()")
|
|
81
|
+
context = @view
|
|
82
|
+
|
|
83
|
+
## evaluate ruby code with context object
|
|
84
|
+
if assigns && !assigns.empty?
|
|
85
|
+
return _evaluate_string(code, context, assigns)
|
|
86
|
+
else
|
|
87
|
+
return context.instance_eval(code)
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
protected
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _localvar_code(_localvars)
|
|
96
|
+
list = _localvars.collect { |_name| "#{_name} = _localvars[#{_name.inspect}]\n" }
|
|
97
|
+
code = list.join()
|
|
98
|
+
return code
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def _evaluate_string(_code, _context, _localvars)
|
|
103
|
+
eval(_localvar_code(_localvars))
|
|
104
|
+
_context.instance_eval(_code)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
end #class
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
class CachedRailsTemplate < RailsTemplate
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
@@cache_table = {}
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def render(template, assigns)
|
|
119
|
+
## template path without suffix
|
|
120
|
+
## (how to get template path name with suffix? I can't find...)
|
|
121
|
+
c = @view.controller
|
|
122
|
+
template_basename = c.template_root + "/" + c.controller_name + "/" + c.action_name
|
|
123
|
+
|
|
124
|
+
## cache template
|
|
125
|
+
proc_obj = @@cache_table[template_basename]
|
|
126
|
+
unless proc_obj
|
|
127
|
+
code = convert(template)
|
|
128
|
+
proc_obj = eval("proc do #{code} end")
|
|
129
|
+
@@cache_table[template_basename] = proc_obj
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
## use @view as context object
|
|
133
|
+
@view.__send__(:evaluate_assigns)
|
|
134
|
+
#or @view.instance_eval("evaluate_assigns()")
|
|
135
|
+
context = @view
|
|
136
|
+
|
|
137
|
+
## evaluate ruby code with context object
|
|
138
|
+
if assigns && !assigns.empty?
|
|
139
|
+
return _evaluate_proc(proc_obj, context, assigns)
|
|
140
|
+
else
|
|
141
|
+
return context.instance_eval(&proc_obj)
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
protected
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def _evaluate_proc(_proc_obj, _context, _localvars)
|
|
150
|
+
eval(_localvar_code(_localvars))
|
|
151
|
+
_context.instance_eval(&_proc_obj)
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
end #class
|
|
156
|
+
|
|
157
|
+
end #module
|
|
158
|
+
|
|
159
|
+
end #module
|
data/lib/erubis/local-setting.rb
CHANGED
data/lib/erubis/main.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
###
|
|
2
|
-
### $Rev:
|
|
3
|
-
### $Release: 2.0
|
|
2
|
+
### $Rev: 41 $
|
|
3
|
+
### $Release: 2.1.0 $
|
|
4
4
|
### copyright(c) 2006 kuwata-lab all rights reserved.
|
|
5
5
|
###
|
|
6
6
|
|
|
@@ -112,15 +112,15 @@ module Erubis
|
|
|
112
112
|
|
|
113
113
|
## action
|
|
114
114
|
action = opts.action
|
|
115
|
-
action ||= '
|
|
115
|
+
action ||= 'convert' if opts.source
|
|
116
116
|
|
|
117
117
|
## lang
|
|
118
118
|
lang = opts.lang || 'ruby'
|
|
119
|
-
action ||= '
|
|
119
|
+
action ||= 'convert' if opts.lang
|
|
120
120
|
|
|
121
121
|
## class name of Eruby
|
|
122
122
|
classname = opts.class
|
|
123
|
-
klass = get_classobj(classname, lang)
|
|
123
|
+
klass = get_classobj(classname, lang, properties[:pi])
|
|
124
124
|
|
|
125
125
|
## kanji code
|
|
126
126
|
$KCODE = opts.kanji if opts.kanji
|
|
@@ -130,31 +130,33 @@ module Erubis
|
|
|
130
130
|
context = load_yamlfiles(yamlfiles, opts)
|
|
131
131
|
|
|
132
132
|
## properties for engine
|
|
133
|
+
properties[:escape] = true if opts.escape && !properties.key?(:escape)
|
|
133
134
|
properties[:pattern] = opts.pattern if opts.pattern
|
|
134
135
|
properties[:trim] = false if opts.notrim
|
|
135
136
|
properties[:preamble] = properties[:postamble] = false if opts.bodyonly
|
|
137
|
+
properties[:pi] = nil if properties[:pi] == true
|
|
136
138
|
|
|
137
139
|
## create engine and extend enhancers
|
|
138
140
|
engine = klass.new(nil, properties)
|
|
139
141
|
enhancers = get_enhancers(opts.enhancers)
|
|
140
|
-
enhancers.push(Erubis::EscapeEnhancer) if opts.escape
|
|
142
|
+
#enhancers.push(Erubis::EscapeEnhancer) if opts.escape
|
|
141
143
|
enhancers.each do |enhancer|
|
|
142
144
|
engine.extend(enhancer)
|
|
143
145
|
engine.bipattern = properties[:bipattern] if enhancer == Erubis::BiPatternEnhancer
|
|
144
146
|
end
|
|
145
147
|
|
|
146
|
-
##
|
|
148
|
+
## convert and execute
|
|
147
149
|
val = nil
|
|
148
150
|
if filenames && !filenames.empty?
|
|
149
151
|
filenames.each do |filename|
|
|
150
152
|
test(?f, filename) or raise CommandOptionError.new("#{filename}: file not found.")
|
|
151
153
|
engine.filename = filename
|
|
152
|
-
engine.
|
|
154
|
+
engine.convert!(File.read(filename))
|
|
153
155
|
print val if val = do_action(action, engine, context, opts)
|
|
154
156
|
end
|
|
155
157
|
else
|
|
156
158
|
engine.filename = '(stdin)'
|
|
157
|
-
engine.
|
|
159
|
+
engine.convert!($stdin.read())
|
|
158
160
|
print val if val = do_action(action, engine, context, opts)
|
|
159
161
|
end
|
|
160
162
|
|
|
@@ -164,7 +166,7 @@ module Erubis
|
|
|
164
166
|
|
|
165
167
|
def do_action(action, engine, context, opts)
|
|
166
168
|
case action
|
|
167
|
-
when '
|
|
169
|
+
when 'convert'
|
|
168
170
|
s = engine.src
|
|
169
171
|
when nil, 'exec', 'execute'
|
|
170
172
|
s = opts.binding ? engine.result(context) : engine.evaluate(context)
|
|
@@ -176,42 +178,61 @@ module Erubis
|
|
|
176
178
|
|
|
177
179
|
def usage
|
|
178
180
|
command = File.basename($0)
|
|
179
|
-
s = <<
|
|
180
|
-
erubis - embedded program
|
|
181
|
+
s = <<END
|
|
182
|
+
erubis - embedded program converter for multi-language
|
|
181
183
|
Usage: #{command} [..options..] [file ...]
|
|
182
184
|
-h, --help : help
|
|
183
185
|
-v : version
|
|
184
|
-
-x :
|
|
186
|
+
-x : converted code
|
|
185
187
|
-T : don't trim spaces around '<% %>'
|
|
186
188
|
-b : body only (no preamble nor postamble)
|
|
187
189
|
-e : escape (equal to '--E Escape')
|
|
188
190
|
-p pattern : embedded pattern (default '<% %>')
|
|
189
|
-
-l lang :
|
|
190
|
-
-E
|
|
191
|
+
-l lang : convert but no execute (ruby/php/c/java/scheme/perl/js)
|
|
192
|
+
-E e1,e2,... : enhancer names (Escape, PercentLine, BiPattern, ...)
|
|
191
193
|
-I path : library include path
|
|
192
194
|
-K kanji : kanji code (euc/sjis/utf8) (default none)
|
|
193
195
|
-f file.yaml : YAML file for context values (read stdin if filename is '-')
|
|
194
196
|
-t : expand tab character in YAML file
|
|
195
197
|
-S : convert mapping key from string to symbol in YAML file
|
|
196
198
|
-B : invoke 'result(binding)' instead of 'evaluate(context)'
|
|
199
|
+
--pi=name : parse '<?name ... ?>' instead of '<% ... %>'
|
|
197
200
|
|
|
198
201
|
END
|
|
202
|
+
#'
|
|
199
203
|
# -c class : class name (XmlEruby/PercentLineEruby/...) (default Eruby)
|
|
200
204
|
# -r library : require library
|
|
201
|
-
# -a : action (
|
|
205
|
+
# -a : action (convert/execute)
|
|
202
206
|
return s
|
|
203
207
|
end
|
|
204
208
|
|
|
209
|
+
|
|
210
|
+
def collect_supported_properties(erubis_klass)
|
|
211
|
+
list = []
|
|
212
|
+
erubis_klass.ancestors.each do |klass|
|
|
213
|
+
if klass.respond_to?(:supported_properties)
|
|
214
|
+
list.concat(klass.supported_properties)
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
return list
|
|
218
|
+
end
|
|
219
|
+
|
|
205
220
|
def show_properties
|
|
206
221
|
s = "supported properties:\n"
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
222
|
+
basic_props = collect_supported_properties(Erubis::Basic::Engine)
|
|
223
|
+
pi_props = collect_supported_properties(Erubis::PI::Engine)
|
|
224
|
+
list = []
|
|
225
|
+
common_props = basic_props & pi_props
|
|
226
|
+
list << ['(common)', common_props]
|
|
227
|
+
list << ['(basic)', basic_props - common_props]
|
|
228
|
+
list << ['(pi)', pi_props - common_props]
|
|
229
|
+
%w[ruby php c java scheme perl javascript].each do |lang|
|
|
230
|
+
klass = Erubis.const_get("E#{lang}")
|
|
231
|
+
list << [lang, collect_supported_properties(klass) - basic_props]
|
|
232
|
+
end
|
|
233
|
+
list.each do |lang, props|
|
|
213
234
|
s << " * #{lang}\n"
|
|
214
|
-
|
|
235
|
+
props.each do |name, default_val, desc|
|
|
215
236
|
s << (" --%-23s : %s\n" % ["#{name}=#{default_val.inspect}", desc])
|
|
216
237
|
end
|
|
217
238
|
end
|
|
@@ -233,7 +254,7 @@ END
|
|
|
233
254
|
end
|
|
234
255
|
|
|
235
256
|
def version
|
|
236
|
-
release = ('$Release: 2.0
|
|
257
|
+
release = ('$Release: 2.1.0 $' =~ /([.\d]+)/) && $1
|
|
237
258
|
return release
|
|
238
259
|
end
|
|
239
260
|
|
|
@@ -283,27 +304,42 @@ END
|
|
|
283
304
|
return options, context
|
|
284
305
|
end
|
|
285
306
|
|
|
286
|
-
|
|
307
|
+
|
|
308
|
+
def untabify(str, width=8)
|
|
309
|
+
list = str.split(/\t/)
|
|
310
|
+
last = list.pop
|
|
287
311
|
sb = ''
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
312
|
+
list.each do |s|
|
|
313
|
+
column = (n = s.rindex(?\n)) ? s.length - n - 1 : s.length
|
|
314
|
+
n = width - (column % width)
|
|
315
|
+
sb << s << (' ' * n)
|
|
291
316
|
end
|
|
292
|
-
|
|
317
|
+
sb << last
|
|
318
|
+
return sb
|
|
293
319
|
end
|
|
294
|
-
|
|
295
|
-
def
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
320
|
+
#--
|
|
321
|
+
#def untabify(str, width=8)
|
|
322
|
+
# sb = ''
|
|
323
|
+
# str.scan(/(.*?)\t/m) do |s, |
|
|
324
|
+
# len = (n = s.rindex(?\n)) ? s.length - n - 1 : s.length
|
|
325
|
+
# sb << s << (" " * (width - len % width))
|
|
326
|
+
# end
|
|
327
|
+
# return $' ? (sb << $') : str
|
|
328
|
+
#end
|
|
329
|
+
#++
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
def get_classobj(classname, lang, pi)
|
|
333
|
+
classname ||= "E#{lang}"
|
|
334
|
+
base_module = pi ? Erubis::PI : Erubis
|
|
299
335
|
begin
|
|
300
|
-
klass =
|
|
336
|
+
klass = base_module.const_get(classname)
|
|
301
337
|
rescue NameError
|
|
302
338
|
klass = nil
|
|
303
339
|
end
|
|
304
340
|
unless klass
|
|
305
341
|
if lang
|
|
306
|
-
msg = "-l #{lang}: invalid language name (class
|
|
342
|
+
msg = "-l #{lang}: invalid language name (class #{base_module.name}::#{classname} not found)."
|
|
307
343
|
else
|
|
308
344
|
msg = "-c #{classname}: invalid class name."
|
|
309
345
|
end
|
|
@@ -342,25 +378,30 @@ END
|
|
|
342
378
|
unless ydoc.is_a?(Hash)
|
|
343
379
|
raise CommandOptionError.new("#{yamlfile}: root object is not a mapping.")
|
|
344
380
|
end
|
|
345
|
-
|
|
381
|
+
intern_hash_keys(ydoc) if opts.intern
|
|
346
382
|
hash.update(ydoc)
|
|
347
383
|
end
|
|
348
384
|
context = hash
|
|
349
385
|
return context
|
|
350
386
|
end
|
|
351
387
|
|
|
352
|
-
def
|
|
353
|
-
if
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
388
|
+
def intern_hash_keys(obj, done={})
|
|
389
|
+
return if done.key?(obj.__id__)
|
|
390
|
+
case obj
|
|
391
|
+
when Hash
|
|
392
|
+
done[obj.__id__] = obj
|
|
393
|
+
obj.keys.each do |key|
|
|
394
|
+
obj[key.intern] = obj.delete(key) if key.is_a?(String)
|
|
395
|
+
end
|
|
396
|
+
obj.values.each do |val|
|
|
397
|
+
intern_hash_keys(val, done) if val.is_a?(Hash) || val.is_a?(Array)
|
|
357
398
|
end
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
399
|
+
when Array
|
|
400
|
+
done[obj.__id__] = obj
|
|
401
|
+
obj.each do |val|
|
|
402
|
+
intern_hash_keys(val, done) if val.is_a?(Hash) || val.is_a?(Array)
|
|
361
403
|
end
|
|
362
404
|
end
|
|
363
|
-
return ydoc
|
|
364
405
|
end
|
|
365
406
|
|
|
366
407
|
end
|