base_rails_app 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (194) hide show
  1. data/LICENSE +1 -0
  2. data/README +1 -0
  3. data/lib/app/controllers/application_controller.rb +55 -0
  4. data/lib/app/controllers/password_resets_controller.rb +45 -0
  5. data/lib/app/controllers/user_sessions_controller.rb +25 -0
  6. data/lib/app/controllers/users_controller.rb +37 -0
  7. data/lib/app/helpers/application_helper.rb +4 -0
  8. data/lib/app/helpers/user_sessions_helper.rb +2 -0
  9. data/lib/app/helpers/users_helper.rb +2 -0
  10. data/lib/app/models/postman.rb +20 -0
  11. data/lib/app/models/user.rb +12 -0
  12. data/lib/app/models/user_session.rb +2 -0
  13. data/lib/app/views/application/404_not_found.html.erb +8 -0
  14. data/lib/app/views/layouts/application.html.erb +57 -0
  15. data/lib/app/views/password_resets/_sidebar.html.erb +0 -0
  16. data/lib/app/views/password_resets/edit.html.erb +33 -0
  17. data/lib/app/views/password_resets/new.html.erb +26 -0
  18. data/lib/app/views/postman/password_reset_instructions.html.erb +3 -0
  19. data/lib/app/views/postman/welcome_email.html.erb +3 -0
  20. data/lib/app/views/user_sessions/_form.html.erb +19 -0
  21. data/lib/app/views/user_sessions/_sidebar.html.erb +13 -0
  22. data/lib/app/views/user_sessions/new.html.erb +15 -0
  23. data/lib/app/views/users/_form.html.erb +28 -0
  24. data/lib/app/views/users/_sidebar.html.erb +6 -0
  25. data/lib/app/views/users/edit.html.erb +19 -0
  26. data/lib/app/views/users/new.html.erb +15 -0
  27. data/lib/app/views/users/show.html.erb +46 -0
  28. data/lib/base_rails_app.rb +5 -0
  29. data/lib/base_rails_app/boot.rb +2 -0
  30. data/lib/base_rails_app/tasks.rb +12 -0
  31. data/lib/config/configatron/cucumber.rb +0 -0
  32. data/lib/config/configatron/defaults.rb +4 -0
  33. data/lib/config/configatron/development.rb +1 -0
  34. data/lib/config/configatron/production.rb +0 -0
  35. data/lib/config/configatron/test.rb +0 -0
  36. data/lib/config/database.yml +25 -0
  37. data/lib/config/deploy.rb +15 -0
  38. data/lib/config/environments/cucumber.rb +22 -0
  39. data/lib/config/environments/development.rb +17 -0
  40. data/lib/config/environments/production.rb +28 -0
  41. data/lib/config/environments/test.rb +28 -0
  42. data/lib/config/gemtronics.rb +36 -0
  43. data/lib/config/initializers/backtrace_silencers.rb +7 -0
  44. data/lib/config/initializers/configatron.rb +1 -0
  45. data/lib/config/initializers/hoptoad.rb +3 -0
  46. data/lib/config/initializers/inflections.rb +10 -0
  47. data/lib/config/initializers/mailers.rb +1 -0
  48. data/lib/config/initializers/mime_types.rb +5 -0
  49. data/lib/config/initializers/new_rails_defaults.rb +21 -0
  50. data/lib/config/initializers/session_store.rb +17 -0
  51. data/lib/config/locales/en.yml +5 -0
  52. data/lib/config/routes.rb +51 -0
  53. data/lib/config/schedule.rb +20 -0
  54. data/lib/db/migrate/20090809175903_create_users.rb +30 -0
  55. data/lib/db/migrate/20090809204840_acts_as_taggable_on_migration.rb +29 -0
  56. data/lib/db/migrate/20090912171353_create_delayed_jobs.rb +20 -0
  57. data/lib/db/migrate/20090912171829_add_delayed_job_extras.rb +11 -0
  58. data/lib/db/migrate/20090929201455_add_more_time_columns_to_dj.rb +11 -0
  59. data/lib/db/schema.rb +72 -0
  60. data/lib/db/seeds.rb +7 -0
  61. data/lib/lib/tasks/cucumber.rake +36 -0
  62. data/lib/lib/tasks/rcov.rake +27 -0
  63. data/lib/lib/tasks/rspec.rake +183 -0
  64. data/lib/vendor/plugins/delayed_job/generators/delayed_job/delayed_job_generator.rb +22 -0
  65. data/lib/vendor/plugins/delayed_job/generators/delayed_job/templates/migration.rb +20 -0
  66. data/lib/vendor/plugins/delayed_job/init.rb +2 -0
  67. data/lib/vendor/plugins/delayed_job/lib/delayed/command.rb +65 -0
  68. data/lib/vendor/plugins/delayed_job/lib/delayed/job.rb +271 -0
  69. data/lib/vendor/plugins/delayed_job/lib/delayed/message_sending.rb +18 -0
  70. data/lib/vendor/plugins/delayed_job/lib/delayed/performable_method.rb +55 -0
  71. data/lib/vendor/plugins/delayed_job/lib/delayed/tasks.rb +15 -0
  72. data/lib/vendor/plugins/delayed_job/lib/delayed/worker.rb +54 -0
  73. data/lib/vendor/plugins/delayed_job/lib/delayed_job.rb +13 -0
  74. data/lib/vendor/plugins/delayed_job/recipes/delayed_job.rb +26 -0
  75. data/lib/vendor/plugins/delayed_job/tasks/jobs.rake +1 -0
  76. data/lib/vendor/plugins/hoptoad_notifier/install.rb +1 -0
  77. data/lib/vendor/plugins/hoptoad_notifier/lib/hoptoad_notifier.rb +418 -0
  78. data/lib/vendor/plugins/hoptoad_notifier/lib/hoptoad_tasks.rb +26 -0
  79. data/lib/vendor/plugins/hoptoad_notifier/recipes/hoptoad.rb +22 -0
  80. data/lib/vendor/plugins/hoptoad_notifier/tasks/hoptoad_notifier_tasks.rake +66 -0
  81. data/lib/vendor/plugins/inherited_resources/README.rdoc +524 -0
  82. data/lib/vendor/plugins/inherited_resources/inherited_resources.gemspec +71 -0
  83. data/lib/vendor/plugins/inherited_resources/init.rb +1 -0
  84. data/lib/vendor/plugins/inherited_resources/lib/inherited_resources.rb +23 -0
  85. data/lib/vendor/plugins/inherited_resources/lib/inherited_resources/actions.rb +79 -0
  86. data/lib/vendor/plugins/inherited_resources/lib/inherited_resources/base.rb +42 -0
  87. data/lib/vendor/plugins/inherited_resources/lib/inherited_resources/base_helpers.rb +363 -0
  88. data/lib/vendor/plugins/inherited_resources/lib/inherited_resources/belongs_to_helpers.rb +89 -0
  89. data/lib/vendor/plugins/inherited_resources/lib/inherited_resources/class_methods.rb +338 -0
  90. data/lib/vendor/plugins/inherited_resources/lib/inherited_resources/dsl.rb +26 -0
  91. data/lib/vendor/plugins/inherited_resources/lib/inherited_resources/dumb_responder.rb +20 -0
  92. data/lib/vendor/plugins/inherited_resources/lib/inherited_resources/has_scope_helpers.rb +83 -0
  93. data/lib/vendor/plugins/inherited_resources/lib/inherited_resources/legacy/respond_to.rb +156 -0
  94. data/lib/vendor/plugins/inherited_resources/lib/inherited_resources/legacy/responder.rb +200 -0
  95. data/lib/vendor/plugins/inherited_resources/lib/inherited_resources/polymorphic_helpers.rb +155 -0
  96. data/lib/vendor/plugins/inherited_resources/lib/inherited_resources/singleton_helpers.rb +95 -0
  97. data/lib/vendor/plugins/inherited_resources/lib/inherited_resources/url_helpers.rb +179 -0
  98. data/lib/vendor/plugins/inherited_resources/test/aliases_test.rb +139 -0
  99. data/lib/vendor/plugins/inherited_resources/test/association_chain_test.rb +125 -0
  100. data/lib/vendor/plugins/inherited_resources/test/base_test.rb +225 -0
  101. data/lib/vendor/plugins/inherited_resources/test/belongs_to_test.rb +87 -0
  102. data/lib/vendor/plugins/inherited_resources/test/class_methods_test.rb +138 -0
  103. data/lib/vendor/plugins/inherited_resources/test/customized_base_test.rb +162 -0
  104. data/lib/vendor/plugins/inherited_resources/test/customized_belongs_to_test.rb +76 -0
  105. data/lib/vendor/plugins/inherited_resources/test/defaults_test.rb +70 -0
  106. data/lib/vendor/plugins/inherited_resources/test/flash_test.rb +88 -0
  107. data/lib/vendor/plugins/inherited_resources/test/has_scope_test.rb +139 -0
  108. data/lib/vendor/plugins/inherited_resources/test/locales/en.yml +17 -0
  109. data/lib/vendor/plugins/inherited_resources/test/nested_belongs_to_test.rb +108 -0
  110. data/lib/vendor/plugins/inherited_resources/test/optional_belongs_to_test.rb +164 -0
  111. data/lib/vendor/plugins/inherited_resources/test/polymorphic_test.rb +186 -0
  112. data/lib/vendor/plugins/inherited_resources/test/redirect_to_test.rb +51 -0
  113. data/lib/vendor/plugins/inherited_resources/test/respond_to_test.rb +155 -0
  114. data/lib/vendor/plugins/inherited_resources/test/singleton_test.rb +83 -0
  115. data/lib/vendor/plugins/inherited_resources/test/test_helper.rb +38 -0
  116. data/lib/vendor/plugins/inherited_resources/test/url_helpers_test.rb +537 -0
  117. data/lib/vendor/plugins/inherited_resources/test/views/cars/edit.html.erb +1 -0
  118. data/lib/vendor/plugins/inherited_resources/test/views/cars/index.html.erb +1 -0
  119. data/lib/vendor/plugins/inherited_resources/test/views/cars/new.html.erb +1 -0
  120. data/lib/vendor/plugins/inherited_resources/test/views/cars/show.html.erb +1 -0
  121. data/lib/vendor/plugins/inherited_resources/test/views/cities/edit.html.erb +1 -0
  122. data/lib/vendor/plugins/inherited_resources/test/views/cities/index.html.erb +1 -0
  123. data/lib/vendor/plugins/inherited_resources/test/views/cities/new.html.erb +1 -0
  124. data/lib/vendor/plugins/inherited_resources/test/views/cities/show.html.erb +1 -0
  125. data/lib/vendor/plugins/inherited_resources/test/views/comments/edit.html.erb +1 -0
  126. data/lib/vendor/plugins/inherited_resources/test/views/comments/index.html.erb +1 -0
  127. data/lib/vendor/plugins/inherited_resources/test/views/comments/new.html.erb +1 -0
  128. data/lib/vendor/plugins/inherited_resources/test/views/comments/show.html.erb +1 -0
  129. data/lib/vendor/plugins/inherited_resources/test/views/employees/edit.html.erb +1 -0
  130. data/lib/vendor/plugins/inherited_resources/test/views/employees/index.html.erb +1 -0
  131. data/lib/vendor/plugins/inherited_resources/test/views/employees/new.html.erb +1 -0
  132. data/lib/vendor/plugins/inherited_resources/test/views/employees/show.html.erb +1 -0
  133. data/lib/vendor/plugins/inherited_resources/test/views/managers/edit.html.erb +1 -0
  134. data/lib/vendor/plugins/inherited_resources/test/views/managers/new.html.erb +1 -0
  135. data/lib/vendor/plugins/inherited_resources/test/views/managers/show.html.erb +1 -0
  136. data/lib/vendor/plugins/inherited_resources/test/views/painters/edit.html.erb +1 -0
  137. data/lib/vendor/plugins/inherited_resources/test/views/painters/index.html.erb +1 -0
  138. data/lib/vendor/plugins/inherited_resources/test/views/painters/new.html.erb +1 -0
  139. data/lib/vendor/plugins/inherited_resources/test/views/painters/show.html.erb +1 -0
  140. data/lib/vendor/plugins/inherited_resources/test/views/pets/edit.html.erb +1 -0
  141. data/lib/vendor/plugins/inherited_resources/test/views/pets/index.html.erb +1 -0
  142. data/lib/vendor/plugins/inherited_resources/test/views/pets/new.html.erb +1 -0
  143. data/lib/vendor/plugins/inherited_resources/test/views/pets/show.html.erb +1 -0
  144. data/lib/vendor/plugins/inherited_resources/test/views/products/edit.html.erb +1 -0
  145. data/lib/vendor/plugins/inherited_resources/test/views/products/index.html.erb +1 -0
  146. data/lib/vendor/plugins/inherited_resources/test/views/products/new.html.erb +1 -0
  147. data/lib/vendor/plugins/inherited_resources/test/views/products/show.html.erb +1 -0
  148. data/lib/vendor/plugins/inherited_resources/test/views/professors/edit.html.erb +1 -0
  149. data/lib/vendor/plugins/inherited_resources/test/views/professors/index.html.erb +1 -0
  150. data/lib/vendor/plugins/inherited_resources/test/views/professors/new.html.erb +1 -0
  151. data/lib/vendor/plugins/inherited_resources/test/views/professors/show.html.erb +1 -0
  152. data/lib/vendor/plugins/inherited_resources/test/views/projects/index.html.erb +1 -0
  153. data/lib/vendor/plugins/inherited_resources/test/views/projects/index.json.erb +1 -0
  154. data/lib/vendor/plugins/inherited_resources/test/views/projects/respond_to_skip_default_template.html.erb +1 -0
  155. data/lib/vendor/plugins/inherited_resources/test/views/projects/respond_with_resource.html.erb +1 -0
  156. data/lib/vendor/plugins/inherited_resources/test/views/students/edit.html.erb +1 -0
  157. data/lib/vendor/plugins/inherited_resources/test/views/students/new.html.erb +1 -0
  158. data/lib/vendor/plugins/inherited_resources/test/views/trees/edit.html.erb +1 -0
  159. data/lib/vendor/plugins/inherited_resources/test/views/trees/index.html.erb +1 -0
  160. data/lib/vendor/plugins/inherited_resources/test/views/trees/new.html.erb +1 -0
  161. data/lib/vendor/plugins/inherited_resources/test/views/trees/show.html.erb +1 -0
  162. data/lib/vendor/plugins/inherited_resources/test/views/users/edit.html.erb +1 -0
  163. data/lib/vendor/plugins/inherited_resources/test/views/users/index.html.erb +1 -0
  164. data/lib/vendor/plugins/inherited_resources/test/views/users/new.html.erb +1 -0
  165. data/lib/vendor/plugins/inherited_resources/test/views/users/show.html.erb +1 -0
  166. data/lib/vendor/plugins/web-app-theme/README.md +22 -0
  167. data/lib/vendor/plugins/web-app-theme/images/avatar.png +0 -0
  168. data/lib/vendor/plugins/web-app-theme/index.html +473 -0
  169. data/lib/vendor/plugins/web-app-theme/javascripts/jquery-1.3.min.js +19 -0
  170. data/lib/vendor/plugins/web-app-theme/javascripts/jquery.localscroll.js +104 -0
  171. data/lib/vendor/plugins/web-app-theme/javascripts/jquery.scrollTo.js +150 -0
  172. data/lib/vendor/plugins/web-app-theme/rails_generators/theme/templates/view_layout_administration.html.erb +48 -0
  173. data/lib/vendor/plugins/web-app-theme/rails_generators/theme/templates/view_layout_sign.html.erb +15 -0
  174. data/lib/vendor/plugins/web-app-theme/rails_generators/theme/theme_generator.rb +38 -0
  175. data/lib/vendor/plugins/web-app-theme/rails_generators/themed/templates/view_edit.html.erb +20 -0
  176. data/lib/vendor/plugins/web-app-theme/rails_generators/themed/templates/view_form.html.erb +10 -0
  177. data/lib/vendor/plugins/web-app-theme/rails_generators/themed/templates/view_new.html.erb +19 -0
  178. data/lib/vendor/plugins/web-app-theme/rails_generators/themed/templates/view_show.html.erb +23 -0
  179. data/lib/vendor/plugins/web-app-theme/rails_generators/themed/templates/view_sidebar.html.erb +13 -0
  180. data/lib/vendor/plugins/web-app-theme/rails_generators/themed/templates/view_signin.html.erb +39 -0
  181. data/lib/vendor/plugins/web-app-theme/rails_generators/themed/templates/view_signup.html.erb +56 -0
  182. data/lib/vendor/plugins/web-app-theme/rails_generators/themed/templates/view_tables.html.erb +50 -0
  183. data/lib/vendor/plugins/web-app-theme/rails_generators/themed/themed_generator.rb +89 -0
  184. data/lib/vendor/plugins/web-app-theme/stylesheets/base.css +336 -0
  185. data/lib/vendor/plugins/web-app-theme/stylesheets/themes/bec-green/style.css +290 -0
  186. data/lib/vendor/plugins/web-app-theme/stylesheets/themes/bec/style.css +301 -0
  187. data/lib/vendor/plugins/web-app-theme/stylesheets/themes/blue/style.css +280 -0
  188. data/lib/vendor/plugins/web-app-theme/stylesheets/themes/default/style.css +267 -0
  189. data/lib/vendor/plugins/web-app-theme/stylesheets/themes/djime-cerulean/style.css +298 -0
  190. data/lib/vendor/plugins/web-app-theme/stylesheets/themes/drastic-dark/style.css +373 -0
  191. data/lib/vendor/plugins/web-app-theme/stylesheets/themes/kathleene/style.css +272 -0
  192. data/lib/vendor/plugins/web-app-theme/stylesheets/themes/orange/style.css +263 -0
  193. data/lib/vendor/plugins/web-app-theme/stylesheets/themes/reidb-greenish/style.css +301 -0
  194. metadata +257 -0
@@ -0,0 +1,71 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{inherited_resources}
5
+ s.version = "0.9.2"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Jos\303\251 Valim"]
9
+ s.date = %q{2009-09-30}
10
+ s.description = %q{Inherited Resources speeds up development by making your controllers inherit all restful actions so you just have to focus on what is important.}
11
+ s.email = %q{jose.valim@gmail.com}
12
+ s.extra_rdoc_files = [
13
+ "README.rdoc"
14
+ ]
15
+ s.files = [
16
+ "CHANGELOG",
17
+ "MIT-LICENSE",
18
+ "README.rdoc",
19
+ "Rakefile",
20
+ "lib/inherited_resources.rb",
21
+ "lib/inherited_resources/actions.rb",
22
+ "lib/inherited_resources/base.rb",
23
+ "lib/inherited_resources/base_helpers.rb",
24
+ "lib/inherited_resources/belongs_to_helpers.rb",
25
+ "lib/inherited_resources/class_methods.rb",
26
+ "lib/inherited_resources/dsl.rb",
27
+ "lib/inherited_resources/dumb_responder.rb",
28
+ "lib/inherited_resources/has_scope_helpers.rb",
29
+ "lib/inherited_resources/legacy/respond_to.rb",
30
+ "lib/inherited_resources/legacy/responder.rb",
31
+ "lib/inherited_resources/polymorphic_helpers.rb",
32
+ "lib/inherited_resources/singleton_helpers.rb",
33
+ "lib/inherited_resources/url_helpers.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/josevalim/inherited_resources}
36
+ s.rdoc_options = ["--charset=UTF-8"]
37
+ s.require_paths = ["lib"]
38
+ s.rubyforge_project = %q{inherited_resources}
39
+ s.rubygems_version = %q{1.3.5}
40
+ s.summary = %q{Inherited Resources speeds up development by making your controllers inherit all restful actions so you just have to focus on what is important.}
41
+ s.test_files = [
42
+ "test/respond_to_test.rb",
43
+ "test/customized_belongs_to_test.rb",
44
+ "test/nested_belongs_to_test.rb",
45
+ "test/base_test.rb",
46
+ "test/redirect_to_test.rb",
47
+ "test/has_scope_test.rb",
48
+ "test/class_methods_test.rb",
49
+ "test/association_chain_test.rb",
50
+ "test/aliases_test.rb",
51
+ "test/flash_test.rb",
52
+ "test/url_helpers_test.rb",
53
+ "test/belongs_to_test.rb",
54
+ "test/customized_base_test.rb",
55
+ "test/polymorphic_test.rb",
56
+ "test/defaults_test.rb",
57
+ "test/singleton_test.rb",
58
+ "test/optional_belongs_to_test.rb",
59
+ "test/test_helper.rb"
60
+ ]
61
+
62
+ if s.respond_to? :specification_version then
63
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
64
+ s.specification_version = 3
65
+
66
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
67
+ else
68
+ end
69
+ else
70
+ end
71
+ end
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), 'lib', 'inherited_resources')
@@ -0,0 +1,23 @@
1
+ # respond_to is the only file that should be loaded before hand. All others
2
+ # are loaded on demand.
3
+ #
4
+ unless defined?(ActionController::Responder)
5
+ require File.join(File.dirname(__FILE__), 'inherited_resources', 'legacy', 'responder')
6
+ require File.join(File.dirname(__FILE__), 'inherited_resources', 'legacy', 'respond_to')
7
+ end
8
+
9
+ module InheritedResources
10
+ ACTIONS = [ :index, :show, :new, :edit, :create, :update, :destroy ] unless self.const_defined?(:ACTIONS)
11
+ end
12
+
13
+ class ActionController::Base
14
+ # If you cannot inherit from InheritedResources::Base you can call
15
+ # inherit_resource in your controller to have all the required modules and
16
+ # funcionality included.
17
+ #
18
+ def self.inherit_resources
19
+ InheritedResources::Base.inherit_resources(self)
20
+ initialize_resources_class_accessors!
21
+ create_resources_url_helpers!
22
+ end
23
+ end
@@ -0,0 +1,79 @@
1
+ module InheritedResources
2
+ # Holds all default actions for InheritedResouces.
3
+ module Actions
4
+
5
+ # GET /resources
6
+ def index(&block)
7
+ respond_with(collection, &block)
8
+ end
9
+ alias :index! :index
10
+
11
+ # GET /resources/1
12
+ def show(&block)
13
+ respond_with(resource, &block)
14
+ end
15
+ alias :show! :show
16
+
17
+ # GET /resources/new
18
+ def new(&block)
19
+ respond_with(build_resource, &block)
20
+ end
21
+ alias :new! :new
22
+
23
+ # GET /resources/1/edit
24
+ def edit(&block)
25
+ respond_with(resource, &block)
26
+ end
27
+ alias :edit! :edit
28
+
29
+ # POST /resources
30
+ def create(options={}, &block)
31
+ object = build_resource
32
+
33
+ if create_resource(object)
34
+ set_flash_message!(:notice, '{{resource_name}} was successfully created.')
35
+ options[:location] ||= resource_url rescue nil
36
+ respond_with_dual_blocks(object, options, true, block)
37
+ else
38
+ set_flash_message!(:error)
39
+ respond_with_dual_blocks(object, options, false, block)
40
+ end
41
+ end
42
+ alias :create! :create
43
+
44
+ # PUT /resources/1
45
+ def update(options={}, &block)
46
+ object = resource
47
+
48
+ if update_resource(object, params[resource_instance_name])
49
+ set_flash_message!(:notice, '{{resource_name}} was successfully updated.')
50
+ options[:location] ||= resource_url rescue nil
51
+ respond_with_dual_blocks(object, options, true, block)
52
+ else
53
+ set_flash_message!(:error)
54
+ respond_with_dual_blocks(object, options, false, block)
55
+ end
56
+ end
57
+ alias :update! :update
58
+
59
+ # DELETE /resources/1
60
+ def destroy(options={}, &block)
61
+ object = resource
62
+
63
+ if destroy_resource(object)
64
+ set_flash_message!(:notice, '{{resource_name}} was successfully destroyed.')
65
+ else
66
+ set_flash_message!(:error, '{{resource_name}} could not be destroyed.')
67
+ end
68
+
69
+ options[:location] ||= collection_url rescue nil
70
+ respond_with_dual_blocks(object, options, nil, block)
71
+ end
72
+ alias :destroy! :destroy
73
+
74
+ # Make aliases protected
75
+ protected :index!, :show!, :new!, :create!, :edit!, :update!, :destroy!
76
+
77
+ end
78
+ end
79
+
@@ -0,0 +1,42 @@
1
+ module InheritedResources
2
+ # = Base
3
+ #
4
+ # This is the base class that holds all actions. If you see the code for each
5
+ # action, they are quite similar to Rails default scaffold.
6
+ #
7
+ # To change your base behavior, you can overwrite your actions and call super,
8
+ # call <tt>default</tt> class method, call <<tt>actions</tt> class method
9
+ # or overwrite some helpers in the base_helpers.rb file.
10
+ #
11
+ class Base < ::ApplicationController
12
+ unloadable
13
+
14
+ # Overwrite inherit_resources to add specific InheritedResources behavior.
15
+ #
16
+ def self.inherit_resources(base)
17
+ base.class_eval do
18
+ include InheritedResources::Actions
19
+ include InheritedResources::BaseHelpers
20
+ extend InheritedResources::ClassMethods
21
+ extend InheritedResources::UrlHelpers
22
+
23
+ # Add at least :html mime type
24
+ respond_to :html
25
+
26
+ helper_method :collection_url, :collection_path, :resource_url, :resource_path,
27
+ :new_resource_url, :new_resource_path, :edit_resource_url, :edit_resource_path,
28
+ :parent_url, :parent_path, :resource, :collection, :resource_class, :association_chain
29
+
30
+ base.with_options :instance_writer => false do |c|
31
+ c.class_inheritable_accessor :resource_class
32
+ c.class_inheritable_array :parents_symbols
33
+ c.class_inheritable_hash :resources_configuration, :scopes_configuration
34
+ end
35
+
36
+ protected :resource_class, :parents_symbols, :resources_configuration, :scopes_configuration
37
+ end
38
+ end
39
+
40
+ inherit_resources(self)
41
+ end
42
+ end
@@ -0,0 +1,363 @@
1
+ # Whenever base is required load the dumb responder since it's used inside actions.
2
+ require File.dirname(__FILE__) + '/dumb_responder.rb'
3
+
4
+ module InheritedResources
5
+ # Base helpers for InheritedResource work. Some methods here can be overwriten
6
+ # and you will need to do that to customize your controllers from time to time.
7
+ #
8
+ module BaseHelpers
9
+
10
+ protected
11
+
12
+ # This is how the collection is loaded.
13
+ #
14
+ # You might want to overwrite this method if you want to add pagination
15
+ # for example. When you do that, don't forget to cache the result in an
16
+ # instance_variable:
17
+ #
18
+ # def collection
19
+ # @projects ||= end_of_association_chain.paginate(params[:page]).all
20
+ # end
21
+ #
22
+ def collection
23
+ get_collection_ivar || set_collection_ivar(end_of_association_chain.find(:all))
24
+ end
25
+
26
+ # This is how the resource is loaded.
27
+ #
28
+ # You might want to overwrite this method when you are using permalink.
29
+ # When you do that, don't forget to cache the result in an
30
+ # instance_variable:
31
+ #
32
+ # def resource
33
+ # @project ||= end_of_association_chain.find_by_permalink!(params[:id])
34
+ # end
35
+ #
36
+ # You also might want to add the exclamation mark at the end of the method
37
+ # because it will raise a 404 if nothing can be found. Otherwise it will
38
+ # probably render a 500 error message.
39
+ #
40
+ def resource
41
+ get_resource_ivar || set_resource_ivar(end_of_association_chain.find(params[:id]))
42
+ end
43
+
44
+ # This method is responsable for building the object on :new and :create
45
+ # methods. If you overwrite it, don't forget to cache the result in an
46
+ # instance variable.
47
+ #
48
+ def build_resource
49
+ get_resource_ivar || set_resource_ivar(end_of_association_chain.send(method_for_build, params[resource_instance_name] || {}))
50
+ end
51
+
52
+ # Responsible for saving the resource on :create method. Overwriting this
53
+ # allow you to control the way resource is saved. Let's say you have a
54
+ # PassworsController who is responsible for finding an user by email and
55
+ # sent password instructions for him. Instead of overwriting the entire
56
+ # :create method, you could do something:
57
+ #
58
+ # def create_resource(object)
59
+ # object.send_instructions_by_email
60
+ # end
61
+ #
62
+ def create_resource(object)
63
+ object.save
64
+ end
65
+
66
+ # Responsible for updating the resource in :update method. This allow you
67
+ # to handle how the resource is gona be updated, let's say in a different
68
+ # way then the usual :update_attributes:
69
+ #
70
+ # def update_resource(object, attributes)
71
+ # object.reset_password!(attributes)
72
+ # end
73
+ #
74
+ def update_resource(object, attributes)
75
+ object.update_attributes(attributes)
76
+ end
77
+
78
+ # Handle the :destroy method for the resource. Overwrite it to call your
79
+ # own method for destroing the resource, as:
80
+ #
81
+ # def destroy_resource(object)
82
+ # object.cancel
83
+ # end
84
+ #
85
+ def destroy_resource(object)
86
+ object.destroy
87
+ end
88
+
89
+ # This class allows you to set a instance variable to begin your
90
+ # association chain. For example, usually your projects belongs to users
91
+ # and that means that they belong to the current logged in user. So you
92
+ # could do this:
93
+ #
94
+ # def begin_of_association_chain
95
+ # @current_user
96
+ # end
97
+ #
98
+ # So every time we instantiate a project, we will do:
99
+ #
100
+ # @current_user.projects.build(params[:project])
101
+ # @current_user.projects.find(params[:id])
102
+ #
103
+ # The variable set in begin_of_association_chain is not sent when building
104
+ # urls, so this is never going to happen when calling resource_url:
105
+ #
106
+ # project_url(@current_user, @project)
107
+ #
108
+ # If the user actually scopes the url, you should use belongs_to method
109
+ # and declare that projects belong to user.
110
+ #
111
+ def begin_of_association_chain
112
+ nil
113
+ end
114
+
115
+ # Returns if the controller has a parent. When only base helpers are loaded,
116
+ # it's always false and should not be overwriten.
117
+ #
118
+ def parent?
119
+ false
120
+ end
121
+
122
+ # Returns the association chain, with all parents (does not include the
123
+ # current resource).
124
+ #
125
+ def association_chain
126
+ @association_chain ||=
127
+ symbols_for_association_chain.inject([begin_of_association_chain]) do |chain, symbol|
128
+ chain << evaluate_parent(symbol, resources_configuration[symbol], chain.last)
129
+ end.compact.freeze
130
+ end
131
+
132
+ # Overwrite this method to provide other interpolation options when
133
+ # the flash message is going to be set.
134
+ #
135
+ # def interpolation_options
136
+ # { }
137
+ # end
138
+
139
+ private
140
+
141
+ # Fast accessor to resource_collection_name
142
+ #
143
+ def resource_collection_name #:nodoc:
144
+ self.resources_configuration[:self][:collection_name]
145
+ end
146
+
147
+ # Fast accessor to resource_instance_name
148
+ #
149
+ def resource_instance_name #:nodoc:
150
+ self.resources_configuration[:self][:instance_name]
151
+ end
152
+
153
+ # This methods gets your begin_of_association_chain, join it with your
154
+ # parents chain and returns the scoped association.
155
+ #
156
+ def end_of_association_chain #:nodoc:
157
+ if chain = association_chain.last
158
+ if method_for_association_chain
159
+ apply_scope_to(chain.send(method_for_association_chain))
160
+ else
161
+ # This only happens when we specify begin_of_association_chain in
162
+ # a singletion controller without parents. In this case, the chain
163
+ # is exactly the begin_of_association_chain which is already an
164
+ # instance and then not scopable.
165
+ chain
166
+ end
167
+ else
168
+ apply_scope_to(resource_class)
169
+ end
170
+ end
171
+
172
+ # Returns the appropriated method to build the resource.
173
+ #
174
+ def method_for_build #:nodoc:
175
+ (begin_of_association_chain || parent?) ? method_for_association_build : :new
176
+ end
177
+
178
+ # Returns the name of the method used for build the resource in cases
179
+ # where we have a parent. This is overwritten in singleton scenarios.
180
+ #
181
+ def method_for_association_build
182
+ :build
183
+ end
184
+
185
+ # Returns the name of the method to be called, before returning the end
186
+ # of the association chain. This is overwriten by singleton cases
187
+ # where no method for association chain is called.
188
+ #
189
+ def method_for_association_chain #:nodoc:
190
+ resource_collection_name
191
+ end
192
+
193
+ # Get resource ivar based on the current resource controller.
194
+ #
195
+ def get_resource_ivar #:nodoc:
196
+ instance_variable_get("@#{resource_instance_name}")
197
+ end
198
+
199
+ # Set resource ivar based on the current resource controller.
200
+ #
201
+ def set_resource_ivar(resource) #:nodoc:
202
+ instance_variable_set("@#{resource_instance_name}", resource)
203
+ end
204
+
205
+ # Get collection ivar based on the current resource controller.
206
+ #
207
+ def get_collection_ivar #:nodoc:
208
+ instance_variable_get("@#{resource_collection_name}")
209
+ end
210
+
211
+ # Set collection ivar based on the current resource controller.
212
+ #
213
+ def set_collection_ivar(collection) #:nodoc:
214
+ instance_variable_set("@#{resource_collection_name}", collection)
215
+ end
216
+
217
+ # Helper to set flash messages. It's powered by I18n API.
218
+ # It checks for messages in the following order:
219
+ #
220
+ # flash.controller_name.action_name.status
221
+ # flash.actions.action_name.status
222
+ #
223
+ # If none is available, a default message is set. So, if you have
224
+ # a CarsController, create action, it will check for:
225
+ #
226
+ # flash.cars.create.status
227
+ # flash.actions.create.status
228
+ #
229
+ # The statuses can be :notice (when the object can be created, updated
230
+ # or destroyed with success) or :error (when the objecy cannot be created
231
+ # or updated).
232
+ #
233
+ # Those messages are interpolated by using the resource class human name.
234
+ # This means you can set:
235
+ #
236
+ # flash:
237
+ # actions:
238
+ # create:
239
+ # notice: "Hooray! {{resource_name}} was successfully created!"
240
+ #
241
+ # But sometimes, flash messages are not that simple. Going back
242
+ # to cars example, you might want to say the brand of the car when it's
243
+ # updated. Well, that's easy also:
244
+ #
245
+ # flash:
246
+ # cars:
247
+ # update:
248
+ # notice: "Hooray! You just tuned your {{car_brand}}!"
249
+ #
250
+ # Since :car_name is not available for interpolation by default, you have
251
+ # to overwrite interpolation_options.
252
+ #
253
+ # def interpolation_options
254
+ # { :car_brand => @car.brand }
255
+ # end
256
+ #
257
+ # Then you will finally have:
258
+ #
259
+ # 'Hooray! You just tuned your Aston Martin!'
260
+ #
261
+ # If your controller is namespaced, for example Admin::CarsController,
262
+ # the messages will be checked in the following order:
263
+ #
264
+ # flash.admin.cars.create.status
265
+ # flash.admin.actions.create.status
266
+ # flash.cars.create.status
267
+ # flash.actions.create.status
268
+ #
269
+ def set_flash_message!(status, default_message=nil)
270
+ return flash[status] = default_message unless defined?(::I18n)
271
+
272
+ resource_name = if resource_class
273
+ if resource_class.respond_to?(:human_name)
274
+ resource_class.human_name
275
+ else
276
+ resource_class.name.underscore.humanize
277
+ end
278
+ else
279
+ "Resource"
280
+ end
281
+
282
+ given_options = if self.respond_to?(:interpolation_options)
283
+ interpolation_options
284
+ else
285
+ {}
286
+ end
287
+
288
+ options = {
289
+ :default => default_message || '',
290
+ :resource_name => resource_name
291
+ }.merge(given_options)
292
+
293
+ defaults = []
294
+ slices = controller_path.split('/')
295
+
296
+ while slices.size > 0
297
+ defaults << :"flash.#{slices.fill(controller_name, -1).join('.')}.#{action_name}.#{status}"
298
+ defaults << :"flash.#{slices.fill(:actions, -1).join('.')}.#{action_name}.#{status}"
299
+ slices.shift
300
+ end
301
+
302
+ options[:default] = defaults.push(options[:default])
303
+ options[:default].flatten!
304
+
305
+ message = ::I18n.t options[:default].shift, options
306
+ flash[status] = message unless message.blank?
307
+ end
308
+
309
+ # Used to allow to specify success and failure within just one block:
310
+ #
311
+ # def create
312
+ # create! do |success, failure|
313
+ # failure.html { redirect_to root_url }
314
+ # end
315
+ # end
316
+ #
317
+ # It also calculates the response url in case a block without arity is
318
+ # given and returns it. Otherwise returns nil.
319
+ #
320
+ def respond_with_dual_blocks(object, options, success, given_block, &block) #:nodoc:
321
+ case given_block.try(:arity)
322
+ when 2
323
+ respond_with(object, options) do |responder|
324
+ dumb_responder = InheritedResources::DumbResponder.new
325
+ if success
326
+ given_block.call(responder, dumb_responder)
327
+ else
328
+ given_block.call(dumb_responder, responder)
329
+ end
330
+ block.try(:call, responder)
331
+ end
332
+ when 1
333
+ if block
334
+ respond_with(object, options) do |responder|
335
+ given_block.call(responder)
336
+ block.call(responder)
337
+ end
338
+ else
339
+ respond_with(object, options, &given_block)
340
+ end
341
+ else
342
+ options[:location] = given_block.call if given_block
343
+ respond_with(object, options, &block)
344
+ end
345
+ end
346
+
347
+ # Hook to apply scopes. By default returns only the target_object given.
348
+ # It's extend by HasScopeHelpers.
349
+ #
350
+ def apply_scope_to(target_object) #:nodoc:
351
+ target_object
352
+ end
353
+
354
+ # Symbols chain in base helpers return nothing. This is later overwriten
355
+ # by belongs_to and can be complex in polymorphic cases.
356
+ #
357
+ def symbols_for_association_chain #:nodoc:
358
+ []
359
+ end
360
+
361
+ end
362
+ end
363
+