kwartz 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +340 -0
- data/ChangeLog +103 -0
- data/README.txt +37 -0
- data/bin/kwartz +12 -0
- data/doc-api/classes/Kwartz.html +218 -0
- data/doc-api/classes/Kwartz/Assertion.html +140 -0
- data/doc-api/classes/Kwartz/AssertionError.html +148 -0
- data/doc-api/classes/Kwartz/AttrInfo.html +320 -0
- data/doc-api/classes/Kwartz/BaseError.html +206 -0
- data/doc-api/classes/Kwartz/BaseTranslator.html +331 -0
- data/doc-api/classes/Kwartz/CharacterType.html +212 -0
- data/doc-api/classes/Kwartz/CommandOptionError.html +154 -0
- data/doc-api/classes/Kwartz/CommandOptions.html +374 -0
- data/doc-api/classes/Kwartz/Config.html +150 -0
- data/doc-api/classes/Kwartz/ConvertError.html +191 -0
- data/doc-api/classes/Kwartz/Converter.html +252 -0
- data/doc-api/classes/Kwartz/CssStyleParser.html +483 -0
- data/doc-api/classes/Kwartz/DocumentRuleset.html +369 -0
- data/doc-api/classes/Kwartz/ElementExpander.html +325 -0
- data/doc-api/classes/Kwartz/ElementInfo.html +312 -0
- data/doc-api/classes/Kwartz/ElementRuleset.html +582 -0
- data/doc-api/classes/Kwartz/EperlHandler.html +338 -0
- data/doc-api/classes/Kwartz/EperlTranslator.html +167 -0
- data/doc-api/classes/Kwartz/ErubisHandler.html +113 -0
- data/doc-api/classes/Kwartz/ErubisTranslator.html +168 -0
- data/doc-api/classes/Kwartz/ErubyHandler.html +337 -0
- data/doc-api/classes/Kwartz/ErubyTranslator.html +167 -0
- data/doc-api/classes/Kwartz/ExpandStatement.html +227 -0
- data/doc-api/classes/Kwartz/Expression.html +119 -0
- data/doc-api/classes/Kwartz/Handler.html +558 -0
- data/doc-api/classes/Kwartz/JstlHandler.html +657 -0
- data/doc-api/classes/Kwartz/JstlTranslator.html +226 -0
- data/doc-api/classes/Kwartz/KwartzError.html +146 -0
- data/doc-api/classes/Kwartz/Main.html +384 -0
- data/doc-api/classes/Kwartz/NativeExpression.html +236 -0
- data/doc-api/classes/Kwartz/NativeStatement.html +254 -0
- data/doc-api/classes/Kwartz/Node.html +156 -0
- data/doc-api/classes/Kwartz/ParseError.html +148 -0
- data/doc-api/classes/Kwartz/PhpHandler.html +333 -0
- data/doc-api/classes/Kwartz/PhpTranslator.html +194 -0
- data/doc-api/classes/Kwartz/PresentationLogicParser.html +830 -0
- data/doc-api/classes/Kwartz/PrintStatement.html +221 -0
- data/doc-api/classes/Kwartz/RailsHandler.html +587 -0
- data/doc-api/classes/Kwartz/RailsTranslator.html +167 -0
- data/doc-api/classes/Kwartz/RubyStyleParser.html +558 -0
- data/doc-api/classes/Kwartz/Ruleset.html +117 -0
- data/doc-api/classes/Kwartz/Statement.html +119 -0
- data/doc-api/classes/Kwartz/StrutsTranslator.html +190 -0
- data/doc-api/classes/Kwartz/TagInfo.html +314 -0
- data/doc-api/classes/Kwartz/TextConverter.html +270 -0
- data/doc-api/classes/Kwartz/Translator.html +318 -0
- data/doc-api/classes/Test.html +107 -0
- data/doc-api/classes/Test/Unit.html +101 -0
- data/doc-api/created.rid +1 -0
- data/doc-api/files/__/README_txt.html +150 -0
- data/doc-api/files/kwartz/assert_rb.html +114 -0
- data/doc-api/files/kwartz/binding/eperl_rb.html +116 -0
- data/doc-api/files/kwartz/binding/erubis_rb.html +116 -0
- data/doc-api/files/kwartz/binding/eruby_rb.html +115 -0
- data/doc-api/files/kwartz/binding/jstl_rb.html +116 -0
- data/doc-api/files/kwartz/binding/php_rb.html +116 -0
- data/doc-api/files/kwartz/binding/rails_rb.html +115 -0
- data/doc-api/files/kwartz/binding/struts_rb.html +117 -0
- data/doc-api/files/kwartz/config_rb.html +107 -0
- data/doc-api/files/kwartz/converter_rb.html +119 -0
- data/doc-api/files/kwartz/error_rb.html +107 -0
- data/doc-api/files/kwartz/main_rb.html +124 -0
- data/doc-api/files/kwartz/node_rb.html +114 -0
- data/doc-api/files/kwartz/parser_rb.html +117 -0
- data/doc-api/files/kwartz/translator_rb.html +115 -0
- data/doc-api/files/kwartz/util/assert-text-equal_rb.html +115 -0
- data/doc-api/files/kwartz/util/testcase-helper_rb.html +115 -0
- data/doc-api/files/kwartz_rb.html +120 -0
- data/doc-api/fr_class_index.html +75 -0
- data/doc-api/fr_file_index.html +45 -0
- data/doc-api/fr_method_index.html +216 -0
- data/doc-api/index.html +24 -0
- data/doc-api/rdoc-style.css +208 -0
- data/doc/docstyle.css +188 -0
- data/doc/p-pattern.html +1207 -0
- data/doc/reference.html +3396 -0
- data/doc/users-guide.html +1670 -0
- data/examples/breadcrumbs1/Makefile +15 -0
- data/examples/breadcrumbs1/breadcrumbs.eruby.plogic +27 -0
- data/examples/breadcrumbs1/breadcrumbs.html +12 -0
- data/examples/breadcrumbs1/breadcrumbs.jstl.plogic +28 -0
- data/examples/breadcrumbs1/breadcrumbs.php.plogic +26 -0
- data/examples/breadcrumbs1/main.php +12 -0
- data/examples/breadcrumbs1/main.rb +12 -0
- data/examples/breadcrumbs2/Makefile +15 -0
- data/examples/breadcrumbs2/breadcrumbs.eruby.plogic +22 -0
- data/examples/breadcrumbs2/breadcrumbs.html +14 -0
- data/examples/breadcrumbs2/breadcrumbs.jstl.plogic +24 -0
- data/examples/breadcrumbs2/breadcrumbs.php.plogic +23 -0
- data/examples/breadcrumbs2/main.php +12 -0
- data/examples/breadcrumbs2/main.rb +12 -0
- data/examples/pagelayout/Makefile +47 -0
- data/examples/pagelayout/content.eruby.plogic +44 -0
- data/examples/pagelayout/content.jstl.plogic +36 -0
- data/examples/pagelayout/content.php.plogic +37 -0
- data/examples/pagelayout/content1.html +36 -0
- data/examples/pagelayout/content2.html +29 -0
- data/examples/pagelayout/design.css +40 -0
- data/examples/pagelayout/layout.html +50 -0
- data/examples/pagelayout/main.php +55 -0
- data/examples/pagelayout/main.rb +77 -0
- data/examples/pagelayout/menu.eruby.plogic +14 -0
- data/examples/pagelayout/menu.html +13 -0
- data/examples/pagelayout/menu.jstl.plogic +14 -0
- data/examples/pagelayout/menu.php.plogic +14 -0
- data/examples/rails1/Makefile +36 -0
- data/examples/rails1/README +19 -0
- data/examples/rails1/application_helper.rb +31 -0
- data/examples/rails1/edit.html +28 -0
- data/examples/rails1/edit.plogic +10 -0
- data/examples/rails1/form.html +52 -0
- data/examples/rails1/form.plogic +33 -0
- data/examples/rails1/layout.plogic +15 -0
- data/examples/rails1/link_to.plogic +19 -0
- data/examples/rails1/list.html +48 -0
- data/examples/rails1/list.plogic +28 -0
- data/examples/rails1/new.html +27 -0
- data/examples/rails1/new.plogic +10 -0
- data/examples/rails1/reader.plogic +29 -0
- data/examples/rails1/show.html +40 -0
- data/examples/rails1/show.plogic +4 -0
- data/examples/rails1/writer.plogic +8 -0
- data/examples/table1/Makefile +15 -0
- data/examples/table1/main.php +11 -0
- data/examples/table1/main.rb +11 -0
- data/examples/table1/table1.eruby.plogic +21 -0
- data/examples/table1/table1.html +16 -0
- data/examples/table1/table1.jstl.plogic +21 -0
- data/examples/table1/table1.php.plogic +22 -0
- data/kwartz.gemspec +55 -0
- data/lib/kwartz.rb +13 -0
- data/lib/kwartz/assert.rb +31 -0
- data/lib/kwartz/binding/eperl.rb +166 -0
- data/lib/kwartz/binding/erubis.rb +61 -0
- data/lib/kwartz/binding/eruby.rb +164 -0
- data/lib/kwartz/binding/jstl.rb +334 -0
- data/lib/kwartz/binding/php.rb +167 -0
- data/lib/kwartz/binding/rails.rb +295 -0
- data/lib/kwartz/binding/struts.rb +109 -0
- data/lib/kwartz/config.rb +28 -0
- data/lib/kwartz/converter.rb +920 -0
- data/lib/kwartz/error.rb +41 -0
- data/lib/kwartz/main.rb +464 -0
- data/lib/kwartz/node.rb +454 -0
- data/lib/kwartz/parser.rb +903 -0
- data/lib/kwartz/translator.rb +153 -0
- data/lib/kwartz/util/assert-text-equal.rb +44 -0
- data/lib/kwartz/util/testcase-helper.rb +112 -0
- data/setup.rb +1331 -0
- data/test/test-compile.rb +36 -0
- data/test/test-compile.yaml +178 -0
- data/test/test-converter.rb +34 -0
- data/test/test-converter.yaml +127 -0
- data/test/test-directives.rb +32 -0
- data/test/test-directives.yaml +1411 -0
- data/test/test-main.rb +464 -0
- data/test/test-parser.rb +54 -0
- data/test/test-parser.yaml +394 -0
- data/test/test-rails.rb +28 -0
- data/test/test-rails.yaml +301 -0
- data/test/test-ruleset.rb +36 -0
- data/test/test-ruleset.yaml +804 -0
- data/test/test.rb +44 -0
- metadata +236 -0
@@ -0,0 +1,334 @@
|
|
1
|
+
###
|
2
|
+
### $Rev: 116 $
|
3
|
+
### $Release: 3.0.0 $
|
4
|
+
### copyright(c) 2004-2006 kuwata-lab.com all rights reserved
|
5
|
+
###
|
6
|
+
|
7
|
+
require 'kwartz/assert'
|
8
|
+
require 'kwartz/converter'
|
9
|
+
require 'kwartz/translator'
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
module Kwartz
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
##
|
18
|
+
## directive handler for JSTL
|
19
|
+
##
|
20
|
+
class JstlHandler < Handler
|
21
|
+
|
22
|
+
|
23
|
+
def initialize(elem_rulesets=[], properties={})
|
24
|
+
super
|
25
|
+
@jstl_ver = properties[:jstl] || 1.2
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
JSTL_DIRECTIVE_PATTERN = /\A(\w+)(?:\s*\(\s*(.*)\))?\z/
|
30
|
+
|
31
|
+
def directive_pattern
|
32
|
+
return JSTL_DIRECTIVE_PATTERN
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
JSTL_MAPPING_PATTERN = /\A'([-:\w]+)',\s*(.*)\z/
|
37
|
+
|
38
|
+
def mapping_pattern
|
39
|
+
return JSTL_MAPPING_PATTERN
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
JSTL_DIRECTIVE_FORMAT = '%s(%s)'
|
44
|
+
|
45
|
+
def directive_format
|
46
|
+
return JSTL_DIRECTIVE_FORMAT
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
def handle(directive_name, directive_arg, directive_str, stag_info, etag_info, cont_stmts, attr_info, append_exprs, stmt_list)
|
51
|
+
ret = super
|
52
|
+
return ret if ret
|
53
|
+
|
54
|
+
d_name = directive_name
|
55
|
+
d_arg = directive_arg
|
56
|
+
d_str = directive_str
|
57
|
+
|
58
|
+
case directive_name
|
59
|
+
|
60
|
+
when :for, :For, :FOR, :list, :List, :LIST
|
61
|
+
is_foreach = d_name == :for || d_name == :For || d_name == :FOR
|
62
|
+
unless d_arg =~ /\A(\w+)\s*:\s*(.*)\z/
|
63
|
+
raise convert_error("'#{d_str}': invalid argument.", stag_info.linenum)
|
64
|
+
end
|
65
|
+
loopvar = $1 ; looplist = $2
|
66
|
+
counter = d_name == :for || d_name == :list ? nil : "#{loopvar}_ctr"
|
67
|
+
toggle = d_name != :FOR && d_name != :LIST ? nil : "#{loopvar}_tgl"
|
68
|
+
status = d_name == :for || d_name == :list ? nil : "#{loopvar}_status"
|
69
|
+
stmt_list << build_print_stmt(stag_info, attr_info, append_exprs) if !is_foreach
|
70
|
+
sb = "<c:forEach var=\"#{loopvar}\" items=\"${#{looplist}}\""
|
71
|
+
sb << " varStatus=\"#{status}\"" if status
|
72
|
+
sb << ">"
|
73
|
+
stmt_list << NativeStatement.new(sb, :foreach)
|
74
|
+
if counter
|
75
|
+
stmt_list << NativeStatement.new("<c:set var=\"#{counter}\" value=\"${#{status}.count}\" />")
|
76
|
+
end
|
77
|
+
if toggle
|
78
|
+
if @jstl_ver < 1.2
|
79
|
+
stmt_list << NativeStatement.new("<c:choose><c:when test=\"${#{status}.count%2==0}\">")
|
80
|
+
stmt_list << NativeStatement.new("<c:set var=\"#{toggle}\" value=\"${self.even}\"/>")
|
81
|
+
stmt_list << NativeStatement.new("</c:when><c:otherwise>")
|
82
|
+
stmt_list << NativeStatement.new("<c:set var=\"#{toggle}\" value=\"${self.odd}\"/>")
|
83
|
+
stmt_list << NativeStatement.new("</c:otherwise></c:choose>")
|
84
|
+
else
|
85
|
+
sb = "<c:set var=\"#{toggle}\" value=\"${#{status}.count%2==0 ? #{self.even} : #{self.odd}}\" />"
|
86
|
+
stmt_list << NativeStatement.new(sb)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
stmt_list << build_print_stmt(stag_info, attr_info, append_exprs) if is_foreach
|
90
|
+
stmt_list.concat(cont_stmts)
|
91
|
+
stmt_list << build_print_stmt(etag_info, nil, nil) if is_foreach
|
92
|
+
stmt_list << NativeStatement.new("</c:forEach>", :foreach)
|
93
|
+
stmt_list << build_print_stmt(etag_info, nil, nil) if !is_foreach
|
94
|
+
|
95
|
+
when :while, :loop
|
96
|
+
raise convert_error("'#{d_str}': jstl doesn't support '#{d_arg}' directive.", stag_info.linenum)
|
97
|
+
|
98
|
+
when :set
|
99
|
+
unless d_arg =~ /\A(\S+)\s*=\s*(.*)\z/
|
100
|
+
raise convert_error("'#{d_str}': invalid argument.", stag_info.linenum)
|
101
|
+
end
|
102
|
+
lhs = $1; rhs = $2
|
103
|
+
sb = "<c:set var=\"#{lhs}\" value=\"${#{rhs}}\" />"
|
104
|
+
stmt_list << NativeStatement.new(sb, :set)
|
105
|
+
stmt_list << build_print_stmt(stag_info, attr_info, append_exprs)
|
106
|
+
stmt_list.concat(cont_stmts)
|
107
|
+
stmt_list << build_print_stmt(etag_info, nil, nil)
|
108
|
+
|
109
|
+
when :if
|
110
|
+
sb = "<c:choose><c:when test=\"${#{d_arg}}\">"
|
111
|
+
stmt_list << NativeStatement.new(sb, :if)
|
112
|
+
stmt_list << build_print_stmt(stag_info, attr_info, append_exprs)
|
113
|
+
stmt_list.concat(cont_stmts)
|
114
|
+
stmt_list << build_print_stmt(etag_info, nil, nil)
|
115
|
+
stmt_list << NativeStatement.new("</c:when></c:choose>", :if)
|
116
|
+
|
117
|
+
when :elseif, :else
|
118
|
+
unless !stmt_list.empty? && (st=stmt_list[-1]).is_a?(NativeStatement) && (st.kind == :if || st.kind == :elseif)
|
119
|
+
raise convert_error("'#{d_str}': previous statement should be 'if' or 'elseif'.", stag_info.linenum)
|
120
|
+
end
|
121
|
+
stmt_list.pop # delete '</c:when></c:choose>'
|
122
|
+
if d_name == :else
|
123
|
+
kind = :else
|
124
|
+
sb = "</c:when><c:otherwise>"
|
125
|
+
stmt_list << NativeStatement.new(sb, :else)
|
126
|
+
sb = "</c:otherwise></c:choose>"
|
127
|
+
else
|
128
|
+
kind = :elseif
|
129
|
+
sb = "</c:when><c:when test=\"${#{d_arg}}\">"
|
130
|
+
stmt_list << NativeStatement.new(sb, :elseif)
|
131
|
+
sb = "</c:when></c:choose>"
|
132
|
+
end
|
133
|
+
stmt_list << build_print_stmt(stag_info, attr_info, append_exprs)
|
134
|
+
stmt_list.concat(cont_stmts)
|
135
|
+
stmt_list << build_print_stmt(etag_info, nil, nil)
|
136
|
+
stmt_list << NativeStatement.new(sb, kind)
|
137
|
+
|
138
|
+
when :default, :Default, :DEFAULT
|
139
|
+
error_if_empty_tag(stag_info, etag_info, d_name, d_arg)
|
140
|
+
stmt_list << build_print_stmt(stag_info, attr_info, append_exprs)
|
141
|
+
flag_escape = d_name == :default ? nil : (d_name == :Default)
|
142
|
+
argstr = cont_stmts[0].args[0]
|
143
|
+
sb = "<c:out value=\"${#{d_arg}}\""
|
144
|
+
sb << " escapeXml=\"#{flag_escape}\"" unless flag_escape == nil
|
145
|
+
sb << " default=#{argstr.dump} />"
|
146
|
+
stmt_list << NativeStatement.new_without_newline(sb)
|
147
|
+
stmt_list << build_print_stmt(etag_info, nil, nil)
|
148
|
+
|
149
|
+
when :catch
|
150
|
+
if d_arg && !d_arg.empty? && d_arg !~ /\A\w+\z/
|
151
|
+
raise convert_error("'#{d_str}': invalid varname.", stag_info.linenum)
|
152
|
+
end
|
153
|
+
sb = "<c:catch"
|
154
|
+
sb << " var=\"#{d_arg}\"" if d_arg && !d_arg.empty?
|
155
|
+
sb << ">"
|
156
|
+
stmt_list << NativeStatement.new(sb)
|
157
|
+
stmt_list.concat(cont_stmts)
|
158
|
+
stmt_list << NativeStatement.new("</c:catch>")
|
159
|
+
|
160
|
+
when :forEach, :forTokens
|
161
|
+
stag, etag = eval "handle_jstl_#{d_name}(#{d_arg})"
|
162
|
+
stmt_list << NativeStatement.new(stag)
|
163
|
+
stmt_list << build_print_stmt(stag_info, attr_info, append_exprs)
|
164
|
+
stmt_list.concat(cont_stmts)
|
165
|
+
stmt_list << build_print_stmt(etag_info, nil, nil)
|
166
|
+
stmt_list << NativeStatement.new(etag)
|
167
|
+
|
168
|
+
when :redirect, :import, :url, :remove
|
169
|
+
lines = eval "handle_jstl_#{d_name}(#{d_arg})"
|
170
|
+
lines.each do |line|
|
171
|
+
stmt_list << NativeStatement.new(line)
|
172
|
+
end
|
173
|
+
|
174
|
+
else
|
175
|
+
return false
|
176
|
+
|
177
|
+
end #case
|
178
|
+
return true
|
179
|
+
|
180
|
+
end #def
|
181
|
+
|
182
|
+
|
183
|
+
protected
|
184
|
+
|
185
|
+
|
186
|
+
def handle_jstl_redirect(options)
|
187
|
+
return _handle_jstl_params('redirect', %w[url context], options)
|
188
|
+
end
|
189
|
+
|
190
|
+
|
191
|
+
def handle_jstl_import(options)
|
192
|
+
return _handle_jstl_params('import', %w[url context charEncoding var scope], options)
|
193
|
+
end
|
194
|
+
|
195
|
+
|
196
|
+
def handle_jstl_url(options)
|
197
|
+
return _handle_jstl_params('url', %w[value context var scope], options)
|
198
|
+
end
|
199
|
+
|
200
|
+
|
201
|
+
def handle_jstl_remove(options)
|
202
|
+
return _handle_jstl_params('remove', %w[var scope], options)
|
203
|
+
end
|
204
|
+
|
205
|
+
|
206
|
+
def handle_jstl_forEach(options)
|
207
|
+
param_list = %w[var items varStatus begin end step]
|
208
|
+
return _handle_jstl_tag('forEach', param_list, options)
|
209
|
+
end
|
210
|
+
|
211
|
+
|
212
|
+
def handle_jstl_forTokens(options)
|
213
|
+
param_list = %w[items delims var varStatus begin end step]
|
214
|
+
return _handle_jstl_tag('forTokens', param_list, options)
|
215
|
+
end
|
216
|
+
|
217
|
+
|
218
|
+
def _handle_jstl_params(tagname, param_list, options)
|
219
|
+
stag, etag = _handle_jstl_tag(tagname, param_list, options)
|
220
|
+
lines = [stag]
|
221
|
+
i = 0
|
222
|
+
options.each do |name, value|
|
223
|
+
i += 1
|
224
|
+
if value.is_a?(Symbol)
|
225
|
+
lines << " <c:param name=\"#{name}\" value=\"${#{value}}\"/>"
|
226
|
+
else
|
227
|
+
#lines << " <c:param name=\"#{name}\" value=\"#{value}\"/>"
|
228
|
+
end
|
229
|
+
end
|
230
|
+
if i == 0
|
231
|
+
stag.sub!(/>\z/, '/>')
|
232
|
+
else
|
233
|
+
lines << etag
|
234
|
+
end
|
235
|
+
return lines
|
236
|
+
end
|
237
|
+
|
238
|
+
|
239
|
+
def _handle_jstl_tag(tagname, param_list, options)
|
240
|
+
sb = "<c:#{tagname}"
|
241
|
+
param_list.each do |param|
|
242
|
+
key = nil
|
243
|
+
if options.key?(param.intern) ; key = param.intern
|
244
|
+
elsif options.key?(param) ; key = param
|
245
|
+
end
|
246
|
+
next if key == nil
|
247
|
+
value = options.delete(key)
|
248
|
+
if value.is_a?(Symbol)
|
249
|
+
sb << " #{param}=\"${#{value}}\""
|
250
|
+
else
|
251
|
+
sb << " #{param}=\"#{value}\""
|
252
|
+
end
|
253
|
+
end
|
254
|
+
sb << ">"
|
255
|
+
stag = sb
|
256
|
+
etag = "</c:#{tagname}>"
|
257
|
+
return stag, etag
|
258
|
+
end
|
259
|
+
|
260
|
+
|
261
|
+
def _evaluate_options(options={})
|
262
|
+
return options
|
263
|
+
end
|
264
|
+
|
265
|
+
|
266
|
+
end #class
|
267
|
+
Handler.register_class('jstl', JstlHandler)
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
##
|
272
|
+
## translator for php
|
273
|
+
##
|
274
|
+
class JstlTranslator < BaseTranslator
|
275
|
+
|
276
|
+
|
277
|
+
JSTL11_EMBED_PATTERNS = [
|
278
|
+
'', '', # statement
|
279
|
+
'<c:out value="${', '}" escapeXml="false"/>', # expression
|
280
|
+
'<c:out value="${', '}"/>' # escaped expression
|
281
|
+
]
|
282
|
+
|
283
|
+
|
284
|
+
JSTL12_EMBED_PATTERNS = [
|
285
|
+
'', '', # statement
|
286
|
+
'<c:out value="${', '}" escapeXml="false"/>', # expression
|
287
|
+
'${', '}' # escaped expression
|
288
|
+
]
|
289
|
+
|
290
|
+
|
291
|
+
def initialize(properties={})
|
292
|
+
jstl_ver = properties[:jstl] || 1.2
|
293
|
+
super(jstl_ver < 1.2 ? JSTL11_EMBED_PATTERNS : JSTL12_EMBED_PATTERNS, properties)
|
294
|
+
@jstl_ver = jstl_ver
|
295
|
+
unless self.header
|
296
|
+
sb = ''
|
297
|
+
if charset = properties[:charset]
|
298
|
+
sb << "<%@ page contentType=\"text/html; charset=#{charset}\" %>" << @nl
|
299
|
+
else
|
300
|
+
#sb << "<%@ page contentType=\"text/html\" %>" << @nl
|
301
|
+
end
|
302
|
+
if @jstl_ver < 1.2
|
303
|
+
sb << '<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>' << @nl
|
304
|
+
else
|
305
|
+
sb << '<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>' << @nl
|
306
|
+
sb << '<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>' << @nl
|
307
|
+
end
|
308
|
+
self.header = sb
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
|
313
|
+
def translate_native_expr(expr)
|
314
|
+
assert unless expr.is_a?(NativeExpression)
|
315
|
+
if expr.code =~ /\A"(.*)"\z/ || expr.code =~ /\A'(.*)'\z/
|
316
|
+
@sb << $1
|
317
|
+
else
|
318
|
+
flag_escape = expr.escape?
|
319
|
+
flag_escape = @escape if flag_escape.nil?
|
320
|
+
if flag_escape == false
|
321
|
+
@sb << @expr_l << expr.code << @expr_r # ex. <c:out value="${expr}" escapeXml="false"/>
|
322
|
+
else
|
323
|
+
@sb << @escape_l << expr.code << @escape_r # ex. <c:out value="${expr}"/>
|
324
|
+
end
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
328
|
+
|
329
|
+
end
|
330
|
+
Translator.register_class('jstl', JstlTranslator)
|
331
|
+
|
332
|
+
|
333
|
+
|
334
|
+
end #module
|
@@ -0,0 +1,167 @@
|
|
1
|
+
###
|
2
|
+
### $Rev: 116 $
|
3
|
+
### $Release: 3.0.0 $
|
4
|
+
### copyright(c) 2004-2006 kuwata-lab.com all rights reserved
|
5
|
+
###
|
6
|
+
|
7
|
+
require 'kwartz/assert'
|
8
|
+
require 'kwartz/converter'
|
9
|
+
require 'kwartz/translator'
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
module Kwartz
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
##
|
18
|
+
## directive handler for PHP
|
19
|
+
##
|
20
|
+
class PhpHandler < Handler
|
21
|
+
|
22
|
+
|
23
|
+
PHP_DIRECTIVE_PATTERN = /\A(\w+)(?:\s*\(\s*(.*)\))?\z/
|
24
|
+
|
25
|
+
def directive_pattern
|
26
|
+
return PHP_DIRECTIVE_PATTERN
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
PHP_MAPPING_PATTERN = /\A'([-:\w]+)',\s*(.*)\z/
|
31
|
+
|
32
|
+
def mapping_pattern
|
33
|
+
return PHP_MAPPING_PATTERN
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
PHP_DIRECTIVE_FORMAT = '%s(%s)'
|
38
|
+
|
39
|
+
def directive_format
|
40
|
+
return PHP_DIRECTIVE_FORMAT
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
def handle(directive_name, directive_arg, directive_str, stag_info, etag_info, cont_stmts, attr_info, append_exprs, stmt_list)
|
45
|
+
ret = super
|
46
|
+
return ret if ret
|
47
|
+
|
48
|
+
d_name = directive_name
|
49
|
+
d_arg = directive_arg
|
50
|
+
d_str = directive_str
|
51
|
+
|
52
|
+
case directive_name
|
53
|
+
|
54
|
+
when :foreach, :Foreach, :FOREACH, :list, :List, :LIST
|
55
|
+
is_foreach = d_name == :foreach || d_name == :Foreach || d_name == :FOREACH
|
56
|
+
unless d_arg =~ /\A.*\s+as\s+(\$\w+)(?:\s*=>\s*\$\w+)?\z/
|
57
|
+
raise convert_error("'#{d_str}': invalid argument.", stag_info.linenum)
|
58
|
+
end
|
59
|
+
loopvar = $1
|
60
|
+
counter = d_name == :foreach || d_name == :list ? nil : "#{loopvar}_ctr"
|
61
|
+
toggle = d_name != :FOREACH && d_name != :LIST ? nil : "#{loopvar}_tgl"
|
62
|
+
stmt_list << build_print_stmt(stag_info, attr_info, append_exprs) if !is_foreach
|
63
|
+
stmt_list << NativeStatement.new("#{counter} = 0;") if counter
|
64
|
+
stmt_list << NativeStatement.new("foreach (#{d_arg}) {", :foreach)
|
65
|
+
stmt_list << NativeStatement.new(" #{counter}++;") if counter
|
66
|
+
stmt_list << NativeStatement.new(" #{toggle} = #{counter}%2==0 ? #{self.even} : #{self.odd};") if toggle
|
67
|
+
stmt_list << build_print_stmt(stag_info, attr_info, append_exprs) if is_foreach
|
68
|
+
stmt_list.concat(cont_stmts)
|
69
|
+
stmt_list << build_print_stmt(etag_info, nil, nil) if is_foreach
|
70
|
+
stmt_list << NativeStatement.new("}", :foreach)
|
71
|
+
stmt_list << build_print_stmt(etag_info, nil, nil) if !is_foreach
|
72
|
+
|
73
|
+
when :while, :loop
|
74
|
+
is_while = d_name == :while
|
75
|
+
stmt_list << build_print_stmt(stag_info, attr_info, append_exprs) if !is_while
|
76
|
+
stmt_list << NativeStatement.new("while (#{d_arg}) {", :while)
|
77
|
+
stmt_list << build_print_stmt(stag_info, attr_info, append_exprs) if is_while
|
78
|
+
stmt_list.concat(cont_stmts)
|
79
|
+
stmt_list << build_print_stmt(etag_info, nil, nil) if is_while
|
80
|
+
stmt_list << NativeStatement.new("}", :while)
|
81
|
+
stmt_list << build_print_stmt(etag_info, nil, nil) if !is_while
|
82
|
+
|
83
|
+
when :set
|
84
|
+
stmt_list << NativeStatement.new("#{d_arg};", :set)
|
85
|
+
stmt_list << build_print_stmt(stag_info, attr_info, append_exprs)
|
86
|
+
stmt_list.concat(cont_stmts)
|
87
|
+
stmt_list << build_print_stmt(etag_info, nil, nil)
|
88
|
+
|
89
|
+
when :if
|
90
|
+
stmt_list << NativeStatement.new("if (#{d_arg}) {", :if)
|
91
|
+
stmt_list << build_print_stmt(stag_info, attr_info, append_exprs)
|
92
|
+
stmt_list.concat(cont_stmts)
|
93
|
+
stmt_list << build_print_stmt(etag_info, nil, nil)
|
94
|
+
stmt_list << NativeStatement.new("}", :if)
|
95
|
+
|
96
|
+
when :elseif, :else
|
97
|
+
unless !stmt_list.empty? && (st=stmt_list[-1]).is_a?(NativeStatement) && (st.kind == :if || st.kind == :elseif)
|
98
|
+
raise convert_error("'#{d_str}': previous statement should be 'if' or 'elsif'.", stag_info.linenum)
|
99
|
+
end
|
100
|
+
stmt_list.pop # delete 'end'
|
101
|
+
if d_name == :else
|
102
|
+
kind = :else
|
103
|
+
stmt_list << NativeStatement.new("} else {", :else)
|
104
|
+
else
|
105
|
+
kind = :elseif
|
106
|
+
stmt_list << NativeStatement.new("} elseif (#{d_arg}) {", :elseif)
|
107
|
+
end
|
108
|
+
stmt_list << build_print_stmt(stag_info, attr_info, append_exprs)
|
109
|
+
stmt_list.concat(cont_stmts)
|
110
|
+
stmt_list << build_print_stmt(etag_info, nil, nil)
|
111
|
+
stmt_list << NativeStatement.new("}", kind)
|
112
|
+
|
113
|
+
when :default, :Default, :DEFAULT
|
114
|
+
error_if_empty_tag(stag_info, etag_info, d_name, d_arg)
|
115
|
+
stmt_list << build_print_stmt(stag_info, attr_info, append_exprs)
|
116
|
+
stmt_list << NativeStatement.new_without_newline("if (#{d_arg}) {", :if)
|
117
|
+
flag_escape = d_name == :default ? nil : (d_name == :Default)
|
118
|
+
stmt_list << PrintStatement.new([ NativeExpression.new(d_arg, flag_escape) ])
|
119
|
+
stmt_list << NativeStatement.new_without_newline("} else {", :else)
|
120
|
+
stmt_list.concat(cont_stmts)
|
121
|
+
stmt_list << NativeStatement.new_without_newline("}", :else)
|
122
|
+
stmt_list << build_print_stmt(etag_info, nil, nil)
|
123
|
+
|
124
|
+
else
|
125
|
+
return false
|
126
|
+
|
127
|
+
end #case
|
128
|
+
return true
|
129
|
+
|
130
|
+
end #def
|
131
|
+
|
132
|
+
|
133
|
+
end #class
|
134
|
+
Handler.register_class('php', PhpHandler)
|
135
|
+
|
136
|
+
|
137
|
+
|
138
|
+
##
|
139
|
+
## translator for php
|
140
|
+
##
|
141
|
+
class PhpTranslator < BaseTranslator
|
142
|
+
|
143
|
+
|
144
|
+
PHP_EMBED_PATTERNS = [
|
145
|
+
'<?php ', ' ?>', # statement
|
146
|
+
'<?php echo ', '; ?>', # expression
|
147
|
+
'<?php echo htmlspecialchars(', '); ?>', # escaped expression
|
148
|
+
]
|
149
|
+
|
150
|
+
|
151
|
+
def initialize(properties={})
|
152
|
+
super(PHP_EMBED_PATTERNS, properties)
|
153
|
+
end
|
154
|
+
|
155
|
+
|
156
|
+
def translate_string(str)
|
157
|
+
str.gsub!(/<\?xml/, '<<?php ?>?xml')
|
158
|
+
super(str)
|
159
|
+
end
|
160
|
+
|
161
|
+
|
162
|
+
end
|
163
|
+
Translator.register_class('php', PhpTranslator)
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
end #module
|