Permalink
Browse files

Allow content to control what field and screens it is displayed in.

Content classes now include a can_display_in? method which contains the logic we use to see if a piece of content should be rendered in a specific <screen, field>.  To provide parity with the default behavior, we simply make sure that the Field.Kind == Content.Kind.
  • Loading branch information...
1 parent 174d161 commit 2af444698e1ec5b790d706c555311bed73df31e4 @bamnet bamnet committed Feb 26, 2014
Showing with 10 additions and 1 deletion.
  1. +7 −0 app/models/content.rb
  2. +3 −1 app/models/subscription.rb
View
@@ -222,4 +222,11 @@ def self.filter_all_content(params)
filtered_contents
end
+ # Determine if a piece of content should be displayed based on screen and field.
+ # By default content can be rendered in any Field which has the same Kind as the Content.
+ # This can be overridden by different content types which can be displayed in different
+ # fields or based on some dynamic criteria implemented in each Content subclass.
+ def can_display_in?(screen, field)
+ return self.kind == field.kind
+ end
end
@@ -32,6 +32,8 @@ def weight_name
# Get an array of all the approved active content to be shown in a screen's field.
def contents
- self.feed.approved_contents.active.where(:kind_id => self.field.kind.id)
+ contents = self.feed.approved_contents.active.all
+ contents.reject!{|c| !c.can_display_in?(self.screen, self.field)}
+ return contents
end
end

0 comments on commit 2af4446

Please sign in to comment.