kwartz 3.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. data/ChangeLog +36 -1
  2. data/LGPL +504 -0
  3. data/README.txt +16 -2
  4. data/bin/kwartz +1 -1
  5. data/doc-api/classes/Kwartz.html +47 -1
  6. data/doc-api/classes/Kwartz/Assertion.html +6 -6
  7. data/doc-api/classes/Kwartz/AssertionError.html +6 -6
  8. data/doc-api/classes/Kwartz/AttrInfo.html +42 -42
  9. data/doc-api/classes/Kwartz/BaseError.html +12 -12
  10. data/doc-api/classes/Kwartz/BaseTranslator.html +210 -43
  11. data/doc-api/classes/Kwartz/CharacterType.html +24 -24
  12. data/doc-api/classes/Kwartz/CommandOptionError.html +7 -7
  13. data/doc-api/classes/Kwartz/CommandOptions.html +49 -49
  14. data/doc-api/classes/Kwartz/Config.html +6 -1
  15. data/doc-api/classes/Kwartz/ConvertError.html +14 -14
  16. data/doc-api/classes/Kwartz/Converter.html +31 -30
  17. data/doc-api/classes/Kwartz/CssStyleParser.html +79 -57
  18. data/doc-api/classes/Kwartz/Defun.html +313 -0
  19. data/doc-api/classes/Kwartz/DocumentRuleset.html +58 -58
  20. data/doc-api/classes/Kwartz/ElementExpander.html +32 -32
  21. data/doc-api/classes/Kwartz/ElementInfo.html +29 -29
  22. data/doc-api/classes/Kwartz/ElementRuleset.html +126 -96
  23. data/doc-api/classes/Kwartz/EperlHandler.html +108 -84
  24. data/doc-api/classes/Kwartz/EperlTranslator.html +7 -7
  25. data/doc-api/classes/Kwartz/ErubisHandler.html +2 -2
  26. data/doc-api/classes/Kwartz/ErubisTranslator.html +8 -8
  27. data/doc-api/classes/Kwartz/ErubyHandler.html +2 -220
  28. data/doc-api/classes/Kwartz/ErubyTranslator.html +7 -7
  29. data/doc-api/classes/Kwartz/ExpandStatement.html +20 -20
  30. data/doc-api/classes/Kwartz/Handler.html +122 -117
  31. data/doc-api/classes/Kwartz/HandlerArgument.html +215 -0
  32. data/doc-api/classes/Kwartz/Helper.html +112 -0
  33. data/doc-api/classes/Kwartz/Helper/ActionViewHelper.html +221 -0
  34. data/doc-api/classes/Kwartz/Helper/RailsTemplate.html +630 -0
  35. data/doc-api/classes/Kwartz/JstlHandler.html +208 -193
  36. data/doc-api/classes/Kwartz/JstlTranslator.html +15 -15
  37. data/doc-api/classes/Kwartz/KwartzError.html +6 -6
  38. data/doc-api/classes/Kwartz/Main.html +39 -23
  39. data/doc-api/classes/Kwartz/NativeExpression.html +18 -18
  40. data/doc-api/classes/Kwartz/NativeStatement.html +25 -25
  41. data/doc-api/classes/Kwartz/Node.html +6 -6
  42. data/doc-api/classes/Kwartz/PIErubisHandler.html +113 -0
  43. data/doc-api/classes/Kwartz/PIErubisTranslator.html +200 -0
  44. data/doc-api/classes/Kwartz/ParseError.html +6 -6
  45. data/doc-api/classes/Kwartz/PhpHandler.html +102 -83
  46. data/doc-api/classes/Kwartz/PhpTranslator.html +14 -14
  47. data/doc-api/classes/Kwartz/PresentationLogicParser.html +136 -128
  48. data/doc-api/classes/Kwartz/PrintStatement.html +19 -19
  49. data/doc-api/classes/Kwartz/RailsHandler.html +121 -118
  50. data/doc-api/classes/Kwartz/RailsTranslator.html +7 -7
  51. data/doc-api/classes/Kwartz/RubyHandler.html +349 -0
  52. data/doc-api/classes/Kwartz/RubyStyleParser.html +85 -85
  53. data/doc-api/classes/Kwartz/RubyTranslator.html +218 -0
  54. data/doc-api/classes/Kwartz/StatementHelper.html +479 -0
  55. data/doc-api/classes/Kwartz/StrutsTranslator.html +12 -12
  56. data/doc-api/classes/Kwartz/TagInfo.html +28 -28
  57. data/doc-api/classes/Kwartz/TextConverter.html +28 -28
  58. data/doc-api/classes/Kwartz/Translator.html +42 -42
  59. data/doc-api/classes/Kwartz/Util.html +284 -0
  60. data/doc-api/created.rid +1 -1
  61. data/doc-api/files/__/README_txt.html +30 -3
  62. data/doc-api/files/kwartz/assert_rb.html +1 -1
  63. data/doc-api/files/kwartz/binding/eperl_rb.html +2 -2
  64. data/doc-api/files/kwartz/binding/erubis_rb.html +3 -3
  65. data/doc-api/files/kwartz/binding/eruby_rb.html +3 -2
  66. data/doc-api/files/kwartz/binding/jstl_rb.html +2 -2
  67. data/doc-api/files/kwartz/binding/php_rb.html +2 -2
  68. data/doc-api/files/kwartz/binding/pierubis_rb.html +116 -0
  69. data/doc-api/files/kwartz/binding/rails_rb.html +2 -2
  70. data/doc-api/files/kwartz/binding/ruby_rb.html +115 -0
  71. data/doc-api/files/kwartz/binding/struts_rb.html +1 -1
  72. data/doc-api/files/kwartz/config_rb.html +2 -2
  73. data/doc-api/files/kwartz/converter_rb.html +3 -2
  74. data/doc-api/files/kwartz/defun_rb.html +116 -0
  75. data/doc-api/files/kwartz/error_rb.html +1 -1
  76. data/doc-api/files/kwartz/helper/rails_rb.html +123 -0
  77. data/doc-api/files/kwartz/main_rb.html +5 -2
  78. data/doc-api/files/kwartz/node_rb.html +2 -2
  79. data/doc-api/files/kwartz/parser_rb.html +2 -2
  80. data/doc-api/files/kwartz/translator_rb.html +2 -2
  81. data/doc-api/files/kwartz/util/assert-text-equal_rb.html +1 -1
  82. data/doc-api/files/kwartz/util/testcase-helper_rb.html +2 -2
  83. data/doc-api/files/kwartz/util_rb.html +107 -0
  84. data/doc-api/files/kwartz_rb.html +3 -2
  85. data/doc-api/fr_class_index.html +11 -0
  86. data/doc-api/fr_file_index.html +5 -0
  87. data/doc-api/fr_method_index.html +242 -190
  88. data/doc/p-pattern.html +94 -94
  89. data/doc/reference.html +847 -612
  90. data/doc/users-guide.html +744 -241
  91. data/examples/rails1/README +2 -2
  92. data/examples/rails1/application_helper.rb +2 -27
  93. data/examples/rails1/link_to.plogic +5 -5
  94. data/examples/rails1/list.plogic +2 -2
  95. data/examples/rails2/app/controllers/application.rb +14 -0
  96. data/examples/rails2/app/controllers/groups_controller.rb +47 -0
  97. data/examples/rails2/app/controllers/members_controller.rb +56 -0
  98. data/examples/rails2/app/helpers/application_helper.rb +6 -0
  99. data/examples/rails2/app/helpers/groups_helper.rb +2 -0
  100. data/examples/rails2/app/helpers/members_helper.rb +2 -0
  101. data/examples/rails2/app/models/group.rb +2 -0
  102. data/examples/rails2/app/models/member.rb +3 -0
  103. data/examples/rails2/app/views/groups/_form.html +30 -0
  104. data/examples/rails2/app/views/groups/_form.plogic +11 -0
  105. data/examples/rails2/app/views/groups/_link.plogic +19 -0
  106. data/examples/rails2/app/views/groups/_read.plogic +7 -0
  107. data/examples/rails2/app/views/groups/edit.cfg.yaml +2 -0
  108. data/examples/rails2/app/views/groups/edit.html +26 -0
  109. data/examples/rails2/app/views/groups/edit.plogic +9 -0
  110. data/examples/rails2/app/views/groups/list.html +48 -0
  111. data/examples/rails2/app/views/groups/list.plogic +32 -0
  112. data/examples/rails2/app/views/groups/new.cfg.yaml +2 -0
  113. data/examples/rails2/app/views/groups/new.html +27 -0
  114. data/examples/rails2/app/views/groups/new.plogic +9 -0
  115. data/examples/rails2/app/views/groups/show.html +27 -0
  116. data/examples/rails2/app/views/groups/show.plogic +2 -0
  117. data/examples/rails2/app/views/layouts/groups.html +23 -0
  118. data/examples/rails2/app/views/layouts/groups.plogic +11 -0
  119. data/examples/rails2/app/views/layouts/members.html +23 -0
  120. data/examples/rails2/app/views/layouts/members.plogic +11 -0
  121. data/examples/rails2/app/views/layouts/members2.html +24 -0
  122. data/examples/rails2/app/views/layouts/members2.plogic +11 -0
  123. data/examples/rails2/app/views/members/_form.plogic +27 -0
  124. data/examples/rails2/app/views/members/_link.plogic +19 -0
  125. data/examples/rails2/app/views/members/_read.plogic +29 -0
  126. data/examples/rails2/app/views/members/edit.cfg.yaml +6 -0
  127. data/examples/rails2/app/views/members/edit.html +27 -0
  128. data/examples/rails2/app/views/members/edit.plogic +10 -0
  129. data/examples/rails2/app/views/members/list.html +53 -0
  130. data/examples/rails2/app/views/members/list.plogic +32 -0
  131. data/examples/rails2/app/views/members/new.html +61 -0
  132. data/examples/rails2/app/views/members/new.plogic +17 -0
  133. data/examples/rails2/app/views/members/show.html +41 -0
  134. data/examples/rails2/app/views/members/show.plogic +3 -0
  135. data/examples/rails2/db/create-tables.mysql.sql +27 -0
  136. data/examples/rails2/db/create-tables.pgsql.sql +27 -0
  137. data/examples/rails2/db/insert-data.sql +21 -0
  138. data/examples/rails2/db/tabledef.yaml +51 -0
  139. data/kwartz.gemspec +4 -4
  140. data/lib/kwartz.rb +10 -2
  141. data/lib/kwartz/assert.rb +1 -1
  142. data/lib/kwartz/binding/eperl.rb +85 -61
  143. data/lib/kwartz/binding/erubis.rb +6 -8
  144. data/lib/kwartz/binding/eruby.rb +5 -120
  145. data/lib/kwartz/binding/jstl.rb +116 -101
  146. data/lib/kwartz/binding/php.rb +79 -60
  147. data/lib/kwartz/binding/pierubis.rb +58 -0
  148. data/lib/kwartz/binding/rails.rb +45 -42
  149. data/lib/kwartz/binding/ruby.rb +193 -0
  150. data/lib/kwartz/binding/struts.rb +1 -1
  151. data/lib/kwartz/config.rb +4 -3
  152. data/lib/kwartz/converter.rb +231 -68
  153. data/lib/kwartz/defun.rb +126 -0
  154. data/lib/kwartz/error.rb +1 -1
  155. data/lib/kwartz/helper/rails.rb +437 -0
  156. data/lib/kwartz/main.rb +30 -38
  157. data/lib/kwartz/node.rb +46 -31
  158. data/lib/kwartz/parser.rb +43 -15
  159. data/lib/kwartz/translator.rb +104 -6
  160. data/lib/kwartz/util.rb +113 -0
  161. data/lib/kwartz/util/assert-text-equal.rb +1 -1
  162. data/lib/kwartz/util/testcase-helper.rb +26 -8
  163. data/test/test-compile.rb +3 -3
  164. data/test/test-compile.yaml +135 -5
  165. data/test/test-converter.rb +16 -8
  166. data/test/test-converter.yaml +307 -76
  167. data/test/test-directives.rb +1 -1
  168. data/test/test-directives.yaml +964 -979
  169. data/test/test-main.rb +61 -146
  170. data/test/test-main.yaml +235 -0
  171. data/test/test-parser.rb +10 -12
  172. data/test/test-parser.yaml +484 -326
  173. data/test/test-rails.rb +1 -1
  174. data/test/test-rails.yaml +37 -37
  175. data/test/test-ruleset.rb +1 -1
  176. data/test/test-ruleset.yaml +34 -40
  177. data/test/test.rb +1 -1
  178. metadata +82 -3
  179. data/COPYING +0 -340
@@ -1,11 +1,12 @@
1
1
  ###
2
- ### $Rev: 111 $
3
- ### $Release: 3.0.0 $
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 < Handler
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
 
@@ -1,6 +1,6 @@
1
1
  ###
2
- ### $Rev: 116 $
3
- ### $Release: 3.0.0 $
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] || 1.2
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(directive_name, directive_arg, directive_str, stag_info, etag_info, cont_stmts, attr_info, append_exprs, stmt_list)
50
+ def handle(stmt_list, handler_arg)
51
51
  ret = super
52
52
  return ret if ret
53
53
 
54
- d_name = directive_name
55
- d_arg = directive_arg
56
- d_str = directive_str
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 directive_name
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
- 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
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
- 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>")
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
- sb = "<c:set var=\"#{toggle}\" value=\"${#{status}.count%2==0 ? #{self.even} : #{self.odd}}\" />"
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
- 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
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
- raise convert_error("'#{d_str}': jstl doesn't support '#{d_arg}' directive.", stag_info.linenum)
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
- 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)
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
- 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)
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
- 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
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
- sb = "</c:when><c:otherwise>"
125
- stmt_list << NativeStatement.new(sb, :else)
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
- sb = "</c:when><c:when test=\"${#{d_arg}}\">"
130
- stmt_list << NativeStatement.new(sb, :elseif)
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 << 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)
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(stag_info, etag_info, d_name, d_arg)
140
- stmt_list << build_print_stmt(stag_info, attr_info, append_exprs)
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
- 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)
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
- 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)
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
- 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)
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
- lines = eval "handle_jstl_#{d_name}(#{d_arg})"
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.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/, '/>')
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
- 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
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
- next if key == nil
247
- value = options.delete(key)
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 << " #{param}=\"${#{value}}\""
264
+ sb << " #{name}=\"${#{value}}\""
250
265
  else
251
- sb << " #{param}=\"#{value}\""
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] || 1.2
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
@@ -1,6 +1,6 @@
1
1
  ###
2
- ### $Rev: 116 $
3
- ### $Release: 3.0.0 $
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(directive_name, directive_arg, directive_str, stag_info, etag_info, cont_stmts, attr_info, append_exprs, stmt_list)
44
+ def handle(stmt_list, handler_arg)
45
45
  ret = super
46
46
  return ret if ret
47
47
 
48
- d_name = directive_name
49
- d_arg = directive_arg
50
- d_str = directive_str
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 directive_name
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
- 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
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 << 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)
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 << 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)
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
- 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)
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(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)
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 << 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)
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