resource_controller_views 0.6.6.views2 → 0.6.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -2,12 +2,6 @@
2
2
 
3
3
  resource_controller makes RESTful controllers easier, more maintainable, and super readable. With the RESTful controller pattern hidden away, you can focus on what makes your controller special.
4
4
 
5
- = Views Extension
6
-
7
- resource_controller_views expands upon resource_controller, allowing you to specify a view "fallback" directory, so you to define standard views used for your standard CRUD operations (as well as any others). Then within your controllers main view directory, you only need to provide views that differ from your application's standard views.
8
-
9
- See towards the bottom of this document for examples.
10
-
11
5
  == Get It
12
6
 
13
7
  Install it as a plugin:
@@ -47,11 +41,11 @@ It's really easy to make changes to the lifecycle of your actions.
47
41
  class ProjectsController < ResourceController::Base
48
42
 
49
43
  new_action.before do
50
- 3.times { current_object.tasks.build }
44
+ 3.times { object.tasks.build }
51
45
  end
52
46
 
53
47
  create.after do
54
- current_object.creator = current_user
48
+ object.creator = current_user
55
49
  end
56
50
 
57
51
  end
@@ -135,7 +129,7 @@ Loading objects in singletons is similar to plural controllers with one exceptio
135
129
  class AccountsController < ResourceController::Singleton
136
130
  private
137
131
  def object
138
- @_rc_object ||= Account.find(session[:account_id])
132
+ @object ||= Account.find(session[:account_id])
139
133
  end
140
134
  end
141
135
 
@@ -175,7 +169,7 @@ Or maybe you used a permalink...
175
169
  class PostsController < ResourceController::Base
176
170
  private
177
171
  def object
178
- @_rc_object ||= end_of_association_chain.find_by_permalink(param)
172
+ @object ||= end_of_association_chain.find_by_permalink(param)
179
173
  end
180
174
  end
181
175
 
@@ -186,7 +180,7 @@ Maybe you have some alternative way of building objects...
186
180
  class PostsController < ResourceController::Base
187
181
  private
188
182
  def build_object
189
- @_rc_object ||= end_of_association_chain.build_my_object_some_funky_way object_params
183
+ @object ||= end_of_association_chain.build_my_object_some_funky_way object_params
190
184
  end
191
185
  end
192
186
 
@@ -226,7 +220,7 @@ Everything, including url generation is handled completely automatically. Take
226
220
  map.resources :products, :has_many => :comments
227
221
  map.resources :users, :has_many => :comments
228
222
 
229
- All you have to do is that, and r_c will infer whichever relationship is present, and perform all the actions at the scope of the parent current_object.
223
+ All you have to do is that, and r_c will infer whichever relationship is present, and perform all the actions at the scope of the parent object.
230
224
 
231
225
  === Parent Helpers
232
226
 
@@ -327,31 +321,6 @@ Or with namespaced, nested controllers...
327
321
 
328
322
  You get the idea. Everything is automagical! All parameters are inferred.
329
323
 
330
- == View Fallback
331
-
332
- With the view extension, you're able to provide default views for all your standard actions, so in effect you really only need to define your CRUD views once, and just have a different form partial in each controller's view directory. For example:
333
-
334
- /app/views/common/edit.html.erb:
335
-
336
- <h1>Editing <%= resource_controller_options[:english_name] %></h1>
337
-
338
- <% form_for :object, object_url do |form| %>
339
- <%= render "form", :form => form %>
340
-
341
- <%= form.submit "Update" %>
342
- <% end %>
343
-
344
- /app/views/posts/_form.html.erb:
345
-
346
- <%= form.label :name %>
347
- <%= form.text_field :name %>
348
-
349
- /app/controllers/posts_controller.rb:
350
-
351
- resource_controller :scaffold_root => "/app/views/common", :english_name => "Post"
352
-
353
- With the extensions installed, a GET to /posts/1/edit would cause Rails to attempt to render /app/views/posts/edit.html.erb. If that cannot be found, resource_controller_views will make Rails attempt to render /app/views/common/edit.html.erb. The common edit helper will then attempt to render the "form" partial, which again uses the same mechanism as for standard views. In the second case however it finds the _form.html.erb partial in the controllers own directory, and so renders that.
354
-
355
324
  == Credits
356
325
 
357
326
  resource_controller was created, and is maintained by {James Golick}[http://jamesgolick.com].
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
- :build: views2
3
- :patch: 6
4
2
  :major: 0
5
3
  :minor: 6
4
+ :build:
5
+ :patch: 6
@@ -19,7 +19,7 @@ module ResourceController
19
19
  build_object
20
20
  load_object
21
21
  before :create
22
- if current_object.save
22
+ if object.save
23
23
  after :create
24
24
  set_flash :create
25
25
  response_for :create
@@ -33,7 +33,7 @@ module ResourceController
33
33
  def update
34
34
  load_object
35
35
  before :update
36
- if current_object.update_attributes object_params
36
+ if object.update_attributes object_params
37
37
  after :update
38
38
  set_flash :update
39
39
  response_for :update
@@ -60,7 +60,7 @@ module ResourceController
60
60
  def destroy
61
61
  load_object
62
62
  before :destroy
63
- if current_object.destroy
63
+ if object.destroy
64
64
  after :destroy
65
65
  set_flash :destroy
66
66
  response_for :destroy
@@ -25,7 +25,7 @@ module ResourceController
25
25
  :hash_for_edit_object_path, :hash_for_new_object_path, :hash_for_collection_url,
26
26
  :hash_for_object_url, :hash_for_edit_object_url, :hash_for_new_object_url, :parent?,
27
27
  :collection_url_options, :object_url_options, :new_object_url_options, :resource_controller_options,
28
- :has_own_partial?, :current_object
28
+ :has_own_partial?
29
29
 
30
30
  end
31
31
 
@@ -34,16 +34,14 @@ module ResourceController
34
34
  # class PostsController < ResourceController::Base
35
35
  # private
36
36
  # def object
37
- # @_rc_object ||= end_of_association_chain.find_by_permalink(param)
37
+ # @object ||= end_of_association_chain.find_by_permalink(param)
38
38
  # end
39
39
  # end
40
40
  #
41
41
  def object
42
- @_rc_object ||= end_of_association_chain.find(param) unless param.nil?
43
- @_rc_object
42
+ @object ||= end_of_association_chain.find(param) unless param.nil?
43
+ @object
44
44
  end
45
-
46
- alias current_object object
47
45
 
48
46
  # Used internally to load the member object in to an instance variable @#{model_name} (i.e. @post)
49
47
  #
@@ -68,7 +66,7 @@ module ResourceController
68
66
  # Builds the object, but doesn't save it, during the new, and create action.
69
67
  #
70
68
  def build_object
71
- @_rc_object ||= end_of_association_chain.send parent? ? :build : :new, object_params
69
+ @object ||= end_of_association_chain.send parent? ? :build : :new, object_params
72
70
  end
73
71
  end
74
72
  end
@@ -7,7 +7,7 @@ module ResourceController
7
7
  # Returns the relevant association proxy of the parent. (i.e. /posts/1/comments # => @post.comments)
8
8
  #
9
9
  def parent_association
10
- @parent_association ||= parent_current_object.send(model_name.to_s.pluralize.to_sym)
10
+ @parent_association ||= parent_object.send(model_name.to_s.pluralize.to_sym)
11
11
  end
12
12
 
13
13
  # Returns the type of the current parent
@@ -28,18 +28,18 @@ module ResourceController
28
28
  # class AccountsController < ResourceController::Singleton
29
29
  # private
30
30
  # def object
31
- # @_rc_object ||= Account.find(session[:account_id])
31
+ # @object ||= Account.find(session[:account_id])
32
32
  # end
33
33
  # end
34
34
  #
35
35
  def object
36
- @_rc_object ||= parent? ? end_of_association_chain : nil
36
+ @object ||= parent? ? end_of_association_chain : nil
37
37
  end
38
38
 
39
39
  # Returns the :has_one association proxy of the parent. (i.e. /users/1/image # => @user.image)
40
40
  #
41
41
  def parent_association
42
- @parent_association ||= parent_current_object.send(model_name.to_sym)
42
+ @parent_association ||= parent_object.send(model_name.to_sym)
43
43
  end
44
44
 
45
45
  # Used internally to provide the options to smart_url in a singleton controller.
@@ -51,7 +51,7 @@ module ResourceController
51
51
  # Builds the object, but doesn't save it, during the new, and create action.
52
52
  #
53
53
  def build_object
54
- @_rc_object ||= singleton_build_object_base.send parent? ? "build_#{model_name}".to_sym : :new, object_params
54
+ @object ||= singleton_build_object_base.send parent? ? "build_#{model_name}".to_sym : :new, object_params
55
55
  end
56
56
 
57
57
  # Singleton controllers don't build off of association proxy, so we can't use end_of_association_chain here
@@ -45,19 +45,19 @@ module ResourceController
45
45
  symbol = type.blank? ? nil : type.gsub(/_/, '').to_sym
46
46
 
47
47
  define_method("#{type}object_url") do |*alternate_object|
48
- smart_url *object_url_options(symbol, alternate_current_object.first)
48
+ smart_url *object_url_options(symbol, alternate_object.first)
49
49
  end
50
50
 
51
51
  define_method("#{type}object_path") do |*alternate_object|
52
- smart_path *object_url_options(symbol, alternate_current_object.first)
52
+ smart_path *object_url_options(symbol, alternate_object.first)
53
53
  end
54
54
 
55
55
  define_method("hash_for_#{type}object_url") do |*alternate_object|
56
- hash_for_smart_url *object_url_options(symbol, alternate_current_object.first)
56
+ hash_for_smart_url *object_url_options(symbol, alternate_object.first)
57
57
  end
58
58
 
59
59
  define_method("hash_for_#{type}object_path") do |*alternate_object|
60
- hash_for_smart_path *object_url_options(symbol, alternate_current_object.first)
60
+ hash_for_smart_path *object_url_options(symbol, alternate_object.first)
61
61
  end
62
62
  end
63
63
 
@@ -16,7 +16,7 @@ module ResourceController
16
16
  # class PostsController < ResourceController::Base
17
17
  # private
18
18
  # def object
19
- # @_rc_object ||= end_of_association_chain.find_by_permalink(param)
19
+ # @object ||= end_of_association_chain.find_by_permalink(param)
20
20
  # end
21
21
  # end
22
22
  module Helpers
@@ -12,11 +12,10 @@ module ResourceController
12
12
  rescue ActionView::MissingTemplate
13
13
  Rails.logger.debug("[DynamicScaffold] Using scaffold partial #{partial_path}")
14
14
 
15
- raise "Attempting to call a resource_controller_views partial from a controller which isn't resource_controller enabled." if !controller.respond_to?(:resource_controller_options)
16
- raise if controller.nil? || controller.resource_controller_options[:scaffold_root].blank?
15
+ raise if controller.nil? || self.class.resource_controller_options[:scaffold_root].blank?
17
16
 
18
17
  scaffold_paths = view_paths.class.new
19
- scaffold_paths.unshift(controller.resource_controller_options[:scaffold_root] || "app/views/scaffold")
18
+ scaffold_paths.unshift(self.class.resource_controller_options[:scaffold_root] || "app/views/scaffold")
20
19
  scaffold_paths.find_template("_#{partial_path}", self.template_format)
21
20
  end
22
21
  end
@@ -8,11 +8,10 @@ module ResourceController
8
8
  def default_template(action_name = self.action_name)
9
9
  view_paths.find_template(default_template_name(action_name), default_template_format)
10
10
  rescue ActionView::MissingTemplate
11
- raise if controller.resource_controller_options[:scaffold_root].blank?
12
- action_name = "index" if action_name.blank?
11
+ raise if self.class.resource_controller_options[:scaffold_root].blank?
13
12
 
14
13
  scaffold_paths = view_paths.class.new
15
- scaffold_paths.unshift(controller.resource_controller_options[:scaffold_root])
14
+ scaffold_paths.unshift(self.class.resource_controller_options[:scaffold_root])
16
15
  scaffold_paths.find_template(action_name, default_template_format)
17
16
  end
18
17
  end
data/lib/urligence.rb CHANGED
@@ -19,7 +19,7 @@ module Urligence
19
19
  config = {}
20
20
  config.merge!(objects.pop) if objects.last.is_a?(Hash)
21
21
 
22
- objects.reject! { |object| current_object.nil? }
22
+ objects.reject! { |object| object.nil? }
23
23
 
24
24
  url_fragments = objects.collect do |obj|
25
25
  if obj.is_a? Symbol
@@ -10,8 +10,8 @@ class Helpers::CurrentObjectsTest < Test::Unit::TestCase
10
10
  @request = stub :path => ""
11
11
  @controller.stubs(:request).returns(@request)
12
12
 
13
- @_rc_object = Post.new
14
- Post.stubs(:find).with("1").returns(@_rc_object)
13
+ @object = Post.new
14
+ Post.stubs(:find).with("1").returns(@object)
15
15
 
16
16
  @collection = mock()
17
17
  Post.stubs(:find).with(:all).returns(@collection)
@@ -37,7 +37,7 @@ class Helpers::CurrentObjectsTest < Test::Unit::TestCase
37
37
 
38
38
  context "object helper" do
39
39
  should "find the correct object" do
40
- assert_equal @_rc_object, @controller.send(:object)
40
+ assert_equal @object, @controller.send(:object)
41
41
  end
42
42
  end
43
43
 
@@ -47,7 +47,7 @@ class Helpers::CurrentObjectsTest < Test::Unit::TestCase
47
47
  end
48
48
 
49
49
  should "load object as instance variable" do
50
- assert_equal @_rc_object, @controller.instance_variable_get("@post")
50
+ assert_equal @object, @controller.instance_variable_get("@post")
51
51
  end
52
52
 
53
53
  context "with an alternate object_name" do
@@ -57,7 +57,7 @@ class Helpers::CurrentObjectsTest < Test::Unit::TestCase
57
57
  end
58
58
 
59
59
  should "use the variable name" do
60
- assert_equal @_rc_object, @controller.instance_variable_get("@asdf")
60
+ assert_equal @object, @controller.instance_variable_get("@asdf")
61
61
  end
62
62
  end
63
63
  end
@@ -7,8 +7,8 @@ class Helpers::InternalTest < Test::Unit::TestCase
7
7
  @params = stub :[] => "1"
8
8
  @controller.stubs(:params).returns(@params)
9
9
 
10
- @_rc_object = Post.new
11
- Post.stubs(:find).with("1").returns(@_rc_object)
10
+ @object = Post.new
11
+ Post.stubs(:find).with("1").returns(@object)
12
12
 
13
13
  @collection = mock()
14
14
  Post.stubs(:find).with(:all).returns(@collection)
@@ -23,8 +23,8 @@ class Helpers::NestedTest < Test::Unit::TestCase
23
23
  @request = stub :path => ""
24
24
  @controller.stubs(:request).returns(@request)
25
25
 
26
- @_rc_object = Post.new
27
- Post.stubs(:find).with("1").returns(@_rc_object)
26
+ @object = Post.new
27
+ Post.stubs(:find).with("1").returns(@object)
28
28
 
29
29
  @collection = mock()
30
30
  Post.stubs(:find).with(:all).returns(@collection)
@@ -10,8 +10,8 @@ class Helpers::UrlsTest < Test::Unit::TestCase
10
10
  @request = stub :path => ""
11
11
  @controller.stubs(:request).returns(@request)
12
12
 
13
- @_rc_object = Post.new
14
- Post.stubs(:find).with("1").returns(@_rc_object)
13
+ @object = Post.new
14
+ Post.stubs(:find).with("1").returns(@object)
15
15
 
16
16
  @collection = mock()
17
17
  Post.stubs(:find).with(:all).returns(@collection)
@@ -33,7 +33,7 @@ class Helpers::UrlsTest < Test::Unit::TestCase
33
33
  end
34
34
 
35
35
  should "return the correct object options" do
36
- assert_equal [nil, nil, [:post, @_rc_object]], @controller.send(:object_url_options)
36
+ assert_equal [nil, nil, [:post, @object]], @controller.send(:object_url_options)
37
37
  end
38
38
 
39
39
  should "return the correct collection options for a namespaced controller" do
@@ -63,8 +63,8 @@ class Helpers::UrlsTest < Test::Unit::TestCase
63
63
  end
64
64
 
65
65
  should "return the correct object options for object_url_options" do
66
- @controller.expects(:object).returns @_rc_object
67
- assert_equal [:edit, [:user, @user], [:post, @_rc_object]], @controller.send(:object_url_options, :edit)
66
+ @controller.expects(:object).returns @object
67
+ assert_equal [:edit, [:user, @user], [:post, @object]], @controller.send(:object_url_options, :edit)
68
68
  end
69
69
 
70
70
  should "return the correct object options for collection" do
@@ -8,8 +8,8 @@ class HelpersTest < ActiveSupport::TestCase
8
8
  @params = stub :[] => "1"
9
9
  @controller.stubs(:params).returns(@params)
10
10
 
11
- @_rc_object = Post.new
12
- Post.stubs(:find).with("1").returns(@_rc_object)
11
+ @object = Post.new
12
+ Post.stubs(:find).with("1").returns(@object)
13
13
 
14
14
  @collection = mock()
15
15
  Post.stubs(:find).with(:all).returns(@collection)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resource_controller_views
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.6.views2
4
+ version: 0.6.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Golick
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2010-03-30 00:00:00 +11:00
14
+ date: 2010-03-17 00:00:00 +11:00
15
15
  default_executable:
16
16
  dependencies: []
17
17
 
@@ -282,9 +282,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
282
282
  version:
283
283
  required_rubygems_version: !ruby/object:Gem::Requirement
284
284
  requirements:
285
- - - ">"
285
+ - - ">="
286
286
  - !ruby/object:Gem::Version
287
- version: 1.3.1
287
+ version: "0"
288
288
  version:
289
289
  requirements: []
290
290