Class: Cms::ContentType
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Cms::ContentType
- Includes:
- EngineHelper
- Defined in:
- app/models/cms/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’.
- .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
Returns the partial used to render the form fields for a given block.
-
#key ⇒ Object
Returns URL friendly ‘key’ which is used to identify this.
- #model_class ⇒ Object
-
#model_class_form_name ⇒ Object
Cms::HtmlBlock -> html_block ThingBlock -> thing_block.
- #path_subject ⇒ Object
-
#route_name ⇒ Object
deprecated
Deprecated.
Should be removed eventually
- #set_content_type_group ⇒ Object
- #target_class ⇒ Object
Methods included from EngineHelper
decorate, #engine_exists?, #engine_name, #main_app_model?, module_name, #path_elements
Instance Attribute Details
#group_name ⇒ Object
Returns the value of attribute group_name.
3 4 5 |
# File 'app/models/cms/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’. Looks first for a class in the Cms
-
namespace, then again without it.
Raises exception if nothing was found.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/models/cms/content_type.rb', line 22 def self.find_by_key(key) class_name = key.tableize.classify content_type = find(:first, :conditions => ["name like ?", "%#{class_name}"]) if content_type.nil? if class_name.constantize.ancestors.include?(Cms::Portlet) content_type = Cms::ContentType.new(:name => class_name) content_type.content_type_group = Cms::ContentTypeGroup.find_by_name('Core') content_type.freeze content_type else raise "Not a Portlet" end else content_type end rescue Exception if class_name.starts_with? "Cms::" return self.find_by_key(class_name.gsub(/Cms::/, "")) end raise "Couldn't find ContentType of class '#{class_name}'" end |
.list ⇒ Object
15 16 17 |
# File 'app/models/cms/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.
95 96 97 98 99 100 101 102 103 104 |
# File 'app/models/cms/content_type.rb', line 95 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
107 108 109 |
# File 'app/models/cms/content_type.rb', line 107 def content_block_type name.demodulize.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
114 115 116 117 118 119 120 |
# File 'app/models/cms/content_type.rb', line 114 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
58 59 60 |
# File 'app/models/cms/content_type.rb', line 58 def display_name model_class.respond_to?(:display_name) ? model_class.display_name : Cms::Behaviors::Connecting.default_naming_for(model_class) end |
#display_name_plural ⇒ Object
62 63 64 |
# File 'app/models/cms/content_type.rb', line 62 def display_name_plural model_class.respond_to?(:display_name_plural) ? model_class.display_name_plural : display_name.pluralize end |
#form ⇒ Object
Returns the partial used to render the form fields for a given block.
50 51 52 53 54 55 56 |
# File 'app/models/cms/content_type.rb', line 50 def form f = model_class.respond_to?(:form) ? model_class.form : "#{name.underscore.pluralize}/form" if main_app_model? f = "cms/#{f}" end f end |
#key ⇒ Object
Returns URL friendly ‘key’ which is used to identify this
45 46 47 |
# File 'app/models/cms/content_type.rb', line 45 def key model_class_form_name end |
#model_class ⇒ Object
66 67 68 |
# File 'app/models/cms/content_type.rb', line 66 def model_class name.constantize end |
#model_class_form_name ⇒ Object
Cms::HtmlBlock -> html_block ThingBlock -> thing_block
90 91 92 |
# File 'app/models/cms/content_type.rb', line 90 def model_class_form_name model_class.model_name.element end |
#path_subject ⇒ Object
84 85 86 |
# File 'app/models/cms/content_type.rb', line 84 def path_subject model_class end |
#route_name ⇒ Object
Should be removed eventually
71 72 73 74 75 76 77 |
# File 'app/models/cms/content_type.rb', line 71 def route_name if model_class.name.starts_with?("Cms") model_class_form_name else "main_app.cms_#{model_class_form_name}" end end |
#set_content_type_group ⇒ Object
122 123 124 125 126 127 |
# File 'app/models/cms/content_type.rb', line 122 def set_content_type_group if group_name group = Cms::ContentTypeGroup.first(:conditions => {:name => group_name}) self.content_type_group = group || build_content_type_group(:name => group_name) end end |
#target_class ⇒ Object
80 81 82 |
# File 'app/models/cms/content_type.rb', line 80 def target_class model_class end |