Class: Cms::ContentType

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
EngineHelper
Defined in:
app/models/cms/content_type.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from EngineHelper

decorate, #engine_exists?, #engine_name, #main_app_model?, module_name, #path_elements

Instance Attribute Details

#group_nameObject

Returns the value of attribute group_name.



6
7
8
# File 'app/models/cms/content_type.rb', line 6

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.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/models/cms/content_type.rb', line 25

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

.listObject



18
19
20
# File 'app/models/cms/content_type.rb', line 18

def self.list
  all.map { |f| f.name.underscore.to_sym }
end

Instance Method Details

#columns_for_indexObject

Allows models to show additional columns when being shown in a list.



98
99
100
101
102
103
104
105
106
107
# File 'app/models/cms/content_type.rb', line 98

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_typeObject

Used in ERB for pathing



110
111
112
# File 'app/models/cms/content_type.rb', line 110

def content_block_type
  name.demodulize.pluralize.underscore
end

#content_block_type_for_listObject

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



117
118
119
120
121
122
123
# File 'app/models/cms/content_type.rb', line 117

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_nameObject



61
62
63
# File 'app/models/cms/content_type.rb', line 61

def display_name
  model_class.respond_to?(:display_name) ? model_class.display_name : Cms::Behaviors::Connecting.default_naming_for(model_class)
end

#display_name_pluralObject



65
66
67
# File 'app/models/cms/content_type.rb', line 65

def display_name_plural
  model_class.respond_to?(:display_name_plural) ? model_class.display_name_plural : display_name.pluralize
end

#formObject

Returns the partial used to render the form fields for a given block.



53
54
55
56
57
58
59
# File 'app/models/cms/content_type.rb', line 53

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

#keyObject

Returns URL friendly ‘key’ which is used to identify this



48
49
50
# File 'app/models/cms/content_type.rb', line 48

def key
  model_class_form_name
end

#model_classObject



69
70
71
# File 'app/models/cms/content_type.rb', line 69

def model_class
  name.constantize
end

#model_class_form_nameObject

Cms::HtmlBlock -> html_block ThingBlock -> thing_block



93
94
95
# File 'app/models/cms/content_type.rb', line 93

def model_class_form_name
  model_class.model_name.element
end

#path_subjectObject



87
88
89
# File 'app/models/cms/content_type.rb', line 87

def path_subject
  model_class
end

#route_nameObject

Deprecated.

Should be removed eventually



74
75
76
77
78
79
80
# File 'app/models/cms/content_type.rb', line 74

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_groupObject



125
126
127
128
129
130
# File 'app/models/cms/content_type.rb', line 125

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_classObject



83
84
85
# File 'app/models/cms/content_type.rb', line 83

def target_class
  model_class
end