kwartz 3.0.0 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +36 -1
- data/LGPL +504 -0
- data/README.txt +16 -2
- data/bin/kwartz +1 -1
- data/doc-api/classes/Kwartz.html +47 -1
- data/doc-api/classes/Kwartz/Assertion.html +6 -6
- data/doc-api/classes/Kwartz/AssertionError.html +6 -6
- data/doc-api/classes/Kwartz/AttrInfo.html +42 -42
- data/doc-api/classes/Kwartz/BaseError.html +12 -12
- data/doc-api/classes/Kwartz/BaseTranslator.html +210 -43
- data/doc-api/classes/Kwartz/CharacterType.html +24 -24
- data/doc-api/classes/Kwartz/CommandOptionError.html +7 -7
- data/doc-api/classes/Kwartz/CommandOptions.html +49 -49
- data/doc-api/classes/Kwartz/Config.html +6 -1
- data/doc-api/classes/Kwartz/ConvertError.html +14 -14
- data/doc-api/classes/Kwartz/Converter.html +31 -30
- data/doc-api/classes/Kwartz/CssStyleParser.html +79 -57
- data/doc-api/classes/Kwartz/Defun.html +313 -0
- data/doc-api/classes/Kwartz/DocumentRuleset.html +58 -58
- data/doc-api/classes/Kwartz/ElementExpander.html +32 -32
- data/doc-api/classes/Kwartz/ElementInfo.html +29 -29
- data/doc-api/classes/Kwartz/ElementRuleset.html +126 -96
- data/doc-api/classes/Kwartz/EperlHandler.html +108 -84
- data/doc-api/classes/Kwartz/EperlTranslator.html +7 -7
- data/doc-api/classes/Kwartz/ErubisHandler.html +2 -2
- data/doc-api/classes/Kwartz/ErubisTranslator.html +8 -8
- data/doc-api/classes/Kwartz/ErubyHandler.html +2 -220
- data/doc-api/classes/Kwartz/ErubyTranslator.html +7 -7
- data/doc-api/classes/Kwartz/ExpandStatement.html +20 -20
- data/doc-api/classes/Kwartz/Handler.html +122 -117
- data/doc-api/classes/Kwartz/HandlerArgument.html +215 -0
- data/doc-api/classes/Kwartz/Helper.html +112 -0
- data/doc-api/classes/Kwartz/Helper/ActionViewHelper.html +221 -0
- data/doc-api/classes/Kwartz/Helper/RailsTemplate.html +630 -0
- data/doc-api/classes/Kwartz/JstlHandler.html +208 -193
- data/doc-api/classes/Kwartz/JstlTranslator.html +15 -15
- data/doc-api/classes/Kwartz/KwartzError.html +6 -6
- data/doc-api/classes/Kwartz/Main.html +39 -23
- data/doc-api/classes/Kwartz/NativeExpression.html +18 -18
- data/doc-api/classes/Kwartz/NativeStatement.html +25 -25
- data/doc-api/classes/Kwartz/Node.html +6 -6
- data/doc-api/classes/Kwartz/PIErubisHandler.html +113 -0
- data/doc-api/classes/Kwartz/PIErubisTranslator.html +200 -0
- data/doc-api/classes/Kwartz/ParseError.html +6 -6
- data/doc-api/classes/Kwartz/PhpHandler.html +102 -83
- data/doc-api/classes/Kwartz/PhpTranslator.html +14 -14
- data/doc-api/classes/Kwartz/PresentationLogicParser.html +136 -128
- data/doc-api/classes/Kwartz/PrintStatement.html +19 -19
- data/doc-api/classes/Kwartz/RailsHandler.html +121 -118
- data/doc-api/classes/Kwartz/RailsTranslator.html +7 -7
- data/doc-api/classes/Kwartz/RubyHandler.html +349 -0
- data/doc-api/classes/Kwartz/RubyStyleParser.html +85 -85
- data/doc-api/classes/Kwartz/RubyTranslator.html +218 -0
- data/doc-api/classes/Kwartz/StatementHelper.html +479 -0
- data/doc-api/classes/Kwartz/StrutsTranslator.html +12 -12
- data/doc-api/classes/Kwartz/TagInfo.html +28 -28
- data/doc-api/classes/Kwartz/TextConverter.html +28 -28
- data/doc-api/classes/Kwartz/Translator.html +42 -42
- data/doc-api/classes/Kwartz/Util.html +284 -0
- data/doc-api/created.rid +1 -1
- data/doc-api/files/__/README_txt.html +30 -3
- data/doc-api/files/kwartz/assert_rb.html +1 -1
- data/doc-api/files/kwartz/binding/eperl_rb.html +2 -2
- data/doc-api/files/kwartz/binding/erubis_rb.html +3 -3
- data/doc-api/files/kwartz/binding/eruby_rb.html +3 -2
- data/doc-api/files/kwartz/binding/jstl_rb.html +2 -2
- data/doc-api/files/kwartz/binding/php_rb.html +2 -2
- data/doc-api/files/kwartz/binding/pierubis_rb.html +116 -0
- data/doc-api/files/kwartz/binding/rails_rb.html +2 -2
- data/doc-api/files/kwartz/binding/ruby_rb.html +115 -0
- data/doc-api/files/kwartz/binding/struts_rb.html +1 -1
- data/doc-api/files/kwartz/config_rb.html +2 -2
- data/doc-api/files/kwartz/converter_rb.html +3 -2
- data/doc-api/files/kwartz/defun_rb.html +116 -0
- data/doc-api/files/kwartz/error_rb.html +1 -1
- data/doc-api/files/kwartz/helper/rails_rb.html +123 -0
- data/doc-api/files/kwartz/main_rb.html +5 -2
- data/doc-api/files/kwartz/node_rb.html +2 -2
- data/doc-api/files/kwartz/parser_rb.html +2 -2
- data/doc-api/files/kwartz/translator_rb.html +2 -2
- data/doc-api/files/kwartz/util/assert-text-equal_rb.html +1 -1
- data/doc-api/files/kwartz/util/testcase-helper_rb.html +2 -2
- data/doc-api/files/kwartz/util_rb.html +107 -0
- data/doc-api/files/kwartz_rb.html +3 -2
- data/doc-api/fr_class_index.html +11 -0
- data/doc-api/fr_file_index.html +5 -0
- data/doc-api/fr_method_index.html +242 -190
- data/doc/p-pattern.html +94 -94
- data/doc/reference.html +847 -612
- data/doc/users-guide.html +744 -241
- data/examples/rails1/README +2 -2
- data/examples/rails1/application_helper.rb +2 -27
- data/examples/rails1/link_to.plogic +5 -5
- data/examples/rails1/list.plogic +2 -2
- data/examples/rails2/app/controllers/application.rb +14 -0
- data/examples/rails2/app/controllers/groups_controller.rb +47 -0
- data/examples/rails2/app/controllers/members_controller.rb +56 -0
- data/examples/rails2/app/helpers/application_helper.rb +6 -0
- data/examples/rails2/app/helpers/groups_helper.rb +2 -0
- data/examples/rails2/app/helpers/members_helper.rb +2 -0
- data/examples/rails2/app/models/group.rb +2 -0
- data/examples/rails2/app/models/member.rb +3 -0
- data/examples/rails2/app/views/groups/_form.html +30 -0
- data/examples/rails2/app/views/groups/_form.plogic +11 -0
- data/examples/rails2/app/views/groups/_link.plogic +19 -0
- data/examples/rails2/app/views/groups/_read.plogic +7 -0
- data/examples/rails2/app/views/groups/edit.cfg.yaml +2 -0
- data/examples/rails2/app/views/groups/edit.html +26 -0
- data/examples/rails2/app/views/groups/edit.plogic +9 -0
- data/examples/rails2/app/views/groups/list.html +48 -0
- data/examples/rails2/app/views/groups/list.plogic +32 -0
- data/examples/rails2/app/views/groups/new.cfg.yaml +2 -0
- data/examples/rails2/app/views/groups/new.html +27 -0
- data/examples/rails2/app/views/groups/new.plogic +9 -0
- data/examples/rails2/app/views/groups/show.html +27 -0
- data/examples/rails2/app/views/groups/show.plogic +2 -0
- data/examples/rails2/app/views/layouts/groups.html +23 -0
- data/examples/rails2/app/views/layouts/groups.plogic +11 -0
- data/examples/rails2/app/views/layouts/members.html +23 -0
- data/examples/rails2/app/views/layouts/members.plogic +11 -0
- data/examples/rails2/app/views/layouts/members2.html +24 -0
- data/examples/rails2/app/views/layouts/members2.plogic +11 -0
- data/examples/rails2/app/views/members/_form.plogic +27 -0
- data/examples/rails2/app/views/members/_link.plogic +19 -0
- data/examples/rails2/app/views/members/_read.plogic +29 -0
- data/examples/rails2/app/views/members/edit.cfg.yaml +6 -0
- data/examples/rails2/app/views/members/edit.html +27 -0
- data/examples/rails2/app/views/members/edit.plogic +10 -0
- data/examples/rails2/app/views/members/list.html +53 -0
- data/examples/rails2/app/views/members/list.plogic +32 -0
- data/examples/rails2/app/views/members/new.html +61 -0
- data/examples/rails2/app/views/members/new.plogic +17 -0
- data/examples/rails2/app/views/members/show.html +41 -0
- data/examples/rails2/app/views/members/show.plogic +3 -0
- data/examples/rails2/db/create-tables.mysql.sql +27 -0
- data/examples/rails2/db/create-tables.pgsql.sql +27 -0
- data/examples/rails2/db/insert-data.sql +21 -0
- data/examples/rails2/db/tabledef.yaml +51 -0
- data/kwartz.gemspec +4 -4
- data/lib/kwartz.rb +10 -2
- data/lib/kwartz/assert.rb +1 -1
- data/lib/kwartz/binding/eperl.rb +85 -61
- data/lib/kwartz/binding/erubis.rb +6 -8
- data/lib/kwartz/binding/eruby.rb +5 -120
- data/lib/kwartz/binding/jstl.rb +116 -101
- data/lib/kwartz/binding/php.rb +79 -60
- data/lib/kwartz/binding/pierubis.rb +58 -0
- data/lib/kwartz/binding/rails.rb +45 -42
- data/lib/kwartz/binding/ruby.rb +193 -0
- data/lib/kwartz/binding/struts.rb +1 -1
- data/lib/kwartz/config.rb +4 -3
- data/lib/kwartz/converter.rb +231 -68
- data/lib/kwartz/defun.rb +126 -0
- data/lib/kwartz/error.rb +1 -1
- data/lib/kwartz/helper/rails.rb +437 -0
- data/lib/kwartz/main.rb +30 -38
- data/lib/kwartz/node.rb +46 -31
- data/lib/kwartz/parser.rb +43 -15
- data/lib/kwartz/translator.rb +104 -6
- data/lib/kwartz/util.rb +113 -0
- data/lib/kwartz/util/assert-text-equal.rb +1 -1
- data/lib/kwartz/util/testcase-helper.rb +26 -8
- data/test/test-compile.rb +3 -3
- data/test/test-compile.yaml +135 -5
- data/test/test-converter.rb +16 -8
- data/test/test-converter.yaml +307 -76
- data/test/test-directives.rb +1 -1
- data/test/test-directives.yaml +964 -979
- data/test/test-main.rb +61 -146
- data/test/test-main.yaml +235 -0
- data/test/test-parser.rb +10 -12
- data/test/test-parser.yaml +484 -326
- data/test/test-rails.rb +1 -1
- data/test/test-rails.yaml +37 -37
- data/test/test-ruleset.rb +1 -1
- data/test/test-ruleset.yaml +34 -40
- data/test/test.rb +1 -1
- metadata +82 -3
- data/COPYING +0 -340
data/lib/kwartz/binding/eruby.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
###
|
2
|
-
### $Rev:
|
3
|
-
### $Release: 3.
|
2
|
+
### $Rev: 124 $
|
3
|
+
### $Release: 3.1.0 $
|
4
4
|
### copyright(c) 2004-2006 kuwata-lab.com all rights reserved
|
5
5
|
###
|
6
6
|
|
7
7
|
require 'kwartz/converter'
|
8
8
|
require 'kwartz/translator'
|
9
|
+
require 'kwartz/binding/ruby'
|
9
10
|
|
10
11
|
|
11
12
|
|
@@ -16,124 +17,8 @@ module Kwartz
|
|
16
17
|
##
|
17
18
|
## directive handler for eRuby
|
18
19
|
##
|
19
|
-
class ErubyHandler <
|
20
|
-
|
21
|
-
|
22
|
-
ERUBY_DIRECTIVE_PATTERN = /\A(\w+)(?:[:\s]\s*(.*))?\z/
|
23
|
-
|
24
|
-
def directive_pattern
|
25
|
-
return ERUBY_DIRECTIVE_PATTERN
|
26
|
-
end
|
27
|
-
|
28
|
-
|
29
|
-
ERUBY_MAPPING_PATTERN = /\A'([-:\w]+)'\s+(.*)\z/
|
30
|
-
|
31
|
-
def mapping_pattern
|
32
|
-
return ERUBY_MAPPING_PATTERN
|
33
|
-
end
|
34
|
-
|
35
|
-
|
36
|
-
ERUBY_DIRECTIVE_FORMAT = '%s: %s'
|
37
|
-
|
38
|
-
def directive_format
|
39
|
-
return ERUBY_DIRECTIVE_FORMAT
|
40
|
-
end
|
41
|
-
|
42
|
-
|
43
|
-
def handle(directive_name, directive_arg, directive_str, stag_info, etag_info, cont_stmts, attr_info, append_exprs, stmt_list)
|
44
|
-
ret = super
|
45
|
-
return ret if ret
|
46
|
-
|
47
|
-
d_name = directive_name
|
48
|
-
d_arg = directive_arg
|
49
|
-
d_str = directive_str
|
50
|
-
|
51
|
-
case directive_name
|
52
|
-
|
53
|
-
when :for, :For, :FOR, :list, :List, :LIST
|
54
|
-
unless d_arg =~ /\A(\w+)(?:,\s*(\w+))?\s+in\s+(.*)\z/ || d_arg =~ /\A(\w+)(?:,(\w+))?\s*[:=]\s*(.*)\z/
|
55
|
-
raise convert_error("#'{d_str}': invalid argument.", stag_info.linenum)
|
56
|
-
end
|
57
|
-
loopvar = $1 ; loopval = $2 ; looplist = $3
|
58
|
-
is_foreach = d_name == :for || d_name == :For || d_name == :FOR
|
59
|
-
counter = d_name == :for || d_name == :list ? nil : "#{loopvar}_ctr"
|
60
|
-
toggle = d_name != :FOR && d_name != :LIST ? nil : "#{loopvar}_tgl"
|
61
|
-
stmt_list << build_print_stmt(stag_info, attr_info, append_exprs) if !is_foreach
|
62
|
-
stmt_list << NativeStatement.new("#{counter} = 0") if counter
|
63
|
-
if loopval
|
64
|
-
stmt_list << NativeStatement.new("#{looplist}.each do |#{loopvar}, #{loopval}|", :foreach)
|
65
|
-
else
|
66
|
-
stmt_list << NativeStatement.new("for #{loopvar} in #{looplist} do", :foreach)
|
67
|
-
end
|
68
|
-
stmt_list << NativeStatement.new(" #{counter} += 1") if counter
|
69
|
-
stmt_list << NativeStatement.new(" #{toggle} = #{counter}%2==0 ? #{self.even} : #{self.odd}") if toggle
|
70
|
-
stmt_list << build_print_stmt(stag_info, attr_info, append_exprs) if is_foreach
|
71
|
-
stmt_list.concat(cont_stmts)
|
72
|
-
stmt_list << build_print_stmt(etag_info, nil, nil) if is_foreach
|
73
|
-
stmt_list << NativeStatement.new("end", :foreach)
|
74
|
-
stmt_list << build_print_stmt(etag_info, nil, nil) if !is_foreach
|
75
|
-
|
76
|
-
when :while, :loop
|
77
|
-
is_while = d_name == :while
|
78
|
-
stmt_list << build_print_stmt(stag_info, attr_info, append_exprs) if !is_while
|
79
|
-
stmt_list << NativeStatement.new("while #{d_arg} do", :while)
|
80
|
-
stmt_list << build_print_stmt(stag_info, attr_info, append_exprs) if is_while
|
81
|
-
stmt_list.concat(cont_stmts)
|
82
|
-
stmt_list << build_print_stmt(etag_info, nil, nil) if is_while
|
83
|
-
stmt_list << NativeStatement.new("end", :while)
|
84
|
-
stmt_list << build_print_stmt(etag_info, nil, nil) if !is_while
|
85
|
-
|
86
|
-
when :set
|
87
|
-
stmt_list << NativeStatement.new(d_arg, :set)
|
88
|
-
stmt_list << build_print_stmt(stag_info, attr_info, append_exprs)
|
89
|
-
stmt_list.concat(cont_stmts)
|
90
|
-
stmt_list << build_print_stmt(etag_info, nil, nil)
|
91
|
-
|
92
|
-
when :if
|
93
|
-
stmt_list << NativeStatement.new("if #{d_arg} then", :if)
|
94
|
-
stmt_list << build_print_stmt(stag_info, attr_info, append_exprs)
|
95
|
-
stmt_list.concat(cont_stmts)
|
96
|
-
stmt_list << build_print_stmt(etag_info, nil, nil)
|
97
|
-
stmt_list << NativeStatement.new("end", :if)
|
98
|
-
|
99
|
-
when :elsif, :else
|
100
|
-
unless !stmt_list.empty? && (st=stmt_list[-1]).is_a?(NativeStatement) && (st.kind == :if || st.kind == :elseif)
|
101
|
-
raise convert_error("'#{d_str}': previous statement should be 'if' or 'elsif'.", stag_info.linenum)
|
102
|
-
end
|
103
|
-
stmt_list.pop # delete 'end'
|
104
|
-
if d_name == :else
|
105
|
-
kind = :else
|
106
|
-
stmt_list << NativeStatement.new("else", :else)
|
107
|
-
else
|
108
|
-
kind = :elseif
|
109
|
-
stmt_list << NativeStatement.new("elsif #{d_arg} then", :elseif)
|
110
|
-
end
|
111
|
-
stmt_list << build_print_stmt(stag_info, attr_info, append_exprs)
|
112
|
-
stmt_list.concat(cont_stmts)
|
113
|
-
stmt_list << build_print_stmt(etag_info, nil, nil)
|
114
|
-
stmt_list << NativeStatement.new("end", kind)
|
115
|
-
|
116
|
-
when :default, :Default, :DEFAULT
|
117
|
-
error_if_empty_tag(stag_info, etag_info, d_name, d_arg)
|
118
|
-
stmt_list << build_print_stmt(stag_info, attr_info, append_exprs)
|
119
|
-
stmt_list << NativeStatement.new_without_newline("if (#{d_arg}) && !(#{d_arg}).to_s.empty? then", :if)
|
120
|
-
flag_escape = d_name == :default ? nil : (d_name == :Default)
|
121
|
-
stmt_list << PrintStatement.new([ NativeExpression.new(d_arg, flag_escape) ])
|
122
|
-
stmt_list << NativeStatement.new_without_newline("else", :else)
|
123
|
-
stmt_list.concat(cont_stmts)
|
124
|
-
stmt_list << NativeStatement.new_without_newline("end", :else)
|
125
|
-
stmt_list << build_print_stmt(etag_info, nil, nil)
|
126
|
-
|
127
|
-
else
|
128
|
-
return false
|
129
|
-
|
130
|
-
end #case
|
131
|
-
return true
|
132
|
-
|
133
|
-
end #def
|
134
|
-
|
135
|
-
|
136
|
-
end #class
|
20
|
+
class ErubyHandler < RubyHandler
|
21
|
+
end
|
137
22
|
Handler.register_class('eruby', ErubyHandler)
|
138
23
|
|
139
24
|
|
data/lib/kwartz/binding/jstl.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
###
|
2
|
-
### $Rev:
|
3
|
-
### $Release: 3.
|
2
|
+
### $Rev: 123 $
|
3
|
+
### $Release: 3.1.0 $
|
4
4
|
### copyright(c) 2004-2006 kuwata-lab.com all rights reserved
|
5
5
|
###
|
6
6
|
|
@@ -22,7 +22,7 @@ module Kwartz
|
|
22
22
|
|
23
23
|
def initialize(elem_rulesets=[], properties={})
|
24
24
|
super
|
25
|
-
@jstl_ver = properties[:jstl] ||
|
25
|
+
@jstl_ver = properties[:jstl] || Config::PROPERTY_JSTL
|
26
26
|
end
|
27
27
|
|
28
28
|
|
@@ -47,128 +47,134 @@ module Kwartz
|
|
47
47
|
end
|
48
48
|
|
49
49
|
|
50
|
-
def handle(
|
50
|
+
def handle(stmt_list, handler_arg)
|
51
51
|
ret = super
|
52
52
|
return ret if ret
|
53
53
|
|
54
|
-
|
55
|
-
|
56
|
-
|
54
|
+
arg = handler_arg
|
55
|
+
d_name = arg.directive_name
|
56
|
+
d_arg = arg.directive_arg
|
57
|
+
d_str = arg.directive_str
|
57
58
|
|
58
|
-
case
|
59
|
+
case d_name
|
59
60
|
|
60
61
|
when :for, :For, :FOR, :list, :List, :LIST
|
61
62
|
is_foreach = d_name == :for || d_name == :For || d_name == :FOR
|
63
|
+
error_if_empty_tag(arg) unless is_foreach
|
62
64
|
unless d_arg =~ /\A(\w+)\s*:\s*(.*)\z/
|
63
|
-
raise convert_error("'#{d_str}': invalid argument.", stag_info.linenum)
|
65
|
+
raise convert_error("'#{d_str}': invalid argument.", arg.stag_info.linenum)
|
64
66
|
end
|
65
67
|
loopvar = $1 ; looplist = $2
|
66
68
|
counter = d_name == :for || d_name == :list ? nil : "#{loopvar}_ctr"
|
67
69
|
toggle = d_name != :FOR && d_name != :LIST ? nil : "#{loopvar}_tgl"
|
68
70
|
status = d_name == :for || d_name == :list ? nil : "#{loopvar}_status"
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
if counter
|
75
|
-
stmt_list << NativeStatement.new("<c:set var=\"#{counter}\" value=\"${#{status}.count}\" />")
|
76
|
-
end
|
71
|
+
foreach_code = "<c:forEach var=\"#{loopvar}\" items=\"${#{looplist}}\""
|
72
|
+
foreach_code << " varStatus=\"#{status}\"" if status
|
73
|
+
foreach_code << ">"
|
74
|
+
code = []
|
75
|
+
code << foreach_code
|
76
|
+
code << "<c:set var=\"#{counter}\" value=\"${#{status}.count}\"/>" if counter
|
77
77
|
if toggle
|
78
78
|
if @jstl_ver < 1.2
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
79
|
+
code << "<c:choose><c:when test=\"${#{status}.count%2==0}\">"
|
80
|
+
code << "<c:set var=\"#{toggle}\" value=\"${self.even}\"/>"
|
81
|
+
code << "</c:when><c:otherwise>"
|
82
|
+
code << "<c:set var=\"#{toggle}\" value=\"${self.odd}\"/>"
|
83
|
+
code << "</c:otherwise></c:choose>"
|
84
84
|
else
|
85
|
-
|
86
|
-
stmt_list << NativeStatement.new(sb)
|
85
|
+
code << "<c:set var=\"#{toggle}\" value=\"${#{status}.count%2==0 ? #{self.even} : #{self.odd}}\"/>"
|
87
86
|
end
|
88
87
|
end
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
88
|
+
end_code = "</c:forEach>"
|
89
|
+
if is_foreach
|
90
|
+
wrap_element_with_native_stmt(stmt_list, arg, code, end_code, :set)
|
91
|
+
else
|
92
|
+
wrap_content_with_native_stmt(stmt_list, arg, code, end_code, :set)
|
93
|
+
end
|
94
94
|
|
95
95
|
when :while, :loop
|
96
|
-
|
96
|
+
msg = "'#{d_str}': jstl doesn't support '#{d_arg}' directive."
|
97
|
+
raise convert_error(msg, arg.stag_info.linenum)
|
97
98
|
|
98
99
|
when :set
|
99
100
|
unless d_arg =~ /\A(\S+)\s*=\s*(.*)\z/
|
100
|
-
raise convert_error("'#{d_str}': invalid argument.", stag_info.linenum)
|
101
|
+
raise convert_error("'#{d_str}': invalid argument.", arg.stag_info.linenum)
|
101
102
|
end
|
102
103
|
lhs = $1; rhs = $2
|
103
|
-
|
104
|
-
stmt_list
|
105
|
-
|
106
|
-
stmt_list.
|
107
|
-
stmt_list <<
|
104
|
+
code = "<c:set var=\"#{lhs}\" value=\"${#{rhs}}\"/>"
|
105
|
+
wrap_element_with_native_stmt(stmt_list, arg, code, nil, :set)
|
106
|
+
#code = "<c:set var=\"#{lhs}\" value=\"${#{rhs}}\"/>"
|
107
|
+
#stmt_list << NativeStatement.new(code, :set)
|
108
|
+
#stmt_list << stag_stmt(arg)
|
109
|
+
#stmt_list.concat(cont_stmts)
|
110
|
+
#stmt_list << etag_stmt(arg)
|
108
111
|
|
109
112
|
when :if
|
110
|
-
|
111
|
-
|
112
|
-
stmt_list
|
113
|
-
stmt_list.
|
114
|
-
stmt_list <<
|
115
|
-
stmt_list
|
113
|
+
start_code = "<c:choose><c:when test=\"${#{d_arg}}\">"
|
114
|
+
end_code = "</c:when></c:choose>"
|
115
|
+
wrap_element_with_native_stmt(stmt_list, arg, start_code, end_code, :if)
|
116
|
+
#stmt_list << NativeStatement.new(start_code, :if)
|
117
|
+
#stmt_list << stag_stmt(arg)
|
118
|
+
#stmt_list.concat(cont_stmts)
|
119
|
+
#stmt_list << etag_stmt(arg)
|
120
|
+
#stmt_list << NativeStatement.new(end, :if)
|
116
121
|
|
117
122
|
when :elseif, :else
|
118
|
-
|
119
|
-
raise convert_error("'#{d_str}': previous statement should be 'if' or 'elseif'.", stag_info.linenum)
|
120
|
-
end
|
123
|
+
error_when_last_stmt_is_not_if(stmt_list, arg)
|
121
124
|
stmt_list.pop # delete '</c:when></c:choose>'
|
122
125
|
if d_name == :else
|
123
126
|
kind = :else
|
124
|
-
|
125
|
-
|
126
|
-
sb = "</c:otherwise></c:choose>"
|
127
|
+
start_code = "</c:when><c:otherwise>"
|
128
|
+
end_code = "</c:otherwise></c:choose>"
|
127
129
|
else
|
128
130
|
kind = :elseif
|
129
|
-
|
130
|
-
|
131
|
-
sb = "</c:when></c:choose>"
|
131
|
+
start_code = "</c:when><c:when test=\"${#{d_arg}}\">"
|
132
|
+
end_code = "</c:when></c:choose>"
|
132
133
|
end
|
133
|
-
stmt_list
|
134
|
-
stmt_list.
|
135
|
-
stmt_list <<
|
136
|
-
stmt_list
|
134
|
+
wrap_element_with_native_stmt(stmt_list, arg, start_code, end_code, kind)
|
135
|
+
#stmt_list << NativeStatement.new(start_code, kind)
|
136
|
+
#stmt_list << stag_stmt
|
137
|
+
#stmt_list.concat(cont_stmts)
|
138
|
+
#stmt_list << etag_stmt
|
139
|
+
#stmt_list << NativeStatement.new(end_code, kind)
|
137
140
|
|
138
141
|
when :default, :Default, :DEFAULT
|
139
|
-
error_if_empty_tag(
|
140
|
-
stmt_list <<
|
142
|
+
error_if_empty_tag(arg)
|
143
|
+
stmt_list << stag_stmt(arg)
|
141
144
|
flag_escape = d_name == :default ? nil : (d_name == :Default)
|
142
|
-
argstr = cont_stmts[0].args[0]
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
stmt_list << NativeStatement.new_without_newline(
|
147
|
-
stmt_list <<
|
145
|
+
argstr = arg.cont_stmts[0].args[0]
|
146
|
+
code = "<c:out value=\"${#{d_arg}}\""
|
147
|
+
code << " escapeXml=\"#{flag_escape}\"" unless flag_escape == nil
|
148
|
+
code << " default=\"#{argstr}\"/>"
|
149
|
+
stmt_list << NativeStatement.new_without_newline(code)
|
150
|
+
stmt_list << etag_stmt(arg)
|
148
151
|
|
149
152
|
when :catch
|
150
153
|
if d_arg && !d_arg.empty? && d_arg !~ /\A\w+\z/
|
151
|
-
raise convert_error("'#{d_str}': invalid varname.", stag_info.linenum)
|
154
|
+
raise convert_error("'#{d_str}': invalid varname.", arg.stag_info.linenum)
|
152
155
|
end
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
stmt_list << NativeStatement.new(
|
157
|
-
stmt_list.concat(cont_stmts)
|
156
|
+
code = "<c:catch"
|
157
|
+
code << " var=\"#{d_arg}\"" if d_arg && !d_arg.empty?
|
158
|
+
code << ">"
|
159
|
+
stmt_list << NativeStatement.new(code)
|
160
|
+
stmt_list.concat(arg.cont_stmts)
|
158
161
|
stmt_list << NativeStatement.new("</c:catch>")
|
159
162
|
|
160
163
|
when :forEach, :forTokens
|
161
|
-
|
162
|
-
|
163
|
-
stmt_list
|
164
|
-
stmt_list.
|
165
|
-
stmt_list <<
|
166
|
-
stmt_list
|
164
|
+
options = eval "{ #{d_arg} }"
|
165
|
+
stag, etag = self.__send__ "handle_jstl_#{d_name}", options
|
166
|
+
wrap_element_with_native_stmt(stmt_list, arg, stag, etag, nil)
|
167
|
+
#stmt_list << NativeStatement.new(stag)
|
168
|
+
#stmt_list << stag_stmt
|
169
|
+
#stmt_list.concat(cont_stmts)
|
170
|
+
#stmt_list << etag_stmt
|
171
|
+
#stmt_list << NativeStatement.new(etag)
|
167
172
|
|
168
173
|
when :redirect, :import, :url, :remove
|
169
|
-
|
174
|
+
options = eval "{ #{d_arg} }"
|
175
|
+
lines = self.__send__ "handle_jstl_#{d_name}", options
|
170
176
|
lines.each do |line|
|
171
|
-
stmt_list << NativeStatement.new(line)
|
177
|
+
stmt_list << NativeStatement.new(line.chomp)
|
172
178
|
end
|
173
179
|
|
174
180
|
else
|
@@ -216,39 +222,48 @@ module Kwartz
|
|
216
222
|
|
217
223
|
|
218
224
|
def _handle_jstl_params(tagname, param_list, options)
|
219
|
-
stag, etag = _handle_jstl_tag(tagname, param_list, options)
|
220
|
-
lines = [stag]
|
225
|
+
stag, etag = _handle_jstl_tag(tagname, param_list, options, true)
|
221
226
|
i = 0
|
222
|
-
options.
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
else
|
227
|
-
#lines << " <c:param name=\"#{name}\" value=\"#{value}\"/>"
|
228
|
-
end
|
229
|
-
end
|
230
|
-
if i == 0
|
231
|
-
stag.sub!(/>\z/, '/>')
|
227
|
+
unknown_param_names = options.keys - param_list
|
228
|
+
lines = []
|
229
|
+
if unknown_param_names.empty?
|
230
|
+
lines << stag.sub(/>\z/, '/>')
|
232
231
|
else
|
232
|
+
lines << stag
|
233
|
+
unknown_param_names.each do |name|
|
234
|
+
value = options[name]
|
235
|
+
if value.is_a?(Symbol)
|
236
|
+
lines << " <c:param name=\"#{name}\" value=\"${#{value}}\"/>"
|
237
|
+
else
|
238
|
+
lines << " <c:param name=\"#{name}\" value=\"#{value}\"/>"
|
239
|
+
end
|
240
|
+
end
|
233
241
|
lines << etag
|
234
242
|
end
|
235
|
-
return lines
|
243
|
+
return lines.join("\n")
|
236
244
|
end
|
237
245
|
|
238
246
|
|
239
|
-
def _handle_jstl_tag(tagname, param_list, options)
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
247
|
+
def _handle_jstl_tag(tagname, param_list, options, ignore_unknown_option=false)
|
248
|
+
options.each do |name, value|
|
249
|
+
next if name.is_a?(String)
|
250
|
+
options[name.to_s] = options.delete(name)
|
251
|
+
end
|
252
|
+
option_names = options.keys
|
253
|
+
unless ignore_unknown_option
|
254
|
+
unkown_option_names = option_names - param_list
|
255
|
+
unless unkown_option_names.empty?
|
256
|
+
msg = "'#{unkown_option_names[0]}': unknown option for '#{tagname}' directive."
|
257
|
+
raise convert_error(msg, nil) # TODO
|
245
258
|
end
|
246
|
-
|
247
|
-
|
259
|
+
end
|
260
|
+
sb = "<c:#{tagname}"
|
261
|
+
(param_list & option_names).each do |name|
|
262
|
+
value = options[name]
|
248
263
|
if value.is_a?(Symbol)
|
249
|
-
sb << " #{
|
264
|
+
sb << " #{name}=\"${#{value}}\""
|
250
265
|
else
|
251
|
-
sb << " #{
|
266
|
+
sb << " #{name}=\"#{value}\""
|
252
267
|
end
|
253
268
|
end
|
254
269
|
sb << ">"
|
@@ -289,7 +304,7 @@ module Kwartz
|
|
289
304
|
|
290
305
|
|
291
306
|
def initialize(properties={})
|
292
|
-
jstl_ver = properties[:jstl] ||
|
307
|
+
jstl_ver = properties[:jstl] || Config::PROPERTY_JSTL
|
293
308
|
super(jstl_ver < 1.2 ? JSTL11_EMBED_PATTERNS : JSTL12_EMBED_PATTERNS, properties)
|
294
309
|
@jstl_ver = jstl_ver
|
295
310
|
unless self.header
|
data/lib/kwartz/binding/php.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
###
|
2
|
-
### $Rev:
|
3
|
-
### $Release: 3.
|
2
|
+
### $Rev: 123 $
|
3
|
+
### $Release: 3.1.0 $
|
4
4
|
### copyright(c) 2004-2006 kuwata-lab.com all rights reserved
|
5
5
|
###
|
6
6
|
|
@@ -41,85 +41,104 @@ module Kwartz
|
|
41
41
|
end
|
42
42
|
|
43
43
|
|
44
|
-
def handle(
|
44
|
+
def handle(stmt_list, handler_arg)
|
45
45
|
ret = super
|
46
46
|
return ret if ret
|
47
47
|
|
48
|
-
|
49
|
-
|
50
|
-
|
48
|
+
arg = handler_arg
|
49
|
+
d_name = arg.directive_name
|
50
|
+
d_arg = arg.directive_arg
|
51
|
+
d_str = arg.directive_str
|
51
52
|
|
52
|
-
case
|
53
|
+
case d_name
|
53
54
|
|
54
55
|
when :foreach, :Foreach, :FOREACH, :list, :List, :LIST
|
55
56
|
is_foreach = d_name == :foreach || d_name == :Foreach || d_name == :FOREACH
|
56
57
|
unless d_arg =~ /\A.*\s+as\s+(\$\w+)(?:\s*=>\s*\$\w+)?\z/
|
57
|
-
raise convert_error("'#{d_str}': invalid argument.", stag_info.linenum)
|
58
|
+
raise convert_error("'#{d_str}': invalid argument.", arg.stag_info.linenum)
|
58
59
|
end
|
59
60
|
loopvar = $1
|
60
61
|
counter = d_name == :foreach || d_name == :list ? nil : "#{loopvar}_ctr"
|
61
62
|
toggle = d_name != :FOREACH && d_name != :LIST ? nil : "#{loopvar}_tgl"
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
stmt_list <<
|
76
|
-
stmt_list << NativeStatement.new("
|
77
|
-
stmt_list <<
|
78
|
-
stmt_list.concat(cont_stmts)
|
79
|
-
stmt_list <<
|
80
|
-
stmt_list << NativeStatement.new("}", :
|
81
|
-
stmt_list <<
|
63
|
+
code = []
|
64
|
+
code << "#{counter} = 0;" if counter
|
65
|
+
code << "foreach (#{d_arg}) {"
|
66
|
+
code << " #{counter}++;" if counter
|
67
|
+
code << " #{toggle} = #{counter}%2==0 ? #{@even} : #{@odd};" if toggle
|
68
|
+
if is_foreach
|
69
|
+
wrap_element_with_native_stmt(stmt_list, arg, code, "}", :foeach)
|
70
|
+
else
|
71
|
+
wrap_content_with_native_stmt(stmt_list, arg, code, "}", :foeach)
|
72
|
+
end
|
73
|
+
#stmt_list << stag_stmt(arg) if !is_foreach
|
74
|
+
#stmt_list << NativeStatement.new("#{counter} = 0;") if counter
|
75
|
+
#stmt_list << NativeStatement.new("foreach (#{d_arg}) {", :foreach)
|
76
|
+
#stmt_list << NativeStatement.new(" #{counter}++;") if counter
|
77
|
+
#stmt_list << NativeStatement.new(" #{toggle} = #{counter}%2==0 ? #{self.even} : #{self.odd};") if toggle
|
78
|
+
#stmt_list << stag_stmt(arg) if is_foreach
|
79
|
+
#stmt_list.concat(arg.cont_stmts)
|
80
|
+
#stmt_list << etag_stmt(arg) if is_foreach
|
81
|
+
#stmt_list << NativeStatement.new("}", :foreach)
|
82
|
+
#stmt_list << etag_stmt(arg) if !is_foreach
|
83
|
+
|
84
|
+
when :while
|
85
|
+
wrap_element_with_native_stmt(stmt_list, arg, "while (#{d_arg}) {", "}", :while)
|
86
|
+
#stmt_list << NativeStatement.new("while (#{d_arg}) {", :while)
|
87
|
+
#stmt_list << stag_stmt
|
88
|
+
#stmt_list.concat(cont_stmts)
|
89
|
+
#stmt_list << etag_stmt
|
90
|
+
#stmt_list << NativeStatement.new("}", :while)
|
91
|
+
|
92
|
+
when :loop
|
93
|
+
error_if_empty_tag(arg)
|
94
|
+
wrap_content_with_native_stmt(stmt_list, arg, "while (#{d_arg}) {", "}", :while)
|
95
|
+
#stmt_list << stag_stmt
|
96
|
+
#stmt_list << NativeStatement.new("while (#{d_arg}) {", :while)
|
97
|
+
#stmt_list.concat(cont_stmts)
|
98
|
+
#stmt_list << NativeStatement.new("}", :while)
|
99
|
+
#stmt_list << etag_stmt
|
82
100
|
|
83
101
|
when :set
|
84
|
-
stmt_list
|
85
|
-
stmt_list <<
|
86
|
-
stmt_list
|
87
|
-
stmt_list
|
102
|
+
wrap_element_with_native_stmt(stmt_list, arg, "#{d_arg};", nil, :set)
|
103
|
+
#stmt_list << NativeStatement.new("#{d_arg};", :set)
|
104
|
+
#stmt_list << stag_stmt
|
105
|
+
#stmt_list.concat(cont_stmts)
|
106
|
+
#stmt_list << etag_stmt
|
88
107
|
|
89
108
|
when :if
|
90
|
-
stmt_list
|
91
|
-
stmt_list <<
|
92
|
-
stmt_list
|
93
|
-
stmt_list
|
94
|
-
stmt_list <<
|
109
|
+
wrap_element_with_native_stmt(stmt_list, arg, "if (#{d_arg}) {", "}", :if)
|
110
|
+
#stmt_list << NativeStatement.new("if (#{d_arg}) {", :if)
|
111
|
+
#stmt_list << stag_stmt
|
112
|
+
#stmt_list.concat(cont_stmts)
|
113
|
+
#stmt_list << etag_stmt
|
114
|
+
#stmt_list << NativeStatement.new("}", :if)
|
95
115
|
|
96
116
|
when :elseif, :else
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
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)
|
117
|
+
error_when_last_stmt_is_not_if(stmt_list, arg)
|
118
|
+
stmt_list.pop # delete '}'
|
119
|
+
kind = d_name == :else ? :else : :elseif
|
120
|
+
code = d_name == :else ? "} else {" : "} elseif (#{d_arg}) {"
|
121
|
+
wrap_element_with_native_stmt(stmt_list, arg, code, "}", kind)
|
122
|
+
#stmt_list << NativeStatement.new(code, kind)
|
123
|
+
#stmt_list << stag_stmt
|
124
|
+
#stmt_list.concat(cont_stmts)
|
125
|
+
#stmt_list << etag_stmt
|
126
|
+
#stmt_list << NativeStatement.new("}", kind)
|
112
127
|
|
113
128
|
when :default, :Default, :DEFAULT
|
114
|
-
error_if_empty_tag(
|
115
|
-
|
116
|
-
stmt_list << NativeStatement.new_without_newline("if (#{d_arg}) {", :if)
|
129
|
+
error_if_empty_tag(arg)
|
130
|
+
expr_code = d_arg
|
117
131
|
flag_escape = d_name == :default ? nil : (d_name == :Default)
|
118
|
-
stmt_list
|
119
|
-
|
120
|
-
stmt_list
|
121
|
-
stmt_list << NativeStatement.new_without_newline("}", :
|
122
|
-
|
132
|
+
add_native_expr_with_default(stmt_list, arg, expr_code, flag_escape,
|
133
|
+
"if (#{d_arg}) {", "} else {", "}")
|
134
|
+
#stmt_list << stag_stmt(arg)
|
135
|
+
#stmt_list << NativeStatement.new_without_newline("if (#{d_arg}) {", :if)
|
136
|
+
#flag_escape = d_name == :default ? nil : (d_name == :Default)
|
137
|
+
#stmt_list << PrintStatement.new([ NativeExpression.new(d_arg, flag_escape) ])
|
138
|
+
#stmt_list << NativeStatement.new_without_newline("} else {", :else)
|
139
|
+
#stmt_list.concat(arg.cont_stmts)
|
140
|
+
#stmt_list << NativeStatement.new_without_newline("}", :else)
|
141
|
+
#stmt_list << etag_stmt(arg)
|
123
142
|
|
124
143
|
else
|
125
144
|
return false
|