Class: Sibu::Page
Class Method Summary
collapse
Instance Method Summary
collapse
#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_query) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
|
# File 'app/models/sibu/page.rb', line 13
def self.lookup(domain_name, page_query)
page_path = (page_query || '').strip.split('?')[0]
if page_path.blank?
joins(:site).where("sibu_sites.domain = ? AND COALESCE(sibu_pages.path, '') = ''", domain_name).first
else
paths = page_path.split('/').inject([]) {|p, s| p << (p.length == 0 ? s : "#{p[-1]}/#{s}")}
joins(:site).where("sibu_sites.domain = ? AND COALESCE(sibu_pages.path, '') IN (?)", domain_name, paths)
.order(path: :desc)
.first
end
end
|
Instance Method Details
#deep_copy ⇒ Object
46
47
48
49
50
|
# File 'app/models/sibu/page.rb', line 46
def deep_copy
new_page = deep_dup
new_page.name = name + ' - copie'
new_page
end
|
#reorder_sections(*ordered_ids) ⇒ Object
59
60
61
62
63
64
|
# File 'app/models/sibu/page.rb', line 59
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_init ⇒ Object
25
26
27
28
29
30
31
|
# File 'app/models/sibu/page.rb', line 25
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_template ⇒ Object
42
43
44
|
# File 'app/models/sibu/page.rb', line 42
def site_template
site.site_template
end
|
#update_path ⇒ Object
33
34
35
36
37
38
39
40
|
# File 'app/models/sibu/page.rb', line 33
def update_path
prefix = site.version == Sibu::Site::DEFAULT_VERSION ? '' : "#{site.version}/"
if is_home == 'true'
self.path = ''
else
self.path = "#{prefix}#{name.parameterize}" if self.path.blank?
end
end
|
#update_templates(sections_templates) ⇒ Object
52
53
54
55
56
57
|
# File 'app/models/sibu/page.rb', line 52
def update_templates(sections_templates)
sections.each do |s|
s["template"] = sections_templates[s["id"]]
end
save
end
|