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
@@ -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
|
data/lib/kwartz/binding/rails.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
###
|
2
|
-
### $Rev:
|
3
|
-
### $Release: 3.
|
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"
|
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]"
|
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"
|
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="#"
|
34
|
+
## <a href="#" kw:d="link_to :action=>'list'">Show list</a>
|
35
35
|
## => <%= link_to 'Show list', :action=>'list' %>
|
36
36
|
##
|
37
|
-
## ##
|
38
|
-
## <a href="#"
|
39
|
-
## => <%=
|
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"
|
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"
|
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"
|
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"
|
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]"
|
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"
|
60
|
+
## <input type="hidden" id="user_id" kw:d="hidden_field">
|
61
61
|
## => <%= hidden_field "user", "id" %>
|
62
|
-
## <input type="hidden" name="user[id]"
|
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"
|
66
|
+
## <input type="checkbox" id="user_chk1" kw:d="check_box">
|
67
67
|
## => <%= check_box "user", "chk1" %>
|
68
|
-
## <input type="checkbox" name="user[chk2]"
|
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"
|
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"
|
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]"
|
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"
|
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(
|
96
|
+
def handle(stmt_list, handler_arg)
|
97
97
|
ret = super
|
98
98
|
return ret if ret
|
99
99
|
|
100
|
-
|
101
|
-
|
102
|
-
|
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
|
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 =
|
115
|
+
replace_elem = d_name.to_s !~ /\Astart_/
|
114
116
|
|
115
|
-
case
|
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(
|
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(
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
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
|
data/lib/kwartz/config.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
###
|
2
|
-
### $Rev:
|
3
|
-
### $Release: 3.
|
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
|