captproton-restfulx 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +50 -0
- data/Rakefile +79 -0
- data/VERSION.yml +4 -0
- data/app_generators/rx_app/USAGE +22 -0
- data/app_generators/rx_app/rx_app_generator.rb +110 -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 +38 -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 +22 -0
- data/app_generators/rx_app/templates/mainapp.mxml +152 -0
- data/app_generators/rx_app/templates/project-textmate.erb +72 -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/restfulx.yml +46 -0
- data/app_generators/rx_app/templates/swfobject.js +5 -0
- data/bin/rx-gen +31 -0
- data/lib/restfulx.rb +90 -0
- data/lib/restfulx/active_foo.rb +181 -0
- data/lib/restfulx/active_record_tasks.rb +90 -0
- data/lib/restfulx/active_record_uuid_helper.rb +17 -0
- data/lib/restfulx/configuration.rb +75 -0
- data/lib/restfulx/datamapper_foo.rb +81 -0
- data/lib/restfulx/rails/recipes.rb +60 -0
- data/lib/restfulx/rails/schema_to_yaml.rb +112 -0
- data/lib/restfulx/rails/schema_to_yaml/extensions/enumerable.rb +8 -0
- data/lib/restfulx/rails/schema_to_yaml/settings/config.rb +17 -0
- data/lib/restfulx/rails/schema_to_yaml/settings/core.rb +73 -0
- data/lib/restfulx/rails/swf_helper.rb +59 -0
- data/lib/restfulx/tasks.rb +110 -0
- data/rails_generators/rx_config/USAGE +19 -0
- data/rails_generators/rx_config/rx_config_generator.rb +151 -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/flex_controller.erb +4 -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.erb +16 -0
- data/rails_generators/rx_config/templates/mainair-app.xml +134 -0
- data/rails_generators/rx_config/templates/mainapp-config.xml +22 -0
- data/rails_generators/rx_config/templates/mainapp.mxml +129 -0
- data/rails_generators/rx_config/templates/project-textmate.erb +72 -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.erb +75 -0
- data/rails_generators/rx_config/templates/restfulx.yml +65 -0
- data/rails_generators/rx_config/templates/restfulx_tasks.rake +9 -0
- data/rails_generators/rx_config/templates/routes.erb +47 -0
- data/rails_generators/rx_config/templates/session_store_flash.erb +1 -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 +31 -0
- data/rails_generators/rx_controller/templates/controller.as.erb +38 -0
- data/rails_generators/rx_main_app/USAGE +8 -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/USAGE +35 -0
- data/rails_generators/rx_scaffold/rx_scaffold_generator.rb +242 -0
- data/rails_generators/rx_scaffold/templates/controllers/default.rb.erb +125 -0
- data/rails_generators/rx_scaffold/templates/controllers/resource_controller.rb.erb +23 -0
- data/rails_generators/rx_scaffold/templates/fixtures.yml.erb +39 -0
- data/rails_generators/rx_scaffold/templates/functional_test.rb +45 -0
- data/rails_generators/rx_scaffold/templates/helper_test.rb +4 -0
- data/rails_generators/rx_scaffold/templates/layouts/default.erb +167 -0
- data/rails_generators/rx_scaffold/templates/migration.rb.erb +46 -0
- data/rails_generators/rx_scaffold/templates/model.as.erb +73 -0
- data/rails_generators/rx_scaffold/templates/model.rb.erb +46 -0
- data/rails_generators/rx_yaml_scaffold/USAGE +51 -0
- data/rails_generators/rx_yaml_scaffold/rx_yaml_scaffold_generator.rb +68 -0
- data/rxgen_generators/rx_config/USAGE +5 -0
- data/rxgen_generators/rx_config/rx_config_generator.rb +21 -0
- data/rxgen_generators/rx_controller/USAGE +10 -0
- data/rxgen_generators/rx_controller/rx_controller_generator.rb +41 -0
- data/rxgen_generators/rx_controller/templates/assist.py +65 -0
- data/rxgen_generators/rx_controller/templates/controller.as.erb +38 -0
- data/rxgen_generators/rx_controller/templates/iso8601.py +92 -0
- data/rxgen_generators/rx_controller/templates/restful.py +136 -0
- data/rxgen_generators/rx_main_app/USAGE +8 -0
- data/rxgen_generators/rx_main_app/rx_main_app_generator.rb +65 -0
- data/rxgen_generators/rx_main_app/templates/main.py.erb +29 -0
- data/rxgen_generators/rx_main_app/templates/mainapp.mxml +152 -0
- data/rxgen_generators/rx_scaffold/USAGE +29 -0
- data/rxgen_generators/rx_scaffold/rx_scaffold_generator.rb +194 -0
- data/rxgen_generators/rx_scaffold/templates/controller.py.erb +27 -0
- data/rxgen_generators/rx_scaffold/templates/layouts/default.erb +167 -0
- data/rxgen_generators/rx_scaffold/templates/model.as.erb +73 -0
- data/rxgen_generators/rx_scaffold/templates/model.py.erb +14 -0
- data/rxgen_generators/rx_yaml_scaffold/USAGE +45 -0
- data/rxgen_generators/rx_yaml_scaffold/rx_yaml_scaffold_generator.rb +47 -0
- data/spec/restfulx_spec.rb +4 -0
- data/spec/spec_helper.rb +13 -0
- data/tasks/restfulx.rake +2 -0
- data/test/rails/controllers/application_controller.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 +54 -0
- data/test/rails/helpers/unit_test_helper.rb +29 -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/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 +234 -0
@@ -0,0 +1,129 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<mx:<%= application_tag %> xmlns:mx="http://www.adobe.com/2006/mxml"
|
3
|
+
xmlns:generated="<%= base_package %>.views.generated.*"
|
4
|
+
paddingBottom="8" paddingLeft="8" paddingRight="8" paddingTop="8"
|
5
|
+
layout="horizontal" styleName="plain" initialize="init()">
|
6
|
+
<mx:Script>
|
7
|
+
<![CDATA[
|
8
|
+
<% if use_air -%>
|
9
|
+
<% if distributed -%>
|
10
|
+
import air.net.SocketMonitor;
|
11
|
+
import org.restfulx.events.PullEndEvent;
|
12
|
+
import org.restfulx.events.PullStartEvent;
|
13
|
+
import org.restfulx.events.PushEndEvent;
|
14
|
+
import org.restfulx.events.PushStartEvent;
|
15
|
+
import org.restfulx.controllers.ChangeController;
|
16
|
+
import org.restfulx.services.ISyncingServiceProvider;
|
17
|
+
import org.restfulx.services.http.XMLHTTPServiceProvider;
|
18
|
+
<% end -%>
|
19
|
+
import org.restfulx.services.air.AIRServiceProvider;
|
20
|
+
<% end -%>
|
21
|
+
import org.restfulx.Rx;
|
22
|
+
import <%= base_package %>.controllers.<%= command_controller_name %>;
|
23
|
+
<% if use_air -%>
|
24
|
+
<% if distributed -%>
|
25
|
+
|
26
|
+
[Bindable]
|
27
|
+
private var socketMonitor:SocketMonitor;
|
28
|
+
|
29
|
+
[Bindable]
|
30
|
+
private var online:Boolean;
|
31
|
+
|
32
|
+
[Bindable]
|
33
|
+
private var syncStatus:String;
|
34
|
+
<% end -%>
|
35
|
+
<% end -%>
|
36
|
+
|
37
|
+
private function init():void {
|
38
|
+
<% if use_air -%>
|
39
|
+
<% if distributed -%>
|
40
|
+
Rx.httpRootUrl = "http://localhost:3000/";
|
41
|
+
Rx.enableSync = true;
|
42
|
+
|
43
|
+
socketMonitor = new SocketMonitor("localhost", 3000);
|
44
|
+
socketMonitor.pollInterval = 2000; /* miliseconds */
|
45
|
+
socketMonitor.addEventListener(StatusEvent.STATUS, onNetworkStatusChange);
|
46
|
+
socketMonitor.start();
|
47
|
+
|
48
|
+
<% end -%>
|
49
|
+
<%= command_controller_name %>.initialize([AIRServiceProvider],
|
50
|
+
AIRServiceProvider.ID, "<%= base_package %>");
|
51
|
+
<% if distributed -%>
|
52
|
+
|
53
|
+
Rx.changes.setSyncProviders(
|
54
|
+
ISyncingServiceProvider(Rx.services.getServiceProvider(AIRServiceProvider.ID)),
|
55
|
+
Rx.services.getServiceProvider(XMLHTTPServiceProvider.ID));
|
56
|
+
|
57
|
+
Rx.changes.addEventListener(PushStartEvent.ID, onPushStart);
|
58
|
+
Rx.changes.addEventListener(PushEndEvent.ID, onPushEnd);
|
59
|
+
Rx.changes.addEventListener(PullStartEvent.ID, onPullStart);
|
60
|
+
Rx.changes.addEventListener(PullEndEvent.ID, onPullEnd);
|
61
|
+
<% end -%>
|
62
|
+
<% else -%>
|
63
|
+
<%= command_controller_name %>.initialize();
|
64
|
+
<% end -%>
|
65
|
+
}
|
66
|
+
<% if use_air -%>
|
67
|
+
<% if distributed -%>
|
68
|
+
|
69
|
+
private function onPushStart(event:Event):void {
|
70
|
+
syncStatus = "Pushing changes ...";
|
71
|
+
}
|
72
|
+
|
73
|
+
private function onPushEnd(event:Event):void {
|
74
|
+
syncStatus = "Push complete.";
|
75
|
+
}
|
76
|
+
|
77
|
+
private function onPullStart(event:Event):void {
|
78
|
+
syncStatus = "Pulling data...";
|
79
|
+
}
|
80
|
+
|
81
|
+
private function onPullEnd(event:Event):void {
|
82
|
+
syncStatus = "Pull complete.";
|
83
|
+
}
|
84
|
+
|
85
|
+
private function onNetworkStatusChange(event:StatusEvent):void {
|
86
|
+
online = (socketMonitor.available) ? true : false;
|
87
|
+
|
88
|
+
if (online) {
|
89
|
+
Rx.defaultServiceId = XMLHTTPServiceProvider.ID;
|
90
|
+
} else {
|
91
|
+
Rx.defaultServiceId = AIRServiceProvider.ID;
|
92
|
+
}
|
93
|
+
}
|
94
|
+
|
95
|
+
private function getCurrentProviderName(id:int):String {
|
96
|
+
switch (id) {
|
97
|
+
case XMLHTTPServiceProvider.ID:
|
98
|
+
return "Rails";
|
99
|
+
case AIRServiceProvider.ID:
|
100
|
+
return "AIR (SQLite)";
|
101
|
+
default :
|
102
|
+
return "No idea";
|
103
|
+
}
|
104
|
+
}
|
105
|
+
<% end -%>
|
106
|
+
<% end -%>
|
107
|
+
]]>
|
108
|
+
</mx:Script>
|
109
|
+
<% if use_air -%>
|
110
|
+
<% if distributed -%>
|
111
|
+
<mx:VBox height="100%">
|
112
|
+
<mx:Label text="Current Provider: {getCurrentProviderName(Rx.defaultServiceId)}"/>
|
113
|
+
<mx:Label text="Status: {online ? 'Online' : 'Offline' }"/>
|
114
|
+
<mx:HBox>
|
115
|
+
<mx:Button label="Push" click="{Rx.changes.push()}" enabled="{online}"/>
|
116
|
+
<mx:Button label="Pull" click="{Rx.changes.pull()}" enabled="{online}"/>
|
117
|
+
</mx:HBox>
|
118
|
+
<mx:Label text="{syncStatus}"/>
|
119
|
+
</mx:VBox>
|
120
|
+
<% end -%>
|
121
|
+
<% end -%>
|
122
|
+
<mx:LinkBar dataProvider="{mainViewStack}" direction="vertical" borderStyle="solid" backgroundColor="#EEEEEE"/>
|
123
|
+
<mx:ViewStack id="mainViewStack" width="100%" height="100%">
|
124
|
+
<!-- For a simple demo, put all the components here. -->
|
125
|
+
<% for component in component_names -%>
|
126
|
+
<generated:<%= component %>/>
|
127
|
+
<% end -%>
|
128
|
+
</mx:ViewStack>
|
129
|
+
</mx:<%= application_tag %>>
|
@@ -0,0 +1,35 @@
|
|
1
|
+
Description:
|
2
|
+
Scaffolds an entire resource, from model and migration to controller and
|
3
|
+
views, along with a full test suite. The resource is ready to use as a
|
4
|
+
starting point for your restful, resource-oriented application.
|
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
|
+
Pass the name of the model, either CamelCased or under_scored, as the first
|
14
|
+
argument, and an optional list of attribute pairs.
|
15
|
+
|
16
|
+
Attribute pairs are column_name:sql_type arguments specifying the
|
17
|
+
model's attributes. Timestamps are added by default, so you don't have to
|
18
|
+
specify them by hand as 'created_at:datetime updated_at:datetime'.
|
19
|
+
|
20
|
+
The syntax for belongs_to, has_one and has_many attributes is as follows:
|
21
|
+
belongs_to:<relationship_name> or
|
22
|
+
belongs_to:<relationship_name>,<another_relationship>,<and_another>
|
23
|
+
|
24
|
+
You don't have to think up every attribute up front, but it helps to
|
25
|
+
sketch out a few so you can start working with the resource immediately.
|
26
|
+
|
27
|
+
For example, `scaffold post title:string body:text published:boolean`
|
28
|
+
gives you a model with those three attributes, a controller that handles
|
29
|
+
the create/show/update/destroy, forms to create and edit your posts, and
|
30
|
+
an index that lists them all, as well as a map.resources :posts
|
31
|
+
declaration in config/routes.rb.
|
32
|
+
|
33
|
+
Examples:
|
34
|
+
`./script/generate rx_scaffold project name:string has_many:tasks`
|
35
|
+
`./script/generate rx_scaffold task name:string belongs_to:project`
|
@@ -0,0 +1,242 @@
|
|
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
|
+
module Commands
|
65
|
+
class Create
|
66
|
+
include SchemaToYaml
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
class RxScaffoldGenerator < Rails::Generator::NamedBase
|
73
|
+
include RestfulX::Configuration
|
74
|
+
include SchemaToYaml
|
75
|
+
|
76
|
+
attr_reader :project_name,
|
77
|
+
:flex_project_name,
|
78
|
+
:base_package,
|
79
|
+
:base_folder,
|
80
|
+
:command_controller_name,
|
81
|
+
:flex_root,
|
82
|
+
:distributed
|
83
|
+
|
84
|
+
attr_reader :belongs_tos,
|
85
|
+
:has_manies,
|
86
|
+
:has_ones,
|
87
|
+
:attachment_field,
|
88
|
+
:has_many_through,
|
89
|
+
:polymorphic,
|
90
|
+
:tree_model,
|
91
|
+
:layout,
|
92
|
+
:ignored_fields,
|
93
|
+
:args_for_generation
|
94
|
+
|
95
|
+
attr_reader :controller_name,
|
96
|
+
:controller_class_path,
|
97
|
+
:controller_file_path,
|
98
|
+
:controller_class_nesting,
|
99
|
+
:controller_class_nesting_depth,
|
100
|
+
:controller_class_name,
|
101
|
+
:controller_underscore_name,
|
102
|
+
:controller_singular_name,
|
103
|
+
:controller_plural_name
|
104
|
+
|
105
|
+
alias_method :controller_file_name, :controller_underscore_name
|
106
|
+
alias_method :controller_table_name, :controller_plural_name
|
107
|
+
|
108
|
+
def initialize(runtime_args, runtime_options = {})
|
109
|
+
super
|
110
|
+
@project_name, @flex_project_name, @command_controller_name, @base_package, @base_folder, @flex_root,
|
111
|
+
@distributed = extract_names
|
112
|
+
@controller_name = @name.pluralize
|
113
|
+
|
114
|
+
base_name, @controller_class_path, @controller_file_path, @controller_class_nesting,
|
115
|
+
@controller_class_nesting_depth = extract_modules(@controller_name)
|
116
|
+
@controller_class_name_without_nesting, @controller_underscore_name, @controller_plural_name = inflect_names(base_name)
|
117
|
+
|
118
|
+
@controller_singular_name=base_name.singularize
|
119
|
+
if @controller_class_nesting.empty?
|
120
|
+
@controller_class_name = @controller_class_name_without_nesting
|
121
|
+
else
|
122
|
+
@controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}"
|
123
|
+
end
|
124
|
+
extract_relationships
|
125
|
+
end
|
126
|
+
|
127
|
+
def manifest
|
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]
|
136
|
+
|
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, "views", "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, "views", "generated", "#{@class_name}Box.mxml"),
|
147
|
+
:assigns => { :resource_controller_name => "#{file_name.pluralize}" }
|
148
|
+
end
|
149
|
+
|
150
|
+
unless options[:skip_fixture]
|
151
|
+
m.template 'fixtures.yml.erb', File.join("test", "fixtures", "#{table_name}.yml"),
|
152
|
+
:collision => :force unless options[:flex_only]
|
153
|
+
end
|
154
|
+
|
155
|
+
unless options[:skip_migration]
|
156
|
+
FileUtils.rm Dir.glob("db/migrate/[0-9]*_create_#{file_path.gsub(/\//, '_').pluralize}.rb"), :force => true
|
157
|
+
m.migration_template 'migration.rb.erb', 'db/migrate', :assigns => {
|
158
|
+
:migration_name => "Create#{file_path.gsub(/\//, '_').pluralize.camelcase.gsub(/::/, '')}"
|
159
|
+
}, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}" unless options[:flex_only]
|
160
|
+
end
|
161
|
+
|
162
|
+
m.directory(File.join('test/functional', controller_class_path))
|
163
|
+
m.directory(File.join('test/unit', class_path))
|
164
|
+
m.directory(File.join('test/unit/helpers', class_path))
|
165
|
+
|
166
|
+
m.template('functional_test.rb', File.join('test/functional', controller_class_path, "#{controller_file_name}_controller_test.rb"))
|
167
|
+
m.template('helper_test.rb', File.join('test/unit/helpers', controller_class_path, "#{controller_file_name}_helper_test.rb"))
|
168
|
+
|
169
|
+
if File.open('config/routes.rb').grep(/^\s*map.resources :#{controller_file_name}/).empty?
|
170
|
+
m.route_resources controller_file_name
|
171
|
+
end
|
172
|
+
|
173
|
+
m.dependency 'rx_controller', [name] + @args, :collision => :force
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
protected
|
178
|
+
def extract_relationships
|
179
|
+
# arrays
|
180
|
+
@belongs_tos = []
|
181
|
+
@has_ones = []
|
182
|
+
@has_manies = []
|
183
|
+
@attachment_field = []
|
184
|
+
@polymorphic = []
|
185
|
+
@tree_model = []
|
186
|
+
@layout = []
|
187
|
+
@ignored_fields = []
|
188
|
+
|
189
|
+
# hashes
|
190
|
+
@has_many_through = {}
|
191
|
+
|
192
|
+
@args.each do |arg|
|
193
|
+
# arrays
|
194
|
+
if arg =~ /^has_one:/
|
195
|
+
@has_ones = arg.split(':')[1].split(',')
|
196
|
+
elsif arg =~ /^has_many:/
|
197
|
+
@has_manies = arg.split(":")[1].split(",")
|
198
|
+
elsif arg =~ /^belongs_to:/
|
199
|
+
@belongs_tos = arg.split(":")[1].split(',')
|
200
|
+
elsif arg =~ /^attachment_field:/
|
201
|
+
@attachment_field = arg.split(":")[1].split(',')
|
202
|
+
elsif arg =~ /^polymorphic:/
|
203
|
+
@polymorphic = arg.split(":")[1].split(',')
|
204
|
+
elsif arg =~ /^tree_model:/
|
205
|
+
@tree_model = arg.split(":")[1].split(',')
|
206
|
+
elsif arg =~ /^layout:/
|
207
|
+
@layout = arg.split(":")[1].split(',')
|
208
|
+
elsif arg =~ /^ignored_fields:/
|
209
|
+
@ignored_fields = arg.split(":")[1].split(',')
|
210
|
+
# hashes
|
211
|
+
elsif arg =~ /^has_many_through:/
|
212
|
+
hmt_arr = arg.split(":")[1].split(',')
|
213
|
+
@has_many_through[hmt_arr.first] = hmt_arr.last
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
# delete special fields from @args ivar
|
218
|
+
%w(has_one has_many belongs_to attachment_field has_many_through
|
219
|
+
polymorphic tree_model layout ignored_fields).each do |special_field|
|
220
|
+
@args.delete_if { |f| f =~ /^(#{special_field}):/ }
|
221
|
+
end
|
222
|
+
|
223
|
+
@args_for_generation = @args.clone
|
224
|
+
|
225
|
+
# delete ignored_fields from @args ivar
|
226
|
+
@ignored_fields.each do |ignored|
|
227
|
+
@args.delete_if { |f| f =~ /^(#{ignored}):/ }
|
228
|
+
end
|
229
|
+
|
230
|
+
end
|
231
|
+
|
232
|
+
def add_options!(opt)
|
233
|
+
opt.separator ''
|
234
|
+
opt.separator 'Options:'
|
235
|
+
opt.on("-f", "--flex-only", "Only generate the Flex/AIR files",
|
236
|
+
"Default: false") { |v| options[:flex_only] = v }
|
237
|
+
opt.on("-r", "--rails-only", "Only generate the Rails files",
|
238
|
+
"Default: false") { |v| options[:rails_only] = v }
|
239
|
+
opt.on("-fv", "--flex-view-only", "Only generate the Flex component files",
|
240
|
+
"Default: false") { |v| options[:flex_view_only] = v }
|
241
|
+
end
|
242
|
+
end
|
@@ -0,0 +1,125 @@
|
|
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
|
+
<% if attachment_field.size > 0 -%>
|
12
|
+
format.fxml { render :fxml => @<%= table_name %>.to_fxml(:methods => [:attachment_url]) }
|
13
|
+
<% else -%>
|
14
|
+
format.fxml { render :fxml => @<%= table_name %> }
|
15
|
+
<% end -%>
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# GET /<%= table_name %>/1
|
20
|
+
# GET /<%= table_name %>/1.xml
|
21
|
+
# GET /<%= table_name %>/1.fxml
|
22
|
+
def show
|
23
|
+
@<%= file_name %> = <%= class_name %>.find(params[:id])
|
24
|
+
|
25
|
+
respond_to do |format|
|
26
|
+
format.html # show.html.erb
|
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 -%>
|
31
|
+
format.fxml { render :fxml => @<%= file_name %> }
|
32
|
+
<% end -%>
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# GET /<%= table_name %>/new
|
37
|
+
# GET /<%= table_name %>/new.xml
|
38
|
+
def new
|
39
|
+
@<%= file_name %> = <%= class_name %>.new
|
40
|
+
|
41
|
+
respond_to do |format|
|
42
|
+
format.html # new.html.erb
|
43
|
+
format.xml { render :xml => @<%= file_name %> }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# GET /<%= table_name %>/1/edit
|
48
|
+
def edit
|
49
|
+
@<%= file_name %> = <%= class_name %>.find(params[:id])
|
50
|
+
end
|
51
|
+
|
52
|
+
# POST /<%= table_name %>
|
53
|
+
# POST /<%= table_name %>.xml
|
54
|
+
# POST /<%= table_name %>.fxml
|
55
|
+
def create
|
56
|
+
@<%= file_name %> = <%= class_name %>.new(params[:<%= file_name %>])
|
57
|
+
|
58
|
+
respond_to do |format|
|
59
|
+
if @<%= file_name %>.save
|
60
|
+
flash[:notice] = '<%= class_name %> was successfully created.'
|
61
|
+
format.html { redirect_to(@<%= file_name %>) }
|
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 -%>
|
66
|
+
format.fxml { render :fxml => @<%= file_name %> }
|
67
|
+
<% end -%>
|
68
|
+
else
|
69
|
+
format.html { render :action => "new" }
|
70
|
+
format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity }
|
71
|
+
format.fxml { render :fxml => @<%= file_name %>.errors }
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# PUT /<%= table_name %>/1
|
77
|
+
# PUT /<%= table_name %>/1.xml
|
78
|
+
# PUT /<%= table_name %>/1.fxml
|
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 -%>
|
90
|
+
@<%= file_name %> = <%= class_name %>.find(params[:id])
|
91
|
+
@saved = @<%= file_name %>.update_attributes(params[:<%= file_name %>])
|
92
|
+
<% end -%>
|
93
|
+
|
94
|
+
respond_to do |format|
|
95
|
+
if @saved
|
96
|
+
flash[:notice] = '<%= class_name %> was successfully updated.'
|
97
|
+
format.html { redirect_to(@<%= file_name %>) }
|
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 -%>
|
102
|
+
format.fxml { render :fxml => @<%= file_name %> }
|
103
|
+
<% end -%>
|
104
|
+
else
|
105
|
+
format.html { render :action => "edit" }
|
106
|
+
format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity }
|
107
|
+
format.fxml { render :fxml => @<%= file_name %>.errors }
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
# DELETE /<%= table_name %>/1
|
113
|
+
# DELETE /<%= table_name %>/1.xml
|
114
|
+
# DELETE /<%= table_name %>/1.fxml
|
115
|
+
def destroy
|
116
|
+
@<%= file_name %> = <%= class_name %>.find(params[:id])
|
117
|
+
@<%= file_name %>.destroy
|
118
|
+
|
119
|
+
respond_to do |format|
|
120
|
+
format.html { redirect_to(<%= table_name %>_url) }
|
121
|
+
format.xml { head :ok }
|
122
|
+
format.fxml { render :fxml => @<%= file_name %> }
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|