Class: Section

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

Direct Known Subclasses

Page

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Adva::HasPermalink

included

Methods included from Adva::HasOptions

included

Class Method Details

.register_type(type) ⇒ Object



9
10
11
# File 'app/models/section.rb', line 9

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

Instance Method Details



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

def nav_children
  contents.roots.published
end

#ownerObject



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

def owner
  site
end

#ownersObject



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

def owners
  owner.owners << owner
end

#published=(published) ⇒ Object



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

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)


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

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)


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

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

#stateObject



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

def state
  published? ? :published : :pending
end

#tag_countsObject



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

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.”



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

def to_param
  permalink
end

#typeObject



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

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