Class: ContentType

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#group_nameObject

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

.listObject



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_indexObject

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_typeObject

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_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



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_nameObject



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_pluralObject



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

#formObject



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

Returns:

  • (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_classObject



56
57
58
# File 'app/models/content_type.rb', line 56

def model_class
  name.tableize.classify.constantize
end

#set_content_type_groupObject



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