Class: Publinator::Section

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.get_by_site_id_and_slug(site_id, section_name) ⇒ Object

current_site.id, params



19
20
21
# File 'app/models/publinator/section.rb', line 19

def self.get_by_site_id_and_slug(site_id, section_name)
  Section.find(:first, :conditions => ["site_id = ? and name = ?", site_id, section_name])
end

.matches?(request) ⇒ Boolean

Returns:

  • (Boolean)


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

def self.matches?(request)
  pt = self.find(:first, :conditions => ["section_slug = ?", request.path_parameters[:section]])
  return pt.present?
end

Instance Method Details

#child_sectionsObject



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

def child_sections
  Section.where(:parent_id => id)
end

#generate_section_slugObject



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

def generate_section_slug
  self.section_slug = name.strip.downcase.gsub(/[^a-zA-Z0-9\-\_]/, '_') if section_slug.blank?
end

#index_itemObject



23
24
25
# File 'app/models/publinator/section.rb', line 23

def index_item
  Publinator::Publication.find_by_section_id_and_slug(id, 'index')
end


31
32
33
# File 'app/models/publinator/section.rb', line 31

def menu_collection
  publications + child_sections
end

#parent_sectionObject



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

def parent_section
  Section.where(:id => parent_id).first if parent_id
end

#pathObject



27
28
29
# File 'app/models/publinator/section.rb', line 27

def path
  "/#{section_slug}"
end

#publishableObject



35
36
37
# File 'app/models/publinator/section.rb', line 35

def publishable
  self
end

#publishablesObject



39
40
41
# File 'app/models/publinator/section.rb', line 39

def publishables
  publications
end