dima-restfulx 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +65 -30
- data/VERSION.yml +4 -0
- data/app_generators/rx_app/rx_app_generator.rb +25 -9
- data/app_generators/rx_app/templates/actionscript.properties +3 -3
- data/app_generators/rx_app/templates/actionscriptair.properties +3 -3
- data/app_generators/rx_app/templates/app.yaml.erb +1 -1
- data/app_generators/rx_app/templates/default_tasks.rake +5 -18
- data/app_generators/rx_app/templates/generate.rb +1 -1
- data/app_generators/rx_app/templates/index.html.erb +1 -1
- data/app_generators/rx_app/templates/mainair-app.xml +3 -3
- data/app_generators/rx_app/templates/mainapp.mxml +107 -2
- data/app_generators/rx_app/templates/project-textmate.erb +4 -4
- data/app_generators/rx_app/templates/project.properties +1 -1
- data/app_generators/rx_app/templates/projectair.properties +1 -1
- data/app_generators/rx_app/templates/restfulx.yml +61 -0
- data/lib/restfulx/active_foo.rb +0 -7
- data/lib/restfulx/active_record_tasks.rb +10 -0
- data/lib/restfulx/configuration.rb +15 -10
- data/lib/restfulx/rails/swf_helper.rb +1 -1
- data/lib/restfulx/schema_to_yaml/extensions/enumerable.rb +7 -0
- data/lib/restfulx/schema_to_yaml/settings/config.rb +16 -0
- data/lib/restfulx/schema_to_yaml/settings/core.rb +70 -0
- data/lib/restfulx/schema_to_yaml.rb +120 -0
- data/lib/restfulx/tasks.rb +68 -42
- data/lib/restfulx/uuid_helper.rb +15 -0
- data/lib/restfulx.rb +5 -28
- data/rails_generators/rx_config/USAGE +2 -1
- data/rails_generators/rx_config/rx_config_generator.rb +78 -53
- data/rails_generators/rx_config/templates/actionscript.properties +3 -3
- data/rails_generators/rx_config/templates/actionscriptair.properties +3 -3
- data/rails_generators/rx_config/templates/flex_controller.erb +4 -0
- data/rails_generators/rx_config/templates/{index.html.erb → index.erb} +2 -4
- data/rails_generators/rx_config/templates/mainair-app.xml +3 -3
- data/rails_generators/rx_config/templates/mainapp.mxml +100 -2
- data/rails_generators/rx_config/templates/project-textmate.erb +4 -4
- data/rails_generators/rx_config/templates/project.properties +1 -1
- data/rails_generators/rx_config/templates/projectair.properties +1 -1
- data/rails_generators/rx_config/templates/restfulx.erb +39 -0
- data/rails_generators/rx_config/templates/restfulx.yml +51 -4
- data/rails_generators/rx_config/templates/restfulx_tasks.rake +3 -0
- data/rails_generators/rx_config/templates/routes.erb +47 -0
- data/rails_generators/rx_controller/rx_controller_generator.rb +9 -6
- data/rails_generators/rx_controller/templates/controller.as.erb +7 -9
- data/{generators → rails_generators}/rx_main_app/USAGE +0 -0
- data/rails_generators/rx_main_app/rx_main_app_generator.rb +60 -0
- data/rails_generators/rx_main_app/templates/mainapp.mxml +129 -0
- data/rails_generators/rx_scaffold/rx_scaffold_generator.rb +89 -35
- data/rails_generators/rx_scaffold/templates/{controller.rb.erb → controllers/default.rb.erb} +29 -1
- data/rails_generators/rx_scaffold/templates/controllers/resource_controller.rb.erb +23 -0
- data/rails_generators/rx_scaffold/templates/fixtures.yml.erb +9 -5
- data/{generators/rx_scaffold/templates/component.mxml.erb → rails_generators/rx_scaffold/templates/layouts/default.erb} +75 -59
- data/rails_generators/rx_scaffold/templates/migration.rb.erb +29 -2
- data/rails_generators/rx_scaffold/templates/model.as.erb +33 -2
- data/rails_generators/rx_scaffold/templates/model.rb.erb +36 -1
- data/rails_generators/rx_yaml_scaffold/rx_yaml_scaffold_generator.rb +29 -10
- data/{generators → rxgen_generators}/rx_config/USAGE +0 -0
- data/{generators → rxgen_generators}/rx_config/rx_config_generator.rb +0 -0
- data/{generators → rxgen_generators}/rx_controller/USAGE +0 -0
- data/{generators → rxgen_generators}/rx_controller/rx_controller_generator.rb +6 -5
- data/{generators → rxgen_generators}/rx_controller/templates/assist.py +2 -2
- data/{generators → rxgen_generators}/rx_controller/templates/controller.as.erb +8 -6
- data/{generators → rxgen_generators}/rx_controller/templates/restful.py +0 -0
- data/rxgen_generators/rx_main_app/USAGE +8 -0
- data/{generators → rxgen_generators}/rx_main_app/rx_main_app_generator.rb +10 -5
- data/{generators → rxgen_generators}/rx_main_app/templates/main.py.erb +0 -0
- data/rxgen_generators/rx_main_app/templates/mainapp.mxml +136 -0
- data/{generators → rxgen_generators}/rx_scaffold/USAGE +0 -0
- data/{generators → rxgen_generators}/rx_scaffold/rx_scaffold_generator.rb +5 -4
- data/{rails_generators → rxgen_generators}/rx_scaffold/templates/component.mxml.erb +24 -52
- data/{generators → rxgen_generators}/rx_scaffold/templates/controller.py.erb +1 -1
- data/{generators → rxgen_generators}/rx_scaffold/templates/model.as.erb +0 -0
- data/{generators → rxgen_generators}/rx_scaffold/templates/model.py.erb +0 -0
- data/{generators → rxgen_generators}/rx_yaml_scaffold/USAGE +0 -0
- data/{generators → rxgen_generators}/rx_yaml_scaffold/rx_yaml_scaffold_generator.rb +0 -0
- metadata +104 -66
- data/History.txt +0 -7
- data/Manifest.txt +0 -127
- data/generators/rx_main_app/templates/mainapp.mxml +0 -35
- data/rdoc/generators/template/html/jamis.rb +0 -588
- data/test/rails/playing_around_in_a_console.txt +0 -71
@@ -61,21 +61,36 @@ module Rails
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
64
|
+
module Commands
|
65
|
+
class Create
|
66
|
+
include SchemaToYaml
|
67
|
+
end
|
68
|
+
end
|
64
69
|
end
|
65
70
|
end
|
66
71
|
|
67
72
|
class RxScaffoldGenerator < Rails::Generator::NamedBase
|
68
|
-
include RestfulX::Configuration
|
73
|
+
include RestfulX::Configuration
|
74
|
+
include SchemaToYaml
|
69
75
|
|
70
76
|
attr_reader :project_name,
|
71
77
|
:flex_project_name,
|
72
78
|
:base_package,
|
73
79
|
:base_folder,
|
74
|
-
:command_controller_name
|
80
|
+
:command_controller_name,
|
81
|
+
:flex_root,
|
82
|
+
:distributed
|
75
83
|
|
76
84
|
attr_reader :belongs_tos,
|
77
85
|
:has_manies,
|
78
|
-
:has_ones
|
86
|
+
:has_ones,
|
87
|
+
:attachment_field,
|
88
|
+
:has_many_through,
|
89
|
+
:polymorphic,
|
90
|
+
:tree_model,
|
91
|
+
:layout,
|
92
|
+
:ignored_fields,
|
93
|
+
:args_for_generation
|
79
94
|
|
80
95
|
attr_reader :controller_name,
|
81
96
|
:controller_class_path,
|
@@ -92,9 +107,10 @@ class RxScaffoldGenerator < Rails::Generator::NamedBase
|
|
92
107
|
|
93
108
|
def initialize(runtime_args, runtime_options = {})
|
94
109
|
super
|
95
|
-
@project_name, @flex_project_name, @command_controller_name, @base_package, @base_folder
|
110
|
+
@project_name, @flex_project_name, @command_controller_name, @base_package, @base_folder, @flex_root,
|
111
|
+
@distributed = extract_names
|
96
112
|
@controller_name = @name.pluralize
|
97
|
-
|
113
|
+
|
98
114
|
base_name, @controller_class_path, @controller_file_path, @controller_class_nesting,
|
99
115
|
@controller_class_nesting_depth = extract_modules(@controller_name)
|
100
116
|
@controller_class_name_without_nesting, @controller_underscore_name, @controller_plural_name = inflect_names(base_name)
|
@@ -109,25 +125,27 @@ class RxScaffoldGenerator < Rails::Generator::NamedBase
|
|
109
125
|
end
|
110
126
|
|
111
127
|
def manifest
|
112
|
-
record do |m|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
m.template 'component.mxml.erb',
|
122
|
-
File.join("app", "flex", base_folder, "components", "generated", "#{@class_name}Box.mxml"),
|
123
|
-
:assigns => { :resource_controller_name => "#{file_name.pluralize}" }
|
128
|
+
record do |m|
|
129
|
+
unless options[:flex_view_only]
|
130
|
+
m.template 'model.as.erb',
|
131
|
+
File.join("#{@flex_root}", base_folder, "models", "#{@class_name}.as"),
|
132
|
+
:assigns => { :resource_controller_name => "#{file_name.pluralize}" }
|
133
|
+
|
134
|
+
m.template "controllers/#{RxSettings.controller_pattern}.rb.erb", File.join("app/controllers",
|
135
|
+
controller_class_path, "#{controller_file_name}_controller.rb") unless options[:flex_only]
|
124
136
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
137
|
+
m.template 'model.rb.erb', File.join("app", "models", "#{file_name}.rb") unless options[:flex_only]
|
138
|
+
end
|
139
|
+
|
140
|
+
if @layout.size > 0
|
141
|
+
m.template "layouts/#{@layout}.erb",
|
142
|
+
File.join("#{@flex_root}", base_folder, "components", "generated", "#{@class_name}Box.mxml"),
|
143
|
+
:assigns => { :resource_controller_name => "#{file_name.pluralize}" }
|
144
|
+
else
|
145
|
+
m.template "layouts/#{RxSettings.layouts.default}.erb",
|
146
|
+
File.join("#{@flex_root}", base_folder, "components", "generated", "#{@class_name}Box.mxml"),
|
147
|
+
:assigns => { :resource_controller_name => "#{file_name.pluralize}" }
|
148
|
+
end
|
131
149
|
|
132
150
|
unless options[:skip_fixture]
|
133
151
|
m.template 'fixtures.yml.erb', File.join("test", "fixtures", "#{table_name}.yml"),
|
@@ -135,11 +153,13 @@ class RxScaffoldGenerator < Rails::Generator::NamedBase
|
|
135
153
|
end
|
136
154
|
|
137
155
|
unless options[:skip_migration]
|
138
|
-
|
156
|
+
FileUtils.rm Dir.glob("db/migrate/[0-9]*_create_#{file_path.gsub(/\//, '_').pluralize}.rb"), :force => true
|
139
157
|
m.migration_template 'migration.rb.erb', 'db/migrate', :assigns => {
|
140
158
|
:migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}"
|
141
159
|
}, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}" unless options[:flex_only]
|
142
160
|
end
|
161
|
+
|
162
|
+
m.route_resources controller_file_name
|
143
163
|
|
144
164
|
m.dependency 'rx_controller', [name] + @args, :collision => :force
|
145
165
|
end
|
@@ -147,33 +167,67 @@ class RxScaffoldGenerator < Rails::Generator::NamedBase
|
|
147
167
|
|
148
168
|
protected
|
149
169
|
def extract_relationships
|
170
|
+
# arrays
|
150
171
|
@belongs_tos = []
|
151
172
|
@has_ones = []
|
152
173
|
@has_manies = []
|
153
|
-
|
174
|
+
@attachment_field = []
|
175
|
+
@polymorphic = []
|
176
|
+
@tree_model = []
|
177
|
+
@layout = []
|
178
|
+
@ignored_fields = []
|
179
|
+
|
180
|
+
# hashes
|
181
|
+
@has_many_through = {}
|
182
|
+
|
154
183
|
@args.each do |arg|
|
184
|
+
# arrays
|
155
185
|
if arg =~ /^has_one:/
|
156
|
-
# arg = "has_one:arg1,arg2", so all the has_one are together
|
157
186
|
@has_ones = arg.split(':')[1].split(',')
|
158
187
|
elsif arg =~ /^has_many:/
|
159
|
-
# arg = "has_many:arg1,arg2", so all the has_many are together
|
160
188
|
@has_manies = arg.split(":")[1].split(",")
|
161
|
-
elsif arg =~ /^belongs_to:/
|
189
|
+
elsif arg =~ /^belongs_to:/
|
162
190
|
@belongs_tos = arg.split(":")[1].split(',')
|
191
|
+
elsif arg =~ /^attachment_field:/
|
192
|
+
@attachment_field = arg.split(":")[1].split(',')
|
193
|
+
elsif arg =~ /^polymorphic:/
|
194
|
+
@polymorphic = arg.split(":")[1].split(',')
|
195
|
+
elsif arg =~ /^tree_model:/
|
196
|
+
@tree_model = arg.split(":")[1].split(',')
|
197
|
+
elsif arg =~ /^layout:/
|
198
|
+
@layout = arg.split(":")[1].split(',')
|
199
|
+
elsif arg =~ /^ignored_fields:/
|
200
|
+
@ignored_fields = arg.split(":")[1].split(',')
|
201
|
+
# hashes
|
202
|
+
elsif arg =~ /^has_many_through:/
|
203
|
+
hmt_arr = arg.split(":")[1].split(',')
|
204
|
+
@has_many_through[hmt_arr.first] = hmt_arr.last
|
163
205
|
end
|
164
206
|
end
|
165
207
|
|
166
|
-
#
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
208
|
+
# delete special fields from @args ivar
|
209
|
+
%w(has_one has_many belongs_to attachment_field has_many_through
|
210
|
+
polymorphic tree_model layout ignored_fields).each do |special_field|
|
211
|
+
@args.delete_if { |f| f =~ /^(#{special_field}):/ }
|
212
|
+
end
|
213
|
+
|
214
|
+
@args_for_generation = @args.clone
|
215
|
+
|
216
|
+
# delete ignored_fields from @args ivar
|
217
|
+
@ignored_fields.each do |ignored|
|
218
|
+
@args.delete_if { |f| f =~ /^(#{ignored}):/ }
|
219
|
+
end
|
220
|
+
|
171
221
|
end
|
172
222
|
|
173
223
|
def add_options!(opt)
|
174
224
|
opt.separator ''
|
175
225
|
opt.separator 'Options:'
|
176
|
-
opt.on("--flex-only", "
|
177
|
-
"Default: false") { |v| options[:flex_only] = v}
|
226
|
+
opt.on("-f", "--flex-only", "Only generate the Flex/AIR files",
|
227
|
+
"Default: false") { |v| options[:flex_only] = v }
|
228
|
+
opt.on("-r", "--rails-only", "Only generate the Rails files",
|
229
|
+
"Default: false") { |v| options[:rails_only] = v }
|
230
|
+
opt.on("-fv", "--flex-view-only", "Only generate the Flex component files",
|
231
|
+
"Default: false") { |v| options[:flex_view_only] = v }
|
178
232
|
end
|
179
233
|
end
|
data/rails_generators/rx_scaffold/templates/{controller.rb.erb → controllers/default.rb.erb}
RENAMED
@@ -8,7 +8,11 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
8
8
|
respond_to do |format|
|
9
9
|
format.html # index.html.erb
|
10
10
|
format.xml { render :xml => @<%= table_name %> }
|
11
|
+
<% if attachment_field.size > 0 -%>
|
12
|
+
format.fxml { render :fxml => @<%= table_name %>.to_fxml(:methods => [:attachment_url]) }
|
13
|
+
<% else -%>
|
11
14
|
format.fxml { render :fxml => @<%= table_name %> }
|
15
|
+
<% end -%>
|
12
16
|
end
|
13
17
|
end
|
14
18
|
|
@@ -21,7 +25,11 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
21
25
|
respond_to do |format|
|
22
26
|
format.html # show.html.erb
|
23
27
|
format.xml { render :xml => @<%= file_name %> }
|
28
|
+
<% if attachment_field.size > 0 -%>
|
29
|
+
format.fxml { render :fxml => @<%= file_name %>.to_fxml(:methods => [:attachment_url]) }
|
30
|
+
<% else -%>
|
24
31
|
format.fxml { render :fxml => @<%= file_name %> }
|
32
|
+
<% end -%>
|
25
33
|
end
|
26
34
|
end
|
27
35
|
|
@@ -52,7 +60,11 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
52
60
|
flash[:notice] = '<%= class_name %> was successfully created.'
|
53
61
|
format.html { redirect_to(@<%= file_name %>) }
|
54
62
|
format.xml { render :xml => @<%= file_name %>, :status => :created, :location => @<%= file_name %> }
|
63
|
+
<% if attachment_field.size > 0 -%>
|
64
|
+
format.fxml { render :fxml => @<%= file_name %>.to_fxml(:methods => [:attachment_url]) }
|
65
|
+
<% else -%>
|
55
66
|
format.fxml { render :fxml => @<%= file_name %> }
|
67
|
+
<% end -%>
|
56
68
|
else
|
57
69
|
format.html { render :action => "new" }
|
58
70
|
format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity }
|
@@ -65,14 +77,30 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
65
77
|
# PUT /<%= table_name %>/1.xml
|
66
78
|
# PUT /<%= table_name %>/1.fxml
|
67
79
|
def update
|
80
|
+
<% if distributed -%>
|
81
|
+
begin
|
82
|
+
@<%= file_name %> = <%= class_name %>.find(params[:id])
|
83
|
+
@saved = @<%= file_name %>.update_attributes(params[:<%= file_name %>])
|
84
|
+
rescue
|
85
|
+
@<%= file_name %> = <%= class_name %>.new(params[:<%= file_name %>])
|
86
|
+
@<%= file_name %>.id = params[:id]
|
87
|
+
@saved = @<%= file_name %>.save
|
88
|
+
end
|
89
|
+
<% else -%>
|
68
90
|
@<%= file_name %> = <%= class_name %>.find(params[:id])
|
91
|
+
@saved = @<%= file_name %>.update_attributes(params[:<%= file_name %>])
|
92
|
+
<% end -%>
|
69
93
|
|
70
94
|
respond_to do |format|
|
71
|
-
if
|
95
|
+
if @saved
|
72
96
|
flash[:notice] = '<%= class_name %> was successfully updated.'
|
73
97
|
format.html { redirect_to(@<%= file_name %>) }
|
74
98
|
format.xml { head :ok }
|
99
|
+
<% if attachment_field.size > 0 -%>
|
100
|
+
format.fxml { render :fxml => @<%= file_name %>.to_fxml(:methods => [:attachment_url]) }
|
101
|
+
<% else -%>
|
75
102
|
format.fxml { render :fxml => @<%= file_name %> }
|
103
|
+
<% end -%>
|
76
104
|
else
|
77
105
|
format.html { render :action => "edit" }
|
78
106
|
format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity }
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class <%= controller_class_name %>Controller < ResourceController::Base
|
2
|
+
|
3
|
+
before_filter :load_fxml_params
|
4
|
+
|
5
|
+
index.wants.fxml { render :fxml => @collection.to_fxml(@fxml_params) }
|
6
|
+
show.wants.fxml { render :fxml => @object.to_fxml(@fxml_params) }
|
7
|
+
create.wants.fxml { render :fxml => @object.to_fxml(@fxml_params) }
|
8
|
+
create.failure.wants.fxml { render :fxml => @object.errors }
|
9
|
+
update.wants.fxml { render :fxml => @object.to_fxml(@fxml_params) }
|
10
|
+
update.failure.wants.fxml { render :fxml => @object.errors }
|
11
|
+
destroy.wants.fxml { render :fxml => @object }
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def collection
|
16
|
+
@collection = end_of_association_chain.all
|
17
|
+
end
|
18
|
+
|
19
|
+
def load_fxml_params
|
20
|
+
@fxml_params = { }
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -2,34 +2,38 @@
|
|
2
2
|
|
3
3
|
<% unless attributes.empty? && belongs_tos.empty? -%>
|
4
4
|
<%= class_name.underscore -%>_one:
|
5
|
+
id: <%%= Fixtures.identify(:<%= class_name.underscore %>_one) %>
|
5
6
|
<% for attribute in attributes -%>
|
6
7
|
<%= attribute.name %>: <%= attribute.default("#{class_name}1") %>
|
7
8
|
<% end -%>
|
8
9
|
<% for model in belongs_tos -%>
|
9
|
-
<%= model
|
10
|
+
<%= model %>_id: <%%= Fixtures.identify(:<%= model %>_one) %>
|
10
11
|
<% end -%>
|
11
12
|
|
12
13
|
<%= class_name.underscore -%>_two:
|
14
|
+
id: <%%= Fixtures.identify(:<%= class_name.underscore %>_two) %>
|
13
15
|
<% for attribute in attributes -%>
|
14
16
|
<%= attribute.name %>: <%= attribute.default("#{class_name}2") %>
|
15
17
|
<% end -%>
|
16
18
|
<% for model in belongs_tos -%>
|
17
|
-
<%= model
|
19
|
+
<%= model %>_id: <%%= Fixtures.identify(:<%= model %>_two) %>
|
18
20
|
<% end -%>
|
19
21
|
|
20
22
|
<%= class_name.underscore -%>_three:
|
23
|
+
id: <%%= Fixtures.identify(:<%= class_name.underscore %>_three) %>
|
21
24
|
<% for attribute in attributes -%>
|
22
25
|
<%= attribute.name %>: <%= attribute.default("#{class_name}3") %>
|
23
26
|
<% end -%>
|
24
27
|
<% for model in belongs_tos -%>
|
25
|
-
<%= model
|
28
|
+
<%= model %>_id: <%%= Fixtures.identify(:<%= model %>_three) %>
|
26
29
|
<% end -%>
|
27
30
|
|
28
31
|
<%= class_name.underscore -%>_four:
|
32
|
+
id: <%%= Fixtures.identify(:<%= class_name.underscore %>_four) %>
|
29
33
|
<% for attribute in attributes -%>
|
30
34
|
<%= attribute.name %>: <%= attribute.default("#{class_name}4") %>
|
31
35
|
<% end -%>
|
32
36
|
<% for model in belongs_tos -%>
|
33
|
-
<%= model
|
34
|
-
<% end -%>
|
37
|
+
<%= model %>_id: <%%= Fixtures.identify(:<%= model %>_four) %>
|
35
38
|
<% end -%>
|
39
|
+
<% end -%>
|
@@ -8,25 +8,34 @@
|
|
8
8
|
<% for model in belongs_tos -%>
|
9
9
|
import <%= base_package %>.models.<%= model.camelcase %>;
|
10
10
|
<% end -%>
|
11
|
+
<% if attachment_field.size > 0 -%>
|
12
|
+
import org.restfulx.utils.RxFileReference;
|
13
|
+
<% end -%>
|
11
14
|
|
12
15
|
[Bindable]
|
13
|
-
private var
|
16
|
+
private var <%= class_name.dcfirst %>:<%= class_name %> = new <%= class_name %>();
|
17
|
+
<% if attachment_field.size > 0 -%>
|
18
|
+
[Bindable]
|
19
|
+
private var fileName:String = "None selected";
|
20
|
+
|
21
|
+
private var file:RxFileReference;
|
22
|
+
<% end -%>
|
14
23
|
|
15
24
|
private function new<%= class_name %>():void {
|
16
|
-
|
25
|
+
<%= class_name.dcfirst %> = new <%= class_name %>();
|
17
26
|
<%= class_name.dcfirst.pluralize %>List.selectedIndex = -1;
|
18
27
|
}
|
19
28
|
|
20
29
|
private function save<%= class_name %>():void {
|
21
|
-
|
22
|
-
|
30
|
+
updateModelProperties();
|
31
|
+
if (<%= class_name.dcfirst %>.id) {
|
32
|
+
<%= class_name.dcfirst %>.update({onSuccess: on<%= class_name %>Update});
|
23
33
|
} else {
|
24
|
-
create<%= class_name %>
|
34
|
+
<%= class_name.dcfirst %>.create({onSuccess: on<%= class_name %>Create});
|
25
35
|
}
|
26
36
|
}
|
27
37
|
|
28
|
-
private function
|
29
|
-
var <%= class_name.dcfirst %>:<%= class_name %> = new <%= class_name %>();
|
38
|
+
private function updateModelProperties():void {
|
30
39
|
<% for attribute in attributes -%>
|
31
40
|
<% if attribute.type == :boolean -%>
|
32
41
|
<%= class_name.dcfirst %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>CheckBox.selected;
|
@@ -41,64 +50,64 @@
|
|
41
50
|
<% else -%>
|
42
51
|
<%= class_name.dcfirst %>.<%= attribute.flex_name %> = <%= attribute.flex_type %>(<%= attribute.flex_name %>TextInput.text);
|
43
52
|
<% end -%>
|
44
|
-
<% end -%>
|
45
|
-
|
53
|
+
<% end -%>
|
46
54
|
<% for model in belongs_tos -%>
|
47
55
|
<%= class_name.dcfirst %>.<%= model.camelcase(:lower) %> = <%= model.camelcase %>(<%= model.camelcase(:lower) %>ComboBox.selectedItem);
|
48
56
|
<% end -%>
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
private function update<%= class_name %>():void {
|
53
|
-
<% for attribute in attributes -%>
|
54
|
-
<% if attribute.type == :boolean -%>
|
55
|
-
_<%= class_name.dcfirst %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>CheckBox.selected;
|
56
|
-
<% elsif attribute.type == :string -%>
|
57
|
-
_<%= class_name.dcfirst %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>TextInput.text;
|
58
|
-
<% elsif attribute.type == :text -%>
|
59
|
-
_<%= class_name.dcfirst %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>TextArea.text;
|
60
|
-
<% elsif attribute.type == :datetime || attribute.type == :time -%>
|
61
|
-
_<%= class_name.dcfirst %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>DateTimeTextInput.date;
|
62
|
-
<% elsif attribute.type == :date -%>
|
63
|
-
_<%= class_name.dcfirst %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>DateField.selectedDate;
|
64
|
-
<% else -%>
|
65
|
-
_<%= class_name.dcfirst %>.<%= attribute.flex_name %> = <%= attribute.flex_type %>(<%= attribute.flex_name %>TextInput.text);
|
66
|
-
<% end -%>
|
57
|
+
<% if attachment_field.size > 0 -%>
|
58
|
+
<%= class_name.dcfirst %>.attachment = file;
|
67
59
|
<% end -%>
|
68
|
-
|
69
|
-
<% for model in belongs_tos -%>
|
70
|
-
_<%= class_name.dcfirst %>.<%= model.camelcase(:lower) %> = <%= model.camelcase %>(<%= model.camelcase(:lower) %>ComboBox.selectedItem);
|
71
|
-
<% end -%>
|
72
|
-
_<%= class_name.dcfirst %>.update({onSuccess: on<%= class_name %>Update});
|
73
60
|
}
|
74
|
-
|
61
|
+
|
75
62
|
private function destroy<%= class_name %>():void {
|
76
|
-
|
63
|
+
<%= class_name.dcfirst %>.destroy({onSuccess: on<%= class_name %>Destroy});
|
77
64
|
}
|
78
|
-
|
65
|
+
|
79
66
|
private function on<%= class_name %>Select():void {
|
80
|
-
|
67
|
+
<%= class_name.dcfirst %> = RxUtils.clone(<%= class_name.dcfirst.pluralize %>List.selectedItem) as <%= class_name %>;
|
81
68
|
}
|
82
|
-
|
83
|
-
private function on<%= class_name %>Create(
|
84
|
-
|
85
|
-
}
|
86
|
-
|
87
|
-
private function on<%= class_name %>Update(<%= class_name.dcfirst %>:<%= class_name %>):void {
|
88
|
-
<%= class_name.dcfirst.pluralize %>List.selectedItem = <%= class_name.dcfirst %>;
|
89
|
-
_<%= class_name.dcfirst %> = RxUtils.clone(<%= class_name.dcfirst %>) as <%= class_name %>;
|
69
|
+
|
70
|
+
private function on<%= class_name %>Create(result:<%= class_name %>):void {
|
71
|
+
<%= class_name.dcfirst %> = new <%= class_name %>;
|
90
72
|
}
|
91
|
-
|
92
|
-
private function on<%= class_name %>
|
93
|
-
|
73
|
+
|
74
|
+
private function on<%= class_name %>Update(result:<%= class_name %>):void {
|
75
|
+
<%= class_name.dcfirst.pluralize %>List.selectedItem = result;
|
76
|
+
on<%= class_name %>Select();
|
94
77
|
}
|
78
|
+
|
79
|
+
private function on<%= class_name %>Destroy(result:<%= class_name %>):void {
|
80
|
+
on<%= class_name %>Create(result);
|
81
|
+
}
|
82
|
+
<% if attachment_field.size > 0 -%>
|
95
83
|
|
96
|
-
private function
|
97
|
-
|
84
|
+
private function chooseFile():void {
|
85
|
+
file = new RxFileReference("<%= attachment_field[0].camelcase(:lower) %>");
|
86
|
+
file.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler, false, 0, true);
|
87
|
+
file.addEventListener(Event.SELECT, selectFile, false, 0, true);
|
88
|
+
file.addEventListener(Event.CANCEL, cancelBrowse, false, 0, true);
|
89
|
+
file.browse();
|
98
90
|
}
|
91
|
+
|
92
|
+
private function selectFile(event:Event):void {
|
93
|
+
fileSelected(event)
|
94
|
+
}
|
95
|
+
|
96
|
+
private function cancelBrowse(event:Event):void {
|
97
|
+
file = null;
|
98
|
+
}
|
99
|
+
|
100
|
+
private function fileSelected(event:Event):void {
|
101
|
+
fileName = RxFileReference(event.target).name;
|
102
|
+
}
|
103
|
+
|
104
|
+
private function ioErrorHandler(event:Event):void {
|
105
|
+
fileChooser.errorString = "Failed to selected a file. Please try again.";
|
106
|
+
}
|
107
|
+
<% end -%>
|
99
108
|
]]></mx:Script>
|
100
109
|
<mx:Panel id="<%= class_name.dcfirst.pluralize %>Panel"
|
101
|
-
title="<%= class_name.pluralize %>" cornerRadius="0" dropShadowEnabled="false" borderStyle="solid"
|
110
|
+
title="<%= class_name.pluralize %>" cornerRadius="0" dropShadowEnabled="false" borderStyle="solid"
|
102
111
|
borderThickness="1" backgroundColor="#EEEEEE" width="25%" height="100%">
|
103
112
|
<mx:List id="<%= class_name.dcfirst.pluralize %>List"
|
104
113
|
width="100%" height="100%"
|
@@ -109,24 +118,31 @@
|
|
109
118
|
click="new<%= class_name %>()"/>
|
110
119
|
</mx:ControlBar>
|
111
120
|
</mx:Panel>
|
112
|
-
<mx:Panel title="Edit <%= class_name %>" cornerRadius="0" dropShadowEnabled="false" borderStyle="solid"
|
121
|
+
<mx:Panel title="Edit <%= class_name %>" cornerRadius="0" dropShadowEnabled="false" borderStyle="solid"
|
113
122
|
borderThickness="1" backgroundColor="#EEEEEE" width="75%" height="100%">
|
114
123
|
<mx:Form width="100%" height="100%">
|
115
124
|
<% for attribute in attributes -%>
|
116
125
|
<mx:FormItem label="<%= attribute.flex_name.ucfirst %>" width="100%">
|
117
126
|
<% if attribute.type == :boolean -%>
|
118
|
-
<mx:CheckBox id="<%= attribute.flex_name %>CheckBox" selected="{
|
127
|
+
<mx:CheckBox id="<%= attribute.flex_name %>CheckBox" selected="{<%= class_name.dcfirst %>.<%= attribute.flex_name %>}"/>
|
119
128
|
<% elsif attribute.type == :string -%>
|
120
|
-
<mx:TextInput id="<%= attribute.flex_name %>TextInput" width="100%" text="{
|
129
|
+
<mx:TextInput id="<%= attribute.flex_name %>TextInput" width="100%" text="{<%= class_name.dcfirst %>.<%= attribute.flex_name %>}"/>
|
121
130
|
<% elsif attribute.type == :text -%>
|
122
|
-
<mx:TextArea id="<%= attribute.flex_name %>TextArea" width="100%" height="200" text="{
|
131
|
+
<mx:TextArea id="<%= attribute.flex_name %>TextArea" width="100%" height="200" text="{<%= class_name.dcfirst %>.<%= attribute.flex_name %>}"/>
|
123
132
|
<% elsif attribute.type == :datetime || attribute.type == :time -%>
|
124
|
-
<rx:DateTimeTextInput id="<%= attribute.flex_name %>DateTimeTextInput" width="200" date="{
|
133
|
+
<rx:DateTimeTextInput id="<%= attribute.flex_name %>DateTimeTextInput" width="200" date="{<%= class_name.dcfirst %>.<%= attribute.flex_name %>}"/>
|
125
134
|
<% elsif attribute.type == :date -%>
|
126
|
-
<mx:DateField id="<%= attribute.flex_name %>DateField" selectedDate="{
|
135
|
+
<mx:DateField id="<%= attribute.flex_name %>DateField" selectedDate="{<%= class_name.dcfirst %>.<%= attribute.flex_name %>}"/>
|
127
136
|
<% else -%>
|
128
|
-
<mx:TextInput id="<%= attribute.flex_name %>TextInput" width="100%" text="{
|
137
|
+
<mx:TextInput id="<%= attribute.flex_name %>TextInput" width="100%" text="{<%= class_name.dcfirst %>.<%= attribute.flex_name %>}"/>
|
138
|
+
<% end -%>
|
139
|
+
</mx:FormItem>
|
129
140
|
<% end -%>
|
141
|
+
<% if attachment_field.size > 0 -%>
|
142
|
+
<mx:FormItem label="<%= attachment_field[0].camelcase %>:" width="100%" id="fileChooser">
|
143
|
+
<mx:Button label="Browse…" id="fileBrowseButton" click="chooseFile()"/>
|
144
|
+
<mx:Label text="{fileName}" maxWidth="190"/>
|
145
|
+
<mx:Image source="{<%= class_name.dcfirst %>.attachmentUrl}"/>
|
130
146
|
</mx:FormItem>
|
131
147
|
<% end -%>
|
132
148
|
<% for model in belongs_tos -%>
|
@@ -134,7 +150,7 @@
|
|
134
150
|
<mx:ComboBox id="<%= model.camelcase(:lower) %>ComboBox" width="200"
|
135
151
|
labelField="{<%= model.camelcase %>.LABEL}"
|
136
152
|
dataProvider="{Rx.models.index(<%= model.camelcase %>)}" prompt="<%= model.camelcase %> ..."
|
137
|
-
selectedItem="{
|
153
|
+
selectedItem="{<%= class_name.dcfirst %>.<%= model.camelcase(:lower) %>}"/>
|
138
154
|
</mx:FormItem>
|
139
155
|
<% end -%>
|
140
156
|
</mx:Form>
|
@@ -142,7 +158,7 @@
|
|
142
158
|
<mx:Button label="Save <%= class_name %>" width="50%" height="30"
|
143
159
|
click="save<%= class_name %>()"/>
|
144
160
|
<mx:Button label="Delete <%= class_name %>" width="50%" height="30"
|
145
|
-
enabled="{
|
161
|
+
enabled="{RxUtils.canDeleteModel(<%= class_name.dcfirst %>)}"
|
146
162
|
click="destroy<%= class_name %>()"/>
|
147
163
|
</mx:ControlBar>
|
148
164
|
</mx:Panel>
|
@@ -1,12 +1,39 @@
|
|
1
1
|
class <%= migration_name %> < ActiveRecord::Migration
|
2
2
|
def self.up
|
3
|
+
<% if distributed -%>
|
4
|
+
create_table :<%= table_name %>, :id => false do |t|
|
5
|
+
t.string :id
|
6
|
+
<% else -%>
|
3
7
|
create_table :<%= table_name %> do |t|
|
4
|
-
<%
|
5
|
-
|
8
|
+
<% end -%>
|
9
|
+
<% for attribute in args_for_generation -%>
|
10
|
+
t.<%= attribute.split(':')[1] %> :<%= attribute.split(':')[0] %>
|
6
11
|
<% end -%>
|
7
12
|
<% for model in belongs_tos -%>
|
13
|
+
<% if distributed -%>
|
14
|
+
t.string :<%= model %>_id
|
15
|
+
<% else -%>
|
8
16
|
t.references :<%= model %>
|
9
17
|
<% end -%>
|
18
|
+
<% end -%>
|
19
|
+
<% if attachment_field.size > 0 -%>
|
20
|
+
<% if RxSettings.attachment_plugin == 'paperclip' -%>
|
21
|
+
# For paperclip
|
22
|
+
t.column :avatar_file_name, :string
|
23
|
+
t.column :avatar_content_type, :string
|
24
|
+
t.column :avatar_file_size, :integer
|
25
|
+
t.column :avatar_updated_at, :datetime
|
26
|
+
<% elsif RxSettings.attachment_plugin == 'attachment_fu' -%>
|
27
|
+
# For attachment_fu
|
28
|
+
t.column :parent_id, :integer
|
29
|
+
t.column :content_type, :string
|
30
|
+
t.column :filename, :string
|
31
|
+
t.column :thumbnail, :string
|
32
|
+
t.column :size, :integer
|
33
|
+
t.column :width, :integer
|
34
|
+
t.column :height, :integer
|
35
|
+
<% end -%>
|
36
|
+
<% end -%>
|
10
37
|
<% unless options[:skip_timestamps] %>
|
11
38
|
t.timestamps
|
12
39
|
<% end -%>
|
@@ -1,12 +1,19 @@
|
|
1
1
|
package <%= base_package %>.models {
|
2
|
-
<% if has_manies.length > 0 -%>
|
2
|
+
<% if has_manies.length > 0 || has_many_through.length > 0 -%>
|
3
3
|
import org.restfulx.collections.ModelsCollection;
|
4
4
|
<% end -%>
|
5
|
+
<% if tree_model.size > 0 -%>
|
6
|
+
<% @tree_or_no_tree = 'RxTreeModel' %>
|
7
|
+
import org.restfulx.models.RxTreeModel
|
8
|
+
<% end -%>
|
9
|
+
<% unless tree_model.size > 0 -%>
|
10
|
+
<% @tree_or_no_tree = 'RxModel' %>
|
5
11
|
import org.restfulx.models.RxModel;
|
12
|
+
<% end -%>
|
6
13
|
|
7
14
|
[Resource(name="<%= resource_controller_name %>")]
|
8
15
|
[Bindable]
|
9
|
-
public class <%= class_name %> extends
|
16
|
+
public class <%= class_name %> extends <%= @tree_or_no_tree %> {
|
10
17
|
<% if attributes && !attributes.empty? && attributes[0].flex_type != "Boolean" -%>
|
11
18
|
public static const LABEL:String = "<%= attributes[0].flex_name %>";
|
12
19
|
<% else -%>
|
@@ -24,6 +31,25 @@ package <%= base_package %>.models {
|
|
24
31
|
[BelongsTo]
|
25
32
|
public var <%= model.camelcase(:lower) %>:<%= model.camelcase %>;
|
26
33
|
|
34
|
+
<% end -%>
|
35
|
+
<% if tree_model.size > 0 -%>
|
36
|
+
[BelongsTo]
|
37
|
+
public var <%= tree_model[0].camelcase(:lower) %>:<%= class_name %>;
|
38
|
+
|
39
|
+
<% end -%>
|
40
|
+
<% for model in polymorphic -%>
|
41
|
+
[BelongsTo(polymorphic="true", dependsOn="Model1, Model2")]
|
42
|
+
public var <%= model.camelcase(:lower) %>:Object;
|
43
|
+
|
44
|
+
<% end -%>
|
45
|
+
<% if has_many_through.size > 0 -%>
|
46
|
+
<% has_many_through.each do |k,v| %>
|
47
|
+
[HasMany]
|
48
|
+
public var <%= k.camelcase(:lower) %>:ModelsCollection;
|
49
|
+
|
50
|
+
[HasMany(through="<%= k.camelcase %>")]
|
51
|
+
public var <%= v.camelcase(:lower) %>:ModelsCollection;
|
52
|
+
<% end -%>
|
27
53
|
<% end -%>
|
28
54
|
<% for model in has_ones -%>
|
29
55
|
[HasOne]
|
@@ -34,6 +60,11 @@ package <%= base_package %>.models {
|
|
34
60
|
[HasMany]
|
35
61
|
public var <%= model.camelcase(:lower) %>:ModelsCollection;
|
36
62
|
|
63
|
+
<% end -%>
|
64
|
+
<% if attachment_field.size > 0 -%>
|
65
|
+
[Ignored]
|
66
|
+
public var attachmentUrl:String;
|
67
|
+
|
37
68
|
<% end -%>
|
38
69
|
public function <%= class_name %>() {
|
39
70
|
super(LABEL);
|