Class: Section

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
HasOptions, HasPermalink
Defined in:
app/models/section.rb

Direct Known Subclasses

Page

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HasPermalink

included

Methods included from HasOptions

included

Class Method Details

.register_type(type) ⇒ Object



13
14
15
# File 'app/models/section.rb', line 13

def self.register_type(type)
  types.push(type) unless types.include?(type)
end

Instance Method Details



95
96
97
# File 'app/models/section.rb', line 95

def nav_children
  contents.roots.published
end

#ownerObject



59
60
61
# File 'app/models/section.rb', line 59

def owner
  site
end

#ownersObject



55
56
57
# File 'app/models/section.rb', line 55

def owners
  owner.owners << owner
end

#published=(published) ⇒ Object



79
80
81
82
83
84
85
# File 'app/models/section.rb', line 79

def published=(published)
  if published.to_i == 1
    self.published_at = Time.current if !published_at
  elsif published.to_i == 0
    self.published_at = nil
  end
end

#published?(parents = false) ⇒ Boolean Also known as: published

Returns:

  • (Boolean)


87
88
89
90
91
92
# File 'app/models/section.rb', line 87

def published?(parents = false)
  return true if self == site.sections.root # the root section is always published
  return false if parents && has_unpublished_ancestor?
  return false if published_at.nil? || published_at > Time.current
  return true
end

#root_section?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'app/models/section.rb', line 71

def root_section?
  self == site.sections.root
end

#stateObject



75
76
77
# File 'app/models/section.rb', line 75

def state
  published? ? :published : :pending
end

#tag_countsObject



67
68
69
# File 'app/models/section.rb', line 67

def tag_counts
  Content.tag_counts :conditions => "section_id = #{id}"
end

#to_paramObject

TODO validates_inclusion_of :contents_per_page, :in => 1..30, :message => “can only be between 1 and 30.”



51
52
53
# File 'app/models/section.rb', line 51

def to_param
  permalink
end

#typeObject



63
64
65
# File 'app/models/section.rb', line 63

def type
  read_attribute(:type) || 'Section'
end