Skip to content

Commit

Permalink
Allow content to control what field and screens it is displayed in.
Browse files Browse the repository at this point in the history
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
bamnet committed Feb 26, 2014
1 parent 174d161 commit 2af4446
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 7 additions & 0 deletions app/models/content.rb
Expand Up @@ -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
4 changes: 3 additions & 1 deletion app/models/subscription.rb
Expand Up @@ -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.