dima-restfulx 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. data/Rakefile +65 -30
  2. data/VERSION.yml +4 -0
  3. data/app_generators/rx_app/rx_app_generator.rb +25 -9
  4. data/app_generators/rx_app/templates/actionscript.properties +3 -3
  5. data/app_generators/rx_app/templates/actionscriptair.properties +3 -3
  6. data/app_generators/rx_app/templates/app.yaml.erb +1 -1
  7. data/app_generators/rx_app/templates/default_tasks.rake +5 -18
  8. data/app_generators/rx_app/templates/generate.rb +1 -1
  9. data/app_generators/rx_app/templates/index.html.erb +1 -1
  10. data/app_generators/rx_app/templates/mainair-app.xml +3 -3
  11. data/app_generators/rx_app/templates/mainapp.mxml +107 -2
  12. data/app_generators/rx_app/templates/project-textmate.erb +4 -4
  13. data/app_generators/rx_app/templates/project.properties +1 -1
  14. data/app_generators/rx_app/templates/projectair.properties +1 -1
  15. data/app_generators/rx_app/templates/restfulx.yml +61 -0
  16. data/lib/restfulx/active_foo.rb +0 -7
  17. data/lib/restfulx/active_record_tasks.rb +10 -0
  18. data/lib/restfulx/configuration.rb +15 -10
  19. data/lib/restfulx/rails/swf_helper.rb +1 -1
  20. data/lib/restfulx/schema_to_yaml/extensions/enumerable.rb +7 -0
  21. data/lib/restfulx/schema_to_yaml/settings/config.rb +16 -0
  22. data/lib/restfulx/schema_to_yaml/settings/core.rb +70 -0
  23. data/lib/restfulx/schema_to_yaml.rb +120 -0
  24. data/lib/restfulx/tasks.rb +68 -42
  25. data/lib/restfulx/uuid_helper.rb +15 -0
  26. data/lib/restfulx.rb +5 -28
  27. data/rails_generators/rx_config/USAGE +2 -1
  28. data/rails_generators/rx_config/rx_config_generator.rb +78 -53
  29. data/rails_generators/rx_config/templates/actionscript.properties +3 -3
  30. data/rails_generators/rx_config/templates/actionscriptair.properties +3 -3
  31. data/rails_generators/rx_config/templates/flex_controller.erb +4 -0
  32. data/rails_generators/rx_config/templates/{index.html.erb → index.erb} +2 -4
  33. data/rails_generators/rx_config/templates/mainair-app.xml +3 -3
  34. data/rails_generators/rx_config/templates/mainapp.mxml +100 -2
  35. data/rails_generators/rx_config/templates/project-textmate.erb +4 -4
  36. data/rails_generators/rx_config/templates/project.properties +1 -1
  37. data/rails_generators/rx_config/templates/projectair.properties +1 -1
  38. data/rails_generators/rx_config/templates/restfulx.erb +39 -0
  39. data/rails_generators/rx_config/templates/restfulx.yml +51 -4
  40. data/rails_generators/rx_config/templates/restfulx_tasks.rake +3 -0
  41. data/rails_generators/rx_config/templates/routes.erb +47 -0
  42. data/rails_generators/rx_controller/rx_controller_generator.rb +9 -6
  43. data/rails_generators/rx_controller/templates/controller.as.erb +7 -9
  44. data/{generators → rails_generators}/rx_main_app/USAGE +0 -0
  45. data/rails_generators/rx_main_app/rx_main_app_generator.rb +60 -0
  46. data/rails_generators/rx_main_app/templates/mainapp.mxml +129 -0
  47. data/rails_generators/rx_scaffold/rx_scaffold_generator.rb +89 -35
  48. data/rails_generators/rx_scaffold/templates/{controller.rb.erb → controllers/default.rb.erb} +29 -1
  49. data/rails_generators/rx_scaffold/templates/controllers/resource_controller.rb.erb +23 -0
  50. data/rails_generators/rx_scaffold/templates/fixtures.yml.erb +9 -5
  51. data/{generators/rx_scaffold/templates/component.mxml.erb → rails_generators/rx_scaffold/templates/layouts/default.erb} +75 -59
  52. data/rails_generators/rx_scaffold/templates/migration.rb.erb +29 -2
  53. data/rails_generators/rx_scaffold/templates/model.as.erb +33 -2
  54. data/rails_generators/rx_scaffold/templates/model.rb.erb +36 -1
  55. data/rails_generators/rx_yaml_scaffold/rx_yaml_scaffold_generator.rb +29 -10
  56. data/{generators → rxgen_generators}/rx_config/USAGE +0 -0
  57. data/{generators → rxgen_generators}/rx_config/rx_config_generator.rb +0 -0
  58. data/{generators → rxgen_generators}/rx_controller/USAGE +0 -0
  59. data/{generators → rxgen_generators}/rx_controller/rx_controller_generator.rb +6 -5
  60. data/{generators → rxgen_generators}/rx_controller/templates/assist.py +2 -2
  61. data/{generators → rxgen_generators}/rx_controller/templates/controller.as.erb +8 -6
  62. data/{generators → rxgen_generators}/rx_controller/templates/restful.py +0 -0
  63. data/rxgen_generators/rx_main_app/USAGE +8 -0
  64. data/{generators → rxgen_generators}/rx_main_app/rx_main_app_generator.rb +10 -5
  65. data/{generators → rxgen_generators}/rx_main_app/templates/main.py.erb +0 -0
  66. data/rxgen_generators/rx_main_app/templates/mainapp.mxml +136 -0
  67. data/{generators → rxgen_generators}/rx_scaffold/USAGE +0 -0
  68. data/{generators → rxgen_generators}/rx_scaffold/rx_scaffold_generator.rb +5 -4
  69. data/{rails_generators → rxgen_generators}/rx_scaffold/templates/component.mxml.erb +24 -52
  70. data/{generators → rxgen_generators}/rx_scaffold/templates/controller.py.erb +1 -1
  71. data/{generators → rxgen_generators}/rx_scaffold/templates/model.as.erb +0 -0
  72. data/{generators → rxgen_generators}/rx_scaffold/templates/model.py.erb +0 -0
  73. data/{generators → rxgen_generators}/rx_yaml_scaffold/USAGE +0 -0
  74. data/{generators → rxgen_generators}/rx_yaml_scaffold/rx_yaml_scaffold_generator.rb +0 -0
  75. metadata +104 -66
  76. data/History.txt +0 -7
  77. data/Manifest.txt +0 -127
  78. data/generators/rx_main_app/templates/mainapp.mxml +0 -35
  79. data/rdoc/generators/template/html/jamis.rb +0 -588
  80. data/test/rails/playing_around_in_a_console.txt +0 -71
@@ -1,6 +1,6 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
- <actionScriptProperties mainApplicationPath="<%= project_name %>.mxml" version="3">
3
- <compiler additionalCompilerArguments="-locale en_US -keep-as3-metadata+=Resource,HasOne,HasMany,BelongsTo,DateTime,Lazy,Ignored" copyDependentFiles="true" enableModuleDebug="true" generateAccessible="false" htmlExpressInstall="true" htmlGenerate="false" htmlHistoryManagement="false" htmlPlayerVersion="9.0.28" htmlPlayerVersionCheck="true" outputFolderPath="bin-debug" sourceFolderPath="app/flex" strict="true" useApolloConfig="true" verifyDigests="true" warn="true">
2
+ <actionScriptProperties mainApplicationPath="<%= flex_project_name %>.mxml" version="3">
3
+ <compiler additionalCompilerArguments="-locale en_US -keep-as3-metadata+=Resource,HasOne,HasMany,BelongsTo,DateTime,Lazy,Ignored" copyDependentFiles="true" enableModuleDebug="true" generateAccessible="false" htmlExpressInstall="true" htmlGenerate="false" htmlHistoryManagement="false" htmlPlayerVersion="9.0.28" htmlPlayerVersionCheck="true" outputFolderPath="bin-debug" sourceFolderPath="<%= flex_root %>" strict="true" useApolloConfig="true" verifyDigests="true" warn="true">
4
4
  <compilerSourcePath/>
5
5
  <libraryPath defaultLinkType="1">
6
6
  <libraryPathEntry kind="4" path=""/>
@@ -9,7 +9,7 @@
9
9
  <sourceAttachmentPath/>
10
10
  </compiler>
11
11
  <applications>
12
- <application path="<%= project_name %>.mxml"/>
12
+ <application path="<%= flex_project_name %>.mxml"/>
13
13
  </applications>
14
14
  <modules/>
15
15
  <buildCSSFiles/>
@@ -0,0 +1,4 @@
1
+ class FlexController < ApplicationController
2
+ def index
3
+ end
4
+ end
@@ -3,15 +3,13 @@
3
3
  <title><%= project_name %></title>
4
4
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
5
5
  <script type="text/javascript" src="javascripts/swfobject.js"></script>
6
- <script type="text/javascript">
7
- swfobject.embedSWF("bin/<%= project_name %>.swf", "mainApp", "100%", "100%", "9.0.0", "expressInstall.swf");
8
- </script>
6
+ <%%= swfobject("/bin/<%= flex_project_name %>.swf") %>
9
7
  <style>
10
8
  body { margin: 0px; overflow: hidden; }
11
9
  </style>
12
10
  </head>
13
11
  <body>
14
- <div id="mainApp">
12
+ <div id="flashContent">
15
13
  <p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>
16
14
  </div>
17
15
  </body>
@@ -15,13 +15,13 @@
15
15
  -->
16
16
 
17
17
  <!-- The application identifier string, unique to this application. Required. -->
18
- <id><%= project_name %></id>
18
+ <id><%= flex_project_name %></id>
19
19
 
20
20
  <!-- Used as the filename for the application. Required. -->
21
- <filename><%= project_name %></filename>
21
+ <filename><%= flex_project_name %></filename>
22
22
 
23
23
  <!-- The name that is displayed in the AIR application installer. Optional. -->
24
- <name><%= project_name %></name>
24
+ <name><%= flex_project_name %></name>
25
25
 
26
26
  <!-- An application version designator (such as "v1", "2.5", or "Alpha 1"). Required. -->
27
27
  <version>v1</version>
@@ -6,20 +6,119 @@
6
6
  <mx:Script>
7
7
  <![CDATA[
8
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 -%>
9
19
  import org.restfulx.services.air.AIRServiceProvider;
10
20
  <% end -%>
11
21
  import org.restfulx.Rx;
12
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 -%>
13
36
 
14
37
  private function init():void {
15
38
  <% if use_air -%>
16
- <%= command_controller_name %>.initialize([AIRServiceProvider], AIRServiceProvider.ID, "<%= base_package %>");
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 -%>
17
62
  <% else -%>
18
63
  <%= command_controller_name %>.initialize();
19
64
  <% end -%>
20
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 -%>
21
107
  ]]>
22
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 -%>
23
122
  <mx:LinkBar dataProvider="{mainViewStack}" direction="vertical" borderStyle="solid" backgroundColor="#EEEEEE"/>
24
123
  <mx:ViewStack id="mainViewStack" width="100%" height="100%">
25
124
  <!-- For a simple demo, put all the components here. -->
@@ -28,4 +127,3 @@
28
127
  <% end -%>
29
128
  </mx:ViewStack>
30
129
  </mx:<%= application_tag %>>
31
-
@@ -3,14 +3,14 @@
3
3
  <plist version="1.0">
4
4
  <dict>
5
5
  <key>currentDocument</key>
6
- <string>app/flex/<%= project_name %>.mxml</string>
6
+ <string>app/flex/<%= flex_project_name %>.mxml</string>
7
7
  <key>documents</key>
8
8
  <array>
9
9
  <dict>
10
10
  <key>expanded</key>
11
11
  <true/>
12
12
  <key>name</key>
13
- <string><%= project_name.underscore %></string>
13
+ <string><%= project_name %></string>
14
14
  <key>regexFolderFilter</key>
15
15
  <string>!.*/(\.[^/]*|CVS|_darcs|_MTN|\{arch\}|blib|.*~\.nib|.*\.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$</string>
16
16
  <key>sourceDirectory</key>
@@ -27,7 +27,7 @@
27
27
  <key>enabled</key>
28
28
  <true/>
29
29
  <key>value</key>
30
- <string>app/flex/<%= project_name %>.mxml</string>
30
+ <string>app/flex/<%= flex_project_name %>.mxml</string>
31
31
  <key>variable</key>
32
32
  <string>TM_FLEX_FILE_SPECS</string>
33
33
  </dict>
@@ -35,7 +35,7 @@
35
35
  <key>enabled</key>
36
36
  <true/>
37
37
  <key>value</key>
38
- <string>public/bin/<%= project_name %>.swf</string>
38
+ <string>public/bin/<%= flex_project_name %>.swf</string>
39
39
  <key>variable</key>
40
40
  <string>TM_FLEX_OUTPUT</string>
41
41
  </dict>
@@ -1,6 +1,6 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <projectDescription>
3
- <name><%= flex_project_name %></name>
3
+ <name><%= project_name %></name>
4
4
  <comment></comment>
5
5
  <projects>
6
6
  </projects>
@@ -1,6 +1,6 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <projectDescription>
3
- <name><%= flex_project_name %></name>
3
+ <name><%= project_name %></name>
4
4
  <comment></comment>
5
5
  <projects>
6
6
  </projects>
@@ -0,0 +1,39 @@
1
+ # When you do file uploads from Flash with File.upload() that, unfortunately generates a new session id,
2
+ # which will fail to authenticate if you are using restful-authentication plugin or equivalent.
3
+ #
4
+ # The following code is a work-around for the Flash bug that prevents file uploader
5
+ # from sending correct session_id. Here, we hack the Session#initialize method and force the session_id
6
+ # to load from the query string via the request URI.
7
+ #
8
+ # Based on the code from http://seventytwo.co.uk/posts/making-swfupload-and-rails-work-together
9
+ #
10
+ class CGI::Session
11
+ alias original_initialize initialize
12
+
13
+ def initialize(request, option = {})
14
+ option = scan_for_session_id(request, '_session_id', option) unless option['session_id']
15
+ original_initialize(request, option)
16
+ end
17
+
18
+ def scan_for_session_id(request, session_key = '_session_id', option = {})
19
+ query_string = if (qs = request.env_table["QUERY_STRING"]) and qs != ""
20
+ qs
21
+ elsif (ru = request.env_table["REQUEST_URI"][0..-1]).include?("?")
22
+ ru[(ru.index("?") + 1)..-1]
23
+ end
24
+ if query_string and query_string.include?(session_key)
25
+ option['session_id'] = query_string.scan(/#{session_key}=(.*?)(&.*?)*$/).flatten.first
26
+ end
27
+ return option
28
+ end
29
+ end
30
+
31
+ # If you have configured your Rails/Flex/AIR application to share authenticity_token
32
+ # comment this out to enable forgery protection. By default, this is disabled to allow
33
+ # generated code to work out of the box.
34
+ ActionController::Base.allow_forgery_protection = false
35
+
36
+ <% if distributed -%>
37
+ # If we are in distributed mode we need to make sure that the RestfulX::UUIDHelper is loaded
38
+ require "restfulx/uuid_helper"
39
+ <% end -%>
@@ -1,14 +1,61 @@
1
1
  # RestfulX code generation configuration options
2
2
 
3
+ # This option controls what the main Flex application file will be called.
4
+ # By default it will be equal to the name of your rails project camelized
5
+ project-name: <%= project_name %>
6
+
7
+ # This options determines what the root folder for generated Flex code is.
8
+ # By default 'app/flex'
9
+ flex-root: <%= flex_root %>
10
+
3
11
  # By default flex models, commands, controllers and components are genearated into
4
- # app/flex/<your rails project name> folder. If you'd like to customize the target folder
12
+ # <flex-root>/<your rails project name> folder. If you'd like to customize the target folder
5
13
  # (to say append a "com" package before your rails project name) uncomment the line below
6
14
  # base-package must follow the usual flex package notation (a string separated by ".")
7
-
8
- #base-package: com.pomodo
15
+ base-package: <%= base_package %>
9
16
 
10
17
  # Main RestfulX controller is typically named AppicationController. This controller is created in
11
18
  # <base-package>.controllers folder. You can customize the name by uncommenting the following line
12
19
  # and changing the controller name.
20
+ controller-name: <%= command_controller_name %>
21
+
22
+ # If you are using Rails on the back-end and Adobe AIR as the client you can generate Rails/Flex/AIR
23
+ # code to take advantage of synchronization (online/offline) support in RestfulX by changing the following
24
+ # option to true. By default distribution is disabled.
25
+ distributed: <%= distributed %>
26
+
27
+ # These options control code-generation options for view components, Flex and Rails models and so on.
28
+ # Allowing you to choose what controller patterns, layouts, attachment plugin you want to use, etc.
29
+ defaults: &defaults
30
+ attachment_plugin: 'paperclip' # => paperclip/attachment_fu
31
+ controller_pattern: 'default' # => default/resource_controller
32
+ layouts:
33
+ default: 'default' # => default (more coming soon)
34
+ ignored: # => ignored tables/fields won't appear in model.yml
35
+ tables: [table1 table2]
36
+ fields: [field1 field2]
37
+
38
+ development:
39
+ <<: *defaults
40
+
41
+ test:
42
+ <<: *defaults
13
43
 
14
- #controller-name: ApplicationController
44
+ production:
45
+ <<: *defaults
46
+
47
+ # Special model.yml fields for RestfulX code-generation:
48
+ #
49
+ # attachment_field: [avatar]
50
+ # * arg takes Paperclip field name, or takes [uploaded_data] for Attachment_Fu
51
+ # belongs_to: [account, profile]
52
+ # has_many: [announcements, files, folders, users]
53
+ # has_many_through: [permissions, roles]
54
+ # * has_many :roles, :through => :permissions
55
+ # has_one: [suitcase]
56
+ # polymorphic: [commentable]
57
+ # tree_model: [parent]
58
+ # layout: [default]
59
+ # * default template is the only current theme, with more coming soon
60
+ # ignored_fields: [children_count, ancestors_count, descendants_count, position]
61
+ # * specify fields you don't want generated for your template
@@ -3,4 +3,7 @@ begin
3
3
  # this will load the latest restfulx gem version
4
4
  require 'restfulx/active_record_tasks'
5
5
  rescue LoadError
6
+ puts "Could not load active_record_tasks from 'restfulx/active_record_tasks'. " <<
7
+ "If you are loading restfulx gem from vendor/gems, adjust the path to active_record_tasks in " <<
8
+ "lib/tasks/restfulx_tasks.rake accordingly."
6
9
  end
@@ -0,0 +1,47 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+
3
+ # Map application root to default RestfulX controller
4
+ map.root :controller => "flex"
5
+
6
+ # The priority is based upon order of creation: first created -> highest priority.
7
+
8
+ # Sample of regular route:
9
+ # map.connect 'products/:id', :controller => 'catalog', :action => 'view'
10
+ # Keep in mind you can assign values other than :controller and :action
11
+
12
+ # Sample of named route:
13
+ # map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
14
+ # This route can be invoked with purchase_url(:id => product.id)
15
+
16
+ # Sample resource route (maps HTTP verbs to controller actions automatically):
17
+ # map.resources :products
18
+
19
+ # Sample resource route with options:
20
+ # map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get }
21
+
22
+ # Sample resource route with sub-resources:
23
+ # map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller
24
+
25
+ # Sample resource route with more complex sub-resources
26
+ # map.resources :products do |products|
27
+ # products.resources :comments
28
+ # products.resources :sales, :collection => { :recent => :get }
29
+ # end
30
+
31
+ # Sample resource route within a namespace:
32
+ # map.namespace :admin do |admin|
33
+ # # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb)
34
+ # admin.resources :products
35
+ # end
36
+
37
+ # You can have the root of your site routed with map.root -- just remember to delete public/index.html.
38
+ # map.root :controller => "welcome"
39
+
40
+ # See how all your routes lay out with "rake routes"
41
+
42
+ # Install the default routes as the lowest priority.
43
+ # Note: These default routes make all actions in every controller accessible via GET requests. You should
44
+ # consider removing the them or commenting them out if you're using named routes and resources.
45
+ map.connect ':controller/:action/:id'
46
+ map.connect ':controller/:action/:id.:format'
47
+ end
@@ -9,20 +9,23 @@ class RxControllerGenerator < Rails::Generator::Base
9
9
  :base_folder,
10
10
  :command_controller_name,
11
11
  :model_names,
12
- :command_names
12
+ :command_names,
13
+ :flex_root,
14
+ :distributed
13
15
 
14
16
  def initialize(runtime_args, runtime_options = {})
15
17
  super
16
- @project_name, @flex_project_name, @command_controller_name, @base_package, @base_folder = extract_names
18
+ @project_name, @flex_project_name, @command_controller_name, @base_package, @base_folder,
19
+ @flex_root, @distributed = extract_names
17
20
 
18
- @model_names = list_as_files("app/flex/#{base_folder}/models")
19
- @command_names = list_as_files("app/flex/#{base_folder}/commands")
21
+ @model_names = list_as_files("#{@flex_root}/#{@base_folder}/models")
22
+ @command_names = list_as_files("#{@flex_root}/#{@base_folder}/commands")
20
23
  end
21
24
 
22
25
  def manifest
23
26
  record do |m|
24
- m.template 'controller.as.erb', File.join("app/flex/#{base_folder}/controllers",
25
- "#{command_controller_name}.as")
27
+ m.template 'controller.as.erb', File.join("#{@flex_root}/#{@base_folder}/controllers",
28
+ "#{@command_controller_name}.as")
26
29
  end
27
30
  end
28
31
  end
@@ -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, extraServices:Array,
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, defaultServiceId:int = -1,
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, extraServices,
31
- defaultServiceId);
30
+ controller = new <%= command_controller_name %>(new SingletonEnforcer,
31
+ extraServices, defaultServiceId);
32
32
  Rx.sessionToken = Application.application.parameters.session_token;
33
- if (Application.application.parameters.authenticity_token) {
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
  }
File without changes
@@ -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 %>>