ruboss4ruby 1.0.5 → 1.1.0

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 (155) hide show
  1. data/History.txt +2 -2
  2. data/Manifest.txt +86 -79
  3. data/README.rdoc +53 -0
  4. data/Rakefile +42 -5
  5. data/app_generators/ruboss_app/USAGE +22 -0
  6. data/app_generators/ruboss_app/ruboss_app_generator.rb +94 -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/app.yaml.erb +12 -0
  10. data/app_generators/ruboss_app/templates/default_tasks.rake +51 -0
  11. data/app_generators/ruboss_app/templates/empty.txt +0 -0
  12. data/{merb_generators/templates/ruboss_config → app_generators/ruboss_app/templates}/expressInstall.swf +0 -0
  13. data/{merb_generators/templates/ruboss_config → app_generators/ruboss_app/templates}/flex.properties +0 -0
  14. data/app_generators/ruboss_app/templates/generate.rb +17 -0
  15. data/{merb_generators/templates/ruboss_config → app_generators/ruboss_app/templates}/html-template/AC_OETags.js +0 -0
  16. data/{merb_generators/templates/ruboss_config → app_generators/ruboss_app/templates}/html-template/history/history.css +0 -0
  17. data/{merb_generators/templates/ruboss_config → app_generators/ruboss_app/templates}/html-template/history/history.js +0 -0
  18. data/{merb_generators/templates/ruboss_config → app_generators/ruboss_app/templates}/html-template/history/historyFrame.html +0 -0
  19. data/{merb_generators/templates/ruboss_config → app_generators/ruboss_app/templates}/html-template/index.template.html +0 -0
  20. data/{merb_generators/templates/ruboss_config → app_generators/ruboss_app/templates}/html-template/playerProductInstall.swf +0 -0
  21. data/{merb_generators/templates/ruboss_config → app_generators/ruboss_app/templates}/index.html.erb +2 -2
  22. data/app_generators/ruboss_app/templates/index.yaml +11 -0
  23. data/{merb_generators/templates/ruboss_config → app_generators/ruboss_app/templates}/mainair-app.xml +3 -3
  24. data/app_generators/ruboss_app/templates/mainapp-config.xml +21 -0
  25. data/{merb_generators/templates/ruboss_flex_app → app_generators/ruboss_app/templates}/mainapp.mxml +6 -9
  26. data/app_generators/ruboss_app/templates/project-textmate.erb +52 -0
  27. data/{merb_generators/templates/ruboss_config → app_generators/ruboss_app/templates}/project.properties +0 -0
  28. data/{merb_generators/templates/ruboss_config → app_generators/ruboss_app/templates}/projectair.properties +0 -0
  29. data/{merb_generators/templates/ruboss_config → app_generators/ruboss_app/templates}/swfobject.js +0 -0
  30. data/bin/ruboss-gen +31 -0
  31. data/generators/ruboss_config/USAGE +5 -0
  32. data/generators/ruboss_config/ruboss_config_generator.rb +19 -0
  33. data/generators/ruboss_controller/USAGE +10 -0
  34. data/generators/ruboss_controller/ruboss_controller_generator.rb +38 -0
  35. data/generators/ruboss_controller/templates/assist.py +65 -0
  36. data/{merb_generators/templates/ruboss_controller → generators/ruboss_controller/templates}/controller.as.erb +7 -6
  37. data/generators/ruboss_controller/templates/restful.py +136 -0
  38. data/generators/ruboss_main_app/USAGE +8 -0
  39. data/generators/ruboss_main_app/ruboss_main_app_generator.rb +60 -0
  40. data/generators/ruboss_main_app/templates/main.py.erb +29 -0
  41. data/generators/ruboss_main_app/templates/mainapp.mxml +35 -0
  42. data/generators/ruboss_scaffold/USAGE +29 -0
  43. data/generators/ruboss_scaffold/ruboss_scaffold_generator.rb +148 -0
  44. data/generators/ruboss_scaffold/templates/component.mxml.erb +149 -0
  45. data/generators/ruboss_scaffold/templates/controller.py.erb +27 -0
  46. data/generators/ruboss_scaffold/templates/model.as.erb +42 -0
  47. data/generators/ruboss_scaffold/templates/model.py.erb +14 -0
  48. data/generators/ruboss_yaml_scaffold/USAGE +45 -0
  49. data/generators/ruboss_yaml_scaffold/ruboss_yaml_scaffold_generator.rb +47 -0
  50. data/lib/ruboss4ruby/active_foo.rb +109 -86
  51. data/lib/ruboss4ruby/active_record_default_methods.rb +66 -0
  52. data/lib/ruboss4ruby/active_record_tasks.rb +10 -4
  53. data/lib/ruboss4ruby/configuration.rb +48 -34
  54. data/lib/ruboss4ruby/datamapper_foo.rb +31 -0
  55. data/lib/ruboss4ruby/{recipes.rb → rails/recipes.rb} +7 -9
  56. data/lib/ruboss4ruby/{ruboss_helper.rb → rails/swf_helper.rb} +14 -8
  57. data/lib/ruboss4ruby/tasks.rb +9 -4
  58. data/lib/ruboss4ruby.rb +72 -27
  59. data/rails_generators/ruboss_config/ruboss_config_generator.rb +3 -15
  60. data/rails_generators/ruboss_config/templates/mainair-app.xml +2 -2
  61. data/rails_generators/ruboss_config/templates/mainapp-config.xml +1 -1
  62. data/rails_generators/ruboss_config/templates/ruboss.yml +2 -4
  63. data/rails_generators/ruboss_config/templates/ruboss_tasks.rake +5 -15
  64. data/rails_generators/ruboss_controller/USAGE +1 -2
  65. data/rails_generators/ruboss_controller/ruboss_controller_generator.rb +3 -14
  66. data/rails_generators/ruboss_controller/templates/controller.as.erb +11 -6
  67. data/rails_generators/ruboss_scaffold/ruboss_scaffold_generator.rb +67 -76
  68. data/rails_generators/ruboss_scaffold/templates/component.mxml.erb +69 -69
  69. data/rails_generators/ruboss_scaffold/templates/model.as.erb +2 -2
  70. data/rails_generators/ruboss_yaml_scaffold/USAGE +38 -1
  71. data/rcl-1.0.txt +0 -0
  72. data/rdoc/generators/template/html/jamis.rb +588 -0
  73. data/ruboss4ruby.gemspec +43 -0
  74. data/spec/ruboss4ruby_spec.rb +7 -0
  75. data/spec/spec_helper.rb +16 -0
  76. data/tasks/ann.rake +80 -0
  77. data/tasks/bones.rake +20 -0
  78. data/tasks/gem.rake +201 -0
  79. data/tasks/git.rake +40 -0
  80. data/tasks/manifest.rake +48 -0
  81. data/tasks/notes.rake +27 -0
  82. data/tasks/post_load.rake +39 -0
  83. data/tasks/rdoc.rake +50 -0
  84. data/tasks/rubyforge.rake +55 -0
  85. data/tasks/setup.rb +279 -0
  86. data/tasks/spec.rake +54 -0
  87. data/tasks/svn.rake +47 -0
  88. data/tasks/test.rake +40 -0
  89. data/test/{controllers → rails/controllers}/application.rb +0 -0
  90. data/test/{controllers → rails/controllers}/locations_controller.rb +0 -0
  91. data/test/{controllers → rails/controllers}/notes_controller.rb +0 -0
  92. data/test/{controllers → rails/controllers}/projects_controller.rb +0 -0
  93. data/test/{controllers → rails/controllers}/tasks_controller.rb +0 -0
  94. data/test/{controllers → rails/controllers}/users_controller.rb +0 -0
  95. data/test/{database.yml → rails/database.yml} +0 -0
  96. data/test/{fixtures → rails/fixtures}/locations.yml +0 -0
  97. data/test/{fixtures → rails/fixtures}/notes.yml +0 -0
  98. data/test/{fixtures → rails/fixtures}/projects.yml +0 -0
  99. data/test/rails/fixtures/simple_properties.yml +19 -0
  100. data/test/{fixtures → rails/fixtures}/tasks.yml +0 -0
  101. data/test/{fixtures → rails/fixtures}/users.yml +0 -0
  102. data/test/{helpers → rails/helpers}/functional_test_helper.rb +0 -11
  103. data/test/rails/helpers/test_helper.rb +61 -0
  104. data/test/rails/helpers/unit_test_helper.rb +30 -0
  105. data/test/{model.yml → rails/model.yml} +0 -0
  106. data/test/{models → rails/models}/location.rb +0 -0
  107. data/test/{models → rails/models}/note.rb +0 -0
  108. data/test/{models → rails/models}/project.rb +1 -3
  109. data/test/rails/models/simple_property.rb +2 -0
  110. data/test/{models → rails/models}/task.rb +1 -1
  111. data/test/{models → rails/models}/user.rb +1 -2
  112. data/test/{playing_around_in_a_console.txt → rails/playing_around_in_a_console.txt} +0 -0
  113. data/test/{schema.rb → rails/schema.rb} +14 -0
  114. data/test/{test.swf → rails/test.swf} +0 -0
  115. data/test/rails/test_active_foo.rb +81 -0
  116. data/test/{test_ruboss_rails_integration_functional.rb → rails/test_ruboss_rails_integration_functional.rb} +4 -9
  117. data/test/{to_fxml_test.rb → rails/test_to_fxml.rb} +35 -37
  118. data/test/rails/test_to_json.rb +23 -0
  119. data/test/{views → rails/views}/notes/empty_params_action.html.erb +0 -0
  120. data/test/{views → rails/views}/notes/index.html.erb +0 -0
  121. metadata +138 -103
  122. data/Generators +0 -5
  123. data/README.txt +0 -37
  124. data/config/hoe.rb +0 -72
  125. data/config/requirements.rb +0 -15
  126. data/lib/ruboss4ruby/generated_attribute.rb +0 -61
  127. data/lib/ruboss4ruby/ruboss_test_helpers.rb +0 -31
  128. data/lib/ruboss4ruby/version.rb +0 -11
  129. data/merb_generators/ruboss_config.rb +0 -105
  130. data/merb_generators/ruboss_controller.rb +0 -61
  131. data/merb_generators/ruboss_flex_app.rb +0 -69
  132. data/merb_generators/ruboss_resource_controller.rb +0 -4
  133. data/merb_generators/ruboss_scaffold.rb +0 -158
  134. data/merb_generators/templates/ruboss_config/ruboss.yml +0 -16
  135. data/merb_generators/templates/ruboss_resource_controller/controller.rb.erb +0 -49
  136. data/script/console +0 -10
  137. data/script/destroy +0 -14
  138. data/script/generate +0 -14
  139. data/script/txt2html +0 -82
  140. data/setup.rb +0 -1585
  141. data/tasks/deployment.rake +0 -34
  142. data/tasks/environment.rake +0 -7
  143. data/tasks/website.rake +0 -17
  144. data/test/helpers/controllers.log +0 -8
  145. data/test/helpers/models.log +0 -170
  146. data/test/helpers/test_helper.rb +0 -25
  147. data/test/helpers/unit_test_helper.rb +0 -23
  148. data/test/test.sqlite3 +0 -0
  149. data/test/test_active_foo.rb +0 -79
  150. data/test/test_swfobject_helper.rb +0 -63
  151. data/website/index.html +0 -63
  152. data/website/index.txt +0 -34
  153. data/website/javascripts/rounded_corners_lite.inc.js +0 -285
  154. data/website/stylesheets/screen.css +0 -138
  155. data/website/template.html.erb +0 -47
@@ -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,129 +18,140 @@ 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
 
10
- class ClassyEmptyArray < Array
11
- def initialize(class_name)
12
- @class_name = class_name
13
- end
14
- def to_fxml(*args) # You need the *args so that it doesn't fail if there are :include or :methods params
15
- empty? ? "<#{@class_name} type=\"array\"/>" : super.to_fxml
16
- end
17
- end
18
-
21
+ # ActiveSupport specific patches. More specifically we add +to_fxml+ methods to Array and
22
+ # Hash conversion modules
19
23
  module ActiveSupport
24
+ # refer to: http://api.rubyonrails.org/ for more details
20
25
  module CoreExtensions
26
+ # Add Flex friendly +to_fxml+ to Hash conversions
21
27
  module Hash
28
+ # refer to: http://api.rubyonrails.org/ for more details
22
29
  module Conversions
30
+
31
+ # Flex friendly XML format, no dashes, etc
23
32
  def to_fxml(options = {})
24
33
  options.merge!(:dasherize => false)
25
- to_xml(options)
34
+ options[:indent] ||= 2
35
+ options.reverse_merge!({ :builder => Builder::XmlMarkup.new(:indent => options[:indent]),
36
+ :root => "hash" })
37
+ options[:builder].instruct! unless options.delete(:skip_instruct)
38
+ dasherize = !options.has_key?(:dasherize) || options[:dasherize]
39
+ root = dasherize ? options[:root].to_s.dasherize : options[:root].to_s
40
+
41
+ options[:builder].__send__(:method_missing, root) do
42
+ each do |key, value|
43
+ case value
44
+ when ::Hash
45
+ value.to_fxml(options.merge({ :root => key, :skip_instruct => true }))
46
+ when ::Array
47
+ value.to_fxml(options.merge({ :root => key, :children => key.to_s.singularize, :skip_instruct => true}))
48
+ when ::Method, ::Proc
49
+ # If the Method or Proc takes two arguments, then
50
+ # pass the suggested child element name. This is
51
+ # used if the Method or Proc will be operating over
52
+ # multiple records and needs to create an containing
53
+ # element that will contain the objects being
54
+ # serialized.
55
+ if 1 == value.arity
56
+ value.call(options.merge({ :root => key, :skip_instruct => true }))
57
+ else
58
+ value.call(options.merge({ :root => key, :skip_instruct => true }), key.to_s.singularize)
59
+ end
60
+ else
61
+ if value.respond_to?(:to_fxml)
62
+ value.to_fxml(options.merge({ :root => key, :skip_instruct => true }))
63
+ else
64
+ type_name = XML_TYPE_NAMES[value.class.name]
65
+
66
+ key = dasherize ? key.to_s.dasherize : key.to_s
67
+
68
+ attributes = options[:skip_types] || value.nil? || type_name.nil? ? { } : { :type => type_name }
69
+ if value.nil?
70
+ attributes[:nil] = true
71
+ end
72
+
73
+ options[:builder].tag!(key,
74
+ XML_FORMATTING[type_name] ? XML_FORMATTING[type_name].call(value) : value,
75
+ attributes
76
+ )
77
+ end
78
+ end
79
+ end
80
+
81
+ yield options[:builder] if block_given?
82
+ end
26
83
  end
27
84
  end
28
85
  end
86
+ # Add Flex friendly to_fxml to array conversions
29
87
  module Array
88
+ # refer to: http://api.rubyonrails.org/ for more details
30
89
  module Conversions
90
+ # Flex friendly XML format (no dashes, etc)
31
91
  def to_fxml(options = {})
32
- options.merge!(:dasherize => false)
33
- to_xml(options)
34
- end
35
- end
36
- end
37
- end
38
- end
92
+ raise "Not all elements respond to to_fxml" unless all? { |e| e.respond_to? :to_fxml }
39
93
 
40
- module ActiveRecord
41
- # Flex friendly XML serialization patches
42
- class Base
43
- class << self
44
- alias_method :old_find, :find unless method_defined?(:old_find)
94
+ options[:root] ||= all? { |e| e.is_a?(first.class) && first.class.to_s != "Hash" } ? first.class.to_s.underscore.pluralize : "records"
95
+ options[:children] ||= options[:root].singularize
96
+ options[:indent] ||= 2
97
+ options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent])
98
+ options.merge!(:dasherize => false)
45
99
 
46
- def find(*args)
47
- result = old_find(*args)
48
- if result.class == Array and result.empty?
49
- result = ClassyEmptyArray.new(self.class_name.tableize)
50
- end
51
- result
52
- end
100
+ root = options.delete(:root).to_s
101
+ children = options.delete(:children)
53
102
 
54
- # TODO: this doesn't work with hash based to_fxml(:include) options, only array based
55
- def default_fxml_methods(*args)
56
- methods = *args.dup
57
- module_eval <<-END
58
- def self.default_fxml_methods_array
59
- return [#{methods.inspect}].flatten
60
- end
61
- END
62
- end
63
-
64
- def default_fxml_includes(*args)
65
- includes = *args.dup
66
- module_eval <<-END
67
- def self.default_fxml_include_params
68
- return [#{includes.inspect}].flatten
103
+ if !options.has_key?(:dasherize) || options[:dasherize]
104
+ root = root.dasherize
69
105
  end
70
- END
71
- end
72
-
73
- def default_fxml_hash(already_included = [])
74
- # return {} unless self.class.respond_to?(:default_fxml_include_params) || self.class.respond_to?(:default_fxml_methods_array)
75
- default_hash = {:include => {}}
76
- default_hash[:methods] = self.default_fxml_methods_array if self.respond_to?(:default_fxml_methods_array)
77
- if self.respond_to?(:default_fxml_include_params)
78
- default_includes = self.default_fxml_include_params
79
- default_hash[:include] = default_includes.inject({}) do |include_hash, included|
80
- next if already_included.include?(included) # We only want to include things once, to avoid infinite loops
81
- included_class = included.to_s.singularize.camelize.constantize
82
- include_hash[included] = included_class.default_fxml_hash(already_included + default_includes)
83
- include_hash
106
+
107
+ options[:builder].instruct! unless options.delete(:skip_instruct)
108
+
109
+ opts = options.merge({ :root => children })
110
+
111
+ xml = options[:builder]
112
+ if empty?
113
+ xml.tag!(root, options[:skip_types] ? {} : {:type => "array"})
114
+ else
115
+ xml.tag!(root, options[:skip_types] ? {} : {:type => "array"}) {
116
+ yield xml if block_given?
117
+ each { |e| e.to_fxml(opts.merge!({ :skip_instruct => true })) }
118
+ }
84
119
  end
85
120
  end
86
- default_hash
87
- end
88
-
89
- # options[:include] can be a Hash, Array, Symbol or nil.
90
- # We always want it as a Hash. This translates includes to a Hash like this:
91
- # If it's a nil, return an empty Hash ({})
92
- # If it's a Hash, then it is just returned
93
- # If it's an array, then it returns a Hash with each array element as a key, and values of empty Hashes.
94
- # 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.
95
- def includes_as_hash(includes = nil)
96
- res = case
97
- when includes.is_a?(Hash)
98
- includes
99
- when includes.nil?
100
- {}
101
- else #Deal with arrays and symbols
102
- res = [includes].flatten.inject({}) {|include_hash, included| include_hash[included] = {} ; include_hash}
103
121
  end
104
- res
105
- end
106
-
107
122
  end
108
123
  end
124
+ end
109
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+.
129
+ module ActiveRecord
130
+ # refer to: http://api.rubyonrails.org/ for more details
110
131
  module Serialization
111
- def to_fxml(options = {})
132
+ # Enforces Flex friendly options on XML and delegates processing to standard +to_xml+
133
+ def to_fxml(options = {}, &block)
112
134
  options.merge!(:dasherize => false)
113
135
  default_except = [:crypted_password, :salt, :remember_token, :remember_token_expires_at]
114
136
  options[:except] = (options[:except] ? options[:except] + default_except : default_except)
115
- options[:methods] = [options[:methods] || []].flatten + (self.class.default_fxml_hash[:methods] || [])
116
- options[:include] = self.class.default_fxml_hash[:include].merge(self.class.includes_as_hash(options[:include]))
117
- to_xml(options)
137
+ to_xml(options, &block)
118
138
  end
119
-
120
139
  end
121
-
140
+
122
141
  # Change the xml serializer so that '?'s are stripped from attribute names.
123
142
  # This makes it possible to serialize methods that end in a question mark, like 'valid?' or 'is_true?'
124
143
  class XmlSerializer
144
+ # Strips '?' from serialized method names
125
145
  def add_tag(attribute)
126
146
  builder.tag!(
127
147
  dasherize? ? attribute.display_name.dasherize : attribute.display_name,
128
148
  attribute.value.to_s,
129
149
  attribute.decorations(!options[:skip_types])
130
150
  )
131
- end
151
+ end
152
+ # Strips '?' from serialized method names
132
153
  class Attribute
154
+ # Strips '?' from serialized method names
133
155
  def display_name
134
156
  @name.gsub('?','')
135
157
  end
@@ -139,6 +161,7 @@ module ActiveRecord
139
161
  # Add more extensive reporting on errors including field name along with a message
140
162
  # when errors are serialized to XML
141
163
  class Errors
164
+ # Flex friendly errors
142
165
  def to_fxml(options={})
143
166
  options[:root] ||= "errors"
144
167
  options[:indent] ||= 2
@@ -0,0 +1,66 @@
1
+ module ActiveRecord
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
15
+ class Base
16
+ class << self
17
+
18
+ # default methods hook
19
+ def default_methods(*args)
20
+ methods = *args.dup
21
+ module_eval <<-END
22
+ def self.default_methods_array
23
+ return [#{methods.inspect}].flatten
24
+ end
25
+ END
26
+ end
27
+
28
+ # default methods hook
29
+ def defaults_hash(already_included = [], ignore_default_methods = nil)
30
+ defaults_hash = {:include => {}}
31
+ unless ignore_default_methods
32
+ defaults_hash[:methods] = self.default_methods_array if self.respond_to?(:default_methods_array)
33
+ end
34
+ defaults_hash
35
+ end
36
+ end
37
+ end
38
+
39
+ # Flex-friendly serialization patches
40
+ module Serialization
41
+
42
+ alias_method :xml_defaults_old_to_xml, :to_xml unless method_defined?(:xml_defaults_old_to_xml)
43
+
44
+ alias_method :json_defaults_old_to_json, :to_json unless method_defined?(:json_defaults_old_to_json)
45
+
46
+ # adds support for default_methods to standard +to_xml+
47
+ def to_xml(options = {}, &block)
48
+ unless options[:ignore_defaults]
49
+ unless options[:ignore_default_methods]
50
+ options[:methods] = [options[:methods] || []].flatten + (self.class.defaults_hash[:methods] || [])
51
+ end
52
+ end
53
+ xml_defaults_old_to_xml(options, &block)
54
+ end
55
+
56
+ # adds support for default_methods to standard +to_json+
57
+ def to_json(options = {}, &block)
58
+ unless options[:ignore_defaults]
59
+ unless options[:ignore_default_methods]
60
+ options[:methods] = [options[:methods] || []].flatten + (self.class.defaults_hash[:methods] || [])
61
+ end
62
+ end
63
+ json_defaults_old_to_json(options, &block)
64
+ end
65
+ end
66
+ end
@@ -1,7 +1,10 @@
1
- require 'ruboss4ruby/tasks'
2
-
3
- # these tasks are active record specific
1
+ # ActiveRecord specific Rake tasks. Namely, nice little extras such as:
2
+ # - db:mysql:stage
3
+ # - db:refresh
4
+ require File.join(File.dirname(__FILE__), 'tasks')
4
5
 
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,60 +1,74 @@
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
2
- def capitalize_without_downcasing
5
+ # Upper-case first character of a string leave the rest of the string intact
6
+ def ucfirst
3
7
  self[0,1].capitalize + self[1..-1]
4
8
  end
5
9
 
6
- def downcase_first_letter
10
+ # Down-case first character of a string leaving the rest of it intact
11
+ def dcfirst
7
12
  self[0,1].downcase + self[1..-1]
8
13
  end
9
-
10
- def camelcase(first_letter = :upper)
11
- case first_letter
12
- when :upper then self.camelize(true)
13
- when :lower then self.camelize(false)
14
- end
15
- end
16
-
17
- def camelize(first_letter_in_uppercase = true)
18
- if first_letter_in_uppercase
19
- self.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
20
- else
21
- self[0,1].downcase + self.camelize[1..-1]
22
- end
23
- end
24
-
25
- def underscore
26
- self.gsub(/::/, '/').
27
- gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
28
- gsub(/([a-z\d])([A-Z])/,'\1_\2').
29
- tr("-", "_").
30
- downcase
31
- end
32
14
  end
33
15
 
34
- module Ruboss
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.
35
19
  module Configuration
36
- APP_ROOT = defined?(RAILS_ROOT) ? RAILS_ROOT : Merb.root
37
-
38
- def extract_names
39
- project_name = APP_ROOT.split("/").last.camelcase
40
- project_name_downcase = project_name.downcase
20
+ APP_ROOT = defined?(RAILS_ROOT) ? RAILS_ROOT : defined?(Merb) ? Merb.root : File.expand_path(".")
41
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
43
+ def extract_names(project = nil)
44
+ if project
45
+ project_name = project.camelcase.gsub(/\s/, '')
46
+ project_name_downcase = project_name.downcase
47
+ else
48
+ project_name = APP_ROOT.split("/").last.camelcase.gsub(/\s/, '')
49
+ project_name_downcase = project_name.downcase
50
+ end
51
+
52
+ # give a chance to override the settings via ruboss.yml
42
53
  begin
43
54
  config = YAML.load(File.open("#{APP_ROOT}/config/ruboss.yml"))
44
55
  base_package = config['base-package'] || project_name_downcase
45
- base_folder = base_package.gsub('.', '/')
46
- controller_name = config['controller-name'] || "#{project_name}Controller"
56
+ base_folder = base_package.gsub('.', '/').gsub(/\s/, '')
57
+ project_name = config['project-name'].camelcase.gsub(/\s/, '') || project_name
58
+ controller_name = config['controller-name'] || "ApplicationController"
47
59
  rescue
48
60
  base_folder = base_package = project_name_downcase
49
- controller_name = "#{project_name}Controller"
61
+ controller_name = "ApplicationController"
50
62
  end
51
63
  [project_name, project_name_downcase, controller_name, base_package, base_folder]
52
64
  end
53
65
 
66
+ # List files ending in *.as (ActionScript) in a given folder
54
67
  def list_as_files(dir_name)
55
68
  Dir.entries(dir_name).grep(/\.as$/).map { |name| name.sub(/\.as$/, "") }.join(", ")
56
69
  end
57
70
 
71
+ # List files ending in *.mxml in a given folder
58
72
  def list_mxml_files(dir_name)
59
73
  Dir.entries(dir_name).grep(/\.mxml$/).map { |name| name.sub(/\.mxml$/, "") }
60
74
  end
@@ -0,0 +1,31 @@
1
+ require 'builder'
2
+ require Ruboss4Ruby::LIB_DIR + 'configuration'
3
+
4
+ # Flex friendly DataMapper patches, more specifically we just add +to_xml+ on
5
+ # ValidationErrors class
6
+ module DataMapper
7
+ # see DataMapper docs for more details
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.
11
+ class ValidationErrors
12
+ # Add Flex-friendly +to_xml+ implementation
13
+ def to_xml
14
+ xml = Builder::XmlMarkup.new(:indent => 2)
15
+ xml.instruct! :xml, :version => "1.0", :encoding => "UTF-8"
16
+ xml.errors do |e|
17
+ @errors.each_key do |attribute|
18
+ @errors[attribute].each do |msg|
19
+ next if msg.nil?
20
+ if attribute == "base"
21
+ e.error("message" => msg)
22
+ else
23
+ e.error("field" => attribute.to_s.camelcase(:lower), "message" => msg)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,10 +1,11 @@
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/recipes'
4
+ #
5
+ # require 'ruboss4ruby/rails/recipes'
6
+ require 'find'
5
7
 
6
8
  Capistrano::Configuration.instance(:must_exist).load do
7
-
8
9
  after "deploy:setup", "deploy:flex:setup"
9
10
 
10
11
  namespace :db do
@@ -15,7 +16,6 @@ Capistrano::Configuration.instance(:must_exist).load do
15
16
  end
16
17
 
17
18
  namespace :deploy do
18
-
19
19
  namespace :flex do
20
20
 
21
21
  desc "Creates the flex_files directory in the shared directory"
@@ -28,7 +28,7 @@ Capistrano::Configuration.instance(:must_exist).load do
28
28
  task :via_dumb_copy, :roles => :app do
29
29
  # the -p flag on mkdir makes intermediate directories (i.e. both /bin and /bin/history),
30
30
  # and doesn't raise an error if any of the directories already exist.
31
- rails_root = File.join(File.dirname(__FILE__), '..', '..', '..', '..')
31
+ rails_root = Dir.pwd # You have to run cap tasks from RAILS_ROOT anyways
32
32
  base_dir = File.join(rails_root, 'public', 'bin')
33
33
  ec2_base_dir = File.join(shared_path, 'flex_files')
34
34
 
@@ -46,7 +46,7 @@ Capistrano::Configuration.instance(:must_exist).load do
46
46
  desc "synchronizes the local and remote public/bin directories using rsync"
47
47
  task :via_rsync, :roles => :app do
48
48
  username = user || ENV['USER']
49
- rails_root = File.join(File.dirname(__FILE__), '..', '..', '..', '..')
49
+ rails_root = Dir.pwd # You have to run cap tasks from RAILS_ROOT anyways
50
50
  execute_on_servers do |server|
51
51
  `rsync -r -p -v -e \"ssh -i #{ssh_options[:keys]}\" #{File.join(rails_root, 'public', 'bin')}/ #{username}@#{server}:#{File.join(shared_path, 'flex_files')}/`
52
52
  end
@@ -55,8 +55,6 @@ Capistrano::Configuration.instance(:must_exist).load do
55
55
  task :make_symlink, :roles => :app do
56
56
  run "ln -s #{shared_path}/flex_files #{release_path}/public/bin"
57
57
  end
58
-
59
58
  end
60
59
  end
61
-
62
60
  end
@@ -1,4 +1,5 @@
1
- module RubossHelper
1
+ # Adds a little helper to make it easier empbedding SWFs in ERB templates.
2
+ module SWFHelper
2
3
 
3
4
  # Creates a swfObject Javascript call. You must include swfobject.js to use this.
4
5
  # See http://code.google.com/p/swfobject/wiki/documentation for full details and documentation
@@ -13,28 +14,33 @@ module RubossHelper
13
14
  :params => nil,
14
15
  :attributes => nil,
15
16
  :create_div => false,
16
- :include_authenticity_token => true
17
+ :include_authenticity_token => true,
18
+ :include_session_token => true
17
19
  })
18
20
  arg_order = [:id, :width, :height, :version, :express_install_swf]
19
21
  js_params = ["'#{swf_url}?#{rails_asset_id(swf_url)}'"]
20
22
  js_params += arg_order.collect {|arg| "'#{params[arg]}'" }
21
23
 
22
- # Add authenticity_token to flashVars. This will only work if flashVars is a Hash or nil
23
- # If it's a string representing the name of a Javascript variable, then you need to add it yourself
24
+ # Add authenticity_token and the session key to flashVars. This will only work if flashVars is a Hash or nil
25
+ # If it's a string representing the name of a Javascript variable, then you need to add them yourself
24
26
  # like this:
25
27
  # <script>
26
28
  # ... other code that defines flashVars and sets some of its parameters
27
29
  # flashVars['authenticity_token'] = <%= form_authenticity_token -%>
30
+ # flashVars['session_token'] = <%= session.session_id -%>
28
31
  # </script>
29
32
  # If you include an authenticity_token parameter in flashVars,
30
33
  # then the Flex app will add it to Ruboss.defaultMetadata, so that it will be sent
31
34
  # back up to your Rails app with every request.
32
- if params[:include_authenticity_token] && ActionController::Base.allow_forgery_protection
33
- params[:flash_vars] = {} if params[:flash_vars].nil?
34
- if params[:flash_vars].is_a?(Hash)
35
+ params[:flash_vars] ||= {}
36
+ if params[:flash_vars].is_a?(Hash)
37
+ if params[:include_authenticity_token] && ActionController::Base.allow_forgery_protection
35
38
  params[:flash_vars].reverse_merge!(:authenticity_token => form_authenticity_token)
36
39
  end
37
- end
40
+ if params[:include_session_token]
41
+ params[:flash_vars].reverse_merge!(:session_token => session.session_id)
42
+ end
43
+ end
38
44
 
39
45
  js_params += [params[:flash_vars], params[:params], params[:attributes]].collect do |hash_or_string|
40
46
  if hash_or_string.is_a?(Hash)
@@ -1,11 +1,14 @@
1
+ # Rake tasks for building Ruboss-based Flex and AIR applications
1
2
  require 'rake'
2
3
  require 'ftools'
3
4
  require 'rexml/document'
4
- require 'ruboss4ruby/configuration'
5
+ require File.join(File.dirname(__FILE__), 'configuration')
5
6
 
6
- APP_ROOT = Ruboss::Configuration::APP_ROOT
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|
@@ -14,10 +17,10 @@ namespace :ruboss do
14
17
  target_project_path = project_path.sub(/.mxml$/, '.swf')
15
18
  target_project_air_descriptor = project_path.sub(/.mxml$/, '-app.xml')
16
19
 
17
- libs = Dir.glob(File.join(APP_ROOT, 'lib', '*.swc'))
20
+ libs = Dir.glob(File.join(APP_ROOT, 'lib', '*.swc')).map {|lib| lib.gsub(' ', '\ ')}
18
21
 
19
22
  cmd = "#{executable} #{opts} -library-path+=#{libs.join(',')} " <<
20
- "-keep-as3-metadata+=Resource,HasOne,HasMany,BelongsTo,DateTime,Lazy,Ignored #{project_path}"
23
+ "-keep-as3-metadata+=Resource,HasOne,HasMany,BelongsTo,DateTime,Lazy,Ignored #{project_path.gsub(' ', '\ ')}"
21
24
  puts "Compiling #{project_path}"
22
25
  if system(cmd)
23
26
  FileUtils.makedirs File.join(APP_ROOT, destination)
@@ -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'