spree 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of spree might be problematic. Click here for more details.

Files changed (182) hide show
  1. data/CHANGELOG +35 -0
  2. data/CONTRIBUTORS +2 -1
  3. data/README.markdown +8 -52
  4. data/app/controllers/account_controller.rb +1 -1
  5. data/app/controllers/addresses_controller.rb +5 -1
  6. data/app/controllers/admin/inventory_settings_controller.rb +13 -0
  7. data/app/controllers/admin/option_types_controller.rb +1 -1
  8. data/app/controllers/admin/orders_controller.rb +14 -8
  9. data/app/controllers/admin/products_controller.rb +2 -0
  10. data/app/controllers/admin/variants_controller.rb +7 -0
  11. data/app/controllers/content_controller.rb +5 -0
  12. data/app/controllers/creditcard_payments_controller.rb +2 -2
  13. data/app/controllers/orders_controller.rb +18 -2
  14. data/app/helpers/admin/inventory_settings_helper.rb +5 -0
  15. data/app/helpers/admin/product_properties_helper.rb +10 -2
  16. data/app/helpers/products_helper.rb +2 -2
  17. data/app/models/address.rb +2 -2
  18. data/app/models/app_configuration.rb +1 -0
  19. data/app/models/creditcard_payment.rb +6 -14
  20. data/app/models/order.rb +6 -12
  21. data/app/models/order_filter.rb +1 -0
  22. data/app/models/product.rb +9 -0
  23. data/app/models/product_property.rb +1 -0
  24. data/app/models/property.rb +0 -1
  25. data/app/models/zone.rb +17 -3
  26. data/app/views/account/login.html.erb +2 -14
  27. data/app/views/admin/configurations/index.html.erb +4 -0
  28. data/app/views/admin/inventory_settings/edit.html.erb +18 -0
  29. data/app/views/admin/inventory_settings/show.html.erb +11 -0
  30. data/app/views/admin/orders/_address.html.erb +1 -1
  31. data/app/views/admin/orders/index.html.erb +5 -1
  32. data/app/views/admin/orders/show.html.erb +3 -3
  33. data/app/views/admin/product_properties/_product_property.html.erb +6 -3
  34. data/app/views/admin/products/_form.html.erb +9 -1
  35. data/app/views/admin/prototypes/select.rjs +3 -1
  36. data/app/views/admin/variants/_form.html.erb +6 -0
  37. data/app/views/admin/variants/index.html.erb +7 -1
  38. data/app/views/creditcard_payments/_form_credit_card.html.erb +1 -1
  39. data/app/views/creditcard_payments/new.html.erb +7 -2
  40. data/app/views/products/show.html.erb +8 -2
  41. data/app/views/shared/_login.html.erb +17 -0
  42. data/app/views/shared/_products.html.erb +1 -1
  43. data/app/views/users/_form.html.erb +1 -1
  44. data/app/views/users/new.html.erb +19 -8
  45. data/config/boot.rb +1 -1
  46. data/config/database.yml +7 -3
  47. data/config/environment.rb +16 -2
  48. data/config/routes.rb +4 -0
  49. data/db/migrate/20081016002224_remove_defunct_order_fields.rb +10 -0
  50. data/db/migrate/20081016162924_drop_category_id_from_products.rb +9 -0
  51. data/db/sample/addresses.yml +14 -0
  52. data/db/sample/orders.yml +0 -1
  53. data/lang/ui/de-DE.yml +2 -1
  54. data/lang/ui/en-US.yml +50 -25
  55. data/lang/ui/es-ES.yml +2 -1
  56. data/lang/ui/it-IT.yml +2 -1
  57. data/lang/ui/pl-PL.yml +1 -0
  58. data/lang/ui/pt-BR.yml +5 -2
  59. data/lib/authenticated_system.rb +1 -1
  60. data/lib/generators/extension/extension_generator.rb +1 -0
  61. data/lib/generators/extension/templates/extension.rb +4 -5
  62. data/lib/generators/extension/templates/tasks.rake +12 -0
  63. data/lib/generators/extension_migration/extension_migration_generator.rb +32 -0
  64. data/lib/generators/extension_migration/templates/migration.rb +7 -0
  65. data/lib/spree.rb +2 -2
  66. data/lib/spree/extension.rb +0 -7
  67. data/lib/spree/extension_loader.rb +0 -8
  68. data/lib/tasks/extensions.rake +47 -0
  69. data/public/javascripts/application.js +34 -0
  70. data/public/javascripts/spree-yui.js +2 -2
  71. data/public/stylesheets/spree.css +11 -1
  72. data/spec/fixtures/preferences.yml +14 -6
  73. data/spec/models/address_spec.rb +78 -0
  74. data/spec/models/country_spec.rb +29 -0
  75. data/spec/models/option_type_spec.rb +36 -0
  76. data/spec/models/option_value_spec.rb +39 -0
  77. data/spec/models/product_option_type_spec.rb +38 -0
  78. data/spec/models/product_property_spec.rb +36 -0
  79. data/spec/models/product_spec.rb +109 -32
  80. data/spec/models/property_spec.rb +38 -0
  81. data/spec/models/prototype_spec.rb +35 -0
  82. data/spec/models/state_spec.rb +28 -0
  83. data/spec/models/taxon_spec.rb +38 -0
  84. data/spec/models/taxonomy_spec.rb +37 -0
  85. data/spec/models/variant_spec.rb +73 -12
  86. data/spec/models/zone_spec.rb +35 -15
  87. data/spec/spec_helper.rb +15 -0
  88. data/spec/views/admin/configurations/index.html.erb_spec.rb +29 -0
  89. data/spec/views/admin/mail_settings/show.html.erb_spec.rb +3 -3
  90. data/spec/views/products/index.html.erb_spec.rb +46 -0
  91. data/spec/views/products/show.html.erb_spec.rb +46 -0
  92. data/vendor/extensions/flat_rate_shipping/README.markdown +3 -0
  93. data/vendor/extensions/flat_rate_shipping/Rakefile +120 -0
  94. data/vendor/extensions/flat_rate_shipping/flat_rate_shipping_extension.rb +17 -0
  95. data/vendor/extensions/flat_rate_shipping/lib/flat_rate_shipping_configuration.rb +7 -0
  96. data/vendor/extensions/flat_rate_shipping/lib/spree/flat_rate_shipping/calculator.rb +9 -0
  97. data/vendor/extensions/flat_rate_shipping/lib/spree/flat_rate_shipping/config.rb +22 -0
  98. data/vendor/extensions/flat_rate_shipping/lib/tasks/flat_rate_shipping_extension_tasks.rake +29 -0
  99. data/vendor/extensions/flat_rate_shipping/spec/spec.opts +6 -0
  100. data/vendor/extensions/flat_rate_shipping/spec/spec_helper.rb +37 -0
  101. data/vendor/extensions/localization/localization_extension.rb +1 -6
  102. data/vendor/extensions/payment_gateway/lib/gateway_config.rb +7 -0
  103. data/vendor/extensions/payment_gateway/lib/spree/gateway/config.rb +22 -0
  104. data/vendor/extensions/payment_gateway/lib/spree/payment_gateway.rb +27 -3
  105. data/vendor/extensions/payment_gateway/payment_gateway_extension.rb +0 -4
  106. data/vendor/extensions/shipping/README.markdown +3 -0
  107. data/vendor/extensions/shipping/Rakefile +120 -0
  108. data/vendor/extensions/shipping/app/controllers/admin/shipping_categories_controller.rb +17 -0
  109. data/vendor/extensions/shipping/app/controllers/admin/shipping_methods_controller.rb +21 -0
  110. data/vendor/extensions/shipping/app/controllers/shipments_controller.rb +84 -0
  111. data/vendor/extensions/shipping/app/helpers/admin/shipping_categories_helper.rb +2 -0
  112. data/vendor/extensions/shipping/app/helpers/admin/shipping_methods_helper.rb +2 -0
  113. data/vendor/extensions/shipping/app/helpers/shipments_helper.rb +20 -0
  114. data/vendor/extensions/shipping/app/models/shipment.rb +11 -0
  115. data/vendor/extensions/shipping/app/models/shipping_category.rb +3 -0
  116. data/vendor/extensions/shipping/app/models/shipping_method.rb +12 -0
  117. data/vendor/extensions/shipping/app/views/admin/shipping_categories/_form.html.erb +6 -0
  118. data/vendor/extensions/shipping/app/views/admin/shipping_categories/edit.html.erb +8 -0
  119. data/vendor/extensions/shipping/app/views/admin/shipping_categories/index.html.erb +24 -0
  120. data/vendor/extensions/shipping/app/views/admin/shipping_categories/new.html.erb +10 -0
  121. data/vendor/extensions/shipping/app/views/admin/shipping_methods/_form.html.erb +14 -0
  122. data/vendor/extensions/shipping/app/views/admin/shipping_methods/edit.html.erb +8 -0
  123. data/vendor/extensions/shipping/app/views/admin/shipping_methods/index.html.erb +28 -0
  124. data/vendor/extensions/shipping/app/views/admin/shipping_methods/new.html.erb +10 -0
  125. data/vendor/extensions/shipping/app/views/orders/fatal_shipping.html.erb +6 -0
  126. data/vendor/extensions/shipping/app/views/shipments/_form.html.erb +46 -0
  127. data/vendor/extensions/shipping/app/views/shipments/edit.html.erb +8 -0
  128. data/vendor/extensions/shipping/app/views/shipments/new.html.erb +8 -0
  129. data/vendor/extensions/shipping/db/migrate/20081003211336_create_shipping_methods.rb +14 -0
  130. data/vendor/extensions/shipping/db/migrate/20081003233427_create_shipping_categories.rb +15 -0
  131. data/vendor/extensions/shipping/db/migrate/20081015001711_create_shipments.rb +14 -0
  132. data/vendor/extensions/shipping/db/migrate/20081023134446_add_product_dimensions.rb +19 -0
  133. data/vendor/extensions/shipping/db/sample/shipping_categories.yml +2 -0
  134. data/vendor/extensions/shipping/db/sample/shipping_methods.yml +12 -0
  135. data/vendor/extensions/shipping/db/sample/zone_members.yml +8 -0
  136. data/vendor/extensions/shipping/db/sample/zones.yml +3 -0
  137. data/vendor/extensions/shipping/lang/en-US.yml +9 -0
  138. data/vendor/extensions/shipping/lib/spree/shipping_calculator.rb +37 -0
  139. data/vendor/extensions/shipping/lib/spree/shipping_error.rb +3 -0
  140. data/vendor/extensions/shipping/lib/tasks/shipping_extension_tasks.rake +29 -0
  141. data/vendor/extensions/shipping/shipping_extension.rb +39 -0
  142. data/vendor/extensions/shipping/spec/controllers/admin/shipping_categories_controller_spec.rb +10 -0
  143. data/vendor/extensions/shipping/spec/controllers/admin/shipping_methods_controller_spec.rb +10 -0
  144. data/vendor/extensions/shipping/spec/models/order_spec.rb +98 -0
  145. data/vendor/extensions/shipping/spec/models/shipment_spec.rb +26 -0
  146. data/vendor/extensions/shipping/spec/models/shipping_category_spec.rb +8 -0
  147. data/vendor/extensions/shipping/spec/models/shipping_method_spec.rb +53 -0
  148. data/vendor/extensions/shipping/spec/spec.opts +6 -0
  149. data/vendor/extensions/shipping/spec/spec_helper.rb +37 -0
  150. data/vendor/extensions/tax_calculator/lib/spree/sales_tax_calculator.rb +12 -4
  151. data/vendor/extensions/tax_calculator/spec/controllers/tax_calculator_spec.rb +0 -4
  152. data/vendor/extensions/tax_calculator/spec/models/sales_tax_calculator_spec.rb +14 -14
  153. data/vendor/extensions/tax_calculator/tax_calculator_extension.rb +0 -4
  154. data/vendor/plugins/resource_controller/README.rdoc +38 -6
  155. data/vendor/plugins/resource_controller/Rakefile +7 -20
  156. data/vendor/plugins/resource_controller/TODO +0 -1
  157. data/vendor/plugins/resource_controller/lib/resource_controller/helpers/current_objects.rb +71 -69
  158. data/vendor/plugins/resource_controller/lib/resource_controller/helpers/internal.rb +69 -65
  159. data/vendor/plugins/resource_controller/lib/resource_controller/helpers/nested.rb +62 -57
  160. data/vendor/plugins/resource_controller/lib/resource_controller/helpers/singleton_customizations.rb +50 -46
  161. data/vendor/plugins/resource_controller/lib/resource_controller/helpers/urls.rb +73 -69
  162. data/vendor/plugins/resource_controller/resource_controller.gemspec +4 -3
  163. data/vendor/plugins/resource_controller/test/app/controllers/cms/personnel_controller.rb +2 -0
  164. data/vendor/plugins/resource_controller/test/app/controllers/cms/photos_controller.rb +6 -0
  165. data/vendor/plugins/resource_controller/test/app/models/personnel.rb +3 -0
  166. data/vendor/plugins/resource_controller/test/app/models/photo.rb +1 -0
  167. data/vendor/plugins/resource_controller/test/app/views/cms/photos/edit.rhtml +17 -0
  168. data/vendor/plugins/resource_controller/test/app/views/cms/photos/index.rhtml +20 -0
  169. data/vendor/plugins/resource_controller/test/app/views/cms/photos/new.rhtml +16 -0
  170. data/vendor/plugins/resource_controller/test/app/views/cms/photos/show.rhtml +8 -0
  171. data/vendor/plugins/resource_controller/test/config/database.yml +9 -0
  172. data/vendor/plugins/resource_controller/test/config/environment.rb +1 -18
  173. data/vendor/plugins/resource_controller/test/config/initializers/inflections.rb +14 -0
  174. data/vendor/plugins/resource_controller/test/config/routes.rb +3 -0
  175. data/vendor/plugins/resource_controller/test/db/migrate/013_create_personnel.rb +11 -0
  176. data/vendor/plugins/resource_controller/test/db/migrate/014_add_personnel_id_to_photos.rb +9 -0
  177. data/vendor/plugins/resource_controller/test/test/fixtures/personnel.yml +5 -0
  178. data/vendor/plugins/resource_controller/test/test/functional/cms/photos_controller_test.rb +43 -0
  179. metadata +136 -6
  180. data/app/models/spree/extension_meta.rb +0 -5
  181. data/app/models/variants.rb +0 -2
  182. data/vendor/plugins/resource_controller/lib/resource_controller/version.rb +0 -9
@@ -1,26 +1,13 @@
1
- require 'rake'
2
- require 'rake/testtask'
3
- require 'rake/rdoctask'
4
- require File.dirname(__FILE__)+'/lib/resource_controller/version'
5
- Dir['tasks/**.rake'].each { |tasks| load tasks }
6
-
7
- desc 'Default: run unit tests.'
8
- task :default => :test
9
-
10
- desc 'Test the ResourceController plugin.'
11
- Rake::TestTask.new(:test) do |t|
12
- t.libs << 'lib'
13
- t.pattern = 'test/test/**/*_test.rb'
14
- t.verbose = true
15
- end
1
+ Dir.chdir('test')
2
+ load 'Rakefile'
16
3
 
17
4
  desc 'Generate documentation for the ResourceController plugin.'
18
5
  Rake::RDocTask.new(:rdoc) do |rdoc|
19
- rdoc.rdoc_dir = 'rdoc'
6
+ rdoc.rdoc_dir = '../rdoc'
20
7
  rdoc.title = 'ResourceController'
21
8
  rdoc.options << '--line-numbers' << '--inline-source'
22
- rdoc.rdoc_files.include('README.rdoc')
23
- rdoc.rdoc_files.include('lib/**/*.rb')
9
+ rdoc.rdoc_files.include('../README.rdoc')
10
+ rdoc.rdoc_files.include('../lib/**/*.rb')
24
11
  end
25
12
 
26
13
  task :upload_docs => :rdoc do
@@ -28,8 +15,8 @@ task :upload_docs => :rdoc do
28
15
  `ssh jamesgolick.com 'rm -Rf /home/apps/jamesgolick.com/public/resource_controller/rdoc'`
29
16
 
30
17
  puts "Uploading current rdoc"
31
- `scp -r rdoc jamesgolick.com:/home/apps/jamesgolick.com/public/resource_controller`
18
+ `scp -r ../rdoc jamesgolick.com:/home/apps/jamesgolick.com/public/resource_controller`
32
19
 
33
20
  puts "Deleting rdoc"
34
- `rm -Rf rdoc`
21
+ `rm -Rf ../rdoc`
35
22
  end
@@ -1 +0,0 @@
1
- Add helper methods for deep_nesting.
@@ -1,79 +1,81 @@
1
- module ResourceController::Helpers::CurrentObjects
2
- protected
3
- # Used internally to return the model for your resource.
4
- #
5
- def model
6
- model_name.to_s.camelize.constantize
7
- end
1
+ module ResourceController
2
+ module Helpers
3
+ module CurrentObjects
4
+ protected
5
+ # Used internally to return the model for your resource.
6
+ #
7
+ def model
8
+ model_name.to_s.camelize.constantize
9
+ end
8
10
 
9
11
 
10
- # Used to fetch the collection for the index method
11
- #
12
- # In order to customize the way the collection is fetched, to add something like pagination, for example, override this method.
13
- #
14
- def collection
15
- end_of_association_chain.find(:all)
16
- end
12
+ # Used to fetch the collection for the index method
13
+ #
14
+ # In order to customize the way the collection is fetched, to add something like pagination, for example, override this method.
15
+ #
16
+ def collection
17
+ end_of_association_chain.find(:all)
18
+ end
17
19
 
18
- # Returns the current param.
19
- #
20
- # Defaults to params[:id].
21
- #
22
- # Override this method if you'd like to use an alternate param name.
23
- #
24
- def param
25
- params[:id]
26
- end
20
+ # Returns the current param.
21
+ #
22
+ # Defaults to params[:id].
23
+ #
24
+ # Override this method if you'd like to use an alternate param name.
25
+ #
26
+ def param
27
+ params[:id]
28
+ end
27
29
 
28
- # Used to fetch the current member object in all of the singular methods that operate on an existing member.
29
- #
30
- # Override this method if you'd like to fetch your objects in some alternate way, like using a permalink.
31
- #
32
- # class PostsController < ResourceController::Base
33
- # private
34
- # def object
35
- # @object ||= end_of_association_chain.find_by_permalink(param)
36
- # end
37
- # end
38
- #
39
- def object
40
- return @object if param.blank?
41
- if param.is_integer?
42
- @object ||= end_of_association_chain.find(param) unless param.nil?
43
- else
44
- # hack by sean to allow permalink objects
45
- @object = end_of_association_chain.find_by_param!(param)
46
- end
47
- @object
48
- =begin
49
- @object ||= end_of_association_chain.find(param) unless param.nil?
50
- @object
51
- =end
52
- end
30
+ # Used to fetch the current member object in all of the singular methods that operate on an existing member.
31
+ #
32
+ # Override this method if you'd like to fetch your objects in some alternate way, like using a permalink.
33
+ #
34
+ # class PostsController < ResourceController::Base
35
+ # private
36
+ # def object
37
+ # @object ||= end_of_association_chain.find_by_permalink(param)
38
+ # end
39
+ # end
40
+ #
41
+ def object
42
+ return @object if param.blank?
43
+ if param.is_integer?
44
+ @object ||= end_of_association_chain.find(param) unless param.nil?
45
+ else
46
+ # hack by sean to allow permalink objects
47
+ @object = end_of_association_chain.find_by_param!(param)
48
+ end
49
+ @object
50
+ #@object ||= end_of_association_chain.find(param) unless param.nil?
51
+ #@object
52
+ end
53
53
 
54
- # Used internally to load the member object in to an instance variable @#{model_name} (i.e. @post)
55
- #
56
- def load_object
57
- instance_variable_set "@#{parent_type}", parent_object if parent?
58
- instance_variable_set "@#{object_name}", object
59
- end
54
+ # Used internally to load the member object in to an instance variable @#{model_name} (i.e. @post)
55
+ #
56
+ def load_object
57
+ instance_variable_set "@#{parent_type}", parent_object if parent?
58
+ instance_variable_set "@#{object_name}", object
59
+ end
60
60
 
61
- # Used internally to load the collection in to an instance variable @#{model_name.pluralize} (i.e. @posts)
62
- #
63
- def load_collection
64
- instance_variable_set "@#{parent_type}", parent_object if parent?
65
- instance_variable_set "@#{object_name.to_s.pluralize}", collection
66
- end
61
+ # Used internally to load the collection in to an instance variable @#{model_name.pluralize} (i.e. @posts)
62
+ #
63
+ def load_collection
64
+ instance_variable_set "@#{parent_type}", parent_object if parent?
65
+ instance_variable_set "@#{object_name.to_s.pluralize}", collection
66
+ end
67
67
 
68
- # Returns the form params. Defaults to params[model_name] (i.e. params["post"])
69
- #
70
- def object_params
71
- params["#{object_name}"]
72
- end
68
+ # Returns the form params. Defaults to params[model_name] (i.e. params["post"])
69
+ #
70
+ def object_params
71
+ params["#{object_name}"]
72
+ end
73
73
 
74
- # Builds the object, but doesn't save it, during the new, and create action.
75
- #
76
- def build_object
77
- @object ||= end_of_association_chain.send parent? ? :build : :new, object_params
74
+ # Builds the object, but doesn't save it, during the new, and create action.
75
+ #
76
+ def build_object
77
+ @object ||= end_of_association_chain.send parent? ? :build : :new, object_params
78
+ end
78
79
  end
80
+ end
79
81
  end
@@ -2,75 +2,79 @@
2
2
  #
3
3
  # All of these methods are used internally to execute the options, set by the user in ActionOptions and FailableActionOptions
4
4
  #
5
- module ResourceController::Helpers::Internal
6
- protected
7
- # Used to actually pass the responses along to the controller's respond_to method.
8
- #
9
- def response_for(action)
10
- respond_to do |wants|
11
- options_for(action).response.each do |method, block|
12
- if block.nil?
13
- wants.send(method)
14
- else
15
- wants.send(method) { instance_eval(&block) }
5
+ module ResourceController
6
+ module Helpers
7
+ module Internal
8
+ protected
9
+ # Used to actually pass the responses along to the controller's respond_to method.
10
+ #
11
+ def response_for(action)
12
+ respond_to do |wants|
13
+ options_for(action).response.each do |method, block|
14
+ if block.nil?
15
+ wants.send(method)
16
+ else
17
+ wants.send(method) { instance_eval(&block) }
18
+ end
19
+ end
16
20
  end
17
21
  end
18
- end
19
- end
22
+
23
+ # Calls the after callbacks for the action, if one is present.
24
+ #
25
+ def after(action)
26
+ invoke_callbacks *options_for(action).after
27
+ end
28
+
29
+ # Calls the before block for the action, if one is present.
30
+ #
31
+ def before(action)
32
+ invoke_callbacks *self.class.send(action).before
33
+ end
20
34
 
21
- # Calls the after callbacks for the action, if one is present.
22
- #
23
- def after(action)
24
- invoke_callbacks *options_for(action).after
25
- end
35
+ # Sets the flash and flash_now for the action, if it is present.
36
+ #
37
+ def set_flash(action)
38
+ set_normal_flash(action)
39
+ set_flash_now(action)
40
+ end
26
41
 
27
- # Calls the before block for the action, if one is present.
28
- #
29
- def before(action)
30
- invoke_callbacks *self.class.send(action).before
31
- end
32
-
33
- # Sets the flash and flash_now for the action, if it is present.
34
- #
35
- def set_flash(action)
36
- set_normal_flash(action)
37
- set_flash_now(action)
38
- end
39
-
40
- # Sets the regular flash (i.e. flash[:notice] = '...')
41
- #
42
- def set_normal_flash(action)
43
- if f = options_for(action).flash
44
- flash[:notice] = f.is_a?(Proc) ? instance_eval(&f) : options_for(action).flash
45
- end
46
- end
47
-
48
- # Sets the flash.now (i.e. flash.now[:notice] = '...')
49
- #
50
- def set_flash_now(action)
51
- if f = options_for(action).flash_now
52
- flash.now[:notice] = f.is_a?(Proc) ? instance_eval(&f) : options_for(action).flash_now
53
- end
54
- end
55
-
56
- # Returns the options for an action, which is a symbol.
57
- #
58
- # Manages splitting things like :create_fails.
59
- #
60
- def options_for(action)
61
- action = action == :new_action ? [action] : "#{action}".split('_').map(&:to_sym)
62
- options = self.class.send(action.first)
63
- options = options.send(action.last == :fails ? :fails : :success) if ResourceController::FAILABLE_ACTIONS.include? action.first
42
+ # Sets the regular flash (i.e. flash[:notice] = '...')
43
+ #
44
+ def set_normal_flash(action)
45
+ if f = options_for(action).flash
46
+ flash[:notice] = f.is_a?(Proc) ? instance_eval(&f) : options_for(action).flash
47
+ end
48
+ end
49
+
50
+ # Sets the flash.now (i.e. flash.now[:notice] = '...')
51
+ #
52
+ def set_flash_now(action)
53
+ if f = options_for(action).flash_now
54
+ flash.now[:notice] = f.is_a?(Proc) ? instance_eval(&f) : options_for(action).flash_now
55
+ end
56
+ end
57
+
58
+ # Returns the options for an action, which is a symbol.
59
+ #
60
+ # Manages splitting things like :create_fails.
61
+ #
62
+ def options_for(action)
63
+ action = action == :new_action ? [action] : "#{action}".split('_').map(&:to_sym)
64
+ options = self.class.send(action.first)
65
+ options = options.send(action.last == :fails ? :fails : :success) if ResourceController::FAILABLE_ACTIONS.include? action.first
66
+
67
+ options
68
+ end
69
+
70
+ def invoke_callbacks(*callbacks)
71
+ unless callbacks.empty?
72
+ callbacks.select { |callback| callback.is_a? Symbol }.each { |symbol| send(symbol) }
64
73
 
65
- options
74
+ block = callbacks.detect { |callback| callback.is_a? Proc }
75
+ instance_eval &block unless block.nil?
76
+ end
77
+ end
66
78
  end
67
-
68
- def invoke_callbacks(*callbacks)
69
- unless callbacks.empty?
70
- callbacks.select { |callback| callback.is_a? Symbol }.each { |symbol| send(symbol) }
71
-
72
- block = callbacks.detect { |callback| callback.is_a? Proc }
73
- instance_eval &block unless block.nil?
74
- end
75
- end
79
+ end
76
80
  end
@@ -1,69 +1,74 @@
1
1
  # Nested and Polymorphic Resource Helpers
2
2
  #
3
- module ResourceController::Helpers::Nested
4
- protected
5
- # Returns the relevant association proxy of the parent. (i.e. /posts/1/comments # => @post.comments)
6
- #
7
- def parent_association
8
- @parent_association ||= parent_object.send(model_name.to_s.pluralize.to_sym)
9
- end
10
-
11
- # Returns the type of the current parent
12
- #
13
- def parent_type
14
- @parent_type ||= parent_type_from_params || parent_type_from_request
15
- end
3
+ module ResourceController
4
+ module Helpers
5
+ module Nested
6
+ protected
7
+ # Returns the relevant association proxy of the parent. (i.e. /posts/1/comments # => @post.comments)
8
+ #
9
+ def parent_association
10
+ @parent_association ||= parent_object.send(model_name.to_s.pluralize.to_sym)
11
+ end
16
12
 
17
- # Returns the type of the current parent extracted from params
18
- #
19
- def parent_type_from_params
20
- [*belongs_to].find { |parent| !params["#{parent}_id".to_sym].nil? }
21
- end
22
-
23
- # Returns the type of the current parent extracted form a request path
24
- #
25
- def parent_type_from_request
26
- [*belongs_to].find { |parent| request.path.split('/').include? parent.to_s }
27
- end
13
+ # Returns the type of the current parent
14
+ #
15
+ def parent_type
16
+ @parent_type ||= parent_type_from_params || parent_type_from_request
17
+ end
28
18
 
29
- # Returns true/false based on whether or not a parent is present.
30
- #
31
- def parent?
32
- !parent_type.nil?
33
- end
19
+ # Returns the type of the current parent extracted from params
20
+ #
21
+ def parent_type_from_params
22
+ [*belongs_to].find { |parent| !params["#{parent}_id".to_sym].nil? }
23
+ end
34
24
 
35
- # Returns true/false based on whether or not a parent is a singleton.
36
- #
37
- def parent_singleton?
38
- !parent_type_from_request.nil?
39
- end
25
+ # Returns the type of the current parent extracted form a request path
26
+ #
27
+ def parent_type_from_request
28
+ [*belongs_to].find { |parent| request.path.split('/').include? parent.to_s }
29
+ end
40
30
 
41
- # Returns the current parent param, if there is a parent. (i.e. params[:post_id])
42
- def parent_param
43
- params["#{parent_type}_id".to_sym]
44
- end
31
+ # Returns true/false based on whether or not a parent is present.
32
+ #
33
+ def parent?
34
+ !parent_type.nil?
35
+ end
45
36
 
46
- # Like the model method, but for a parent relationship.
47
- #
48
- def parent_model
49
- parent_type.to_s.camelize.constantize
50
- end
37
+ # Returns true/false based on whether or not a parent is a singleton.
38
+ #
39
+ def parent_singleton?
40
+ !parent_type_from_request.nil? && parent_type_from_params.nil?
41
+ end
51
42
 
52
- # Returns the current parent object if a parent object is present.
53
- #
54
- def parent_object
55
- parent? && !parent_singleton? ? parent_model_find(parent_param) : nil
56
- end
43
+ # Returns the current parent param, if there is a parent. (i.e. params[:post_id])
44
+ def parent_param
45
+ params["#{parent_type}_id".to_sym]
46
+ end
57
47
 
58
- # hack by sean to allow permalink parents
59
- def parent_model_find(parent_param)
60
- return parent_model.find(parent_param) if parent_param.is_integer?
61
- parent_model.find_by_param!(parent_param)
62
- end
48
+ # Like the model method, but for a parent relationship.
49
+ #
50
+ def parent_model
51
+ parent_type.to_s.camelize.constantize
52
+ end
63
53
 
64
- # If there is a parent, returns the relevant association proxy. Otherwise returns model.
65
- #
66
- def end_of_association_chain
67
- parent? ? parent_association : model
54
+ # Returns the current parent object if a parent object is present.
55
+ #
56
+ def parent_object
57
+ # hack by sean to allow permalink parents
58
+ parent? && !parent_singleton? ? parent_model_find(parent_param) : nil
59
+ end
60
+
61
+ # hack by sean to allow permalink parents
62
+ def parent_model_find(parent_param)
63
+ return parent_model.find(parent_param) if parent_param.is_integer?
64
+ parent_model.find_by_param!(parent_param)
65
+ end
66
+
67
+ # If there is a parent, returns the relevant association proxy. Otherwise returns model.
68
+ #
69
+ def end_of_association_chain
70
+ parent? ? parent_association : model
71
+ end
68
72
  end
73
+ end
69
74
  end