sibu 0.8.1 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +20 -20
  3. data/README.md +38 -38
  4. data/Rakefile +36 -36
  5. data/app/assets/config/sibu_manifest.js +2 -2
  6. data/app/assets/fonts/sibu/Sibu.eot +0 -0
  7. data/app/assets/fonts/sibu/Sibu.svg +13 -13
  8. data/app/assets/fonts/sibu/Sibu.ttf +0 -0
  9. data/app/assets/fonts/sibu/Sibu.woff +0 -0
  10. data/app/assets/javascripts/cropper/cropper.js +3694 -3694
  11. data/app/assets/javascripts/quill/quill.js +11401 -11401
  12. data/app/assets/javascripts/sibu/common.js +6 -6
  13. data/app/assets/javascripts/sibu/sibu.js.erb +156 -155
  14. data/app/assets/javascripts/tabs/van11y-accessible-tab-panel-aria.js +465 -465
  15. data/app/assets/stylesheets/cropper/cropper.css +304 -304
  16. data/app/assets/stylesheets/quill/quill.snow.css +945 -945
  17. data/app/assets/stylesheets/sibu/defaults.scss +317 -336
  18. data/app/assets/stylesheets/sibu/icons.scss +40 -40
  19. data/app/assets/stylesheets/sibu/sibu.css +131 -131
  20. data/app/controllers/sibu/application_controller.rb +14 -14
  21. data/app/controllers/sibu/documents_controller.rb +35 -35
  22. data/app/controllers/sibu/images_controller.rb +78 -78
  23. data/app/controllers/sibu/pages_controller.rb +197 -197
  24. data/app/controllers/sibu/sites_controller.rb +81 -81
  25. data/app/helpers/sibu/application_helper.rb +11 -11
  26. data/app/helpers/sibu/documents_helper.rb +4 -4
  27. data/app/helpers/sibu/images_helper.rb +4 -4
  28. data/app/helpers/sibu/pages_helper.rb +217 -194
  29. data/app/helpers/sibu/sites_helper.rb +23 -23
  30. data/app/jobs/sibu/application_job.rb +4 -4
  31. data/app/mailers/sibu/application_mailer.rb +6 -6
  32. data/app/models/concerns/sibu/document_uploader.rb +8 -8
  33. data/app/models/concerns/sibu/image_uploader.rb +31 -31
  34. data/app/models/concerns/sibu/sections_concern.rb +134 -134
  35. data/app/models/concerns/sibu/style_uploader.rb +1 -1
  36. data/app/models/concerns/sibu/user_concern.rb +9 -8
  37. data/app/models/sibu/application_record.rb +5 -5
  38. data/app/models/sibu/document.rb +16 -16
  39. data/app/models/sibu/dynamic_style.rb +76 -76
  40. data/app/models/sibu/image.rb +10 -19
  41. data/app/models/sibu/page.rb +66 -66
  42. data/app/models/sibu/site.rb +97 -97
  43. data/app/models/sibu/site_template.rb +22 -22
  44. data/app/views/layouts/sibu/application.html.erb +23 -23
  45. data/app/views/layouts/sibu/edit_content.html.erb +262 -262
  46. data/app/views/layouts/sibu/site.html.erb +45 -45
  47. data/app/views/sibu/documents/_form.html.erb +14 -14
  48. data/app/views/sibu/documents/index.html.erb +37 -37
  49. data/app/views/sibu/documents/new.html.erb +12 -12
  50. data/app/views/sibu/images/_edit_form.html.erb +23 -23
  51. data/app/views/sibu/images/_form.html.erb +34 -34
  52. data/app/views/sibu/images/edit.js.erb +2 -2
  53. data/app/views/sibu/images/index.html.erb +31 -13
  54. data/app/views/sibu/images/new.html.erb +12 -12
  55. data/app/views/sibu/images/show.html.erb +2 -2
  56. data/app/views/sibu/pages/_code_edit_panel.html.erb +17 -17
  57. data/app/views/sibu/pages/_element_actions.html.erb +4 -4
  58. data/app/views/sibu/pages/_error_panel.html.erb +4 -4
  59. data/app/views/sibu/pages/_form.html.erb +62 -62
  60. data/app/views/sibu/pages/_group_edit_panel.html.erb +3 -3
  61. data/app/views/sibu/pages/_link_edit_panel.html.erb +50 -50
  62. data/app/views/sibu/pages/_map_edit_panel.html.erb +27 -27
  63. data/app/views/sibu/pages/_media_edit_panel.html.erb +63 -46
  64. data/app/views/sibu/pages/_new_section_panel.html.erb +43 -43
  65. data/app/views/sibu/pages/_paragraph_edit_panel.html.erb +18 -18
  66. data/app/views/sibu/pages/_text_edit_panel.html.erb +19 -19
  67. data/app/views/sibu/pages/child_element.js.erb +6 -6
  68. data/app/views/sibu/pages/clone_element.js.erb +6 -6
  69. data/app/views/sibu/pages/create_section.js.erb +6 -6
  70. data/app/views/sibu/pages/delete_element.js.erb +6 -6
  71. data/app/views/sibu/pages/delete_section.js.erb +6 -6
  72. data/app/views/sibu/pages/destroy.html.erb +2 -2
  73. data/app/views/sibu/pages/edit.html.erb +8 -8
  74. data/app/views/sibu/pages/edit_content.html.erb +3 -3
  75. data/app/views/sibu/pages/edit_element.js.erb +105 -100
  76. data/app/views/sibu/pages/edit_section.js.erb +7 -7
  77. data/app/views/sibu/pages/index.html.erb +40 -40
  78. data/app/views/sibu/pages/new.html.erb +8 -8
  79. data/app/views/sibu/pages/new_section.js.erb +19 -19
  80. data/app/views/sibu/pages/show.html.erb +3 -3
  81. data/app/views/sibu/pages/update.html.erb +2 -2
  82. data/app/views/sibu/pages/update_element.js.erb +5 -5
  83. data/app/views/sibu/pages/update_section.js.erb +5 -5
  84. data/app/views/sibu/sites/_form.html.erb +125 -125
  85. data/app/views/sibu/sites/destroy.html.erb +2 -2
  86. data/app/views/sibu/sites/edit.html.erb +9 -9
  87. data/app/views/sibu/sites/edit_styles.html.erb +8 -8
  88. data/app/views/sibu/sites/index.html.erb +41 -41
  89. data/app/views/sibu/sites/new.html.erb +18 -18
  90. data/app/views/sibu/sites/update.html.erb +2 -2
  91. data/config/initializers/constants.rb +2 -2
  92. data/config/initializers/shrine.rb +18 -18
  93. data/config/routes.rb +30 -30
  94. data/config/tinymce.yml +5 -5
  95. data/db/migrate/20180124095041_create_sibu_sites.rb +12 -12
  96. data/db/migrate/20180124095213_create_sibu_pages.rb +15 -15
  97. data/db/migrate/20180124145030_create_sibu_site_templates.rb +10 -10
  98. data/db/migrate/20180125231638_add_user_id_to_sites.rb +5 -5
  99. data/db/migrate/20180126114522_rename_url_to_path_in_pages.rb +5 -5
  100. data/db/migrate/20180126114628_add_domain_to_sites.rb +5 -5
  101. data/db/migrate/20180127211533_create_sibu_images.rb +11 -11
  102. data/db/migrate/20180208082317_rename_images_user_id_to_site_id.rb +5 -5
  103. data/db/migrate/20180208125024_rename_image_data_column.rb +5 -5
  104. data/db/migrate/20180210181644_add_defaults_to_site_templates.rb +6 -6
  105. data/db/migrate/20180214134653_add_fields_to_sites.rb +5 -5
  106. data/db/migrate/20180227151519_add_default_templates_to_site_templates.rb +5 -5
  107. data/db/migrate/20180301121902_add_style_data_to_sites.rb +5 -5
  108. data/db/migrate/20180301152101_add_default_styles_to_templates.rb +5 -5
  109. data/db/migrate/20180321144021_move_images_to_user_level.rb +7 -7
  110. data/db/migrate/20180321170310_add_version_to_sibu_sites.rb +7 -7
  111. data/db/migrate/20180405095448_create_sibu_documents.rb +10 -10
  112. data/db/migrate/20190110204854_add_custom_data_to_sibu_pages.rb +5 -5
  113. data/lib/sibu.rb +4 -4
  114. data/lib/sibu/engine.rb +19 -19
  115. data/lib/sibu/utils.rb +14 -14
  116. data/lib/sibu/version.rb +3 -3
  117. data/lib/tasks/sibu_tasks.rake +4 -4
  118. metadata +7 -7
@@ -1,16 +1,16 @@
1
- module Sibu
2
- class Document < ApplicationRecord
3
- include DocumentUploader::Attachment.new(:file, cache: :documents_cache, store: :documents_store)
4
- extend Sibu::UserConcern
5
-
6
- validates_presence_of :file_data
7
-
8
- def metadata
9
- JSON.parse(file_data, symbolize_names: true)[:metadata]
10
- end
11
-
12
- def file_name
13
- metadata[:filename]
14
- end
15
- end
16
- end
1
+ module Sibu
2
+ class Document < ApplicationRecord
3
+ include DocumentUploader::Attachment.new(:file, cache: :documents_cache, store: :documents_store)
4
+ extend Sibu::UserConcern
5
+
6
+ validates_presence_of :file_data
7
+
8
+ def metadata
9
+ JSON.parse(file_data, symbolize_names: true)[:metadata]
10
+ end
11
+
12
+ def file_name
13
+ metadata[:filename]
14
+ end
15
+ end
16
+ end
@@ -1,77 +1,77 @@
1
- module Sibu
2
- class DynamicStyle
3
-
4
- attr_reader :site, :body, :env, :filename, :scss_file
5
-
6
- def initialize(site_id)
7
- @site = Sibu::Site.find(site_id)
8
- @filename = "#{site_id}_#{Time.current.to_i}"
9
- @scss_file = File.new(scss_file_path, 'w')
10
- @body = ERB.new(File.read(template_file_path)).result(binding)
11
- @env = Rails.application.assets
12
- end
13
-
14
- def compile
15
- find_or_create_scss
16
-
17
- begin
18
- scss_file.write generate_css
19
- scss_file.flush
20
- scss_file.close
21
- css_file_path = scss_file_path.gsub('scss', 'css')
22
- File.rename(scss_file_path, css_file_path)
23
- site.update(style: File.new(css_file_path))
24
- rescue Exception => ex
25
- Rails.logger.error(ex)
26
- ensure
27
- File.delete(scss_file_path) if scss_file_path && File.exist?(scss_file_path)
28
- File.delete(css_file_path) if css_file_path && File.exist?(css_file_path)
29
- end
30
- end
31
-
32
- def self.refresh_styles
33
- Sibu::Site.all.each do |s|
34
- Sibu::DynamicStyle.new(s.id).compile
35
- end
36
- end
37
-
38
- private
39
-
40
- def template_file_path
41
- @template_file_path ||= File.join(Rails.root, 'lib', 'assets', '_default_template.scss.erb')
42
- end
43
-
44
- def scss_tmpfile_path
45
- @scss_file_path ||= File.join(Rails.root, 'app', 'assets', 'stylesheets', 'templates')
46
- FileUtils.mkdir_p(@scss_file_path) unless File.exists?(@scss_file_path)
47
- @scss_file_path
48
- end
49
-
50
- def scss_file_path
51
- @scss_file_path ||= File.join(scss_tmpfile_path, "#{filename}.scss")
52
- end
53
-
54
- def find_or_create_scss
55
- File.open(scss_file_path, 'w') {|f| f.write(body)}
56
- end
57
-
58
- def generate_css
59
- Sass::Engine.new(asset_source, {
60
- syntax: :scss,
61
- cache: false,
62
- read_cache: false,
63
- style: :compressed
64
- }).render
65
- end
66
-
67
- def asset_source
68
- if env.find_asset(filename)
69
- env.find_asset(filename).source
70
- else
71
- uri = Sprockets::URIUtils.build_asset_uri(scss_file.path, type: "text/css")
72
- asset = Sprockets::UnloadedAsset.new(uri, env)
73
- env.load(asset.uri).source
74
- end
75
- end
76
- end
1
+ module Sibu
2
+ class DynamicStyle
3
+
4
+ attr_reader :site, :body, :env, :filename, :scss_file
5
+
6
+ def initialize(site_id)
7
+ @site = Sibu::Site.find(site_id)
8
+ @filename = "#{site_id}_#{Time.current.to_i}"
9
+ @scss_file = File.new(scss_file_path, 'w')
10
+ @body = ERB.new(File.read(template_file_path)).result(binding)
11
+ @env = Rails.application.assets
12
+ end
13
+
14
+ def compile
15
+ find_or_create_scss
16
+
17
+ begin
18
+ scss_file.write generate_css
19
+ scss_file.flush
20
+ scss_file.close
21
+ css_file_path = scss_file_path.gsub('scss', 'css')
22
+ File.rename(scss_file_path, css_file_path)
23
+ site.update(style: File.new(css_file_path))
24
+ rescue Exception => ex
25
+ Rails.logger.error(ex)
26
+ ensure
27
+ File.delete(scss_file_path) if scss_file_path && File.exist?(scss_file_path)
28
+ File.delete(css_file_path) if css_file_path && File.exist?(css_file_path)
29
+ end
30
+ end
31
+
32
+ def self.refresh_styles
33
+ Sibu::Site.all.each do |s|
34
+ Sibu::DynamicStyle.new(s.id).compile
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def template_file_path
41
+ @template_file_path ||= File.join(Rails.root, 'lib', 'assets', '_default_template.scss.erb')
42
+ end
43
+
44
+ def scss_tmpfile_path
45
+ @scss_file_path ||= File.join(Rails.root, 'app', 'assets', 'stylesheets', 'templates')
46
+ FileUtils.mkdir_p(@scss_file_path) unless File.exists?(@scss_file_path)
47
+ @scss_file_path
48
+ end
49
+
50
+ def scss_file_path
51
+ @scss_file_path ||= File.join(scss_tmpfile_path, "#{filename}.scss")
52
+ end
53
+
54
+ def find_or_create_scss
55
+ File.open(scss_file_path, 'w') {|f| f.write(body)}
56
+ end
57
+
58
+ def generate_css
59
+ Sass::Engine.new(asset_source, {
60
+ syntax: :scss,
61
+ cache: false,
62
+ read_cache: false,
63
+ style: :compressed
64
+ }).render
65
+ end
66
+
67
+ def asset_source
68
+ if env.find_asset(filename)
69
+ env.find_asset(filename).source
70
+ else
71
+ uri = Sprockets::URIUtils.build_asset_uri(scss_file.path, type: "text/css")
72
+ asset = Sprockets::UnloadedAsset.new(uri, env)
73
+ env.load(asset.uri).source
74
+ end
75
+ end
76
+ end
77
77
  end
@@ -1,19 +1,10 @@
1
- module Sibu
2
- class Image < ApplicationRecord
3
- include ImageUploader::Attachment.new(:file)
4
- extend Sibu::UserConcern
5
-
6
- store :metadata, accessors: [:alt, :reference, :credits], coder: JSON
7
-
8
- validates_presence_of :file_data
9
-
10
- def self.empty
11
- empty_img = where("metadata ILIKE '%default_empty_image%'").first
12
- if empty_img.nil?
13
- empty_img = new(reference: 'default_empty_image', file: File.new('app/assets/images/empty.png'))
14
- empty_img.save
15
- end
16
- empty_img
17
- end
18
- end
19
- end
1
+ module Sibu
2
+ class Image < ApplicationRecord
3
+ include ImageUploader::Attachment.new(:file)
4
+ extend Sibu::UserConcern
5
+
6
+ store :metadata, accessors: [:alt, :reference, :credits], coder: JSON
7
+
8
+ validates_presence_of :file_data
9
+ end
10
+ end
@@ -1,66 +1,66 @@
1
- module Sibu
2
- class Page < ApplicationRecord
3
- include Sibu::SectionsConcern
4
-
5
- belongs_to :site, :class_name => 'Sibu::Site'
6
-
7
- store :custom_data, accessors: [:header_code, :footer_code], coder: JSON
8
- store :metadata, accessors: [:title, :description, :keywords, :source, :external_id, :is_home], coder: JSON
9
-
10
- before_save :update_path
11
- validates_presence_of :name, :site
12
-
13
- def self.lookup(domain_name, page_query)
14
- page_path = (page_query || '').strip.split('?')[0]
15
- if page_path.blank?
16
- joins(:site).where("sibu_sites.domain = ? AND COALESCE(sibu_pages.path, '') = ''", domain_name).first
17
- else
18
- paths = page_path.split('/').inject([]) {|p, s| p << (p.length == 0 ? s : "#{p[-1]}/#{s}")}
19
- joins(:site).where("sibu_sites.domain = ? AND COALESCE(sibu_pages.path, '') IN (?)", domain_name, paths)
20
- .order(path: :desc)
21
- .first
22
- end
23
- end
24
-
25
- def save_and_init
26
- if valid?
27
- template_defaults = site.site_template.pages.first
28
- self.sections = template_defaults[:sections] if template_defaults
29
- end
30
- save
31
- end
32
-
33
- def update_path
34
- prefix = site.version == Sibu::Site::DEFAULT_VERSION ? '' : "#{site.version}/"
35
- if is_home == 'true'
36
- self.path = ''
37
- else
38
- self.path = "#{prefix}#{name.parameterize}" if self.path.blank?
39
- end
40
- end
41
-
42
- def site_template
43
- site.site_template
44
- end
45
-
46
- def deep_copy
47
- new_page = deep_dup
48
- new_page.name = name + ' - copie'
49
- new_page
50
- end
51
-
52
- def update_templates(sections_templates)
53
- sections.each do |s|
54
- s["template"] = sections_templates[s["id"]]
55
- end
56
- save
57
- end
58
-
59
- def reorder_sections(*ordered_ids)
60
- if ordered_ids.length == sections.length
61
- self.sections = ordered_ids.map {|section_id| sections.find {|sec| sec["id"] == section_id}}
62
- save
63
- end
64
- end
65
- end
66
- end
1
+ module Sibu
2
+ class Page < ApplicationRecord
3
+ include Sibu::SectionsConcern
4
+
5
+ belongs_to :site, :class_name => 'Sibu::Site'
6
+
7
+ store :custom_data, accessors: [:header_code, :footer_code], coder: JSON
8
+ store :metadata, accessors: [:title, :description, :keywords, :source, :external_id, :is_home], coder: JSON
9
+
10
+ before_save :update_path
11
+ validates_presence_of :name, :site
12
+
13
+ def self.lookup(domain_name, page_query)
14
+ page_path = (page_query || '').strip.split('?')[0]
15
+ if page_path.blank?
16
+ joins(:site).where("sibu_sites.domain = ? AND COALESCE(sibu_pages.path, '') = ''", domain_name).first
17
+ else
18
+ paths = page_path.split('/').inject([]) {|p, s| p << (p.length == 0 ? s : "#{p[-1]}/#{s}")}
19
+ joins(:site).where("sibu_sites.domain = ? AND COALESCE(sibu_pages.path, '') IN (?)", domain_name, paths)
20
+ .order(path: :desc)
21
+ .first
22
+ end
23
+ end
24
+
25
+ def save_and_init
26
+ if valid?
27
+ template_defaults = site.site_template.pages.first
28
+ self.sections = template_defaults[:sections] if template_defaults
29
+ end
30
+ save
31
+ end
32
+
33
+ def update_path
34
+ prefix = site.version == Sibu::Site::DEFAULT_VERSION ? '' : "#{site.version}/"
35
+ if is_home == 'true'
36
+ self.path = ''
37
+ else
38
+ self.path = "#{prefix}#{name.parameterize}" if self.path.blank?
39
+ end
40
+ end
41
+
42
+ def site_template
43
+ site.site_template
44
+ end
45
+
46
+ def deep_copy
47
+ new_page = deep_dup
48
+ new_page.name = name + ' - copie'
49
+ new_page
50
+ end
51
+
52
+ def update_templates(sections_templates)
53
+ sections.each do |s|
54
+ s["template"] = sections_templates[s["id"]]
55
+ end
56
+ save
57
+ end
58
+
59
+ def reorder_sections(*ordered_ids)
60
+ if ordered_ids.length == sections.length
61
+ self.sections = ordered_ids.map {|section_id| sections.find {|sec| sec["id"] == section_id}}
62
+ save
63
+ end
64
+ end
65
+ end
66
+ end
@@ -1,97 +1,97 @@
1
- module Sibu
2
- class Site < ApplicationRecord
3
- include StyleUploader::Attachment.new(:style, cache: :styles_cache, store: :styles_store)
4
- include Sibu::SectionsConcern
5
- extend Sibu::UserConcern
6
-
7
- store :custom_data, accessors: [:primary_font, :secondary_font, :primary_color, :secondary_color, :header_code, :footer_code],
8
- coder: JSON
9
- store :metadata, accessors: [:analytics_id], coder: JSON
10
-
11
- belongs_to :site_template, :class_name => 'Sibu::SiteTemplate'
12
- has_many :pages, :class_name => 'Sibu::Page', dependent: :destroy
13
-
14
- validates_presence_of :name, :site_template, :version
15
-
16
- DEFAULT_VERSION = 'fr'
17
-
18
- def style_url
19
- style ? style.url : site_template.path
20
- end
21
-
22
- def main_color
23
- primary_color.blank? ? site_template.primary_color : primary_color
24
- end
25
-
26
- def alt_color
27
- secondary_color.blank? ? site_template.secondary_color : secondary_color
28
- end
29
-
30
- def main_font
31
- primary_font.blank? ? site_template.primary_font : primary_font
32
- end
33
-
34
- def alt_font
35
- secondary_font.blank? ? site_template.secondary_font : secondary_font
36
- end
37
-
38
- def section_template(section)
39
- "#{site_template.path}/#{section["category"]}/#{section["template"]}"
40
- end
41
-
42
- def not_found
43
- "shared/#{site_template.path}/not_found"
44
- end
45
-
46
- def page(path)
47
- pages.where(path: path).first
48
- end
49
-
50
- def page_by_id(page_id)
51
- pages.where(id: page_id).select(:id, :path).first
52
- end
53
-
54
- def save_and_init
55
- if valid?
56
- self.sections = site_template.sections
57
- site_template.pages.each do |p|
58
- self.pages << Sibu::Page.new(p)
59
- end
60
- self.primary_color = site_template.primary_color
61
- self.secondary_color = site_template.secondary_color
62
- self.primary_font = site_template.primary_font
63
- self.secondary_font = site_template.secondary_font
64
- end
65
- save
66
- end
67
-
68
- def pages_path_by_id
69
- Hash[pages.collect {|p| [p.id.to_s, p.path]}]
70
- end
71
-
72
- def init_pages(source)
73
- site_data = Rails.application.config.sibu[:site_data][source]
74
- site_data.pages.each do |p|
75
- self.pages << Sibu::Page.new(p)
76
- end
77
- save!
78
- end
79
-
80
- def init_sections(source)
81
- site_data = Rails.application.config.sibu[:site_data][source]
82
- self.sections = site_data.sections(self)
83
- save!
84
- end
85
-
86
- def deep_copy
87
- site_copy = deep_dup
88
- pages.each do |p|
89
- site_copy.name = name + ' - copie'
90
- site_copy.domain = nil
91
- site_copy.pages << p.deep_dup
92
- end
93
-
94
- site_copy
95
- end
96
- end
97
- end
1
+ module Sibu
2
+ class Site < ApplicationRecord
3
+ include StyleUploader::Attachment.new(:style, cache: :styles_cache, store: :styles_store)
4
+ include Sibu::SectionsConcern
5
+ extend Sibu::UserConcern
6
+
7
+ store :custom_data, accessors: [:primary_font, :secondary_font, :primary_color, :secondary_color, :header_code, :footer_code],
8
+ coder: JSON
9
+ store :metadata, accessors: [:analytics_id], coder: JSON
10
+
11
+ belongs_to :site_template, :class_name => 'Sibu::SiteTemplate'
12
+ has_many :pages, :class_name => 'Sibu::Page', dependent: :destroy
13
+
14
+ validates_presence_of :name, :site_template, :version
15
+
16
+ DEFAULT_VERSION = 'fr'
17
+
18
+ def style_url
19
+ style ? style.url : site_template.path
20
+ end
21
+
22
+ def main_color
23
+ primary_color.blank? ? site_template.primary_color : primary_color
24
+ end
25
+
26
+ def alt_color
27
+ secondary_color.blank? ? site_template.secondary_color : secondary_color
28
+ end
29
+
30
+ def main_font
31
+ primary_font.blank? ? site_template.primary_font : primary_font
32
+ end
33
+
34
+ def alt_font
35
+ secondary_font.blank? ? site_template.secondary_font : secondary_font
36
+ end
37
+
38
+ def section_template(section)
39
+ "#{site_template.path}/#{section["category"]}/#{section["template"]}"
40
+ end
41
+
42
+ def not_found
43
+ "shared/#{site_template.path}/not_found"
44
+ end
45
+
46
+ def page(path)
47
+ pages.where(path: path).first
48
+ end
49
+
50
+ def page_by_id(page_id)
51
+ pages.where(id: page_id).select(:id, :path).first
52
+ end
53
+
54
+ def save_and_init
55
+ if valid?
56
+ self.sections = site_template.sections
57
+ site_template.pages.each do |p|
58
+ self.pages << Sibu::Page.new(p)
59
+ end
60
+ self.primary_color = site_template.primary_color
61
+ self.secondary_color = site_template.secondary_color
62
+ self.primary_font = site_template.primary_font
63
+ self.secondary_font = site_template.secondary_font
64
+ end
65
+ save
66
+ end
67
+
68
+ def pages_path_by_id
69
+ Hash[pages.collect {|p| [p.id.to_s, p.path]}]
70
+ end
71
+
72
+ def init_pages(source)
73
+ site_data = Rails.application.config.sibu[:site_data][source]
74
+ site_data.pages.each do |p|
75
+ self.pages << Sibu::Page.new(p)
76
+ end
77
+ save!
78
+ end
79
+
80
+ def init_sections(source)
81
+ site_data = Rails.application.config.sibu[:site_data][source]
82
+ self.sections = site_data.sections(self)
83
+ save!
84
+ end
85
+
86
+ def deep_copy
87
+ site_copy = deep_dup
88
+ pages.each do |p|
89
+ site_copy.name = name + ' - copie'
90
+ site_copy.domain = nil
91
+ site_copy.pages << p.deep_dup
92
+ end
93
+
94
+ site_copy
95
+ end
96
+ end
97
+ end