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
@@ -0,0 +1,58 @@
1
+ ###
2
+ ### $Rev: 137 $
3
+ ### $Release: 3.1.0 $
4
+ ### copyright(c) 2004-2006 kuwata-lab.com all rights reserved
5
+ ###
6
+
7
+ require 'kwartz/converter'
8
+ require 'kwartz/translator'
9
+ require 'kwartz/binding/ruby'
10
+
11
+
12
+
13
+ module Kwartz
14
+
15
+
16
+
17
+ class PIErubisHandler < RubyHandler
18
+ end
19
+ Handler.register_class('pierubis', PIErubisHandler)
20
+
21
+
22
+
23
+ ##
24
+ ## translator for Erubis
25
+ ##
26
+ class PIErubisTranslator < BaseTranslator
27
+
28
+
29
+ PIERUBIS_EMBED_PATTERNS = [
30
+ '<?rb ', ' ?>', # statement
31
+ '@!{', '}@', # expression
32
+ '@{', '}@', # escaped expression
33
+ ]
34
+
35
+
36
+ def initialize(properties={})
37
+ super(PIERUBIS_EMBED_PATTERNS, properties)
38
+ #@escape = true if @escape == nil
39
+ end
40
+
41
+
42
+ def translate_native_expr(expr)
43
+ assert unless expr.is_a?(NativeExpression)
44
+ if expr.code.include?(?}) || expr.code.include?(?>)
45
+ @expr_l, @expr_r, @escape_l, @escape_r = '<%=', '%>', '<%==', '%>'
46
+ else
47
+ @expr_l, @expr_r, @escape_l, @escape_r = '@!{', '}@', '@{', '}@'
48
+ end
49
+ super(expr)
50
+ end
51
+
52
+
53
+ end
54
+ Translator.register_class('pierubis', PIErubisTranslator)
55
+
56
+
57
+
58
+ end #module
@@ -1,6 +1,6 @@
1
1
  ###
2
- ### $Rev: 110 $
3
- ### $Release: 3.0.0 $
2
+ ### $Rev: 135 $
3
+ ### $Release: 3.1.0 $
4
4
  ### copyright(c) 2004-2006 kuwata-lab.com all rights reserved
5
5
  ###
6
6
 
@@ -23,65 +23,65 @@ module Kwartz
23
23
  ## directive examples.
24
24
  ##
25
25
  ## ## text_field, password_field
26
- ## <input type="text" size="10" maxsize="20" title="text_field 'user', 'name'">
26
+ ## <input type="text" size="10" maxsize="20" kw:d="text_field 'user', 'name'">
27
27
  ## => <%= text_field 'user', 'name', :size=>10, :maxsize=>20 %>
28
- ## <input type="text" name="user[name]" title="text_field :size=>10">
28
+ ## <input type="text" name="user[name]" kw:d="text_field :size=>10">
29
29
  ## => <%= text_field "user", "name", :size=>10 %>
30
- ## <input type="text" id="user_name" size="10" title="text_field">
30
+ ## <input type="text" id="user_name" size="10" kw:d="text_field">
31
31
  ## => <%= text_field "user", "name", :size=>10 %>
32
32
  ##
33
33
  ## ## link_to, link_to_remote
34
- ## <a href="#" title="link_to :action=>'list'">Show list</a>
34
+ ## <a href="#" kw:d="link_to :action=>'list'">Show list</a>
35
35
  ## => <%= link_to 'Show list', :action=>'list' %>
36
36
  ##
37
- ## ## start_link_to, start_link_to_remote
38
- ## <a href="#" title="start_link_to :action=>'list'">Show list</a>
39
- ## => <%= start_link_to 'action'=>'list' %>Show list</a>
37
+ ## ## start_link_tag, start_remote_link_tag
38
+ ## <a href="#" kw:d="start_link_tag :action=>'list'">Show list</a>
39
+ ## => <%= start_link_tag 'action'=>'list' %>Show list</a>
40
40
  ##
41
41
  ## ## mail_to
42
- ## <a href="mail:www@example.com" title="mail_to">admin</a>
42
+ ## <a href="mail:www@example.com" kw:d="mail_to">admin</a>
43
43
  ## => <%= mail_to "www@example.com", "admin" %>
44
44
  ##
45
45
  ## ## form_tag
46
- ## <form action="show" title="form_tag :id=>2"> ... </form>
46
+ ## <form action="show" kw:d="form_tag :id=>2"> ... </form>
47
47
  ## => <%= form_tag :action=>"show", :id=>2 %> ... </form>
48
48
  ##
49
49
  ## ## submit_tag
50
- ## <input type="submit" value="OK" title="submit_tag">
50
+ ## <input type="submit" value="OK" kw:d="submit_tag">
51
51
  ## => <%= submit_tag "OK" %>
52
52
  ##
53
53
  ## ## text_area
54
- ## <textarea cols="30" rows="3" id="user_desc" title="text_area"></textarea>
54
+ ## <textarea cols="30" rows="3" id="user_desc" kw:d="text_area"></textarea>
55
55
  ## => <%= text_area "user", "desc", :cols=>30, :rows=>3 %>
56
- ## <textarea cols="30" rows="3" name="user[desc]" title="text_area"></textarea>
56
+ ## <textarea cols="30" rows="3" name="user[desc]" kw:d="text_area"></textarea>
57
57
  ## => <%= text_area "user", "desc", :cols=>30, :rows=>3 %>
58
58
  ##
59
59
  ## ## hidden_field
60
- ## <input type="hidden" id="user_id" title="hidden_field">
60
+ ## <input type="hidden" id="user_id" kw:d="hidden_field">
61
61
  ## => <%= hidden_field "user", "id" %>
62
- ## <input type="hidden" name="user[id]" title="hidden_field">
62
+ ## <input type="hidden" name="user[id]" kw:d="hidden_field">
63
63
  ## => <%= hidden_field "user", "id" %>
64
64
  ##
65
65
  ## ## check_box
66
- ## <input type="checkbox" id="user_chk1" title="check_box">
66
+ ## <input type="checkbox" id="user_chk1" kw:d="check_box">
67
67
  ## => <%= check_box "user", "chk1" %>
68
- ## <input type="checkbox" name="user[chk2]" title="check_box">
68
+ ## <input type="checkbox" name="user[chk2]" kw:d="check_box">
69
69
  ## => <%= check_box "user", "chk2" %>
70
70
  ##
71
71
  ## ## radio_button
72
- ## <input type="radio" id="user_radio" value="val1" title="radio_button">
72
+ ## <input type="radio" id="user_radio" value="val1" kw:d="radio_button">
73
73
  ## => <%= radio_button "user", "radio", "val1" %>
74
- ## <input type="radio" name="user[radio]" value="val2" title="radio_button">
74
+ ## <input type="radio" name="user[radio]" value="val2" kw:d="radio_button">
75
75
  ## => <%= radio_button "user", "radio", "val2" %>
76
76
  ##
77
77
  ## ## select, collection_select, country_select, time_zone_select, date_select, datetime_select
78
- ## <select name="user[birth]" title="date_select :start_year=>1970">
78
+ ## <select name="user[birth]" kw:d="date_select :start_year=>1970">
79
79
  ## <option value="2000">2000</option>
80
80
  ## </select>
81
81
  ## => <% date_select "user", "birth", :start_year=>1970 %>
82
82
  ##
83
83
  ## ## image_tag, link_image_to, link_to_image
84
- ## <img src="foo.gif" alt="text" width="20" heigth="10" title="image_tag :size=>'30x40'">
84
+ ## <img src="foo.gif" alt="text" width="20" heigth="10" kw:d="image_tag :size=>'30x40'">
85
85
  ## => <%= image_tag "foo.gif", :alt=>"text", :size=>'30x40' %>
86
86
  ##
87
87
 
@@ -93,16 +93,18 @@ module Kwartz
93
93
  ##
94
94
  ## everytime return true whenever directive name is unknown.
95
95
  ##
96
- def handle(directive_name, directive_arg, directive_str, stag_info, etag_info, cont_stmts, attr_info, append_exprs, stmt_list)
96
+ def handle(stmt_list, handler_arg)
97
97
  ret = super
98
98
  return ret if ret
99
99
 
100
- d_name = directive_name
101
- d_arg = directive_arg
102
- d_str = directive_str
100
+ arg = handler_arg
101
+ d_name = arg.directive_name
102
+ d_arg = arg.directive_arg
103
+ d_str = arg.directive_str
104
+ attr_info = arg.attr_info
103
105
 
104
106
  ## parse 'name="user[name]"' or 'id="user_name"'
105
- case directive_name.to_s
107
+ case d_name.to_s
106
108
  when /(_|\A)radio_button\z/
107
109
  add_directive_object_and_method_and_value(d_arg, attr_info)
108
110
  when /_field\z/, /_area\z/, /_box\z/, /(_|\A)select\z/, 'input'
@@ -110,9 +112,9 @@ module Kwartz
110
112
  end
111
113
 
112
114
  ## replace whole element, or only start tag
113
- replace_elem = directive_name.to_s !~ /\Astart_/
115
+ replace_elem = d_name.to_s !~ /\Astart_/
114
116
 
115
- case directive_name
117
+ case d_name
116
118
 
117
119
  when :text_field, :password_field, :hidden_field
118
120
  #add_directive_object_and_method(d_arg, attr_info)
@@ -124,13 +126,13 @@ module Kwartz
124
126
  add_directive_integer_option(d_arg, 'size', attr_info['size'])
125
127
 
126
128
  when :link_to, :link_to_remote, :link_to_unless_current
127
- add_directive_content_as_arg(d_arg, cont_stmts)
129
+ add_directive_content_as_arg(d_arg, arg.cont_stmts)
128
130
 
129
131
  when :anchor, :anchor_remote
130
132
  replace_elem = false
131
133
 
132
134
  when :mail_to
133
- add_directive_content_as_arg(d_arg, cont_stmts)
135
+ add_directive_content_as_arg(d_arg, arg.cont_stmts)
134
136
  add_directive_attr_as_arg(d_arg, attr_info, 'href')
135
137
  d_arg.sub!(/\A\'mailto:/, "'")
136
138
 
@@ -168,7 +170,7 @@ module Kwartz
168
170
  end #case
169
171
 
170
172
  ##
171
- print_directive(d_name, d_arg, stag_info, etag_info, cont_stmts, attr_info, stmt_list, replace_elem)
173
+ print_directive(stmt_list, arg, replace_elem)
172
174
 
173
175
  return true # everytime return true
174
176
 
@@ -249,17 +251,18 @@ module Kwartz
249
251
  end
250
252
 
251
253
 
252
- def print_directive(d_name, d_arg, stag_info, etag_info, cont_stmts, attr_info, stmt_list, replace_elem=true)
253
- head_space = stag_info.head_space
254
- tail_space = (etag_info || stag_info).tail_space
255
- args = []
256
- args << head_space if head_space
257
- args << NativeExpression.new("#{d_name} #{d_arg}")
258
- args << tail_space if tail_space
259
- stmt_list << PrintStatement.new(args)
254
+ def print_directive(stmt_list, handler_arg, replace_elem=true)
255
+ arg = handler_arg
256
+ head_space = arg.stag_info.head_space
257
+ tail_space = (arg.etag_info || arg.stag_info).tail_space
258
+ pargs = []
259
+ pargs << head_space if head_space
260
+ pargs << NativeExpression.new("#{arg.directive_name} #{arg.directive_arg}")
261
+ pargs << tail_space if tail_space
262
+ stmt_list << PrintStatement.new(pargs)
260
263
  unless replace_elem
261
- stmt_list.concat(cont_stmts)
262
- stmt_list << PrintStatement.new([etag_info.tag_text])
264
+ stmt_list.concat(arg.cont_stmts)
265
+ stmt_list << PrintStatement.new([arg.etag_info.tag_text])
263
266
  end
264
267
  end
265
268
 
@@ -0,0 +1,193 @@
1
+ ###
2
+ ### $Rev: 128 $
3
+ ### $Release: 3.1.0 $
4
+ ### copyright(c) 2004-2006 kuwata-lab.com all rights reserved
5
+ ###
6
+
7
+ require 'kwartz/converter'
8
+ require 'kwartz/translator'
9
+
10
+
11
+
12
+ module Kwartz
13
+
14
+
15
+
16
+ ##
17
+ ## directive handler for Ruby
18
+ ##
19
+ class RubyHandler < Handler
20
+
21
+
22
+ RUBY_DIRECTIVE_PATTERN = /\A(\w+)(?:[:\s]\s*(.*))?\z/
23
+
24
+ def directive_pattern
25
+ return RUBY_DIRECTIVE_PATTERN
26
+ end
27
+
28
+
29
+ RUBY_MAPPING_PATTERN = /\A'([-:\w]+)'\s+(.*)\z/
30
+
31
+ def mapping_pattern
32
+ return RUBY_MAPPING_PATTERN
33
+ end
34
+
35
+
36
+ RUBY_DIRECTIVE_FORMAT = '%s: %s'
37
+
38
+ def directive_format
39
+ return RUBY_DIRECTIVE_FORMAT
40
+ end
41
+
42
+
43
+ def handle(stmt_list, handler_arg)
44
+ ret = super
45
+ return ret if ret
46
+
47
+ arg = handler_arg
48
+ d_name = arg.directive_name
49
+ d_arg = arg.directive_arg
50
+ d_str = arg.directive_str
51
+ #stag_info = arg.stag_info
52
+ #etag_info = arg.etag_info
53
+ #cont_stmts = arg.cont_stmts
54
+
55
+ case d_name
56
+
57
+ when :for, :For, :FOR, :list, :List, :LIST
58
+ unless d_arg =~ /\A(\w+)(?:,\s*(\w+))?\s+in\s+(.*)\z/ \
59
+ || d_arg =~ /\A(\w+)(?:,(\w+))?\s*[:=]\s*(.*)\z/
60
+ raise convert_error("'#{d_str}': invalid argument.", arg.stag_info.linenum)
61
+ end
62
+ loopvar = $1 ; loopval = $2 ; looplist = $3
63
+ is_foreach = d_name == :for || d_name == :For || d_name == :FOR
64
+ counter = d_name == :for || d_name == :list ? nil : "#{loopvar}_ctr"
65
+ toggle = d_name != :FOR && d_name != :LIST ? nil : "#{loopvar}_tgl"
66
+ foreach_code = loopval ? "#{looplist}.each do |#{loopvar}, #{loopval}|" \
67
+ : "for #{loopvar} in #{looplist} do"
68
+ code = []
69
+ code << "#{counter} = 0" if counter
70
+ code << foreach_code
71
+ code << " #{counter} += 1" if counter
72
+ code << " #{toggle} = #{counter}%2==0 ? #{@even} : #{@odd}" if toggle
73
+ if is_foreach
74
+ wrap_element_with_native_stmt(stmt_list, arg, code, "end", :foreach)
75
+ else
76
+ wrap_content_with_native_stmt(stmt_list, arg, code, "end", :foreach)
77
+ end
78
+
79
+ when :while
80
+ wrap_element_with_native_stmt(stmt_list, arg, "while #{d_arg} do", "end", :while)
81
+ #stmt_list << NativeStatement.new("while #{d_arg} do", :while)
82
+ #stmt_list << stag_stmt(arg)
83
+ #stmt_list.concat(arg.cont_stmts)
84
+ #stmt_list << etag_stmt(arg)
85
+ #stmt_list << NativeStatement.new("end", :while)
86
+
87
+ when :loop
88
+ error_if_empty_tag(arg)
89
+ wrap_content_with_native_stmt(stmt_list, arg, "while #{d_arg} do", "end", :while)
90
+ #stmt_list << stag_stmt(arg)
91
+ #stmt_list << NativeStatement.new("while #{d_arg} do", :while)
92
+ #stmt_list.concat(arg.cont_stmts)
93
+ #stmt_list << NativeStatement.new("end", :while)
94
+ #stmt_list << etag_stmt(arg)
95
+
96
+ when :set
97
+ wrap_element_with_native_stmt(stmt_list, arg, d_arg, nil, :set)
98
+ #stmt_list << NativeStatement.new(d_arg, :set)
99
+ #stmt_list << stag_stmt(arg)
100
+ #stmt_list.concat(arg.cont_stmts)
101
+ #stmt_list << etag_stmt(arg)
102
+
103
+ when :if
104
+ wrap_element_with_native_stmt(stmt_list, arg, "if #{d_arg} then", "end", :if)
105
+ #stmt_list << NativeStatement.new("if #{d_arg} then", :if)
106
+ #stmt_list << stag_stmt(arg)
107
+ #stmt_list.concat(arg.cont_stmts)
108
+ #stmt_list << etag_stmt(arg)
109
+ #stmt_list << NativeStatement.new("end", :if)
110
+
111
+ when :elsif, :else
112
+ error_when_last_stmt_is_not_if(stmt_list, arg)
113
+ stmt_list.pop # delete 'end'
114
+ kind = d_name == :else ? :else : :elseif
115
+ code = d_name == :else ? "else" : "elsif #{d_arg} then"
116
+ wrap_element_with_native_stmt(stmt_list, arg, code, "end", kind)
117
+ #stmt_list << NativeStatement.new(code, kind)
118
+ #stmt_list << stag_stmt(arg)
119
+ #stmt_list.concat(arg.cont_stmts)
120
+ #stmt_list << etag_stmt(arg)
121
+ #stmt_list << NativeStatement.new("end", kind)
122
+
123
+ when :default, :Default, :DEFAULT
124
+ error_if_empty_tag(arg)
125
+ expr_code = d_arg
126
+ flag_escape = d_name == :default ? nil : (d_name == :Default)
127
+ add_native_expr_with_default(stmt_list, arg, expr_code, flag_escape,
128
+ "if (#{d_arg}) && !(#{d_arg}).to_s.empty? then",
129
+ "else", "end")
130
+ #stmt_list << stag_stmt(arg)
131
+ #stmt_list << NativeStatement.new_without_newline("if (#{d_arg}) && !(#{d_arg}).to_s.empty? then", :if)
132
+ #flag_escape = d_name == :default ? nil : (d_name == :Default)
133
+ #stmt_list << PrintStatement.new([ NativeExpression.new(d_arg, flag_escape) ])
134
+ #stmt_list << NativeStatement.new_without_newline("else", :else)
135
+ #stmt_list.concat(arg.cont_stmts)
136
+ #stmt_list << NativeStatement.new_without_newline("end", :else)
137
+ #stmt_list << etag_stmt(arg)
138
+
139
+ else
140
+ return false
141
+
142
+ end #case
143
+ return true
144
+
145
+ end #def
146
+
147
+
148
+ end #class
149
+ Handler.register_class('ruby', RubyHandler)
150
+
151
+
152
+
153
+ ##
154
+ ## translator for eRuby
155
+ ##
156
+ class RubyTranslator < BaseTranslator
157
+
158
+
159
+ def initialize(properties={})
160
+ escapefunc = properties[:escapefunc] || 'ERB::Util.h'
161
+ marks = ['', '', '_buf << (', ').to_s; ', "_buf << #{escapefunc}(", '); ']
162
+ super(marks, properties)
163
+ @header = '_buf = ""; ' unless @header == false
164
+ @footer = '; _buf' + @nl unless @footer == false
165
+ end
166
+
167
+
168
+ def translate_string(str)
169
+ return if str.nil? || str.empty?
170
+ #str.gsub!(/['\\]/, '\\\\\&')
171
+ #@sb << "_buf << '#{str}'; "
172
+ str.gsub!(/["\\]/, '\\\\\&')
173
+ if str[-1] == ?\n
174
+ str.chop!
175
+ @sb << "_buf << \"#{str}\\n\";" << @nl
176
+ else
177
+ @sb << "_buf << \"#{str}\"; "
178
+ end
179
+ end
180
+
181
+
182
+ def translate(stmt_list)
183
+ stmt_list2 = optimize_print_stmts(stmt_list)
184
+ return super(stmt_list2)
185
+ end
186
+
187
+
188
+ end #class
189
+ Translator.register_class('ruby', RubyTranslator)
190
+
191
+
192
+
193
+ end #module
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 111 $
3
- ### $Release: 3.0.0 $
3
+ ### $Release: 3.1.0 $
4
4
  ### copyright(c) 2004-2006 kuwata-lab.com all rights reserved
5
5
  ###
6
6
 
@@ -1,6 +1,6 @@
1
1
  ###
2
- ### $Rev: 110 $
3
- ### $Release: 3.0.0 $
2
+ ### $Rev: 135 $
3
+ ### $Release: 3.1.0 $
4
4
  ### copyright(c) 2004-2006 kuwata-lab.com all rights reserved
5
5
  ###
6
6
 
@@ -15,8 +15,9 @@ module Kwartz
15
15
  PROPERTY_ODD = "'odd'"
16
16
  PROPERTY_EVEN = "'even'"
17
17
  PROPERTY_LANG = 'eruby'
18
- PROPERTY_DATTR = 'title'
18
+ PROPERTY_DATTR = 'kw:d' # or 'title'
19
19
  PROPERTY_DELSPAN = false # delete dummy <span> tag or not
20
+ PROPERTY_JSTL = 1.2 # jstl version (1.2 or 1.1)
20
21
  #
21
22
  NO_ETAGS = [ 'input', 'img' ,'br', 'hr', 'meta', 'link' ]
22
23
  #ALLOW_DUPLICATE_ID = false