Class: ContentType
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ContentType
- Defined in:
- app/models/content_type.rb
Instance Attribute Summary collapse
-
#group_name ⇒ Object
Returns the value of attribute group_name.
Class Method Summary collapse
-
.find_by_key(key) ⇒ Object
Given a ‘key’ like ‘html_blocks’ or ‘portlet’ Raises exception if nothing was found.
- .list ⇒ Object
Instance Method Summary collapse
-
#columns_for_index ⇒ Object
Allows models to show additional columns when being shown in a list.
-
#content_block_type ⇒ Object
Used in ERB for pathing.
-
#content_block_type_for_list ⇒ Object
This is used for situations where you want different to use a type for the list page This is true for portlets, where you don’t want to list all portlets of a given type, You want to list all portlets.
- #display_name ⇒ Object
- #display_name_plural ⇒ Object
- #form ⇒ Object
- #is_child_of?(content_type) ⇒ Boolean
- #model_class ⇒ Object
- #set_content_type_group ⇒ Object
Instance Attribute Details
#group_name ⇒ Object
Returns the value of attribute group_name.
3 4 5 |
# File 'app/models/content_type.rb', line 3 def group_name @group_name end |
Class Method Details
.find_by_key(key) ⇒ Object
Given a ‘key’ like ‘html_blocks’ or ‘portlet’ Raises exception if nothing was found.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/models/content_type.rb', line 21 def self.find_by_key(key) class_name = key.tableize.classify content_type = find_by_name(class_name) if content_type.nil? if class_name.constantize.ancestors.include?(Portlet) content_type = ContentType.new(:name => class_name) content_type.content_type_group = ContentTypeGroup.find_by_name('Core') content_type.freeze content_type else raise "Not a Portlet" end else content_type end rescue Exception raise "Couldn't find ContentType of class '#{class_name}'" end |
.list ⇒ Object
15 16 17 |
# File 'app/models/content_type.rb', line 15 def self.list all.map { |f| f.name.underscore.to_sym } end |
Instance Method Details
#columns_for_index ⇒ Object
Allows models to show additional columns when being shown in a list.
61 62 63 64 65 66 67 68 69 70 |
# File 'app/models/content_type.rb', line 61 def columns_for_index if model_class.respond_to?(:columns_for_index) model_class.columns_for_index.map do |column| column.respond_to?(:humanize) ? {:label => column.humanize, :method => column} : column end else [{:label => "Name", :method => :name, :order => "name"}, {:label => "Updated On", :method => :updated_on_string, :order => "updated_at"}] end end |
#content_block_type ⇒ Object
Used in ERB for pathing
73 74 75 |
# File 'app/models/content_type.rb', line 73 def content_block_type name.pluralize.underscore end |
#content_block_type_for_list ⇒ Object
This is used for situations where you want different to use a type for the list page This is true for portlets, where you don’t want to list all portlets of a given type, You want to list all portlets
80 81 82 83 84 85 86 |
# File 'app/models/content_type.rb', line 80 def content_block_type_for_list if model_class.respond_to?(:content_block_type_for_list) model_class.content_block_type_for_list else content_block_type end end |
#display_name ⇒ Object
48 49 50 |
# File 'app/models/content_type.rb', line 48 def display_name model_class.respond_to?(:display_name) ? model_class.display_name : model_class.to_s.titleize end |
#display_name_plural ⇒ Object
52 53 54 |
# File 'app/models/content_type.rb', line 52 def display_name_plural model_class.respond_to?(:display_name_plural) ? model_class.display_name_plural : display_name.pluralize end |
#form ⇒ Object
44 45 46 |
# File 'app/models/content_type.rb', line 44 def form model_class.respond_to?(:form) ? model_class.form : "cms/#{name.underscore.pluralize}/form" end |
#is_child_of?(content_type) ⇒ Boolean
40 41 42 |
# File 'app/models/content_type.rb', line 40 def is_child_of?(content_type) name.constantize.ancestors.map{|c| c.name}.include?(content_type.name) end |
#model_class ⇒ Object
56 57 58 |
# File 'app/models/content_type.rb', line 56 def model_class name.tableize.classify.constantize end |
#set_content_type_group ⇒ Object
88 89 90 91 92 93 |
# File 'app/models/content_type.rb', line 88 def set_content_type_group if group_name group = ContentTypeGroup.first(:conditions => {:name => group_name}) self.content_type_group = group || build_content_type_group(:name => group_name) end end |