dima-ruboss4ruby 1.0.5 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. data/History.txt +2 -3
  2. data/Manifest.txt +46 -37
  3. data/README.rdoc +12 -10
  4. data/Rakefile +37 -0
  5. data/app_generators/ruboss_app/USAGE +13 -0
  6. data/app_generators/ruboss_app/ruboss_app_generator.rb +88 -0
  7. data/{merb_generators/templates/ruboss_config → app_generators/ruboss_app/templates}/actionscript.properties +1 -1
  8. data/{merb_generators/templates/ruboss_config → app_generators/ruboss_app/templates}/actionscriptair.properties +0 -0
  9. data/app_generators/ruboss_app/templates/default_tasks.rake +51 -0
  10. data/{merb_generators/templates/ruboss_config → app_generators/ruboss_app/templates}/expressInstall.swf +0 -0
  11. data/{merb_generators/templates/ruboss_config → app_generators/ruboss_app/templates}/flex.properties +0 -0
  12. data/app_generators/ruboss_app/templates/generate.rb +21 -0
  13. data/{merb_generators/templates/ruboss_config → app_generators/ruboss_app/templates}/html-template/AC_OETags.js +0 -0
  14. data/{merb_generators/templates/ruboss_config → app_generators/ruboss_app/templates}/html-template/history/history.css +0 -0
  15. data/{merb_generators/templates/ruboss_config → app_generators/ruboss_app/templates}/html-template/history/history.js +0 -0
  16. data/{merb_generators/templates/ruboss_config → app_generators/ruboss_app/templates}/html-template/history/historyFrame.html +0 -0
  17. data/{merb_generators/templates/ruboss_config → app_generators/ruboss_app/templates}/html-template/index.template.html +0 -0
  18. data/{merb_generators/templates/ruboss_config → app_generators/ruboss_app/templates}/html-template/playerProductInstall.swf +0 -0
  19. data/{merb_generators/templates/ruboss_config → app_generators/ruboss_app/templates}/index.html.erb +2 -2
  20. data/{merb_generators/templates/ruboss_config → app_generators/ruboss_app/templates}/mainair-app.xml +3 -3
  21. data/app_generators/ruboss_app/templates/mainapp-config.xml +21 -0
  22. data/{merb_generators/templates/ruboss_flex_app → app_generators/ruboss_app/templates}/mainapp.mxml +6 -9
  23. data/app_generators/ruboss_app/templates/project-textmate.erb +52 -0
  24. data/{merb_generators/templates/ruboss_config → app_generators/ruboss_app/templates}/project.properties +0 -0
  25. data/{merb_generators/templates/ruboss_config → app_generators/ruboss_app/templates}/projectair.properties +0 -0
  26. data/{merb_generators/templates/ruboss_config → app_generators/ruboss_app/templates}/swfobject.js +0 -0
  27. data/bin/ruboss-gen +17 -0
  28. data/generators/ruboss_config/USAGE +5 -0
  29. data/generators/ruboss_config/ruboss_config_generator.rb +24 -0
  30. data/generators/ruboss_controller/USAGE +10 -0
  31. data/generators/ruboss_controller/ruboss_controller_generator.rb +34 -0
  32. data/{merb_generators/templates/ruboss_controller → generators/ruboss_controller/templates}/controller.as.erb +0 -4
  33. data/generators/ruboss_main_app/USAGE +8 -0
  34. data/generators/ruboss_main_app/ruboss_main_app_generator.rb +46 -0
  35. data/generators/ruboss_main_app/templates/mainapp.mxml +31 -0
  36. data/generators/ruboss_scaffold/USAGE +29 -0
  37. data/generators/ruboss_scaffold/ruboss_scaffold_generator.rb +117 -0
  38. data/generators/ruboss_scaffold/templates/component.mxml.erb +149 -0
  39. data/generators/ruboss_scaffold/templates/model.as.erb +42 -0
  40. data/generators/ruboss_yaml_scaffold/USAGE +7 -0
  41. data/generators/ruboss_yaml_scaffold/ruboss_yaml_scaffold_generator.rb +43 -0
  42. data/lib/ruboss4ruby/active_foo.rb +0 -64
  43. data/lib/ruboss4ruby/active_record_default_methods.rb +54 -0
  44. data/lib/ruboss4ruby/configuration.rb +13 -28
  45. data/lib/ruboss4ruby/datamapper_foo.rb +1 -1
  46. data/lib/ruboss4ruby/rails/recipes.rb +58 -0
  47. data/lib/ruboss4ruby/rails/swf_helper.rb +59 -0
  48. data/lib/ruboss4ruby/tasks.rb +1 -1
  49. data/lib/ruboss4ruby.rb +35 -15
  50. data/rails_generators/ruboss_config/ruboss_config_generator.rb +2 -2
  51. data/rails_generators/ruboss_config/templates/mainair-app.xml +2 -2
  52. data/rails_generators/ruboss_controller/USAGE +1 -2
  53. data/rails_generators/ruboss_controller/ruboss_controller_generator.rb +1 -1
  54. data/rails_generators/ruboss_scaffold/ruboss_scaffold_generator.rb +1 -1
  55. data/rails_generators/ruboss_scaffold/templates/component.mxml.erb +69 -69
  56. data/rails_generators/ruboss_scaffold/templates/model.as.erb +1 -1
  57. data/ruboss4ruby.gemspec +43 -0
  58. data/spec/ruboss4ruby_spec.rb +7 -0
  59. data/spec/spec_helper.rb +16 -0
  60. data/test/rails/controllers/application.rb +15 -0
  61. data/test/rails/controllers/locations_controller.rb +93 -0
  62. data/test/rails/controllers/notes_controller.rb +96 -0
  63. data/test/rails/controllers/projects_controller.rb +93 -0
  64. data/test/rails/controllers/tasks_controller.rb +93 -0
  65. data/test/rails/controllers/users_controller.rb +93 -0
  66. data/test/rails/database.yml +4 -0
  67. data/test/rails/fixtures/locations.yml +8 -0
  68. data/test/rails/fixtures/notes.yml +17 -0
  69. data/test/rails/fixtures/projects.yml +25 -0
  70. data/test/rails/fixtures/simple_properties.yml +19 -0
  71. data/test/rails/fixtures/tasks.yml +46 -0
  72. data/test/rails/fixtures/users.yml +13 -0
  73. data/test/rails/helpers/functional_test_helper.rb +21 -0
  74. data/test/rails/helpers/test_helper.rb +61 -0
  75. data/test/rails/helpers/unit_test_helper.rb +30 -0
  76. data/test/rails/model.yml +35 -0
  77. data/test/rails/models/location.rb +4 -0
  78. data/test/rails/models/note.rb +3 -0
  79. data/test/rails/models/project.rb +4 -0
  80. data/test/rails/models/simple_property.rb +2 -0
  81. data/test/rails/models/task.rb +20 -0
  82. data/test/rails/models/user.rb +22 -0
  83. data/test/rails/playing_around_in_a_console.txt +71 -0
  84. data/test/rails/schema.rb +77 -0
  85. data/test/rails/test.swf +1 -0
  86. data/test/rails/test_active_foo.rb +81 -0
  87. data/test/rails/test_ruboss_rails_integration_functional.rb +22 -0
  88. data/test/rails/test_to_fxml.rb +77 -0
  89. data/test/rails/test_to_json.rb +23 -0
  90. data/test/rails/views/notes/empty_params_action.html.erb +1 -0
  91. data/test/rails/views/notes/index.html.erb +1 -0
  92. metadata +121 -92
  93. data/Generators +0 -7
  94. data/lib/ruboss4ruby/generated_attribute.rb +0 -61
  95. data/merb_generators/ruboss_config.rb +0 -103
  96. data/merb_generators/ruboss_controller.rb +0 -59
  97. data/merb_generators/ruboss_flex_app.rb +0 -67
  98. data/merb_generators/ruboss_resource.rb +0 -37
  99. data/merb_generators/ruboss_resource_controller.rb +0 -80
  100. data/merb_generators/ruboss_scaffold.rb +0 -157
  101. data/merb_generators/templates/ruboss_config/ruboss.yml +0 -16
  102. data/merb_generators/templates/ruboss_resource_controller/controller_ar.rb.erb +0 -49
  103. data/merb_generators/templates/ruboss_resource_controller/controller_dm.rb.erb +0 -46
  104. data/merb_generators/templates/ruboss_resource_controller/spec/controllers/%file_name%_spec.rb +0 -7
  105. data/merb_generators/templates/ruboss_resource_controller/spec/requests/%file_name%_spec.rb +0 -1
  106. data/merb_generators/templates/ruboss_resource_controller/test/controllers/%file_name%_test.rb +0 -17
@@ -0,0 +1,34 @@
1
+ class RubossControllerGenerator < RubiGen::Base
2
+ include Ruboss4Ruby::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
+ :component_names,
12
+ :use_air,
13
+ :application_tag
14
+
15
+ def initialize(runtime_args, runtime_options = {})
16
+ super
17
+ @project_name, @flex_project_name, @command_controller_name, @base_package, @base_folder = extract_names
18
+
19
+ @model_names = list_as_files("app/flex/#{base_folder}/models")
20
+ @command_names = list_as_files("app/flex/#{base_folder}/commands")
21
+ end
22
+
23
+ def manifest
24
+ record do |m|
25
+ m.template 'controller.as.erb', File.join("app/flex/#{base_folder}/controllers",
26
+ "#{command_controller_name}.as")
27
+ end
28
+ end
29
+
30
+ protected
31
+ def banner
32
+ "Usage: #{$0} #{spec.name}"
33
+ end
34
+ end
@@ -29,10 +29,6 @@ package <%= base_package %>.controllers {
29
29
  if (!RubossUtils.isEmpty(airDatabaseName)) Ruboss.airDatabaseName = airDatabaseName;
30
30
  controller = new <%= command_controller_name %>(new SingletonEnforcer, extraServices,
31
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
32
  }
37
33
  }
38
34
  }
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Refreshes main Flex/AIR application file to make sure that
3
+ any of the generated components are included. Warning,
4
+ this will wipe your main application file. Used mostly
5
+ during code generation phase.
6
+
7
+ Examples:
8
+ `./script/generate ruboss_main_app`
@@ -0,0 +1,46 @@
1
+ class RubossMainAppGenerator < RubiGen::Base
2
+ include Ruboss4Ruby::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
+ :component_names,
12
+ :use_air,
13
+ :application_tag
14
+
15
+ def initialize(runtime_args, runtime_options = {})
16
+ super
17
+ @project_name, @flex_project_name, @command_controller_name, @base_package, @base_folder = extract_names
18
+
19
+ project_file_name = APP_ROOT + '/.project'
20
+ if File.exist?(project_file_name)
21
+ @use_air = true if File.read(project_file_name) =~/com.adobe.flexbuilder.apollo.apollobuilder/m
22
+ end
23
+
24
+ if @use_air
25
+ @application_tag = 'WindowedApplication'
26
+ else
27
+ @application_tag = 'Application'
28
+ end
29
+
30
+ @component_names = []
31
+ if File.exists?("app/flex/#{base_folder}/components/generated")
32
+ @component_names = list_mxml_files("app/flex/#{base_folder}/components/generated")
33
+ end
34
+ end
35
+
36
+ def manifest
37
+ record do |m|
38
+ m.template 'mainapp.mxml', File.join('app', 'flex', "#{project_name}.mxml")
39
+ end
40
+ end
41
+
42
+ protected
43
+ def banner
44
+ "Usage: #{$0} #{spec.name}"
45
+ end
46
+ end
@@ -0,0 +1,31 @@
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
+ import org.ruboss.services.air.AIRServiceProvider;
10
+ <% end -%>
11
+ import org.ruboss.Ruboss;
12
+ import <%= base_package %>.controllers.<%= command_controller_name %>;
13
+
14
+ private function init():void {
15
+ <% if use_air -%>
16
+ <%= command_controller_name %>.initialize([AIRServiceProvider], AIRServiceProvider.ID, "<%= base_package %>");
17
+ <% else -%>
18
+ <%= command_controller_name %>.initialize();
19
+ <% end -%>
20
+ }
21
+ ]]>
22
+ </mx:Script>
23
+ <mx:LinkBar dataProvider="{mainViewStack}" direction="vertical" borderStyle="solid" backgroundColor="#EEEEEE"/>
24
+ <mx:ViewStack id="mainViewStack" width="100%" height="100%">
25
+ <!-- For a simple demo, put all the components here. -->
26
+ <% for component in component_names -%>
27
+ <generated:<%= component %>/>
28
+ <% end -%>
29
+ </mx:ViewStack>
30
+ </mx:<%= application_tag %>>
31
+
@@ -0,0 +1,29 @@
1
+ Description:
2
+ Scaffolds an entire Ruboss resources. The resource is ready to use as a
3
+ starting point for your restful, resource-oriented application.
4
+
5
+ ruboss_scaffold :
6
+ 1. Generates all required Flex code.
7
+ 2. You can pass special belongs_to, has_one and has_many attributes
8
+ to generate appropriate relationships.
9
+
10
+ Pass the name of the model, either CamelCased or under_scored, as the first
11
+ argument, and an optional list of attribute pairs.
12
+
13
+ Attribute pairs are column_name:sql_type arguments specifying the
14
+ model's attributes. Timestamps are added by default, so you don't have to
15
+ specify them by hand as 'created_at:datetime updated_at:datetime'.
16
+
17
+ The syntax for belongs_to, has_one and has_many attributes is as follows:
18
+ belongs_to:<relationship_name> or
19
+ belongs_to:<relationship_name>,<another_relationship>,<and_another>
20
+
21
+ You don't have to think up every attribute up front, but it helps to
22
+ sketch out a few so you can start working with the resource immediately.
23
+
24
+ For example, `ruboss_scaffold post title:string body:text published:boolean`
25
+ gives you a model with those three attributes.
26
+
27
+ Examples:
28
+ `./script/generate ruboss_scaffold project name:string has_many:tasks`
29
+ `./script/generate ruboss_scaffold task name:string belongs_to:project`
@@ -0,0 +1,117 @@
1
+ module Ruboss4Ruby
2
+ module Generator
3
+ class GeneratedAttribute
4
+ attr_accessor :name, :type, :flex_name
5
+
6
+ def initialize(name, type)
7
+ @name, @type = name, type.to_sym
8
+ @flex_name = name.camelcase(:lower)
9
+ end
10
+
11
+ def flex_type
12
+ @flex_type = case type
13
+ when :integer then 'int'
14
+ when :date, :datetime, :time then 'Date'
15
+ when :boolean then 'Boolean'
16
+ when :float, :decimal then 'Number'
17
+ else
18
+ 'String'
19
+ end
20
+ end
21
+
22
+ def flex_default(prefix = '')
23
+ @flex_default = case type
24
+ when :integer, :float, :decimal then '0'
25
+ when :string, :text then '""'
26
+ when :boolean then 'false'
27
+ else
28
+ 'null'
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ class RubossScaffoldGenerator < RubiGen::Base
36
+ include Ruboss4Ruby::Configuration
37
+
38
+ attr_reader :project_name,
39
+ :flex_project_name,
40
+ :base_package,
41
+ :base_folder,
42
+ :command_controller_name
43
+
44
+ attr_reader :belongs_tos,
45
+ :has_manies,
46
+ :has_ones
47
+
48
+ attr_reader :name,
49
+ :class_name,
50
+ :file_name
51
+
52
+ attr_accessor :constructor_args
53
+
54
+ def initialize(runtime_args, runtime_options = {})
55
+ super
56
+
57
+ # Name argument is required.
58
+ usage if runtime_args.empty?
59
+
60
+ @args = runtime_args.dup
61
+ @name = @args.shift
62
+ @file_name = @name.underscore
63
+ @class_name = @name.camelize
64
+
65
+ @project_name, @flex_project_name, @command_controller_name, @base_package, @base_folder = extract_names
66
+
67
+ @belongs_tos = []
68
+ @has_ones = []
69
+ @has_manies = []
70
+ # Figure out has_one, has_many and belongs_to based on args
71
+ @args.each do |arg|
72
+ if arg =~ /^has_one:/
73
+ # arg = "has_one:arg1,arg2", so all the has_one are together
74
+ @has_ones = arg.split(':')[1].split(',')
75
+ elsif arg =~ /^has_many:/
76
+ # arg = "has_many:arg1,arg2", so all the has_many are together
77
+ @has_manies = arg.split(":")[1].split(",")
78
+ elsif arg =~ /^belongs_to:/ # belongs_to:arg1,arg2
79
+ @belongs_tos = arg.split(":")[1].split(',')
80
+ end
81
+ end
82
+
83
+ # Remove the has_one and has_many arguments since they are
84
+ # not for consumption by the scaffold generator, and since
85
+ # we have already used them to set the @belongs_tos, @has_ones and
86
+ # @has_manies.
87
+ @args.delete_if { |elt| elt =~ /^(has_one|has_many|belongs_to):/ }
88
+ end
89
+
90
+ def manifest
91
+ record do |m|
92
+ # Generate Flex AS model and MXML component based on the
93
+ # Ruboss templates.
94
+
95
+ puts @file_name
96
+
97
+ m.template 'model.as.erb',
98
+ File.join("app", 'flex', base_folder, "models", "#{@class_name}.as"),
99
+ :assigns => { :resource_controller_name => "#{file_name.pluralize}" }
100
+
101
+ m.template 'component.mxml.erb',
102
+ File.join("app", 'flex', base_folder, "components", "generated", "#{@class_name}Box.mxml"),
103
+ :assigns => { :resource_controller_name => "#{file_name.pluralize}" }
104
+
105
+ # Run the rcontroller generator to clobber the
106
+ # RubossCommandController subclass to include the new models.
107
+ m.dependency 'ruboss_controller', [name] + @args, :collision => :force
108
+ end
109
+ end
110
+
111
+ protected
112
+ def attributes
113
+ @attributes ||= @args.collect do |attribute|
114
+ Ruboss4Ruby::Generator::GeneratedAttribute.new(*attribute.split(":"))
115
+ end
116
+ end
117
+ 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.dcfirst %>:<%= class_name %> = new <%= class_name %>();
14
+
15
+ private function new<%= class_name %>():void {
16
+ _<%= class_name.dcfirst %> = new <%= class_name %>();
17
+ <%= class_name.dcfirst.pluralize %>List.selectedIndex = -1;
18
+ }
19
+
20
+ private function save<%= class_name %>():void {
21
+ if (_<%= class_name.dcfirst %>.id) {
22
+ update<%= class_name %>();
23
+ } else {
24
+ create<%= class_name %>();
25
+ }
26
+ }
27
+
28
+ private function create<%= class_name %>():void {
29
+ var <%= class_name.dcfirst %>:<%= class_name %> = new <%= class_name %>();
30
+ <% for attribute in attributes -%>
31
+ <% if attribute.type == :boolean -%>
32
+ <%= class_name.dcfirst %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>CheckBox.selected;
33
+ <% elsif attribute.type == :string -%>
34
+ <%= class_name.dcfirst %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>TextInput.text;
35
+ <% elsif attribute.type == :text -%>
36
+ <%= class_name.dcfirst %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>TextArea.text;
37
+ <% elsif attribute.type == :datetime || attribute.type == :time -%>
38
+ <%= class_name.dcfirst %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>DateTimeTextInput.date;
39
+ <% elsif attribute.type == :date -%>
40
+ <%= class_name.dcfirst %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>DateField.selectedDate;
41
+ <% else -%>
42
+ <%= class_name.dcfirst %>.<%= attribute.flex_name %> = <%= attribute.flex_type %>(<%= attribute.flex_name %>TextInput.text);
43
+ <% end -%>
44
+ <% end -%>
45
+
46
+ <% for model in belongs_tos -%>
47
+ <%= class_name.dcfirst %>.<%= model.camelcase(:lower) %> = <%= model.camelcase %>(<%= model.camelcase(:lower) %>ComboBox.selectedItem);
48
+ <% end -%>
49
+ <%= class_name.dcfirst %>.create({onSuccess: on<%= class_name %>Create});
50
+ }
51
+
52
+ private function update<%= class_name %>():void {
53
+ <% for attribute in attributes -%>
54
+ <% if attribute.type == :boolean -%>
55
+ _<%= class_name.dcfirst %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>CheckBox.selected;
56
+ <% elsif attribute.type == :string -%>
57
+ _<%= class_name.dcfirst %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>TextInput.text;
58
+ <% elsif attribute.type == :text -%>
59
+ _<%= class_name.dcfirst %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>TextArea.text;
60
+ <% elsif attribute.type == :datetime || attribute.type == :time -%>
61
+ _<%= class_name.dcfirst %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>DateTimeTextInput.date;
62
+ <% elsif attribute.type == :date -%>
63
+ _<%= class_name.dcfirst %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>DateField.selectedDate;
64
+ <% else -%>
65
+ _<%= class_name.dcfirst %>.<%= attribute.flex_name %> = <%= attribute.flex_type %>(<%= attribute.flex_name %>TextInput.text);
66
+ <% end -%>
67
+ <% end -%>
68
+
69
+ <% for model in belongs_tos -%>
70
+ _<%= class_name.dcfirst %>.<%= model.camelcase(:lower) %> = <%= model.camelcase %>(<%= model.camelcase(:lower) %>ComboBox.selectedItem);
71
+ <% end -%>
72
+ _<%= class_name.dcfirst %>.update({onSuccess: on<%= class_name %>Update});
73
+ }
74
+
75
+ private function destroy<%= class_name %>():void {
76
+ _<%= class_name.dcfirst %>.destroy({onSuccess: on<%= class_name %>Destroy});
77
+ }
78
+
79
+ private function on<%= class_name %>Select():void {
80
+ _<%= class_name.dcfirst %> = RubossUtils.clone(<%= class_name.dcfirst.pluralize %>List.selectedItem) as <%= class_name %>;
81
+ }
82
+
83
+ private function on<%= class_name %>Create(<%= class_name.dcfirst %>:<%= class_name %>):void {
84
+ _<%= class_name.dcfirst %> = new <%= class_name %>;
85
+ }
86
+
87
+ private function on<%= class_name %>Update(<%= class_name.dcfirst %>:<%= class_name %>):void {
88
+ <%= class_name.dcfirst.pluralize %>List.selectedItem = <%= class_name.dcfirst %>;
89
+ _<%= class_name.dcfirst %> = RubossUtils.clone(<%= class_name.dcfirst %>) as <%= class_name %>;
90
+ }
91
+
92
+ private function on<%= class_name %>Destroy(<%= class_name.dcfirst %>:<%= class_name %>):void {
93
+ on<%= class_name %>Create(<%= class_name.dcfirst %>);
94
+ }
95
+
96
+ private function canDelete<%= class_name %>(<%= class_name.dcfirst %>:<%= class_name %>):Boolean {
97
+ return <%= class_name.dcfirst %> != null && !RubossUtils.isEmpty(<%= class_name.dcfirst %>.id);
98
+ }
99
+ ]]></mx:Script>
100
+ <mx:Panel id="<%= class_name.dcfirst.pluralize %>Panel"
101
+ title="<%= class_name.pluralize %>" cornerRadius="0" dropShadowEnabled="false" borderStyle="solid"
102
+ borderThickness="1" backgroundColor="#EEEEEE" width="25%" height="100%">
103
+ <mx:List id="<%= class_name.dcfirst.pluralize %>List"
104
+ width="100%" height="100%"
105
+ dataProvider="{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.ucfirst %>" width="100%">
117
+ <% if attribute.type == :boolean -%>
118
+ <mx:CheckBox id="<%= attribute.flex_name %>CheckBox" selected="{_<%= class_name.dcfirst %>.<%= attribute.flex_name %>}"/>
119
+ <% elsif attribute.type == :string -%>
120
+ <mx:TextInput id="<%= attribute.flex_name %>TextInput" width="100%" text="{_<%= class_name.dcfirst %>.<%= attribute.flex_name %>}"/>
121
+ <% elsif attribute.type == :text -%>
122
+ <mx:TextArea id="<%= attribute.flex_name %>TextArea" width="100%" height="200" text="{_<%= class_name.dcfirst %>.<%= attribute.flex_name %>}"/>
123
+ <% elsif attribute.type == :datetime || attribute.type == :time -%>
124
+ <rcomponents:DateTimeTextInput id="<%= attribute.flex_name %>DateTimeTextInput" width="200" date="{_<%= class_name.dcfirst %>.<%= attribute.flex_name %>}"/>
125
+ <% elsif attribute.type == :date -%>
126
+ <mx:DateField id="<%= attribute.flex_name %>DateField" selectedDate="{_<%= class_name.dcfirst %>.<%= attribute.flex_name %>}"/>
127
+ <% else -%>
128
+ <mx:TextInput id="<%= attribute.flex_name %>TextInput" width="100%" text="{_<%= class_name.dcfirst %>.<%= attribute.flex_name %>}"/>
129
+ <% end -%>
130
+ </mx:FormItem>
131
+ <% end -%>
132
+ <% for model in belongs_tos -%>
133
+ <mx:FormItem label="<%= model.camelcase %>" width="100%">
134
+ <mx:ComboBox id="<%= model.camelcase(:lower) %>ComboBox" width="200"
135
+ labelField="{<%= model.camelcase %>.LABEL}"
136
+ dataProvider="{Ruboss.models.index(<%= model.camelcase %>)}" prompt="<%= model.camelcase %> ..."
137
+ selectedItem="{_<%= class_name.dcfirst %>.<%= model.camelcase(:lower) %>}" />
138
+ </mx:FormItem>
139
+ <% end -%>
140
+ </mx:Form>
141
+ <mx:ControlBar width="100%">
142
+ <mx:Button label="Save <%= class_name %>" width="50%" height="30"
143
+ click="save<%= class_name %>()"/>
144
+ <mx:Button label="Delete <%= class_name %>" width="50%" height="30"
145
+ enabled="{canDelete<%= class_name %>(_<%= class_name.dcfirst %>)}"
146
+ click="destroy<%= class_name %>()"/>
147
+ </mx:ControlBar>
148
+ </mx:Panel>
149
+ </mx:HBox>
@@ -0,0 +1,42 @@
1
+ package <%= base_package %>.models {
2
+ <% if has_manies.length > 0 -%>
3
+ import org.ruboss.collections.ModelsCollection;
4
+ <% end -%>
5
+ import org.ruboss.models.RubossModel;
6
+
7
+ [Resource(name="<%= resource_controller_name %>")]
8
+ [Bindable]
9
+ public class <%= class_name %> extends RubossModel {
10
+ <% if attributes && !attributes.empty? && attributes[0].flex_type != "Boolean" -%>
11
+ public static const LABEL:String = "<%= attributes[0].flex_name %>";
12
+ <% else -%>
13
+ public static const LABEL:String = "id";
14
+ <% end -%>
15
+
16
+ <% for attribute in attributes -%>
17
+ <% if attribute.type == :datetime || attribute.type == :time -%>
18
+ [DateTime]
19
+ <% end -%>
20
+ public var <%= attribute.flex_name %>:<%= attribute.flex_type %>;
21
+
22
+ <% end -%>
23
+ <% for model in belongs_tos -%>
24
+ [BelongsTo]
25
+ public var <%= model.camelcase(:lower) %>:<%= model.camelcase %>;
26
+
27
+ <% end -%>
28
+ <% for model in has_ones -%>
29
+ [HasOne]
30
+ public var <%= model.camelcase(:lower) %>:<%= model.camelcase %>;
31
+
32
+ <% end -%>
33
+ <% for model in has_manies -%>
34
+ [HasMany]
35
+ public var <%= model.camelcase(:lower) %>:ModelsCollection;
36
+
37
+ <% end -%>
38
+ public function <%= class_name %>() {
39
+ super(LABEL);
40
+ }
41
+ }
42
+ }
@@ -0,0 +1,7 @@
1
+ Description:
2
+ Scaffolds an entire application based on db/model.yml file. This generator
3
+ transforms entries in db/model.yml into command line calls to
4
+ "ruboss_scaffold".
5
+
6
+ Examples:
7
+ `./script/generate ruboss_yaml_scaffold`
@@ -0,0 +1,43 @@
1
+ require 'yaml'
2
+
3
+ class RubossYamlScaffoldGenerator < RubiGen::Base
4
+ include Ruboss4Ruby::Configuration
5
+
6
+ def extract_attrs(line, attrs)
7
+ attrs.each do |key,value|
8
+ if value.class == Array
9
+ line << " #{key}:#{value.join(',')}"
10
+ else
11
+ line << " #{key}:#{value}"
12
+ end
13
+ end
14
+ line
15
+ end
16
+
17
+ def manifest
18
+ record do |m|
19
+ models = YAML.load(File.open(File.join(APP_ROOT, 'db/model.yml'), 'r'))
20
+ models.each do |model|
21
+ line = ""
22
+ attrs = model[1]
23
+ if attrs.class == Array
24
+ attrs.each do |elm|
25
+ line = extract_attrs(line, elm)
26
+ end
27
+ else
28
+ line = extract_attrs(line, attrs)
29
+ end
30
+ line = model[0].camelcase + " " + line
31
+ puts 'running: ruboss_scaffold ' + line
32
+ RubiGen::Scripts::Generate.new.run(["ruboss_scaffold"] + line.split)
33
+ puts 'done ...'
34
+ end
35
+ RubiGen::Scripts::Generate.new.run(["ruboss_main_app"])
36
+ end
37
+ end
38
+
39
+ protected
40
+ def banner
41
+ "Usage: #{$0} #{spec.name}"
42
+ end
43
+ end
@@ -12,9 +12,6 @@ module ActiveSupport
12
12
  module Hash
13
13
  module Conversions
14
14
  def to_fxml(options = {})
15
- if self.empty? && !options[:root]
16
- raise "empty hash being converted to FXML must specify :root option, e.g. <class_name>.to_s.underscore.pluralize"
17
- end
18
15
  options.merge!(:dasherize => false)
19
16
  options[:indent] ||= 2
20
17
  options.reverse_merge!({ :builder => Builder::XmlMarkup.new(:indent => options[:indent]),
@@ -71,9 +68,6 @@ module ActiveSupport
71
68
  module Array
72
69
  module Conversions
73
70
  def to_fxml(options = {})
74
- if self.empty? && !options[:root]
75
- raise "empty array being converted to FXML must specify :root option, e.g. <class_name>.to_s.underscore.pluralize"
76
- end
77
71
  raise "Not all elements respond to to_fxml" unless all? { |e| e.respond_to? :to_fxml }
78
72
 
79
73
  options[:root] ||= all? { |e| e.is_a?(first.class) && first.class.to_s != "Hash" } ? first.class.to_s.underscore.pluralize : "records"
@@ -110,64 +104,6 @@ end
110
104
 
111
105
  module ActiveRecord
112
106
  # Flex friendly XML serialization patches
113
- class Base
114
- class << self
115
- # TODO: this doesn't work with hash based to_fxml(:include) options, only array based
116
- def default_fxml_methods(*args)
117
- methods = *args.dup
118
- module_eval <<-END
119
- def self.default_fxml_methods_array
120
- return [#{methods.inspect}].flatten
121
- end
122
- END
123
- end
124
-
125
- def default_fxml_includes(*args)
126
- includes = *args.dup
127
- module_eval <<-END
128
- def self.default_fxml_include_params
129
- return [#{includes.inspect}].flatten
130
- end
131
- END
132
- end
133
-
134
- def default_fxml_hash(already_included = [])
135
- # return {} unless self.class.respond_to?(:default_fxml_include_params) || self.class.respond_to?(:default_fxml_methods_array)
136
- default_hash = {:include => {}}
137
- default_hash[:methods] = self.default_fxml_methods_array if self.respond_to?(:default_fxml_methods_array)
138
- if self.respond_to?(:default_fxml_include_params)
139
- default_includes = self.default_fxml_include_params
140
- default_hash[:include] = default_includes.inject({}) do |include_hash, included|
141
- next if already_included.include?(included) # We only want to include things once, to avoid infinite loops
142
- included_class = included.to_s.singularize.camelize.constantize
143
- include_hash[included] = included_class.default_fxml_hash(already_included + default_includes)
144
- include_hash
145
- end
146
- end
147
- default_hash
148
- end
149
-
150
- # options[:include] can be a Hash, Array, Symbol or nil.
151
- # We always want it as a Hash. This translates includes to a Hash like this:
152
- # If it's a nil, return an empty Hash ({})
153
- # If it's a Hash, then it is just returned
154
- # If it's an array, then it returns a Hash with each array element as a key, and values of empty Hashes.
155
- # If it's a symbol, then it returns a Hash with a single key/value pair, with the symbol as the key and an empty Hash as the value.
156
- def includes_as_hash(includes = nil)
157
- res = case
158
- when includes.is_a?(Hash)
159
- includes
160
- when includes.nil?
161
- {}
162
- else #Deal with arrays and symbols
163
- res = [includes].flatten.inject({}) {|include_hash, included| include_hash[included] = {} ; include_hash}
164
- end
165
- res
166
- end
167
-
168
- end
169
- end
170
-
171
107
  module Serialization
172
108
  def to_fxml(options = {}, &block)
173
109
  options.merge!(:dasherize => false)
@@ -0,0 +1,54 @@
1
+ module ActiveRecord
2
+
3
+ class Base
4
+ class << self
5
+
6
+ def default_methods(*args)
7
+ methods = *args.dup
8
+ module_eval <<-END
9
+ def self.default_methods_array
10
+ return [#{methods.inspect}].flatten
11
+ end
12
+ END
13
+ end
14
+
15
+ def defaults_hash(already_included = [], ignore_default_methods = nil)
16
+ defaults_hash = {:include => {}}
17
+ unless ignore_default_methods
18
+ defaults_hash[:methods] = self.default_methods_array if self.respond_to?(:default_methods_array)
19
+ end
20
+ defaults_hash
21
+ end
22
+
23
+ end
24
+
25
+ end
26
+
27
+ module Serialization
28
+
29
+ alias_method :xml_defaults_old_to_xml, :to_xml unless method_defined?(:xml_defaults_old_to_xml)
30
+
31
+ alias_method :json_defaults_old_to_json, :to_json unless method_defined?(:json_defaults_old_to_json)
32
+
33
+ def to_xml(options = {}, &block)
34
+ unless options[:ignore_defaults]
35
+ unless options[:ignore_default_methods]
36
+ options[:methods] = [options[:methods] || []].flatten + (self.class.defaults_hash[:methods] || [])
37
+ end
38
+ end
39
+ xml_defaults_old_to_xml(options, &block)
40
+ end
41
+
42
+ def to_json(options = {}, &block)
43
+ unless options[:ignore_defaults]
44
+ unless options[:ignore_default_methods]
45
+ options[:methods] = [options[:methods] || []].flatten + (self.class.defaults_hash[:methods] || [])
46
+ end
47
+ end
48
+ json_defaults_old_to_json(options, &block)
49
+ end
50
+
51
+ end
52
+
53
+
54
+ end