Class: Sibu::Site

Inherits:
ApplicationRecord show all
Extended by:
UserConcern
Includes:
SectionsConcern
Defined in:
app/models/sibu/site.rb

Constant Summary collapse

DEFAULT_VERSION =
'fr'

Instance Method Summary collapse

Methods included from UserConcern

for_user

Methods included from SectionsConcern

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

Instance Method Details

#alt_colorObject



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

def alt_color
  secondary_color.blank? ? site_template.secondary_color : secondary_color
end

#alt_fontObject



34
35
36
# File 'app/models/sibu/site.rb', line 34

def alt_font
  secondary_font.blank? ? site_template.secondary_font : secondary_font
end

#deep_copyObject



100
101
102
103
104
105
106
107
108
109
# File 'app/models/sibu/site.rb', line 100

def deep_copy
  site_copy = deep_dup
  pages.each do |p|
    site_copy.name = name + ' - copie'
    site_copy.domain = nil
    site_copy.pages << p.deep_dup
  end

  site_copy
end

#init_pages(source) ⇒ Object



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

def init_pages(source)
  site_data = Rails.application.config.sibu[:site_data][source]
  site_data.pages.each do |p|
    self.pages << Sibu::Page.new(p)
  end
  save!
end

#init_sections(source) ⇒ Object



94
95
96
97
98
# File 'app/models/sibu/site.rb', line 94

def init_sections(source)
  site_data = Rails.application.config.sibu[:site_data][source]
  self.sections = site_data.sections(self)
  save!
end

#main_colorObject



22
23
24
# File 'app/models/sibu/site.rb', line 22

def main_color
  primary_color.blank? ? site_template.primary_color : primary_color
end

#main_fontObject



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

def main_font
  primary_font.blank? ? site_template.primary_font : primary_font
end

#not_foundObject



42
43
44
# File 'app/models/sibu/site.rb', line 42

def not_found
  "shared/#{site_template.path}/not_found"
end

#page(path) ⇒ Object



46
47
48
# File 'app/models/sibu/site.rb', line 46

def page(path)
  pages.where(path: path).first
end

#page_by_id(page_id) ⇒ Object



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

def page_by_id(page_id)
  pages.where(id: page_id).select(:id, :path).first
end

#pages_path_by_idObject



75
76
77
# File 'app/models/sibu/site.rb', line 75

def pages_path_by_id
  Hash[pages.collect {|p| [p.id.to_s, p.path]}]
end

#save_and_initObject



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/models/sibu/site.rb', line 61

def save_and_init
  if valid?
    self.sections = site_template.sections
    site_template.pages.each do |p|
      self.pages << Sibu::Page.new(p)
    end
    self.primary_color = site_template.primary_color
    self.secondary_color = site_template.secondary_color
    self.primary_font = site_template.primary_font
    self.secondary_font = site_template.secondary_font
  end
  save
end

#section_template(section) ⇒ Object



38
39
40
# File 'app/models/sibu/site.rb', line 38

def section_template(section)
  "#{site_template.path}/#{section["category"]}/#{section["template"]}"
end

#style_urlObject



18
19
20
# File 'app/models/sibu/site.rb', line 18

def style_url
  style ? style.url : site_template.path
end

#update_pathsObject



54
55
56
57
58
59
# File 'app/models/sibu/site.rb', line 54

def update_paths
  pages.each do |p|
    p.update_path(true)
    p.save
  end
end