Class: Section

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

Direct Known Subclasses

Page

Constant Summary collapse

@@types =
['Page']

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.register_type(type) ⇒ Object



42
43
44
45
# File 'app/models/section.rb', line 42

def register_type(type)
  @@types << type
  @@types.uniq!
end

Instance Method Details



92
93
94
# File 'app/models/section.rb', line 92

def nav_children
  contents.roots.published
end

#ownerObject



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

def owner
  site
end

#ownersObject



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

def owners
  owner.owners << owner
end

#published=(published) ⇒ Object



76
77
78
79
80
81
82
# File 'app/models/section.rb', line 76

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)


84
85
86
87
88
89
# File 'app/models/section.rb', line 84

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)


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

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

#stateObject



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

def state
  published? ? :published : :pending
end

#tag_countsObject



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

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

#to_paramObject



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

def to_param
  permalink
end

#typeObject



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

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