dima-ruboss4ruby 1.0.5

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.
Files changed (78) hide show
  1. data/Generators +7 -0
  2. data/History.txt +4 -0
  3. data/Manifest.txt +116 -0
  4. data/README.rdoc +23 -0
  5. data/gpl-3.0.txt +674 -0
  6. data/lib/ruboss4ruby.rb +84 -0
  7. data/lib/ruboss4ruby/active_foo.rb +221 -0
  8. data/lib/ruboss4ruby/active_record_tasks.rb +75 -0
  9. data/lib/ruboss4ruby/configuration.rb +59 -0
  10. data/lib/ruboss4ruby/datamapper_foo.rb +25 -0
  11. data/lib/ruboss4ruby/generated_attribute.rb +61 -0
  12. data/lib/ruboss4ruby/tasks.rb +80 -0
  13. data/merb_generators/ruboss_config.rb +103 -0
  14. data/merb_generators/ruboss_controller.rb +59 -0
  15. data/merb_generators/ruboss_flex_app.rb +67 -0
  16. data/merb_generators/ruboss_resource.rb +37 -0
  17. data/merb_generators/ruboss_resource_controller.rb +80 -0
  18. data/merb_generators/ruboss_scaffold.rb +157 -0
  19. data/merb_generators/templates/ruboss_config/actionscript.properties +16 -0
  20. data/merb_generators/templates/ruboss_config/actionscriptair.properties +16 -0
  21. data/merb_generators/templates/ruboss_config/expressInstall.swf +0 -0
  22. data/merb_generators/templates/ruboss_config/flex.properties +2 -0
  23. data/merb_generators/templates/ruboss_config/html-template/AC_OETags.js +276 -0
  24. data/merb_generators/templates/ruboss_config/html-template/history/history.css +6 -0
  25. data/merb_generators/templates/ruboss_config/html-template/history/history.js +645 -0
  26. data/merb_generators/templates/ruboss_config/html-template/history/historyFrame.html +29 -0
  27. data/merb_generators/templates/ruboss_config/html-template/index.template.html +121 -0
  28. data/merb_generators/templates/ruboss_config/html-template/playerProductInstall.swf +0 -0
  29. data/merb_generators/templates/ruboss_config/index.html.erb +18 -0
  30. data/merb_generators/templates/ruboss_config/mainair-app.xml +134 -0
  31. data/merb_generators/templates/ruboss_config/project.properties +18 -0
  32. data/merb_generators/templates/ruboss_config/projectair.properties +24 -0
  33. data/merb_generators/templates/ruboss_config/ruboss.yml +16 -0
  34. data/merb_generators/templates/ruboss_config/swfobject.js +5 -0
  35. data/merb_generators/templates/ruboss_controller/controller.as.erb +40 -0
  36. data/merb_generators/templates/ruboss_flex_app/mainapp.mxml +34 -0
  37. data/merb_generators/templates/ruboss_resource_controller/controller_ar.rb.erb +49 -0
  38. data/merb_generators/templates/ruboss_resource_controller/controller_dm.rb.erb +46 -0
  39. data/merb_generators/templates/ruboss_resource_controller/spec/controllers/%file_name%_spec.rb +7 -0
  40. data/merb_generators/templates/ruboss_resource_controller/spec/requests/%file_name%_spec.rb +1 -0
  41. data/merb_generators/templates/ruboss_resource_controller/test/controllers/%file_name%_test.rb +17 -0
  42. data/rails_generators/ruboss_config/USAGE +18 -0
  43. data/rails_generators/ruboss_config/ruboss_config_generator.rb +114 -0
  44. data/rails_generators/ruboss_config/templates/actionscript.properties +16 -0
  45. data/rails_generators/ruboss_config/templates/actionscriptair.properties +16 -0
  46. data/rails_generators/ruboss_config/templates/expressInstall.swf +0 -0
  47. data/rails_generators/ruboss_config/templates/flex.properties +2 -0
  48. data/rails_generators/ruboss_config/templates/html-template/AC_OETags.js +276 -0
  49. data/rails_generators/ruboss_config/templates/html-template/history/history.css +6 -0
  50. data/rails_generators/ruboss_config/templates/html-template/history/history.js +645 -0
  51. data/rails_generators/ruboss_config/templates/html-template/history/historyFrame.html +29 -0
  52. data/rails_generators/ruboss_config/templates/html-template/index.template.html +121 -0
  53. data/rails_generators/ruboss_config/templates/html-template/playerProductInstall.swf +0 -0
  54. data/rails_generators/ruboss_config/templates/index.html.erb +18 -0
  55. data/rails_generators/ruboss_config/templates/mainair-app.xml +134 -0
  56. data/rails_generators/ruboss_config/templates/mainapp-config.xml +21 -0
  57. data/rails_generators/ruboss_config/templates/mainapp.mxml +31 -0
  58. data/rails_generators/ruboss_config/templates/project-textmate.erb +52 -0
  59. data/rails_generators/ruboss_config/templates/project.properties +18 -0
  60. data/rails_generators/ruboss_config/templates/projectair.properties +24 -0
  61. data/rails_generators/ruboss_config/templates/ruboss.yml +14 -0
  62. data/rails_generators/ruboss_config/templates/ruboss_tasks.rake +5 -0
  63. data/rails_generators/ruboss_config/templates/swfobject.js +5 -0
  64. data/rails_generators/ruboss_controller/USAGE +11 -0
  65. data/rails_generators/ruboss_controller/ruboss_controller_generator.rb +31 -0
  66. data/rails_generators/ruboss_controller/templates/controller.as.erb +40 -0
  67. data/rails_generators/ruboss_scaffold/USAGE +35 -0
  68. data/rails_generators/ruboss_scaffold/ruboss_scaffold_generator.rb +177 -0
  69. data/rails_generators/ruboss_scaffold/templates/component.mxml.erb +149 -0
  70. data/rails_generators/ruboss_scaffold/templates/controller.rb.erb +97 -0
  71. data/rails_generators/ruboss_scaffold/templates/fixtures.yml.erb +35 -0
  72. data/rails_generators/ruboss_scaffold/templates/migration.rb.erb +19 -0
  73. data/rails_generators/ruboss_scaffold/templates/model.as.erb +42 -0
  74. data/rails_generators/ruboss_scaffold/templates/model.rb.erb +11 -0
  75. data/rails_generators/ruboss_yaml_scaffold/USAGE +14 -0
  76. data/rails_generators/ruboss_yaml_scaffold/ruboss_yaml_scaffold_generator.rb +44 -0
  77. data/rcl-1.0.txt +0 -0
  78. metadata +197 -0
@@ -0,0 +1,14 @@
1
+ # Ruboss code generation configuration options
2
+
3
+ # 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
5
+ # (to say append a "com" package before your rails project name) uncomment the line below
6
+ # base-package must follow the usual flex package notation (a string separated by ".")
7
+
8
+ #base-package: com.pomodo
9
+
10
+ # Main ruboss controller is typically named AppicationController. This controller is created in
11
+ # <base-package>.controllers folder. You can customize the name by uncommenting the following line
12
+ # and changing the controller name.
13
+
14
+ #controller-name: ApplicationController
@@ -0,0 +1,5 @@
1
+ # if the gem is not installed system wide, we'll just skip the tasks
2
+ begin
3
+ require 'ruboss4ruby/active_record_tasks'
4
+ rescue LoadError
5
+ end
@@ -0,0 +1,5 @@
1
+ /* SWFObject v2.0 <http://code.google.com/p/swfobject/>
2
+ Copyright (c) 2007 Geoff Stearns, Michael Williams, and Bobby van der Sluis
3
+ This software is released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
4
+ */
5
+ var swfobject=function(){var Z="undefined",P="object",B="Shockwave Flash",h="ShockwaveFlash.ShockwaveFlash",W="application/x-shockwave-flash",K="SWFObjectExprInst",G=window,g=document,N=navigator,f=[],H=[],Q=null,L=null,T=null,S=false,C=false;var a=function(){var l=typeof g.getElementById!=Z&&typeof g.getElementsByTagName!=Z&&typeof g.createElement!=Z&&typeof g.appendChild!=Z&&typeof g.replaceChild!=Z&&typeof g.removeChild!=Z&&typeof g.cloneNode!=Z,t=[0,0,0],n=null;if(typeof N.plugins!=Z&&typeof N.plugins[B]==P){n=N.plugins[B].description;if(n){n=n.replace(/^.*\s+(\S+\s+\S+$)/,"$1");t[0]=parseInt(n.replace(/^(.*)\..*$/,"$1"),10);t[1]=parseInt(n.replace(/^.*\.(.*)\s.*$/,"$1"),10);t[2]=/r/.test(n)?parseInt(n.replace(/^.*r(.*)$/,"$1"),10):0}}else{if(typeof G.ActiveXObject!=Z){var o=null,s=false;try{o=new ActiveXObject(h+".7")}catch(k){try{o=new ActiveXObject(h+".6");t=[6,0,21];o.AllowScriptAccess="always"}catch(k){if(t[0]==6){s=true}}if(!s){try{o=new ActiveXObject(h)}catch(k){}}}if(!s&&o){try{n=o.GetVariable("$version");if(n){n=n.split(" ")[1].split(",");t=[parseInt(n[0],10),parseInt(n[1],10),parseInt(n[2],10)]}}catch(k){}}}}var v=N.userAgent.toLowerCase(),j=N.platform.toLowerCase(),r=/webkit/.test(v)?parseFloat(v.replace(/^.*webkit\/(\d+(\.\d+)?).*$/,"$1")):false,i=false,q=j?/win/.test(j):/win/.test(v),m=j?/mac/.test(j):/mac/.test(v);/*@cc_on i=true;@if(@_win32)q=true;@elif(@_mac)m=true;@end@*/return{w3cdom:l,pv:t,webkit:r,ie:i,win:q,mac:m}}();var e=function(){if(!a.w3cdom){return }J(I);if(a.ie&&a.win){try{g.write("<script id=__ie_ondomload defer=true src=//:><\/script>");var i=c("__ie_ondomload");if(i){i.onreadystatechange=function(){if(this.readyState=="complete"){this.parentNode.removeChild(this);V()}}}}catch(j){}}if(a.webkit&&typeof g.readyState!=Z){Q=setInterval(function(){if(/loaded|complete/.test(g.readyState)){V()}},10)}if(typeof g.addEventListener!=Z){g.addEventListener("DOMContentLoaded",V,null)}M(V)}();function V(){if(S){return }if(a.ie&&a.win){var m=Y("span");try{var l=g.getElementsByTagName("body")[0].appendChild(m);l.parentNode.removeChild(l)}catch(n){return }}S=true;if(Q){clearInterval(Q);Q=null}var j=f.length;for(var k=0;k<j;k++){f[k]()}}function J(i){if(S){i()}else{f[f.length]=i}}function M(j){if(typeof G.addEventListener!=Z){G.addEventListener("load",j,false)}else{if(typeof g.addEventListener!=Z){g.addEventListener("load",j,false)}else{if(typeof G.attachEvent!=Z){G.attachEvent("onload",j)}else{if(typeof G.onload=="function"){var i=G.onload;G.onload=function(){i();j()}}else{G.onload=j}}}}}function I(){var l=H.length;for(var j=0;j<l;j++){var m=H[j].id;if(a.pv[0]>0){var k=c(m);if(k){H[j].width=k.getAttribute("width")?k.getAttribute("width"):"0";H[j].height=k.getAttribute("height")?k.getAttribute("height"):"0";if(O(H[j].swfVersion)){if(a.webkit&&a.webkit<312){U(k)}X(m,true)}else{if(H[j].expressInstall&&!C&&O("6.0.65")&&(a.win||a.mac)){D(H[j])}else{d(k)}}}}else{X(m,true)}}}function U(m){var k=m.getElementsByTagName(P)[0];if(k){var p=Y("embed"),r=k.attributes;if(r){var o=r.length;for(var n=0;n<o;n++){if(r[n].nodeName.toLowerCase()=="data"){p.setAttribute("src",r[n].nodeValue)}else{p.setAttribute(r[n].nodeName,r[n].nodeValue)}}}var q=k.childNodes;if(q){var s=q.length;for(var l=0;l<s;l++){if(q[l].nodeType==1&&q[l].nodeName.toLowerCase()=="param"){p.setAttribute(q[l].getAttribute("name"),q[l].getAttribute("value"))}}}m.parentNode.replaceChild(p,m)}}function F(i){if(a.ie&&a.win&&O("8.0.0")){G.attachEvent("onunload",function(){var k=c(i);if(k){for(var j in k){if(typeof k[j]=="function"){k[j]=function(){}}}k.parentNode.removeChild(k)}})}}function D(j){C=true;var o=c(j.id);if(o){if(j.altContentId){var l=c(j.altContentId);if(l){L=l;T=j.altContentId}}else{L=b(o)}if(!(/%$/.test(j.width))&&parseInt(j.width,10)<310){j.width="310"}if(!(/%$/.test(j.height))&&parseInt(j.height,10)<137){j.height="137"}g.title=g.title.slice(0,47)+" - Flash Player Installation";var n=a.ie&&a.win?"ActiveX":"PlugIn",k=g.title,m="MMredirectURL="+G.location+"&MMplayerType="+n+"&MMdoctitle="+k,p=j.id;if(a.ie&&a.win&&o.readyState!=4){var i=Y("div");p+="SWFObjectNew";i.setAttribute("id",p);o.parentNode.insertBefore(i,o);o.style.display="none";G.attachEvent("onload",function(){o.parentNode.removeChild(o)})}R({data:j.expressInstall,id:K,width:j.width,height:j.height},{flashvars:m},p)}}function d(j){if(a.ie&&a.win&&j.readyState!=4){var i=Y("div");j.parentNode.insertBefore(i,j);i.parentNode.replaceChild(b(j),i);j.style.display="none";G.attachEvent("onload",function(){j.parentNode.removeChild(j)})}else{j.parentNode.replaceChild(b(j),j)}}function b(n){var m=Y("div");if(a.win&&a.ie){m.innerHTML=n.innerHTML}else{var k=n.getElementsByTagName(P)[0];if(k){var o=k.childNodes;if(o){var j=o.length;for(var l=0;l<j;l++){if(!(o[l].nodeType==1&&o[l].nodeName.toLowerCase()=="param")&&!(o[l].nodeType==8)){m.appendChild(o[l].cloneNode(true))}}}}}return m}function R(AE,AC,q){var p,t=c(q);if(typeof AE.id==Z){AE.id=q}if(a.ie&&a.win){var AD="";for(var z in AE){if(AE[z]!=Object.prototype[z]){if(z=="data"){AC.movie=AE[z]}else{if(z.toLowerCase()=="styleclass"){AD+=' class="'+AE[z]+'"'}else{if(z!="classid"){AD+=" "+z+'="'+AE[z]+'"'}}}}}var AB="";for(var y in AC){if(AC[y]!=Object.prototype[y]){AB+='<param name="'+y+'" value="'+AC[y]+'" />'}}t.outerHTML='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'+AD+">"+AB+"</object>";F(AE.id);p=c(AE.id)}else{if(a.webkit&&a.webkit<312){var AA=Y("embed");AA.setAttribute("type",W);for(var x in AE){if(AE[x]!=Object.prototype[x]){if(x=="data"){AA.setAttribute("src",AE[x])}else{if(x.toLowerCase()=="styleclass"){AA.setAttribute("class",AE[x])}else{if(x!="classid"){AA.setAttribute(x,AE[x])}}}}}for(var w in AC){if(AC[w]!=Object.prototype[w]){if(w!="movie"){AA.setAttribute(w,AC[w])}}}t.parentNode.replaceChild(AA,t);p=AA}else{var s=Y(P);s.setAttribute("type",W);for(var v in AE){if(AE[v]!=Object.prototype[v]){if(v.toLowerCase()=="styleclass"){s.setAttribute("class",AE[v])}else{if(v!="classid"){s.setAttribute(v,AE[v])}}}}for(var u in AC){if(AC[u]!=Object.prototype[u]&&u!="movie"){E(s,u,AC[u])}}t.parentNode.replaceChild(s,t);p=s}}return p}function E(k,i,j){var l=Y("param");l.setAttribute("name",i);l.setAttribute("value",j);k.appendChild(l)}function c(i){return g.getElementById(i)}function Y(i){return g.createElement(i)}function O(k){var j=a.pv,i=k.split(".");i[0]=parseInt(i[0],10);i[1]=parseInt(i[1],10);i[2]=parseInt(i[2],10);return(j[0]>i[0]||(j[0]==i[0]&&j[1]>i[1])||(j[0]==i[0]&&j[1]==i[1]&&j[2]>=i[2]))?true:false}function A(m,j){if(a.ie&&a.mac){return }var l=g.getElementsByTagName("head")[0],k=Y("style");k.setAttribute("type","text/css");k.setAttribute("media","screen");if(!(a.ie&&a.win)&&typeof g.createTextNode!=Z){k.appendChild(g.createTextNode(m+" {"+j+"}"))}l.appendChild(k);if(a.ie&&a.win&&typeof g.styleSheets!=Z&&g.styleSheets.length>0){var i=g.styleSheets[g.styleSheets.length-1];if(typeof i.addRule==P){i.addRule(m,j)}}}function X(k,i){var j=i?"visible":"hidden";if(S){c(k).style.visibility=j}else{A("#"+k,"visibility:"+j)}}return{registerObject:function(l,i,k){if(!a.w3cdom||!l||!i){return }var j={};j.id=l;j.swfVersion=i;j.expressInstall=k?k:false;H[H.length]=j;X(l,false)},getObjectById:function(l){var i=null;if(a.w3cdom&&S){var j=c(l);if(j){var k=j.getElementsByTagName(P)[0];if(!k||(k&&typeof j.SetVariable!=Z)){i=j}else{if(typeof k.SetVariable!=Z){i=k}}}}return i},embedSWF:function(n,u,r,t,j,m,k,p,s){if(!a.w3cdom||!n||!u||!r||!t||!j){return }r+="";t+="";if(O(j)){X(u,false);var q=(typeof s==P)?s:{};q.data=n;q.width=r;q.height=t;var o=(typeof p==P)?p:{};if(typeof k==P){for(var l in k){if(k[l]!=Object.prototype[l]){if(typeof o.flashvars!=Z){o.flashvars+="&"+l+"="+k[l]}else{o.flashvars=l+"="+k[l]}}}}J(function(){R(q,o,u);if(q.id==u){X(u,true)}})}else{if(m&&!C&&O("6.0.65")&&(a.win||a.mac)){X(u,false);J(function(){var i={};i.id=i.altContentId=u;i.width=r;i.height=t;i.expressInstall=m;D(i)})}}},getFlashPlayerVersion:function(){return{major:a.pv[0],minor:a.pv[1],release:a.pv[2]}},hasFlashPlayerVersion:O,createSWF:function(k,j,i){if(a.w3cdom&&S){return R(k,j,i)}else{return undefined}},createCSS:function(j,i){if(a.w3cdom){A(j,i)}},addDomLoadEvent:J,addLoadEvent:M,getQueryParamValue:function(m){var l=g.location.search||g.location.hash;if(m==null){return l}if(l){var k=l.substring(1).split("&");for(var j=0;j<k.length;j++){if(k[j].substring(0,k[j].indexOf("="))==m){return k[j].substring((k[j].indexOf("=")+1))}}}return""},expressInstallCallback:function(){if(C&&L){var i=c(K);if(i){i.parentNode.replaceChild(L,i);if(T){X(T,true);if(a.ie&&a.win){L.style.display="block"}}L=null;T=null;C=false}}}}}();
@@ -0,0 +1,11 @@
1
+ Description:
2
+ Generates/updates the main Flex application controller, typically
3
+ app/flex/<yourappname>/controllers/<YourAppName>Controller.as, e.g.
4
+ app/flex/pomodo/controllers/PomodoController.as
5
+
6
+ It pulls out all available models and commands from respective
7
+ folders and makes sure they'll be pulled into the Flex application
8
+ at runtime. Doesn't require any arguments or options.
9
+
10
+ Examples:
11
+ `./script/generate ruboss_controller`
@@ -0,0 +1,31 @@
1
+ class RubossControllerGenerator < Rails::Generator::Base
2
+ include Ruboss::Configuration
3
+
4
+ attr_reader :project_name,
5
+ :flex_project_name,
6
+ :base_package,
7
+ :base_folder,
8
+ :command_controller_name,
9
+ :model_names,
10
+ :command_names
11
+
12
+ def initialize(runtime_args, runtime_options = {})
13
+ super
14
+ @project_name, @flex_project_name, @command_controller_name, @base_package, @base_folder = extract_names
15
+
16
+ @model_names = list_as_files("app/flex/#{base_folder}/models")
17
+ @command_names = list_as_files("app/flex/#{base_folder}/commands")
18
+ end
19
+
20
+ def manifest
21
+ record do |m|
22
+ m.template 'controller.as.erb', File.join("app/flex/#{base_folder}/controllers",
23
+ "#{command_controller_name}.as")
24
+ end
25
+ end
26
+
27
+ protected
28
+ def banner
29
+ "Usage: #{$0} #{spec.name}"
30
+ end
31
+ end
@@ -0,0 +1,40 @@
1
+ package <%= base_package %>.controllers {
2
+ import <%= base_package %>.models.*;
3
+ import <%= base_package %>.commands.*;
4
+
5
+ import mx.core.Application;
6
+ import org.ruboss.Ruboss;
7
+ import org.ruboss.controllers.RubossApplicationController;
8
+ import org.ruboss.utils.RubossUtils;
9
+
10
+ public class <%= command_controller_name %> extends RubossApplicationController {
11
+ private static var controller:<%= command_controller_name %>;
12
+
13
+ public static var models:Array = [<%= model_names %>]; /* Models */
14
+
15
+ public static var commands:Array = [<%= command_names %>]; /* Commands */
16
+
17
+ public function <%= command_controller_name %>(enforcer:SingletonEnforcer, extraServices:Array,
18
+ defaultServiceId:int = -1) {
19
+ super(commands, models, extraServices, defaultServiceId);
20
+ }
21
+
22
+ public static function get instance():<%= command_controller_name %> {
23
+ if (controller == null) initialize();
24
+ return controller;
25
+ }
26
+
27
+ public static function initialize(extraServices:Array = null, defaultServiceId:int = -1,
28
+ airDatabaseName:String = null):void {
29
+ if (!RubossUtils.isEmpty(airDatabaseName)) Ruboss.airDatabaseName = airDatabaseName;
30
+ controller = new <%= command_controller_name %>(new SingletonEnforcer, extraServices,
31
+ defaultServiceId);
32
+ Ruboss.sessionToken = Application.application.parameters.session_token;
33
+ if (Application.application.parameters.authenticity_token) {
34
+ Ruboss.defaultMetadata = { authenticity_token : Application.application.parameters.authenticity_token };
35
+ }
36
+ }
37
+ }
38
+ }
39
+
40
+ class SingletonEnforcer {}
@@ -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
+ ruboss_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 ruboss_scaffold project name:string has_many:tasks`
35
+ `./script/generate ruboss_scaffold task name:string belongs_to:project`
@@ -0,0 +1,177 @@
1
+ module Rails
2
+ module Generator
3
+ class GeneratedAttribute
4
+ attr_accessor :name, :type, :column, :flex_name
5
+
6
+ def initialize(name, type)
7
+ @name, @type = name, type.to_sym
8
+ @flex_name = name.camelcase(:lower)
9
+ @column = ActiveRecord::ConnectionAdapters::Column.new(name, nil, @type)
10
+ end
11
+
12
+ def field_type
13
+ @field_type ||= case type
14
+ when :integer, :float, :decimal then :text_field
15
+ when :datetime, :timestamp, :time then :datetime_select
16
+ when :date then :date_select
17
+ when :string then :text_field
18
+ when :text then :text_area
19
+ when :boolean then :check_box
20
+ else
21
+ :text_field
22
+ end
23
+ end
24
+
25
+ def default(prefix = '')
26
+ @default = case type
27
+ when :integer then 1
28
+ when :float then 1.5
29
+ when :decimal then "9.99"
30
+ when :datetime, :timestamp, :time then Time.now.to_s(:db)
31
+ when :date then Date.today.to_s(:db)
32
+ when :string then prefix + name.camelize + "String"
33
+ when :text then prefix + name.camelize + "Text"
34
+ when :boolean then false
35
+ else
36
+ ""
37
+ end
38
+ end
39
+
40
+ def flex_type
41
+ @flex_type = case type
42
+ when :integer then 'int'
43
+ when :date, :datetime, :time then 'Date'
44
+ when :boolean then 'Boolean'
45
+ when :float, :decimal then 'Number'
46
+ else
47
+ 'String'
48
+ end
49
+ end
50
+
51
+ def flex_default(prefix = '')
52
+ @flex_default = case type
53
+ when :integer, :float, :decimal then '0'
54
+ when :string, :text then '""'
55
+ when :boolean then 'false'
56
+ else
57
+ 'null'
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ class RubossScaffoldGenerator < Rails::Generator::NamedBase
65
+ include Ruboss::Configuration
66
+
67
+ attr_reader :project_name,
68
+ :flex_project_name,
69
+ :base_package,
70
+ :base_folder,
71
+ :command_controller_name
72
+
73
+ attr_reader :belongs_tos,
74
+ :has_manies,
75
+ :has_ones
76
+
77
+ attr_reader :controller_name,
78
+ :controller_class_path,
79
+ :controller_file_path,
80
+ :controller_class_nesting,
81
+ :controller_class_nesting_depth,
82
+ :controller_class_name,
83
+ :controller_underscore_name,
84
+ :controller_singular_name,
85
+ :controller_plural_name
86
+
87
+ attr_accessor :constructor_args
88
+
89
+ alias_method :controller_file_name, :controller_underscore_name
90
+ alias_method :controller_table_name, :controller_plural_name
91
+
92
+ def initialize(runtime_args, runtime_options = {})
93
+ super
94
+ @project_name, @flex_project_name, @command_controller_name, @base_package, @base_folder = extract_names
95
+ @controller_name = @name.pluralize
96
+
97
+ base_name, @controller_class_path, @controller_file_path, @controller_class_nesting,
98
+ @controller_class_nesting_depth = extract_modules(@controller_name)
99
+ @controller_class_name_without_nesting, @controller_underscore_name, @controller_plural_name = inflect_names(base_name)
100
+
101
+ @controller_singular_name=base_name.singularize
102
+ if @controller_class_nesting.empty?
103
+ @controller_class_name = @controller_class_name_without_nesting
104
+ else
105
+ @controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}"
106
+ end
107
+
108
+ @belongs_tos = []
109
+ @has_ones = []
110
+ @has_manies = []
111
+ # Figure out has_one, has_many and belongs_to based on args
112
+ @args.each do |arg|
113
+ if arg =~ /^has_one:/
114
+ # arg = "has_one:arg1,arg2", so all the has_one are together
115
+ @has_ones = arg.split(':')[1].split(',')
116
+ elsif arg =~ /^has_many:/
117
+ # arg = "has_many:arg1,arg2", so all the has_many are together
118
+ @has_manies = arg.split(":")[1].split(",")
119
+ elsif arg =~ /^belongs_to:/ # belongs_to:arg1,arg2
120
+ @belongs_tos = arg.split(":")[1].split(',')
121
+ end
122
+ end
123
+
124
+ # Remove the has_one and has_many arguments since they are
125
+ # not for consumption by the scaffold generator, and since
126
+ # we have already used them to set the @belongs_tos, @has_ones and
127
+ # @has_manies.
128
+ @args.delete_if { |elt| elt =~ /^(has_one|has_many|belongs_to):/ }
129
+ end
130
+
131
+ def manifest
132
+ record do |m|
133
+ m.dependency 'scaffold', [name] + @args, :skip_migration => true, :collision => :skip unless options[:flex_only]
134
+
135
+ # Generate Flex AS model and MXML component based on the
136
+ # Ruboss templates.
137
+ m.template 'model.as.erb',
138
+ File.join("app", "flex", base_folder, "models", "#{@class_name}.as"),
139
+ :assigns => { :resource_controller_name => "#{file_name.pluralize}" }
140
+
141
+ m.template 'component.mxml.erb',
142
+ File.join("app", "flex", base_folder, "components", "generated", "#{@class_name}Box.mxml"),
143
+ :assigns => { :resource_controller_name => "#{file_name.pluralize}" }
144
+
145
+ m.template 'controller.rb.erb', File.join("app/controllers", controller_class_path,
146
+ "#{controller_file_name}_controller.rb"), :collision => :force unless options[:flex_only]
147
+
148
+ # Create a new generated ActiveRecord model based on the Ruboss templates.
149
+ m.template 'model.rb.erb', File.join("app", "models", "#{file_name}.rb"),
150
+ :collision => :force unless options[:flex_only]
151
+
152
+ unless options[:skip_fixture]
153
+ m.template 'fixtures.yml.erb', File.join("test", "fixtures", "#{table_name}.yml"),
154
+ :collision => :force unless options[:flex_only]
155
+ end
156
+
157
+ unless options[:skip_migration]
158
+ m.directory 'schema/migration'
159
+ m.migration_template 'migration.rb.erb', 'db/migrate', :assigns => {
160
+ :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}"
161
+ }, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}" unless options[:flex_only]
162
+ end
163
+
164
+ # Run the rcontroller generator to clobber the
165
+ # RubossCommandController subclass to include the new models.
166
+ m.dependency 'ruboss_controller', [name] + @args, :collision => :force
167
+ end
168
+ end
169
+
170
+ protected
171
+ def add_options!(opt)
172
+ opt.separator ''
173
+ opt.separator 'Options:'
174
+ opt.on("-f", "--flex-only", "Scaffold Flex code only",
175
+ "Default: false") { |v| options[:flex_only] = v}
176
+ end
177
+ 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.ruboss.components.*">
4
+ <mx:Script><![CDATA[
5
+ import org.ruboss.Ruboss;
6
+ import org.ruboss.utils.RubossUtils;
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.downcase_first_letter %>:<%= class_name %> = new <%= class_name %>();
14
+
15
+ private function new<%= class_name %>():void {
16
+ _<%= class_name.downcase_first_letter %> = new <%= class_name %>();
17
+ <%= class_name.downcase_first_letter.pluralize %>List.selectedIndex = -1;
18
+ }
19
+
20
+ private function save<%= class_name %>():void {
21
+ if (_<%= class_name.downcase_first_letter %>.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.downcase_first_letter %>:<%= class_name %> = new <%= class_name %>();
30
+ <% for attribute in attributes -%>
31
+ <% if attribute.type == :boolean -%>
32
+ <%= class_name.downcase_first_letter %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>CheckBox.selected;
33
+ <% elsif attribute.type == :string -%>
34
+ <%= class_name.downcase_first_letter %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>TextInput.text;
35
+ <% elsif attribute.type == :text -%>
36
+ <%= class_name.downcase_first_letter %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>TextArea.text;
37
+ <% elsif attribute.type == :datetime || attribute.type == :time -%>
38
+ <%= class_name.downcase_first_letter %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>DateTimeTextInput.date;
39
+ <% elsif attribute.type == :date -%>
40
+ <%= class_name.downcase_first_letter %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>DateField.selectedDate;
41
+ <% else -%>
42
+ <%= class_name.downcase_first_letter %>.<%= 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.downcase_first_letter %>.<%= model.camelcase(:lower) %> = <%= model.camelcase %>(<%= model.camelcase(:lower) %>ComboBox.selectedItem);
48
+ <% end -%>
49
+ <%= class_name.downcase_first_letter %>.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.downcase_first_letter %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>CheckBox.selected;
56
+ <% elsif attribute.type == :string -%>
57
+ _<%= class_name.downcase_first_letter %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>TextInput.text;
58
+ <% elsif attribute.type == :text -%>
59
+ _<%= class_name.downcase_first_letter %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>TextArea.text;
60
+ <% elsif attribute.type == :datetime || attribute.type == :time -%>
61
+ _<%= class_name.downcase_first_letter %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>DateTimeTextInput.date;
62
+ <% elsif attribute.type == :date -%>
63
+ _<%= class_name.downcase_first_letter %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>DateField.selectedDate;
64
+ <% else -%>
65
+ _<%= class_name.downcase_first_letter %>.<%= 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.downcase_first_letter %>.<%= model.camelcase(:lower) %> = <%= model.camelcase %>(<%= model.camelcase(:lower) %>ComboBox.selectedItem);
71
+ <% end -%>
72
+ _<%= class_name.downcase_first_letter %>.update({onSuccess: on<%= class_name %>Update});
73
+ }
74
+
75
+ private function destroy<%= class_name %>():void {
76
+ _<%= class_name.downcase_first_letter %>.destroy({onSuccess: on<%= class_name %>Destroy});
77
+ }
78
+
79
+ private function on<%= class_name %>Select():void {
80
+ _<%= class_name.downcase_first_letter %> = RubossUtils.clone(<%= class_name.downcase_first_letter.pluralize %>List.selectedItem) as <%= class_name %>;
81
+ }
82
+
83
+ private function on<%= class_name %>Create(<%= class_name.downcase_first_letter %>:<%= class_name %>):void {
84
+ _<%= class_name.downcase_first_letter %> = new <%= class_name %>;
85
+ }
86
+
87
+ private function on<%= class_name %>Update(<%= class_name.downcase_first_letter %>:<%= class_name %>):void {
88
+ <%= class_name.downcase_first_letter.pluralize %>List.selectedItem = <%= class_name.downcase_first_letter %>;
89
+ _<%= class_name.downcase_first_letter %> = RubossUtils.clone(<%= class_name.downcase_first_letter %>) as <%= class_name %>;
90
+ }
91
+
92
+ private function on<%= class_name %>Destroy(<%= class_name.downcase_first_letter %>:<%= class_name %>):void {
93
+ on<%= class_name %>Create(<%= class_name.downcase_first_letter %>);
94
+ }
95
+
96
+ private function canDelete<%= class_name %>(<%= class_name.downcase_first_letter %>:<%= class_name %>):Boolean {
97
+ return <%= class_name.downcase_first_letter %> != null && <%= class_name.downcase_first_letter %>.id != 0;
98
+ }
99
+ ]]></mx:Script>
100
+ <mx:Panel id="<%= class_name.downcase_first_letter.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.downcase_first_letter.pluralize %>List"
104
+ width="100%" height="100%"
105
+ dataProvider="{Ruboss.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.capitalize_without_downcasing %>" width="100%">
117
+ <% if attribute.type == :boolean -%>
118
+ <mx:CheckBox id="<%= attribute.flex_name %>CheckBox" selected="{_<%= class_name.downcase_first_letter %>.<%= attribute.flex_name %>}"/>
119
+ <% elsif attribute.type == :string -%>
120
+ <mx:TextInput id="<%= attribute.flex_name %>TextInput" width="100%" text="{_<%= class_name.downcase_first_letter %>.<%= attribute.flex_name %>}"/>
121
+ <% elsif attribute.type == :text -%>
122
+ <mx:TextArea id="<%= attribute.flex_name %>TextArea" width="100%" height="200" text="{_<%= class_name.downcase_first_letter %>.<%= attribute.flex_name %>}"/>
123
+ <% elsif attribute.type == :datetime || attribute.type == :time -%>
124
+ <rcomponents:DateTimeTextInput id="<%= attribute.flex_name %>DateTimeTextInput" width="200" date="{_<%= class_name.downcase_first_letter %>.<%= attribute.flex_name %>}"/>
125
+ <% elsif attribute.type == :date -%>
126
+ <mx:DateField id="<%= attribute.flex_name %>DateField" selectedDate="{_<%= class_name.downcase_first_letter %>.<%= attribute.flex_name %>}"/>
127
+ <% else -%>
128
+ <mx:TextInput id="<%= attribute.flex_name %>TextInput" width="100%" text="{_<%= class_name.downcase_first_letter %>.<%= 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="{Ruboss.models.index(<%= model.camelcase %>)}" prompt="<%= model.camelcase %> ..."
137
+ selectedItem="{_<%= class_name.downcase_first_letter %>.<%= 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.downcase_first_letter %>)}"
146
+ click="destroy<%= class_name %>()"/>
147
+ </mx:ControlBar>
148
+ </mx:Panel>
149
+ </mx:HBox>