Permalink
Browse files

Fixes #1673 by adding support for not including the record itself in …

…the nesting and passing :uncached_nested_url as the attribute to access on the record for its nesting. Sneaky.
  • Loading branch information...
1 parent be6ff4a commit 4fa540ea675925dcdbc92b24feb3663144fc014f @parndt parndt committed May 25, 2012
@@ -9,6 +9,7 @@ class Activity
# Total number of activies to show for a given class of activity
attr_accessor :limit
+ # Other objects, like parents, to include in the nesting structure
attr_accessor :nested_with
# SQL order by string to specify how to order the activities in the activity feed for
@@ -21,6 +22,10 @@ class Activity
# Image asset to use to represent updated instance of the class thisa activity represents
attr_accessor :updated_image
+ # Boolean; whether or not to use the record itself when constructing the nesting
+ # Default true
+ attr_accessor :use_record_in_nesting
+
# Creates a new instance of Activity for a registered Refinery Plugin. An optional
# hash of options can be specified to customize the values of each attribute
# accessor defined on this class. Each key specified in the options hash should be a
@@ -31,7 +36,8 @@ class Activity
# Activity.new(:limit => 10, :title => "Newest Activity!")
#
# Warning:
- # for the nested_with option, pass in the reverse order of ancestry e.g. [parent.parent_of_parent, parent]
+ # for the nested_with option, pass in the reverse order of ancestry
+ # e.g. [parent.parent_of_parent, parent]
def initialize(options = {})
{
:class_name => nil,
@@ -43,7 +49,8 @@ def initialize(options = {})
:title => "title",
:updated_image => "edit.png",
:url => nil,
- :url_prefix => "edit"
+ :url_prefix => "edit",
+ :use_record_in_nesting => true
}.merge(options).each { |key, value| self.send(:"#{key}=", value) }
end
@@ -80,11 +87,15 @@ def klass
end
# to use in a URL like edit_refinery_admin_group_individuals_path(record.group, record)
- # which will help you if you're using nested routed.
+ # which will help you if you're using nested routes.
def nesting(record_string = "record")
- self.nested_with.inject("") { |nest_chain, nesting|
- nest_chain << "#{record_string}.#{nesting},"
- }
+ @nesting ||= begin
+ chain = self.nested_with.inject([]) { |nest_chain, nesting|
+ nest_chain << "#{record_string}.#{nesting}"
+ }
+ chain << record_string if self.use_record_in_nesting
+ chain.join(',')
+ end
end
attr_writer :url_prefix
@@ -16,7 +16,7 @@ def activity_message_for(record)
:what => record.send(activity.title),
:kind => record.class.model_name.human,
:action => t("with_article \"#{article}\"", :scope => "refinery.#{action}")
- ).downcase.capitalize, eval("#{activity.url}(#{activity.nesting("record")}record)")
+ ).downcase.capitalize, eval("#{activity.url}(#{activity.nesting("record")})")
end
end
@@ -24,7 +24,11 @@ class Engine < ::Rails::Engine
plugin.name = 'refinery_pages'
plugin.version = %q{2.0.0}
plugin.menu_match = %r{refinery/page(_part|s_dialog)?s$}
- plugin.activity = { :class_name => :'refinery/page' }
+ plugin.activity = {
+ :class_name => :'refinery/page',
+ :nested_with => [:uncached_nested_url],
+ :use_record_in_nesting => false
+ }
plugin.url = proc { Refinery::Core::Engine.routes.url_helpers.admin_pages_path }
end
end

0 comments on commit 4fa540e

Please sign in to comment.