dima-ruboss4ruby 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/History.txt +2 -2
  2. data/Manifest.txt +9 -3
  3. data/README.rdoc +43 -15
  4. data/Rakefile +9 -4
  5. data/app_generators/ruboss_app/USAGE +11 -2
  6. data/app_generators/ruboss_app/ruboss_app_generator.rb +21 -15
  7. data/app_generators/ruboss_app/templates/app.yaml.erb +12 -0
  8. data/app_generators/ruboss_app/templates/default_tasks.rake +1 -1
  9. data/app_generators/ruboss_app/templates/empty.txt +0 -0
  10. data/app_generators/ruboss_app/templates/generate.rb +1 -5
  11. data/app_generators/ruboss_app/templates/index.yaml +11 -0
  12. data/app_generators/ruboss_app/templates/mainair-app.xml +1 -1
  13. data/bin/ruboss-gen +18 -4
  14. data/generators/ruboss_config/ruboss_config_generator.rb +0 -5
  15. data/generators/ruboss_controller/ruboss_controller_generator.rb +15 -10
  16. data/generators/ruboss_controller/templates/assist.py +65 -0
  17. data/generators/ruboss_controller/templates/restful.py +136 -0
  18. data/generators/ruboss_main_app/ruboss_main_app_generator.rb +18 -4
  19. data/generators/ruboss_main_app/templates/main.py.erb +29 -0
  20. data/generators/ruboss_main_app/templates/mainapp.mxml +5 -1
  21. data/generators/ruboss_scaffold/ruboss_scaffold_generator.rb +77 -46
  22. data/generators/ruboss_scaffold/templates/controller.py.erb +27 -0
  23. data/generators/ruboss_scaffold/templates/model.as.erb +1 -1
  24. data/generators/ruboss_scaffold/templates/model.py.erb +14 -0
  25. data/generators/ruboss_yaml_scaffold/USAGE +42 -4
  26. data/generators/ruboss_yaml_scaffold/ruboss_yaml_scaffold_generator.rb +8 -4
  27. data/lib/ruboss4ruby.rb +15 -2
  28. data/lib/ruboss4ruby/active_foo.rb +32 -3
  29. data/lib/ruboss4ruby/active_record_default_methods.rb +19 -7
  30. data/lib/ruboss4ruby/active_record_tasks.rb +9 -3
  31. data/lib/ruboss4ruby/configuration.rb +32 -0
  32. data/lib/ruboss4ruby/datamapper_foo.rb +6 -0
  33. data/lib/ruboss4ruby/rails/recipes.rb +5 -3
  34. data/lib/ruboss4ruby/rails/swf_helper.rb +1 -0
  35. data/lib/ruboss4ruby/tasks.rb +5 -0
  36. data/rails_generators/ruboss_config/ruboss_config_generator.rb +14 -13
  37. data/rails_generators/ruboss_config/templates/mainair-app.xml +1 -1
  38. data/rails_generators/ruboss_config/templates/ruboss_tasks.rake +1 -0
  39. data/rails_generators/ruboss_controller/ruboss_controller_generator.rb +2 -5
  40. data/rails_generators/ruboss_scaffold/ruboss_scaffold_generator.rb +66 -62
  41. data/rails_generators/ruboss_scaffold/templates/model.as.erb +1 -1
  42. data/rails_generators/ruboss_yaml_scaffold/USAGE +38 -1
  43. data/rails_generators/ruboss_yaml_scaffold/ruboss_yaml_scaffold_generator.rb +0 -5
  44. data/rcl-1.0.txt +0 -0
  45. data/rdoc/generators/template/html/jamis.rb +588 -0
  46. data/ruboss4ruby.gemspec +12 -12
  47. metadata +15 -26
@@ -29,15 +29,19 @@ class RubossYamlScaffoldGenerator < RubiGen::Base
29
29
  end
30
30
  line = model[0].camelcase + " " + line
31
31
  puts 'running: ruboss_scaffold ' + line
32
- RubiGen::Scripts::Generate.new.run(["ruboss_scaffold"] + line.split)
32
+ RubiGen::Scripts::Generate.new.run(line.split, :generator => 'ruboss_scaffold',
33
+ :gae => options[:gae])
33
34
  puts 'done ...'
34
35
  end
35
- RubiGen::Scripts::Generate.new.run(["ruboss_main_app"])
36
+ RubiGen::Scripts::Generate.new.run([], :generator => 'ruboss_main_app', :gae => options[:gae])
36
37
  end
37
38
  end
38
39
 
39
40
  protected
40
- def banner
41
- "Usage: #{$0} #{spec.name}"
41
+ def add_options!(opt)
42
+ opt.separator ''
43
+ opt.separator 'Options:'
44
+ opt.on("--gae", "Generate Google App Engine Python classes in addition to Ruboss Flex resources.",
45
+ "Default: false") { |v| options[:gae] = v }
42
46
  end
43
47
  end
data/lib/ruboss4ruby.rb CHANGED
@@ -1,8 +1,12 @@
1
+ # Sets up all the relevant configuration options and brings together
2
+ # patches for Rails, Merb, ActiveRecord and Data Mapper.
3
+ #
4
+ # Loads Ruboss specific rake tasks if appropriate.
1
5
  module Ruboss4Ruby
2
6
 
3
7
  # :stopdoc:
4
- VERSION = '1.1.0'
5
- RUBOSS_FRAMEWORK_VERSION = '1.1.0'
8
+ VERSION = '1.1.1'
9
+ RUBOSS_FRAMEWORK_VERSION = '1.1.1'
6
10
  LIB_DIR = File.join(File.dirname(__FILE__), 'ruboss4ruby/')
7
11
  # :startdoc:
8
12
 
@@ -54,7 +58,10 @@ elsif defined?(ActionController::Base)
54
58
 
55
59
  ActionView::Base.send :include, SWFHelper unless ActionView::Base.included_modules.include?(SWFHelper)
56
60
 
61
+ # We mess with default +render+ implementation a bit to add support for expressions
62
+ # such as format.fxml { render :fxml => @foo }
57
63
  module ActionController
64
+ # Override render to add support for render :fxml
58
65
  class Base
59
66
  alias_method :old_render, :render unless method_defined?(:old_render)
60
67
 
@@ -72,6 +79,8 @@ elsif defined?(ActionController::Base)
72
79
  end
73
80
  end
74
81
 
82
+ # It is possible to pass metadata with any Ruboss model. This module adds support for
83
+ # extracting that metadata into the standard params hash.
75
84
  module Ruboss4RubyController
76
85
  private
77
86
 
@@ -89,7 +98,11 @@ elsif defined?(ActionController::Base)
89
98
  end
90
99
 
91
100
  module ActiveRecord
101
+ # ActiveRecord named scopes are computed *before* ruboss4ruby gem gets loaded
102
+ # this patch addresses that and makes sure +to_fxml+ calls are properly
103
+ # delegated
92
104
  module NamedScope
105
+ # make sure we properly delegate +to_fxml+ calls to the proxy
93
106
  class Scope
94
107
  delegate :to_fxml, :to => :proxy_found
95
108
  end
@@ -1,4 +1,15 @@
1
- #ActiveRecord+ActiveSupport specific patches
1
+ # There's a number of things that ActiveRecord/ActiveSupport and the rest of the family get
2
+ # ~wrong~ from the point of view of Flex clients.
3
+ #
4
+ # Some of these things are:
5
+ # * Date formats
6
+ # * XML format (Flex *really* doesn't like dashes in XML messages)
7
+ # * Errors (we need to be more specific and communicate what went wrong *where*)
8
+ #
9
+ # This is where we try to fix this stuff.
10
+ #
11
+ # Some of the things that are done can be called _monkey_ _patching_ while others can
12
+ # be called extensions. Caveat emptor.
2
13
 
3
14
  # Flex friendly date, datetime formats
4
15
  ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS.merge!(:flex_date => "%Y/%m/%d")
@@ -7,10 +18,17 @@ ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!(:flex_date
7
18
  Hash::XML_FORMATTING['date'] = Proc.new { |date| date.to_s(:flex_date) }
8
19
  Hash::XML_FORMATTING['datetime'] = Proc.new { |datetime| datetime.to_s(:flex_datetime) }
9
20
 
21
+ # ActiveSupport specific patches. More specifically we add +to_fxml+ methods to Array and
22
+ # Hash conversion modules
10
23
  module ActiveSupport
24
+ # refer to: http://api.rubyonrails.org/ for more details
11
25
  module CoreExtensions
26
+ # Add Flex friendly +to_fxml+ to Hash conversions
12
27
  module Hash
28
+ # refer to: http://api.rubyonrails.org/ for more details
13
29
  module Conversions
30
+
31
+ # Flex friendly XML format, no dashes, etc
14
32
  def to_fxml(options = {})
15
33
  options.merge!(:dasherize => false)
16
34
  options[:indent] ||= 2
@@ -65,8 +83,11 @@ module ActiveSupport
65
83
  end
66
84
  end
67
85
  end
86
+ # Add Flex friendly to_fxml to array conversions
68
87
  module Array
88
+ # refer to: http://api.rubyonrails.org/ for more details
69
89
  module Conversions
90
+ # Flex friendly XML format (no dashes, etc)
70
91
  def to_fxml(options = {})
71
92
  raise "Not all elements respond to to_fxml" unless all? { |e| e.respond_to? :to_fxml }
72
93
 
@@ -102,9 +123,13 @@ module ActiveSupport
102
123
  end
103
124
  end
104
125
 
126
+ # Flex friendly ActiveRecord patches. More specifically XML serialization improvements.
127
+ # These won't override whatever you may normally do with XML, hence there's Flex specific
128
+ # name for this stuff +to_fxml+.
105
129
  module ActiveRecord
106
- # Flex friendly XML serialization patches
130
+ # refer to: http://api.rubyonrails.org/ for more details
107
131
  module Serialization
132
+ # Enforces Flex friendly options on XML and delegates processing to standard +to_xml+
108
133
  def to_fxml(options = {}, &block)
109
134
  options.merge!(:dasherize => false)
110
135
  default_except = [:crypted_password, :salt, :remember_token, :remember_token_expires_at]
@@ -116,14 +141,17 @@ module ActiveRecord
116
141
  # Change the xml serializer so that '?'s are stripped from attribute names.
117
142
  # This makes it possible to serialize methods that end in a question mark, like 'valid?' or 'is_true?'
118
143
  class XmlSerializer
144
+ # Strips '?' from serialized method names
119
145
  def add_tag(attribute)
120
146
  builder.tag!(
121
147
  dasherize? ? attribute.display_name.dasherize : attribute.display_name,
122
148
  attribute.value.to_s,
123
149
  attribute.decorations(!options[:skip_types])
124
150
  )
125
- end
151
+ end
152
+ # Strips '?' from serialized method names
126
153
  class Attribute
154
+ # Strips '?' from serialized method names
127
155
  def display_name
128
156
  @name.gsub('?','')
129
157
  end
@@ -133,6 +161,7 @@ module ActiveRecord
133
161
  # Add more extensive reporting on errors including field name along with a message
134
162
  # when errors are serialized to XML
135
163
  class Errors
164
+ # Flex friendly errors
136
165
  def to_fxml(options={})
137
166
  options[:root] ||= "errors"
138
167
  options[:indent] ||= 2
@@ -1,8 +1,21 @@
1
1
  module ActiveRecord
2
-
2
+ #
3
+ # We also add support for serializing model methods along the lines of:
4
+ #
5
+ # class Project < ActiveRecord::Base
6
+ # default_methods :foobar
7
+ #
8
+ # def foobar
9
+ # 'foobar'
10
+ # end
11
+ # end
12
+ #
13
+ # When you do +to_fxml+ on this model method foobar will be automatically
14
+ # serialized as a simple attribute
3
15
  class Base
4
16
  class << self
5
17
 
18
+ # default methods hook
6
19
  def default_methods(*args)
7
20
  methods = *args.dup
8
21
  module_eval <<-END
@@ -11,7 +24,8 @@ module ActiveRecord
11
24
  end
12
25
  END
13
26
  end
14
-
27
+
28
+ # default methods hook
15
29
  def defaults_hash(already_included = [], ignore_default_methods = nil)
16
30
  defaults_hash = {:include => {}}
17
31
  unless ignore_default_methods
@@ -19,17 +33,17 @@ module ActiveRecord
19
33
  end
20
34
  defaults_hash
21
35
  end
22
-
23
36
  end
24
-
25
37
  end
26
38
 
39
+ # Flex-friendly serialization patches
27
40
  module Serialization
28
41
 
29
42
  alias_method :xml_defaults_old_to_xml, :to_xml unless method_defined?(:xml_defaults_old_to_xml)
30
43
 
31
44
  alias_method :json_defaults_old_to_json, :to_json unless method_defined?(:json_defaults_old_to_json)
32
45
 
46
+ # adds support for default_methods to standard +to_xml+
33
47
  def to_xml(options = {}, &block)
34
48
  unless options[:ignore_defaults]
35
49
  unless options[:ignore_default_methods]
@@ -39,6 +53,7 @@ module ActiveRecord
39
53
  xml_defaults_old_to_xml(options, &block)
40
54
  end
41
55
 
56
+ # adds support for default_methods to standard +to_json+
42
57
  def to_json(options = {}, &block)
43
58
  unless options[:ignore_defaults]
44
59
  unless options[:ignore_default_methods]
@@ -47,8 +62,5 @@ module ActiveRecord
47
62
  end
48
63
  json_defaults_old_to_json(options, &block)
49
64
  end
50
-
51
65
  end
52
-
53
-
54
66
  end
@@ -1,7 +1,10 @@
1
+ # ActiveRecord specific Rake tasks. Namely, nice little extras such as:
2
+ # - db:mysql:stage
3
+ # - db:refresh
1
4
  require File.join(File.dirname(__FILE__), 'tasks')
2
5
 
3
- # these tasks are active record specific
4
-
6
+ # stores local copy of the application environment ('production', 'test', etc)
7
+ # so that appropriate values in config/database.yml are used
5
8
  APP_ENV = defined?(ENV['RAILS_ENV']) ? ENV['RAILS_ENV'] : ENV['MERB_ENV']
6
9
 
7
10
  namespace :db do
@@ -26,7 +29,10 @@ namespace :db do
26
29
  stage_database(db_names, admin_password, db_user_name, db_password)
27
30
  end
28
31
  end
29
-
32
+
33
+ # Performs MySQL database set-up based on the username and password
34
+ # provided. Also updates Rails config/database.yml file with database
35
+ # username and password
30
36
  def stage_database(db_names, admin_password, db_user_name, db_password)
31
37
  sql_command = ""
32
38
 
@@ -1,17 +1,45 @@
1
+ # Interestingly enough there's no way to *just* upper-case or down-case first letter of a given
2
+ # string. Ruby's own +capitalize+ actually downcases all the rest of the characters in the string
3
+ # We patch the class to add our own implementation.
1
4
  class String
5
+ # Upper-case first character of a string leave the rest of the string intact
2
6
  def ucfirst
3
7
  self[0,1].capitalize + self[1..-1]
4
8
  end
5
9
 
10
+ # Down-case first character of a string leaving the rest of it intact
6
11
  def dcfirst
7
12
  self[0,1].downcase + self[1..-1]
8
13
  end
9
14
  end
10
15
 
11
16
  module Ruboss4Ruby
17
+ # Computes necessary configuration options from the environment. This can be used in Rails, Merb
18
+ # or standalone from the command line.
12
19
  module Configuration
13
20
  APP_ROOT = defined?(RAILS_ROOT) ? RAILS_ROOT : defined?(Merb) ? Merb.root : File.expand_path(".")
14
21
 
22
+ # Extract project, package, controller names from the environment. This will respect
23
+ # config/ruboss.yml if it exists, you can override all of the defaults there. The defaults are:
24
+ # - *base-package* same as project name downcased
25
+ # - *controller-name* 'ApplicationController'
26
+ #
27
+ # Here's a sample ruboss.yml file:
28
+ #
29
+ # Ruboss code generation configuration options
30
+ #
31
+ # By default flex models, commands, controllers and components are genearated into
32
+ # app/flex/<your rails project name> folder. If you'd like to customize the target folder
33
+ # (to say append a "com" package before your rails project name) uncomment the line below
34
+ # base-package must follow the usual flex package notation (a string separated by ".")
35
+ #
36
+ # base-package: com.pomodo
37
+ #
38
+ # Main ruboss controller is typically named AppicationController. This controller is created in
39
+ # <base-package>.controllers folder. You can customize the name by uncommenting the following line
40
+ # and changing the controller name.
41
+ #
42
+ # controller-name: ApplicationController
15
43
  def extract_names(project = nil)
16
44
  if project
17
45
  project_name = project.camelcase.gsub(/\s/, '')
@@ -21,10 +49,12 @@ module Ruboss4Ruby
21
49
  project_name_downcase = project_name.downcase
22
50
  end
23
51
 
52
+ # give a chance to override the settings via ruboss.yml
24
53
  begin
25
54
  config = YAML.load(File.open("#{APP_ROOT}/config/ruboss.yml"))
26
55
  base_package = config['base-package'] || project_name_downcase
27
56
  base_folder = base_package.gsub('.', '/').gsub(/\s/, '')
57
+ project_name = config['project-name'].camelcase.gsub(/\s/, '') || project_name
28
58
  controller_name = config['controller-name'] || "ApplicationController"
29
59
  rescue
30
60
  base_folder = base_package = project_name_downcase
@@ -33,10 +63,12 @@ module Ruboss4Ruby
33
63
  [project_name, project_name_downcase, controller_name, base_package, base_folder]
34
64
  end
35
65
 
66
+ # List files ending in *.as (ActionScript) in a given folder
36
67
  def list_as_files(dir_name)
37
68
  Dir.entries(dir_name).grep(/\.as$/).map { |name| name.sub(/\.as$/, "") }.join(", ")
38
69
  end
39
70
 
71
+ # List files ending in *.mxml in a given folder
40
72
  def list_mxml_files(dir_name)
41
73
  Dir.entries(dir_name).grep(/\.mxml$/).map { |name| name.sub(/\.mxml$/, "") }
42
74
  end
@@ -1,9 +1,15 @@
1
1
  require 'builder'
2
2
  require Ruboss4Ruby::LIB_DIR + 'configuration'
3
3
 
4
+ # Flex friendly DataMapper patches, more specifically we just add +to_xml+ on
5
+ # ValidationErrors class
4
6
  module DataMapper
7
+ # see DataMapper docs for more details
5
8
  module Validate
9
+ # By default DataMapper validation errors doesn't have +to_xml+ method. This is
10
+ # actually very useful when dealing with remote stateful clients such as Flex/AIR.
6
11
  class ValidationErrors
12
+ # Add Flex-friendly +to_xml+ implementation
7
13
  def to_xml
8
14
  xml = Builder::XmlMarkup.new(:indent => 2)
9
15
  xml.instruct! :xml, :version => "1.0", :encoding => "UTF-8"
@@ -1,7 +1,9 @@
1
- require 'find'
2
-
1
+ # Adds Capistrano recipes for deploying Flex applications
2
+ #
3
3
  # To use these recipes, add the following to your Capfile:
4
- # require 'ruboss4ruby/rails/recipes'
4
+ #
5
+ # require 'ruboss4ruby/rails/recipes'
6
+ require 'find'
5
7
 
6
8
  Capistrano::Configuration.instance(:must_exist).load do
7
9
  after "deploy:setup", "deploy:flex:setup"
@@ -1,3 +1,4 @@
1
+ # Adds a little helper to make it easier empbedding SWFs in ERB templates.
1
2
  module SWFHelper
2
3
 
3
4
  # Creates a swfObject Javascript call. You must include swfobject.js to use this.
@@ -1,3 +1,4 @@
1
+ # Rake tasks for building Ruboss-based Flex and AIR applications
1
2
  require 'rake'
2
3
  require 'ftools'
3
4
  require 'rexml/document'
@@ -6,6 +7,8 @@ require File.join(File.dirname(__FILE__), 'configuration')
6
7
  APP_ROOT = Ruboss4Ruby::Configuration::APP_ROOT
7
8
 
8
9
  namespace :ruboss do
10
+ # Compile the main Flex/AIR application using given executable to the given
11
+ # destination folder
9
12
  def compile_app(executable, destination, opts = '')
10
13
  app_properties = REXML::Document.new(File.open(File.join(APP_ROOT, ".actionScriptProperties")))
11
14
  app_properties.elements.each("*/applications/application") do |elm|
@@ -43,11 +46,13 @@ namespace :ruboss do
43
46
  end
44
47
  end
45
48
 
49
+ # Find what the main application is based on .actionScriptProperties file
46
50
  def get_main_application
47
51
  app_properties = REXML::Document.new(File.open(File.join(APP_ROOT, ".actionScriptProperties")))
48
52
  app_properties.root.attributes['mainApplicationPath'].split("/").last
49
53
  end
50
54
 
55
+ # Get appropriate executable based on platform
51
56
  def get_executable(executable)
52
57
  if RUBY_PLATFORM =~ /mswin32/
53
58
  executable << '.exe'
@@ -1,4 +1,5 @@
1
1
  require 'open-uri'
2
+ require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'ruboss4ruby') if !defined?(Ruboss4Ruby)
2
3
 
3
4
  class RubossConfigGenerator < Rails::Generator::Base
4
5
  include Ruboss4Ruby::Configuration
@@ -97,18 +98,18 @@ class RubossConfigGenerator < Rails::Generator::Base
97
98
  end
98
99
 
99
100
  protected
100
- def add_options!(opt)
101
- opt.separator ''
102
- opt.separator 'Options:'
103
- opt.on("-m", "--main-only", "Only generate the main Flex/AIR application file.",
104
- "Default: false") { |v| options[:main_only] = v }
105
- opt.on("-a", "--air", "Configure AIR project instead of Flex. Flex is default.",
106
- "Default: false") { |v| options[:air_config] = v }
107
- opt.on("-s", "--skip-framework", "Don't fetch the latest framework binary. You'll have to link/build the framework yourself.",
108
- "Default: false") { |v| options[:skip_framework] = v }
109
- end
101
+ def add_options!(opt)
102
+ opt.separator ''
103
+ opt.separator 'Options:'
104
+ opt.on("-m", "--main-only", "Only generate the main Flex/AIR application file.",
105
+ "Default: false") { |v| options[:main_only] = v }
106
+ opt.on("-a", "--air", "Configure AIR project instead of Flex. Flex is default.",
107
+ "Default: false") { |v| options[:air_config] = v }
108
+ opt.on("-s", "--skip-framework", "Don't fetch the latest framework binary. You'll have to link/build the framework yourself.",
109
+ "Default: false") { |v| options[:skip_framework] = v }
110
+ end
110
111
 
111
- def banner
112
- "Usage: #{$0} #{spec.name}"
113
- end
112
+ def banner
113
+ "Usage: #{$0} #{spec.name}"
114
+ end
114
115
  end
@@ -1,5 +1,5 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
- <application xmlns="http://ns.adobe.com/air/application/1.0">
2
+ <application xmlns="http://ns.adobe.com/air/application/1.5">
3
3
 
4
4
  <!-- Adobe AIR Application Descriptor File Template.
5
5
 
@@ -1,5 +1,6 @@
1
1
  # if the gem is not installed system wide, we'll just skip the tasks
2
2
  begin
3
+ # this will load the latest ruboss4ruby gem version
3
4
  require 'ruboss4ruby/active_record_tasks'
4
5
  rescue LoadError
5
6
  end
@@ -1,3 +1,5 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'ruboss4ruby') if !defined?(Ruboss4Ruby)
2
+
1
3
  class RubossControllerGenerator < Rails::Generator::Base
2
4
  include Ruboss4Ruby::Configuration
3
5
 
@@ -23,9 +25,4 @@ class RubossControllerGenerator < Rails::Generator::Base
23
25
  "#{command_controller_name}.as")
24
26
  end
25
27
  end
26
-
27
- protected
28
- def banner
29
- "Usage: #{$0} #{spec.name}"
30
- end
31
28
  end