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 +123 -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 +25 -0
- data/bin/rx-gen +1 -1
- data/lib/restfulx/active_foo.rb +0 -8
- data/lib/restfulx/active_record_tasks.rb +9 -0
- data/lib/restfulx/active_record_uuid_helper.rb +17 -0
- data/lib/restfulx/configuration.rb +19 -31
- 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 +70 -0
- data/lib/restfulx/rails/schema_to_yaml.rb +121 -0
- data/lib/restfulx/rails/swf_helper.rb +1 -6
- data/lib/restfulx/tasks.rb +68 -42
- data/lib/restfulx.rb +4 -35
- data/rails_generators/rx_config/USAGE +2 -1
- data/rails_generators/rx_config/rx_config_generator.rb +80 -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 +38 -0
- data/rails_generators/rx_config/templates/restfulx.yml +55 -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/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 +88 -34
- 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_controller/rx_controller_generator.rb +7 -5
- data/{generators → rxgen_generators}/rx_controller/templates/assist.py +3 -3
- data/{generators → rxgen_generators}/rx_controller/templates/controller.as.erb +8 -6
- data/rxgen_generators/rx_controller/templates/iso8601.py +92 -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/rxgen_generators/rx_main_app/templates/mainapp.mxml +152 -0
- data/{generators → rxgen_generators}/rx_scaffold/rx_scaffold_generator.rb +6 -5
- data/{rails_generators → rxgen_generators}/rx_scaffold/templates/component.mxml.erb +24 -52
- data/spec/restfulx_spec.rb +1 -4
- data/spec/spec_helper.rb +0 -3
- data/tasks/restfulx.rake +2 -0
- metadata +102 -81
- 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/tasks/ann.rake +0 -80
- data/tasks/bones.rake +0 -20
- data/tasks/gem.rake +0 -201
- data/tasks/git.rake +0 -40
- data/tasks/manifest.rake +0 -48
- data/tasks/notes.rake +0 -27
- data/tasks/post_load.rake +0 -39
- data/tasks/rdoc.rake +0 -50
- data/tasks/rubyforge.rake +0 -55
- data/tasks/setup.rb +0 -279
- data/tasks/spec.rake +0 -54
- data/tasks/svn.rake +0 -47
- data/tasks/test.rake +0 -40
- data/test/rails/playing_around_in_a_console.txt +0 -71
- /data/{generators → rails_generators}/rx_main_app/USAGE +0 -0
- /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/templates/restful.py +0 -0
- /data/{generators → rxgen_generators}/rx_main_app/templates/main.py.erb +0 -0
- /data/{generators → rxgen_generators}/rx_scaffold/USAGE +0 -0
- /data/{generators → rxgen_generators}/rx_scaffold/templates/controller.py.erb +0 -0
- /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
@@ -14,8 +14,8 @@ package <%= base_package %>.controllers {
|
|
14
14
|
|
15
15
|
public static var commands:Array = [<%= command_names %>]; /* Commands */
|
16
16
|
|
17
|
-
public function <%= command_controller_name %>(enforcer:SingletonEnforcer,
|
18
|
-
defaultServiceId:int = -1) {
|
17
|
+
public function <%= command_controller_name %>(enforcer:SingletonEnforcer,
|
18
|
+
extraServices:Array, defaultServiceId:int = -1) {
|
19
19
|
super(commands, models, extraServices, defaultServiceId);
|
20
20
|
}
|
21
21
|
|
@@ -24,15 +24,13 @@ package <%= base_package %>.controllers {
|
|
24
24
|
return controller;
|
25
25
|
}
|
26
26
|
|
27
|
-
public static function initialize(extraServices:Array = null,
|
28
|
-
airDatabaseName:String = null):void {
|
27
|
+
public static function initialize(extraServices:Array = null,
|
28
|
+
defaultServiceId:int = -1, airDatabaseName:String = null):void {
|
29
29
|
if (!RxUtils.isEmpty(airDatabaseName)) Rx.airDatabaseName = airDatabaseName;
|
30
|
-
controller = new <%= command_controller_name %>(new SingletonEnforcer,
|
31
|
-
defaultServiceId);
|
30
|
+
controller = new <%= command_controller_name %>(new SingletonEnforcer,
|
31
|
+
extraServices, defaultServiceId);
|
32
32
|
Rx.sessionToken = Application.application.parameters.session_token;
|
33
|
-
|
34
|
-
Rx.defaultMetadata = { authenticity_token : Application.application.parameters.authenticity_token };
|
35
|
-
}
|
33
|
+
Rx.authenticityToken = Application.application.parameters.authenticity_token;
|
36
34
|
}
|
37
35
|
}
|
38
36
|
}
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'restfulx') if !defined?(RestfulX)
|
2
|
+
|
3
|
+
module Rails
|
4
|
+
module Generator
|
5
|
+
module Commands
|
6
|
+
class Create
|
7
|
+
include SchemaToYaml
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class RxMainAppGenerator < Rails::Generator::Base
|
14
|
+
include RestfulX::Configuration
|
15
|
+
|
16
|
+
attr_reader :project_name,
|
17
|
+
:flex_project_name,
|
18
|
+
:base_package,
|
19
|
+
:base_folder,
|
20
|
+
:command_controller_name,
|
21
|
+
:model_names,
|
22
|
+
:component_names,
|
23
|
+
:controller_names,
|
24
|
+
:use_air,
|
25
|
+
:application_tag,
|
26
|
+
:flex_root,
|
27
|
+
:distributed
|
28
|
+
|
29
|
+
def initialize(runtime_args, runtime_options = {})
|
30
|
+
super
|
31
|
+
@project_name, @flex_project_name, @command_controller_name, @base_package, @base_folder,
|
32
|
+
@flex_root, @distributed = extract_names
|
33
|
+
|
34
|
+
project_file_name = APP_ROOT + '/.project'
|
35
|
+
if File.exist?(project_file_name)
|
36
|
+
@use_air = true if File.read(project_file_name) =~/com.adobe.flexbuilder.apollo.apollobuilder/m
|
37
|
+
end
|
38
|
+
|
39
|
+
if @use_air
|
40
|
+
@application_tag = 'WindowedApplication'
|
41
|
+
else
|
42
|
+
@application_tag = 'Application'
|
43
|
+
end
|
44
|
+
|
45
|
+
@component_names = []
|
46
|
+
if File.exists?("#{flex_root}/#{base_folder}/components/generated")
|
47
|
+
@component_names = list_mxml_files("#{flex_root}/#{base_folder}/components/generated")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def manifest
|
52
|
+
record do |m|
|
53
|
+
m.template 'mainapp.mxml', File.join("#{flex_root}", "#{flex_project_name}.mxml")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def banner
|
58
|
+
"Usage: #{$0} #{spec.name}"
|
59
|
+
end
|
60
|
+
end
|
@@ -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 %>.components.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 %>>
|
@@ -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)
|
@@ -110,24 +126,26 @@ class RxScaffoldGenerator < Rails::Generator::NamedBase
|
|
110
126
|
|
111
127
|
def manifest
|
112
128
|
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}" }
|
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 -%>
|