Class: Sibu::Page

Inherits:
ApplicationRecord show all
Includes:
SectionsConcern
Defined in:
app/models/sibu/page.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SectionsConcern

#child_element, #clone_element, #create_section, #delete_element, #delete_section, #element, #elements, #elt, #find_or_init, #section, #update_element

Class Method Details

.lookup(domain_name, page_path) ⇒ Object



12
13
14
15
# File 'app/models/sibu/page.rb', line 12

def self.lookup(domain_name, page_path)
  joins(:site).where("sibu_sites.domain = ? AND ((sibu_sites.version = ? AND COALESCE(sibu_pages.path, '') = ?) OR sibu_pages.path = LTRIM(REPLACE(?, sibu_sites.version, ''), '/'))",
                     domain_name, Sibu::Site::DEFAULT_VERSION, page_path.nil? ? '' : page_path.strip, page_path.nil? ? '' : page_path.strip).first
end

Instance Method Details

#deep_copyObject



34
35
36
37
38
# File 'app/models/sibu/page.rb', line 34

def deep_copy
  new_page = deep_dup
  new_page.name = name + ' - copie'
  new_page
end

#reorder_sections(*ordered_ids) ⇒ Object



47
48
49
50
51
52
# File 'app/models/sibu/page.rb', line 47

def reorder_sections(*ordered_ids)
  if ordered_ids.length == sections.length
    self.sections = ordered_ids.map {|section_id| sections.find {|sec| sec["id"] == section_id}}
    save
  end
end

#save_and_initObject



17
18
19
20
21
22
23
# File 'app/models/sibu/page.rb', line 17

def save_and_init
  if valid?
    template_defaults = site.site_template.pages.first
    self.sections = template_defaults[:sections]  if template_defaults
  end
  save
end

#site_templateObject



30
31
32
# File 'app/models/sibu/page.rb', line 30

def site_template
  site.site_template
end

#update_pathObject

Todo : fix me (is_home flag ?)



26
27
28
# File 'app/models/sibu/page.rb', line 26

def update_path
  self.path = name.parameterize if self.path.blank? && name != 'Accueil'
end

#update_templates(sections_templates) ⇒ Object



40
41
42
43
44
45
# File 'app/models/sibu/page.rb', line 40

def update_templates(sections_templates)
  sections.each do |s|
    s["template"] = sections_templates[s["id"]]
  end
  save
end