restfulx 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +7 -0
- data/Manifest.txt +127 -0
- data/README.rdoc +50 -0
- data/Rakefile +42 -0
- data/app_generators/rx_app/USAGE +22 -0
- data/app_generators/rx_app/rx_app_generator.rb +94 -0
- data/app_generators/rx_app/templates/actionscript.properties +16 -0
- data/app_generators/rx_app/templates/actionscriptair.properties +16 -0
- data/app_generators/rx_app/templates/app.yaml.erb +12 -0
- data/app_generators/rx_app/templates/default_tasks.rake +51 -0
- data/app_generators/rx_app/templates/empty.txt +0 -0
- data/app_generators/rx_app/templates/expressInstall.swf +0 -0
- data/app_generators/rx_app/templates/flex.properties +2 -0
- data/app_generators/rx_app/templates/generate.rb +17 -0
- data/app_generators/rx_app/templates/html-template/AC_OETags.js +276 -0
- data/app_generators/rx_app/templates/html-template/history/history.css +6 -0
- data/app_generators/rx_app/templates/html-template/history/history.js +645 -0
- data/app_generators/rx_app/templates/html-template/history/historyFrame.html +29 -0
- data/app_generators/rx_app/templates/html-template/index.template.html +121 -0
- data/app_generators/rx_app/templates/html-template/playerProductInstall.swf +0 -0
- data/app_generators/rx_app/templates/index.html.erb +18 -0
- data/app_generators/rx_app/templates/index.yaml +11 -0
- data/app_generators/rx_app/templates/mainair-app.xml +134 -0
- data/app_generators/rx_app/templates/mainapp-config.xml +21 -0
- data/app_generators/rx_app/templates/mainapp.mxml +31 -0
- data/app_generators/rx_app/templates/project-textmate.erb +52 -0
- data/app_generators/rx_app/templates/project.properties +18 -0
- data/app_generators/rx_app/templates/projectair.properties +24 -0
- data/app_generators/rx_app/templates/swfobject.js +5 -0
- data/bin/rx-gen +31 -0
- data/generators/rx_config/USAGE +5 -0
- data/generators/rx_config/rx_config_generator.rb +19 -0
- data/generators/rx_controller/USAGE +10 -0
- data/generators/rx_controller/rx_controller_generator.rb +39 -0
- data/generators/rx_controller/templates/assist.py +65 -0
- data/generators/rx_controller/templates/controller.as.erb +36 -0
- data/generators/rx_controller/templates/restful.py +136 -0
- data/generators/rx_main_app/USAGE +8 -0
- data/generators/rx_main_app/rx_main_app_generator.rb +60 -0
- data/generators/rx_main_app/templates/main.py.erb +29 -0
- data/generators/rx_main_app/templates/mainapp.mxml +35 -0
- data/generators/rx_scaffold/USAGE +29 -0
- data/generators/rx_scaffold/rx_scaffold_generator.rb +146 -0
- data/generators/rx_scaffold/templates/component.mxml.erb +149 -0
- data/generators/rx_scaffold/templates/controller.py.erb +27 -0
- data/generators/rx_scaffold/templates/model.as.erb +42 -0
- data/generators/rx_scaffold/templates/model.py.erb +14 -0
- data/generators/rx_yaml_scaffold/USAGE +45 -0
- data/generators/rx_yaml_scaffold/rx_yaml_scaffold_generator.rb +47 -0
- data/lib/restfulx/active_foo.rb +186 -0
- data/lib/restfulx/active_record_tasks.rb +81 -0
- data/lib/restfulx/configuration.rb +76 -0
- data/lib/restfulx/datamapper_foo.rb +31 -0
- data/lib/restfulx/rails/recipes.rb +60 -0
- data/lib/restfulx/rails/swf_helper.rb +60 -0
- data/lib/restfulx/tasks.rb +85 -0
- data/lib/restfulx.rb +117 -0
- data/rails_generators/rx_config/USAGE +18 -0
- data/rails_generators/rx_config/rx_config_generator.rb +115 -0
- data/rails_generators/rx_config/templates/actionscript.properties +16 -0
- data/rails_generators/rx_config/templates/actionscriptair.properties +16 -0
- data/rails_generators/rx_config/templates/expressInstall.swf +0 -0
- data/rails_generators/rx_config/templates/flex.properties +2 -0
- data/rails_generators/rx_config/templates/html-template/AC_OETags.js +276 -0
- data/rails_generators/rx_config/templates/html-template/history/history.css +6 -0
- data/rails_generators/rx_config/templates/html-template/history/history.js +645 -0
- data/rails_generators/rx_config/templates/html-template/history/historyFrame.html +29 -0
- data/rails_generators/rx_config/templates/html-template/index.template.html +121 -0
- data/rails_generators/rx_config/templates/html-template/playerProductInstall.swf +0 -0
- data/rails_generators/rx_config/templates/index.html.erb +18 -0
- data/rails_generators/rx_config/templates/mainair-app.xml +134 -0
- data/rails_generators/rx_config/templates/mainapp-config.xml +21 -0
- data/rails_generators/rx_config/templates/mainapp.mxml +31 -0
- data/rails_generators/rx_config/templates/project-textmate.erb +52 -0
- data/rails_generators/rx_config/templates/project.properties +18 -0
- data/rails_generators/rx_config/templates/projectair.properties +24 -0
- data/rails_generators/rx_config/templates/restfulx.yml +14 -0
- data/rails_generators/rx_config/templates/restfulx_tasks.rake +6 -0
- data/rails_generators/rx_config/templates/swfobject.js +5 -0
- data/rails_generators/rx_controller/USAGE +10 -0
- data/rails_generators/rx_controller/rx_controller_generator.rb +28 -0
- data/rails_generators/rx_controller/templates/controller.as.erb +40 -0
- data/rails_generators/rx_scaffold/USAGE +35 -0
- data/rails_generators/rx_scaffold/rx_scaffold_generator.rb +179 -0
- data/rails_generators/rx_scaffold/templates/component.mxml.erb +149 -0
- data/rails_generators/rx_scaffold/templates/controller.rb.erb +97 -0
- data/rails_generators/rx_scaffold/templates/fixtures.yml.erb +35 -0
- data/rails_generators/rx_scaffold/templates/migration.rb.erb +19 -0
- data/rails_generators/rx_scaffold/templates/model.as.erb +42 -0
- data/rails_generators/rx_scaffold/templates/model.rb.erb +11 -0
- data/rails_generators/rx_yaml_scaffold/USAGE +51 -0
- data/rails_generators/rx_yaml_scaffold/rx_yaml_scaffold_generator.rb +49 -0
- data/rdoc/generators/template/html/jamis.rb +588 -0
- data/spec/restfulx_spec.rb +7 -0
- data/spec/spec_helper.rb +16 -0
- data/tasks/ann.rake +80 -0
- data/tasks/bones.rake +20 -0
- data/tasks/gem.rake +201 -0
- data/tasks/git.rake +40 -0
- data/tasks/manifest.rake +48 -0
- data/tasks/notes.rake +27 -0
- data/tasks/post_load.rake +39 -0
- data/tasks/rdoc.rake +50 -0
- data/tasks/rubyforge.rake +55 -0
- data/tasks/setup.rb +279 -0
- data/tasks/spec.rake +54 -0
- data/tasks/svn.rake +47 -0
- data/tasks/test.rake +40 -0
- data/test/rails/controllers/application.rb +15 -0
- data/test/rails/controllers/locations_controller.rb +93 -0
- data/test/rails/controllers/notes_controller.rb +96 -0
- data/test/rails/controllers/projects_controller.rb +93 -0
- data/test/rails/controllers/tasks_controller.rb +93 -0
- data/test/rails/controllers/users_controller.rb +93 -0
- data/test/rails/database.yml +4 -0
- data/test/rails/fixtures/locations.yml +8 -0
- data/test/rails/fixtures/notes.yml +17 -0
- data/test/rails/fixtures/projects.yml +25 -0
- data/test/rails/fixtures/simple_properties.yml +19 -0
- data/test/rails/fixtures/tasks.yml +46 -0
- data/test/rails/fixtures/users.yml +13 -0
- data/test/rails/helpers/functional_test_helper.rb +21 -0
- data/test/rails/helpers/test_helper.rb +61 -0
- data/test/rails/helpers/unit_test_helper.rb +30 -0
- data/test/rails/model.yml +35 -0
- data/test/rails/models/location.rb +4 -0
- data/test/rails/models/note.rb +3 -0
- data/test/rails/models/project.rb +4 -0
- data/test/rails/models/simple_property.rb +2 -0
- data/test/rails/models/task.rb +18 -0
- data/test/rails/models/user.rb +20 -0
- data/test/rails/playing_around_in_a_console.txt +71 -0
- data/test/rails/schema.rb +77 -0
- data/test/rails/test.swf +1 -0
- data/test/rails/test_active_foo.rb +36 -0
- data/test/rails/test_rails_integration_functional.rb +22 -0
- data/test/rails/test_to_fxml.rb +35 -0
- data/test/rails/test_to_json.rb +23 -0
- data/test/rails/views/notes/empty_params_action.html.erb +1 -0
- data/test/rails/views/notes/index.html.erb +1 -0
- metadata +227 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'restfulx') if !defined?(RestfulX)
|
|
2
|
+
|
|
3
|
+
module Rails
|
|
4
|
+
module Generator
|
|
5
|
+
class GeneratedAttribute
|
|
6
|
+
attr_accessor :name, :type, :column, :flex_name
|
|
7
|
+
|
|
8
|
+
def initialize(name, type)
|
|
9
|
+
@name, @type = name, type.to_sym
|
|
10
|
+
@flex_name = name.camelcase(:lower)
|
|
11
|
+
@column = ActiveRecord::ConnectionAdapters::Column.new(name, nil, @type)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def field_type
|
|
15
|
+
@field_type ||= case type
|
|
16
|
+
when :integer, :float, :decimal then :text_field
|
|
17
|
+
when :datetime, :timestamp, :time then :datetime_select
|
|
18
|
+
when :date then :date_select
|
|
19
|
+
when :string then :text_field
|
|
20
|
+
when :text then :text_area
|
|
21
|
+
when :boolean then :check_box
|
|
22
|
+
else
|
|
23
|
+
:text_field
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def default(prefix = '')
|
|
28
|
+
@default = case type
|
|
29
|
+
when :integer then 1
|
|
30
|
+
when :float then 1.5
|
|
31
|
+
when :decimal then "9.99"
|
|
32
|
+
when :datetime, :timestamp, :time then Time.now.to_s(:db)
|
|
33
|
+
when :date then Date.today.to_s(:db)
|
|
34
|
+
when :string then prefix + name.camelize + "String"
|
|
35
|
+
when :text then prefix + name.camelize + "Text"
|
|
36
|
+
when :boolean then false
|
|
37
|
+
else
|
|
38
|
+
""
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def flex_type
|
|
43
|
+
@flex_type = case type
|
|
44
|
+
when :integer then 'int'
|
|
45
|
+
when :date, :datetime, :time then 'Date'
|
|
46
|
+
when :boolean then 'Boolean'
|
|
47
|
+
when :float, :decimal then 'Number'
|
|
48
|
+
else
|
|
49
|
+
'String'
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def flex_default
|
|
54
|
+
@flex_default = case type
|
|
55
|
+
when :integer then '0'
|
|
56
|
+
when :date, :datetime, :time then 'new Date'
|
|
57
|
+
when :boolean then 'false'
|
|
58
|
+
when :float, :decimal then 'new Number'
|
|
59
|
+
else
|
|
60
|
+
"\"\""
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
class RxScaffoldGenerator < Rails::Generator::NamedBase
|
|
68
|
+
include RestfulX::Configuration
|
|
69
|
+
|
|
70
|
+
attr_reader :project_name,
|
|
71
|
+
:flex_project_name,
|
|
72
|
+
:base_package,
|
|
73
|
+
:base_folder,
|
|
74
|
+
:command_controller_name
|
|
75
|
+
|
|
76
|
+
attr_reader :belongs_tos,
|
|
77
|
+
:has_manies,
|
|
78
|
+
:has_ones
|
|
79
|
+
|
|
80
|
+
attr_reader :controller_name,
|
|
81
|
+
:controller_class_path,
|
|
82
|
+
:controller_file_path,
|
|
83
|
+
:controller_class_nesting,
|
|
84
|
+
:controller_class_nesting_depth,
|
|
85
|
+
:controller_class_name,
|
|
86
|
+
:controller_underscore_name,
|
|
87
|
+
:controller_singular_name,
|
|
88
|
+
:controller_plural_name
|
|
89
|
+
|
|
90
|
+
alias_method :controller_file_name, :controller_underscore_name
|
|
91
|
+
alias_method :controller_table_name, :controller_plural_name
|
|
92
|
+
|
|
93
|
+
def initialize(runtime_args, runtime_options = {})
|
|
94
|
+
super
|
|
95
|
+
@project_name, @flex_project_name, @command_controller_name, @base_package, @base_folder = extract_names
|
|
96
|
+
@controller_name = @name.pluralize
|
|
97
|
+
|
|
98
|
+
base_name, @controller_class_path, @controller_file_path, @controller_class_nesting,
|
|
99
|
+
@controller_class_nesting_depth = extract_modules(@controller_name)
|
|
100
|
+
@controller_class_name_without_nesting, @controller_underscore_name, @controller_plural_name = inflect_names(base_name)
|
|
101
|
+
|
|
102
|
+
@controller_singular_name=base_name.singularize
|
|
103
|
+
if @controller_class_nesting.empty?
|
|
104
|
+
@controller_class_name = @controller_class_name_without_nesting
|
|
105
|
+
else
|
|
106
|
+
@controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}"
|
|
107
|
+
end
|
|
108
|
+
extract_relationships
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def manifest
|
|
112
|
+
record do |m|
|
|
113
|
+
m.dependency 'scaffold', [name] + @args, :skip_migration => true, :collision => :skip unless options[:flex_only]
|
|
114
|
+
|
|
115
|
+
# Generate Flex AS model and MXML component based on the
|
|
116
|
+
# RestfulX templates.
|
|
117
|
+
m.template 'model.as.erb',
|
|
118
|
+
File.join("app", "flex", base_folder, "models", "#{@class_name}.as"),
|
|
119
|
+
:assigns => { :resource_controller_name => "#{file_name.pluralize}" }
|
|
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}" }
|
|
124
|
+
|
|
125
|
+
m.template 'controller.rb.erb', File.join("app/controllers", controller_class_path,
|
|
126
|
+
"#{controller_file_name}_controller.rb"), :collision => :force unless options[:flex_only]
|
|
127
|
+
|
|
128
|
+
# Create a new generated ActiveRecord model based on the RestfulX templates.
|
|
129
|
+
m.template 'model.rb.erb', File.join("app", "models", "#{file_name}.rb"),
|
|
130
|
+
:collision => :force unless options[:flex_only]
|
|
131
|
+
|
|
132
|
+
unless options[:skip_fixture]
|
|
133
|
+
m.template 'fixtures.yml.erb', File.join("test", "fixtures", "#{table_name}.yml"),
|
|
134
|
+
:collision => :force unless options[:flex_only]
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
unless options[:skip_migration]
|
|
138
|
+
m.directory 'schema/migration'
|
|
139
|
+
m.migration_template 'migration.rb.erb', 'db/migrate', :assigns => {
|
|
140
|
+
:migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}"
|
|
141
|
+
}, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}" unless options[:flex_only]
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
m.dependency 'rx_controller', [name] + @args, :collision => :force
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
protected
|
|
149
|
+
def extract_relationships
|
|
150
|
+
@belongs_tos = []
|
|
151
|
+
@has_ones = []
|
|
152
|
+
@has_manies = []
|
|
153
|
+
# Figure out has_one, has_many and belongs_to based on args
|
|
154
|
+
@args.each do |arg|
|
|
155
|
+
if arg =~ /^has_one:/
|
|
156
|
+
# arg = "has_one:arg1,arg2", so all the has_one are together
|
|
157
|
+
@has_ones = arg.split(':')[1].split(',')
|
|
158
|
+
elsif arg =~ /^has_many:/
|
|
159
|
+
# arg = "has_many:arg1,arg2", so all the has_many are together
|
|
160
|
+
@has_manies = arg.split(":")[1].split(",")
|
|
161
|
+
elsif arg =~ /^belongs_to:/ # belongs_to:arg1,arg2
|
|
162
|
+
@belongs_tos = arg.split(":")[1].split(',')
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
# Remove the has_one and has_many arguments since they are
|
|
167
|
+
# not for consumption by the scaffold generator, and since
|
|
168
|
+
# we have already used them to set the @belongs_tos, @has_ones and
|
|
169
|
+
# @has_manies.
|
|
170
|
+
@args.delete_if { |elt| elt =~ /^(has_one|has_many|belongs_to):/ }
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def add_options!(opt)
|
|
174
|
+
opt.separator ''
|
|
175
|
+
opt.separator 'Options:'
|
|
176
|
+
opt.on("--flex-only", "Scaffold Flex code only",
|
|
177
|
+
"Default: false") { |v| options[:flex_only] = v}
|
|
178
|
+
end
|
|
179
|
+
end
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" label="<%= class_name %>"
|
|
3
|
+
xmlns:rcomponents="org.restfulx.components.*">
|
|
4
|
+
<mx:Script><![CDATA[
|
|
5
|
+
import org.restfulx.Rx;
|
|
6
|
+
import org.restfulx.utils.RxUtils;
|
|
7
|
+
import <%= base_package %>.models.<%= class_name %>;
|
|
8
|
+
<% for model in belongs_tos -%>
|
|
9
|
+
import <%= base_package %>.models.<%= model.camelcase %>;
|
|
10
|
+
<% end -%>
|
|
11
|
+
|
|
12
|
+
[Bindable]
|
|
13
|
+
private var _<%= class_name.dcfirst %>:<%= class_name %> = new <%= class_name %>();
|
|
14
|
+
|
|
15
|
+
private function new<%= class_name %>():void {
|
|
16
|
+
_<%= class_name.dcfirst %> = new <%= class_name %>();
|
|
17
|
+
<%= class_name.dcfirst.pluralize %>List.selectedIndex = -1;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
private function save<%= class_name %>():void {
|
|
21
|
+
if (_<%= class_name.dcfirst %>.id) {
|
|
22
|
+
update<%= class_name %>();
|
|
23
|
+
} else {
|
|
24
|
+
create<%= class_name %>();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
private function create<%= class_name %>():void {
|
|
29
|
+
var <%= class_name.dcfirst %>:<%= class_name %> = new <%= class_name %>();
|
|
30
|
+
<% for attribute in attributes -%>
|
|
31
|
+
<% if attribute.type == :boolean -%>
|
|
32
|
+
<%= class_name.dcfirst %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>CheckBox.selected;
|
|
33
|
+
<% elsif attribute.type == :string -%>
|
|
34
|
+
<%= class_name.dcfirst %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>TextInput.text;
|
|
35
|
+
<% elsif attribute.type == :text -%>
|
|
36
|
+
<%= class_name.dcfirst %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>TextArea.text;
|
|
37
|
+
<% elsif attribute.type == :datetime || attribute.type == :time -%>
|
|
38
|
+
<%= class_name.dcfirst %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>DateTimeTextInput.date;
|
|
39
|
+
<% elsif attribute.type == :date -%>
|
|
40
|
+
<%= class_name.dcfirst %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>DateField.selectedDate;
|
|
41
|
+
<% else -%>
|
|
42
|
+
<%= class_name.dcfirst %>.<%= attribute.flex_name %> = <%= attribute.flex_type %>(<%= attribute.flex_name %>TextInput.text);
|
|
43
|
+
<% end -%>
|
|
44
|
+
<% end -%>
|
|
45
|
+
|
|
46
|
+
<% for model in belongs_tos -%>
|
|
47
|
+
<%= class_name.dcfirst %>.<%= model.camelcase(:lower) %> = <%= model.camelcase %>(<%= model.camelcase(:lower) %>ComboBox.selectedItem);
|
|
48
|
+
<% end -%>
|
|
49
|
+
<%= class_name.dcfirst %>.create({onSuccess: on<%= class_name %>Create});
|
|
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 -%>
|
|
67
|
+
<% 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
|
+
}
|
|
74
|
+
|
|
75
|
+
private function destroy<%= class_name %>():void {
|
|
76
|
+
_<%= class_name.dcfirst %>.destroy({onSuccess: on<%= class_name %>Destroy});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
private function on<%= class_name %>Select():void {
|
|
80
|
+
_<%= class_name.dcfirst %> = RxUtils.clone(<%= class_name.dcfirst.pluralize %>List.selectedItem) as <%= class_name %>;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
private function on<%= class_name %>Create(<%= class_name.dcfirst %>:<%= class_name %>):void {
|
|
84
|
+
_<%= class_name.dcfirst %> = new <%= class_name %>;
|
|
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 %>;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private function on<%= class_name %>Destroy(<%= class_name.dcfirst %>:<%= class_name %>):void {
|
|
93
|
+
on<%= class_name %>Create(<%= class_name.dcfirst %>);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
private function canDelete<%= class_name %>(<%= class_name.dcfirst %>:<%= class_name %>):Boolean {
|
|
97
|
+
return <%= class_name.dcfirst %> != null && !RxUtils.isEmpty(<%= class_name.dcfirst %>.id);
|
|
98
|
+
}
|
|
99
|
+
]]></mx:Script>
|
|
100
|
+
<mx:Panel id="<%= class_name.dcfirst.pluralize %>Panel"
|
|
101
|
+
title="<%= class_name.pluralize %>" cornerRadius="0" dropShadowEnabled="false" borderStyle="solid"
|
|
102
|
+
borderThickness="1" backgroundColor="#EEEEEE" width="25%" height="100%">
|
|
103
|
+
<mx:List id="<%= class_name.dcfirst.pluralize %>List"
|
|
104
|
+
width="100%" height="100%"
|
|
105
|
+
dataProvider="{Rx.models.index(<%= class_name %>)}"
|
|
106
|
+
change="on<%= class_name %>Select()"/>
|
|
107
|
+
<mx:ControlBar width="100%">
|
|
108
|
+
<mx:Button label="New <%= class_name %>" width="100%" height="30"
|
|
109
|
+
click="new<%= class_name %>()"/>
|
|
110
|
+
</mx:ControlBar>
|
|
111
|
+
</mx:Panel>
|
|
112
|
+
<mx:Panel title="Edit <%= class_name %>" cornerRadius="0" dropShadowEnabled="false" borderStyle="solid"
|
|
113
|
+
borderThickness="1" backgroundColor="#EEEEEE" width="75%" height="100%">
|
|
114
|
+
<mx:Form width="100%" height="100%">
|
|
115
|
+
<% for attribute in attributes -%>
|
|
116
|
+
<mx:FormItem label="<%= attribute.flex_name.ucfirst %>" width="100%">
|
|
117
|
+
<% if attribute.type == :boolean -%>
|
|
118
|
+
<mx:CheckBox id="<%= attribute.flex_name %>CheckBox" selected="{_<%= class_name.dcfirst %>.<%= attribute.flex_name %>}"/>
|
|
119
|
+
<% elsif attribute.type == :string -%>
|
|
120
|
+
<mx:TextInput id="<%= attribute.flex_name %>TextInput" width="100%" text="{_<%= class_name.dcfirst %>.<%= attribute.flex_name %>}"/>
|
|
121
|
+
<% elsif attribute.type == :text -%>
|
|
122
|
+
<mx:TextArea id="<%= attribute.flex_name %>TextArea" width="100%" height="200" text="{_<%= class_name.dcfirst %>.<%= attribute.flex_name %>}"/>
|
|
123
|
+
<% elsif attribute.type == :datetime || attribute.type == :time -%>
|
|
124
|
+
<rcomponents:DateTimeTextInput id="<%= attribute.flex_name %>DateTimeTextInput" width="200" date="{_<%= class_name.dcfirst %>.<%= attribute.flex_name %>}"/>
|
|
125
|
+
<% elsif attribute.type == :date -%>
|
|
126
|
+
<mx:DateField id="<%= attribute.flex_name %>DateField" selectedDate="{_<%= class_name.dcfirst %>.<%= attribute.flex_name %>}"/>
|
|
127
|
+
<% else -%>
|
|
128
|
+
<mx:TextInput id="<%= attribute.flex_name %>TextInput" width="100%" text="{_<%= class_name.dcfirst %>.<%= attribute.flex_name %>}"/>
|
|
129
|
+
<% end -%>
|
|
130
|
+
</mx:FormItem>
|
|
131
|
+
<% end -%>
|
|
132
|
+
<% for model in belongs_tos -%>
|
|
133
|
+
<mx:FormItem label="<%= model.camelcase %>" width="100%">
|
|
134
|
+
<mx:ComboBox id="<%= model.camelcase(:lower) %>ComboBox" width="200"
|
|
135
|
+
labelField="{<%= model.camelcase %>.LABEL}"
|
|
136
|
+
dataProvider="{Rx.models.index(<%= model.camelcase %>)}" prompt="<%= model.camelcase %> ..."
|
|
137
|
+
selectedItem="{_<%= class_name.dcfirst %>.<%= model.camelcase(:lower) %>}" />
|
|
138
|
+
</mx:FormItem>
|
|
139
|
+
<% end -%>
|
|
140
|
+
</mx:Form>
|
|
141
|
+
<mx:ControlBar width="100%">
|
|
142
|
+
<mx:Button label="Save <%= class_name %>" width="50%" height="30"
|
|
143
|
+
click="save<%= class_name %>()"/>
|
|
144
|
+
<mx:Button label="Delete <%= class_name %>" width="50%" height="30"
|
|
145
|
+
enabled="{canDelete<%= class_name %>(_<%= class_name.dcfirst %>)}"
|
|
146
|
+
click="destroy<%= class_name %>()"/>
|
|
147
|
+
</mx:ControlBar>
|
|
148
|
+
</mx:Panel>
|
|
149
|
+
</mx:HBox>
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
class <%= controller_class_name %>Controller < ApplicationController
|
|
2
|
+
# GET /<%= table_name %>
|
|
3
|
+
# GET /<%= table_name %>.xml
|
|
4
|
+
# GET /<%= table_name %>.fxml
|
|
5
|
+
def index
|
|
6
|
+
@<%= table_name %> = <%= class_name %>.find(:all)
|
|
7
|
+
|
|
8
|
+
respond_to do |format|
|
|
9
|
+
format.html # index.html.erb
|
|
10
|
+
format.xml { render :xml => @<%= table_name %> }
|
|
11
|
+
format.fxml { render :fxml => @<%= table_name %> }
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# GET /<%= table_name %>/1
|
|
16
|
+
# GET /<%= table_name %>/1.xml
|
|
17
|
+
# GET /<%= table_name %>/1.fxml
|
|
18
|
+
def show
|
|
19
|
+
@<%= file_name %> = <%= class_name %>.find(params[:id])
|
|
20
|
+
|
|
21
|
+
respond_to do |format|
|
|
22
|
+
format.html # show.html.erb
|
|
23
|
+
format.xml { render :xml => @<%= file_name %> }
|
|
24
|
+
format.fxml { render :fxml => @<%= file_name %> }
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# GET /<%= table_name %>/new
|
|
29
|
+
# GET /<%= table_name %>/new.xml
|
|
30
|
+
def new
|
|
31
|
+
@<%= file_name %> = <%= class_name %>.new
|
|
32
|
+
|
|
33
|
+
respond_to do |format|
|
|
34
|
+
format.html # new.html.erb
|
|
35
|
+
format.xml { render :xml => @<%= file_name %> }
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# GET /<%= table_name %>/1/edit
|
|
40
|
+
def edit
|
|
41
|
+
@<%= file_name %> = <%= class_name %>.find(params[:id])
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# POST /<%= table_name %>
|
|
45
|
+
# POST /<%= table_name %>.xml
|
|
46
|
+
# POST /<%= table_name %>.fxml
|
|
47
|
+
def create
|
|
48
|
+
@<%= file_name %> = <%= class_name %>.new(params[:<%= file_name %>])
|
|
49
|
+
|
|
50
|
+
respond_to do |format|
|
|
51
|
+
if @<%= file_name %>.save
|
|
52
|
+
flash[:notice] = '<%= class_name %> was successfully created.'
|
|
53
|
+
format.html { redirect_to(@<%= file_name %>) }
|
|
54
|
+
format.xml { render :xml => @<%= file_name %>, :status => :created, :location => @<%= file_name %> }
|
|
55
|
+
format.fxml { render :fxml => @<%= file_name %> }
|
|
56
|
+
else
|
|
57
|
+
format.html { render :action => "new" }
|
|
58
|
+
format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity }
|
|
59
|
+
format.fxml { render :fxml => @<%= file_name %>.errors }
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# PUT /<%= table_name %>/1
|
|
65
|
+
# PUT /<%= table_name %>/1.xml
|
|
66
|
+
# PUT /<%= table_name %>/1.fxml
|
|
67
|
+
def update
|
|
68
|
+
@<%= file_name %> = <%= class_name %>.find(params[:id])
|
|
69
|
+
|
|
70
|
+
respond_to do |format|
|
|
71
|
+
if @<%= file_name %>.update_attributes(params[:<%= file_name %>])
|
|
72
|
+
flash[:notice] = '<%= class_name %> was successfully updated.'
|
|
73
|
+
format.html { redirect_to(@<%= file_name %>) }
|
|
74
|
+
format.xml { head :ok }
|
|
75
|
+
format.fxml { render :fxml => @<%= file_name %> }
|
|
76
|
+
else
|
|
77
|
+
format.html { render :action => "edit" }
|
|
78
|
+
format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity }
|
|
79
|
+
format.fxml { render :fxml => @<%= file_name %>.errors }
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# DELETE /<%= table_name %>/1
|
|
85
|
+
# DELETE /<%= table_name %>/1.xml
|
|
86
|
+
# DELETE /<%= table_name %>/1.fxml
|
|
87
|
+
def destroy
|
|
88
|
+
@<%= file_name %> = <%= class_name %>.find(params[:id])
|
|
89
|
+
@<%= file_name %>.destroy
|
|
90
|
+
|
|
91
|
+
respond_to do |format|
|
|
92
|
+
format.html { redirect_to(<%= table_name %>_url) }
|
|
93
|
+
format.xml { head :ok }
|
|
94
|
+
format.fxml { render :fxml => @<%= file_name %> }
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
|
2
|
+
|
|
3
|
+
<% unless attributes.empty? && belongs_tos.empty? -%>
|
|
4
|
+
<%= class_name.underscore -%>_one:
|
|
5
|
+
<% for attribute in attributes -%>
|
|
6
|
+
<%= attribute.name %>: <%= attribute.default("#{class_name}1") %>
|
|
7
|
+
<% end -%>
|
|
8
|
+
<% for model in belongs_tos -%>
|
|
9
|
+
<%= model %>: <%= model %>_one
|
|
10
|
+
<% end -%>
|
|
11
|
+
|
|
12
|
+
<%= class_name.underscore -%>_two:
|
|
13
|
+
<% for attribute in attributes -%>
|
|
14
|
+
<%= attribute.name %>: <%= attribute.default("#{class_name}2") %>
|
|
15
|
+
<% end -%>
|
|
16
|
+
<% for model in belongs_tos -%>
|
|
17
|
+
<%= model %>: <%= model %>_two
|
|
18
|
+
<% end -%>
|
|
19
|
+
|
|
20
|
+
<%= class_name.underscore -%>_three:
|
|
21
|
+
<% for attribute in attributes -%>
|
|
22
|
+
<%= attribute.name %>: <%= attribute.default("#{class_name}3") %>
|
|
23
|
+
<% end -%>
|
|
24
|
+
<% for model in belongs_tos -%>
|
|
25
|
+
<%= model %>: <%= model %>_three
|
|
26
|
+
<% end -%>
|
|
27
|
+
|
|
28
|
+
<%= class_name.underscore -%>_four:
|
|
29
|
+
<% for attribute in attributes -%>
|
|
30
|
+
<%= attribute.name %>: <%= attribute.default("#{class_name}4") %>
|
|
31
|
+
<% end -%>
|
|
32
|
+
<% for model in belongs_tos -%>
|
|
33
|
+
<%= model %>: <%= model %>_four
|
|
34
|
+
<% end -%>
|
|
35
|
+
<% end -%>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
class <%= migration_name %> < ActiveRecord::Migration
|
|
2
|
+
def self.up
|
|
3
|
+
create_table :<%= table_name %> do |t|
|
|
4
|
+
<% for attribute in attributes -%>
|
|
5
|
+
t.<%= attribute.type %> :<%= attribute.name %>
|
|
6
|
+
<% end -%>
|
|
7
|
+
<% for model in belongs_tos -%>
|
|
8
|
+
t.references :<%= model %>
|
|
9
|
+
<% end -%>
|
|
10
|
+
<% unless options[:skip_timestamps] %>
|
|
11
|
+
t.timestamps
|
|
12
|
+
<% end -%>
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.down
|
|
17
|
+
drop_table :<%= table_name %>
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
package <%= base_package %>.models {
|
|
2
|
+
<% if has_manies.length > 0 -%>
|
|
3
|
+
import org.restfulx.collections.ModelsCollection;
|
|
4
|
+
<% end -%>
|
|
5
|
+
import org.restfulx.models.RxModel;
|
|
6
|
+
|
|
7
|
+
[Resource(name="<%= resource_controller_name %>")]
|
|
8
|
+
[Bindable]
|
|
9
|
+
public class <%= class_name %> extends RxModel {
|
|
10
|
+
<% if attributes && !attributes.empty? && attributes[0].flex_type != "Boolean" -%>
|
|
11
|
+
public static const LABEL:String = "<%= attributes[0].flex_name %>";
|
|
12
|
+
<% else -%>
|
|
13
|
+
public static const LABEL:String = "id";
|
|
14
|
+
<% end -%>
|
|
15
|
+
|
|
16
|
+
<% for attribute in attributes -%>
|
|
17
|
+
<% if attribute.type == :datetime || attribute.type == :time -%>
|
|
18
|
+
[DateTime]
|
|
19
|
+
<% end -%>
|
|
20
|
+
public var <%= attribute.flex_name %>:<%= attribute.flex_type %> = <%= attribute.flex_default %>;
|
|
21
|
+
|
|
22
|
+
<% end -%>
|
|
23
|
+
<% for model in belongs_tos -%>
|
|
24
|
+
[BelongsTo]
|
|
25
|
+
public var <%= model.camelcase(:lower) %>:<%= model.camelcase %>;
|
|
26
|
+
|
|
27
|
+
<% end -%>
|
|
28
|
+
<% for model in has_ones -%>
|
|
29
|
+
[HasOne]
|
|
30
|
+
public var <%= model.camelcase(:lower) %>:<%= model.camelcase %>;
|
|
31
|
+
|
|
32
|
+
<% end -%>
|
|
33
|
+
<% for model in has_manies -%>
|
|
34
|
+
[HasMany]
|
|
35
|
+
public var <%= model.camelcase(:lower) %>:ModelsCollection;
|
|
36
|
+
|
|
37
|
+
<% end -%>
|
|
38
|
+
public function <%= class_name %>() {
|
|
39
|
+
super(LABEL);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
class <%= class_name %> < ActiveRecord::Base
|
|
2
|
+
<% for model in belongs_tos -%>
|
|
3
|
+
belongs_to :<%= model %>
|
|
4
|
+
<% end -%>
|
|
5
|
+
<% for model in has_ones -%>
|
|
6
|
+
has_one :<%= model %>
|
|
7
|
+
<% end -%>
|
|
8
|
+
<% for model in has_manies -%>
|
|
9
|
+
has_many :<%= model %>
|
|
10
|
+
<% end -%>
|
|
11
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
Description:
|
|
2
|
+
Scaffolds an entire application based on db/model.yml file. This generator
|
|
3
|
+
transforms entries in db/model.yml into command line calls to
|
|
4
|
+
"rx_scaffold".
|
|
5
|
+
|
|
6
|
+
rx_scaffold delegates the underlying rails code generation to "scaffold"
|
|
7
|
+
and extends it in a number of ways:
|
|
8
|
+
1. Generates all required Flex code.
|
|
9
|
+
2. You can pass special belongs_to, has_one and has_many attributes
|
|
10
|
+
to generate *all* appropriate relationships. No more manual code
|
|
11
|
+
editing.
|
|
12
|
+
|
|
13
|
+
Examples:
|
|
14
|
+
`./script/generate rx_yaml_scaffold`
|
|
15
|
+
|
|
16
|
+
Sample Model File:
|
|
17
|
+
project:
|
|
18
|
+
- name: string
|
|
19
|
+
- notes: text
|
|
20
|
+
- start_date: date
|
|
21
|
+
- end_date: date
|
|
22
|
+
- completed: boolean
|
|
23
|
+
- belongs_to: [user]
|
|
24
|
+
- has_many: [tasks]
|
|
25
|
+
|
|
26
|
+
location:
|
|
27
|
+
- name: string
|
|
28
|
+
- notes: text
|
|
29
|
+
- belongs_to: [user]
|
|
30
|
+
- has_many: [tasks]
|
|
31
|
+
|
|
32
|
+
task:
|
|
33
|
+
- name: string
|
|
34
|
+
- notes: text
|
|
35
|
+
- start_time: datetime
|
|
36
|
+
- end_time: datetime
|
|
37
|
+
- completed: boolean
|
|
38
|
+
- next_action: boolean
|
|
39
|
+
- belongs_to: [project, location, user]
|
|
40
|
+
|
|
41
|
+
note:
|
|
42
|
+
- content: text
|
|
43
|
+
- belongs_to: [user]
|
|
44
|
+
|
|
45
|
+
user:
|
|
46
|
+
- login: string
|
|
47
|
+
- first_name: string
|
|
48
|
+
- last_name: string
|
|
49
|
+
- email: string
|
|
50
|
+
- has_many: [tasks, projects, locations]
|
|
51
|
+
- has_one: [note]
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
require 'yaml'
|
|
2
|
+
|
|
3
|
+
class RxYamlScaffoldGenerator < Rails::Generator::Base
|
|
4
|
+
def extract_attrs(line, attrs)
|
|
5
|
+
attrs.each do |key,value|
|
|
6
|
+
if value.class == Array
|
|
7
|
+
line << " #{key}:#{value.join(',')}"
|
|
8
|
+
else
|
|
9
|
+
line << " #{key}:#{value}"
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
line
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def manifest
|
|
16
|
+
record do |m|
|
|
17
|
+
models = YAML.load(File.open(File.join(RAILS_ROOT, 'db/model.yml'), 'r'))
|
|
18
|
+
models.each do |model|
|
|
19
|
+
line = ""
|
|
20
|
+
attrs = model[1]
|
|
21
|
+
if attrs.class == Array
|
|
22
|
+
attrs.each do |elm|
|
|
23
|
+
line = extract_attrs(line, elm)
|
|
24
|
+
end
|
|
25
|
+
else
|
|
26
|
+
line = extract_attrs(line, attrs)
|
|
27
|
+
end
|
|
28
|
+
line = model[0].camelcase + " " + line
|
|
29
|
+
puts 'running: rx_scaffold ' + line
|
|
30
|
+
Rails::Generator::Scripts::Generate.new.run(["rx_scaffold"] + line.split,
|
|
31
|
+
:flex_only => options[:flex_only])
|
|
32
|
+
puts 'done ...'
|
|
33
|
+
sleep 1
|
|
34
|
+
end
|
|
35
|
+
Rails::Generator::Scripts::Generate.new.run(["rx_config"], :main_only => true,
|
|
36
|
+
:skip_framework => options[:skip_framework])
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
protected
|
|
41
|
+
def add_options!(opt)
|
|
42
|
+
opt.separator ''
|
|
43
|
+
opt.separator 'Options:'
|
|
44
|
+
opt.on("--flex-only", "Only generate the Flex/AIR files.",
|
|
45
|
+
"Default: false") { |v| options[:flex_only] = v }
|
|
46
|
+
opt.on("--skip-framework", "Don't fetch the latest framework binary. You'll have to link/build the framework yourself.",
|
|
47
|
+
"Default: false") { |v| options[:skip_framework] = v }
|
|
48
|
+
end
|
|
49
|
+
end
|