sibu 0.2.5 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/images/sibu/empty.png +0 -0
  3. data/app/assets/javascripts/cropper/cropper.js +3695 -0
  4. data/app/assets/javascripts/sibu/sibu.js.erb +25 -0
  5. data/app/assets/stylesheets/cropper/cropper.css +305 -0
  6. data/app/assets/stylesheets/sibu/sibu.css +1 -0
  7. data/app/controllers/sibu/application_controller.rb +4 -0
  8. data/app/controllers/sibu/images_controller.rb +7 -11
  9. data/app/controllers/sibu/pages_controller.rb +14 -4
  10. data/app/controllers/sibu/sites_controller.rb +13 -3
  11. data/app/helpers/sibu/application_helper.rb +4 -0
  12. data/app/helpers/sibu/pages_helper.rb +1 -9
  13. data/app/helpers/sibu/sites_helper.rb +8 -4
  14. data/app/models/concerns/sibu/image_uploader.rb +2 -2
  15. data/app/models/concerns/sibu/user_concern.rb +9 -0
  16. data/app/models/sibu/image.rb +12 -4
  17. data/app/models/sibu/page.rb +12 -1
  18. data/app/models/sibu/site.rb +19 -2
  19. data/app/views/sibu/images/_edit_form.html.erb +4 -4
  20. data/app/views/sibu/images/_form.html.erb +2 -2
  21. data/app/views/sibu/images/index.html.erb +3 -3
  22. data/app/views/sibu/images/new.html.erb +4 -0
  23. data/app/views/sibu/pages/_form.html.erb +0 -7
  24. data/app/views/sibu/pages/_media_edit_panel.html.erb +24 -12
  25. data/app/views/sibu/pages/edit_element.js.erb +54 -39
  26. data/app/views/sibu/pages/index.html.erb +1 -0
  27. data/app/views/sibu/pages/update_element.js.erb +1 -1
  28. data/app/views/sibu/sites/_form.html.erb +35 -13
  29. data/app/views/sibu/sites/edit.html.erb +1 -0
  30. data/app/views/sibu/sites/index.html.erb +4 -1
  31. data/config/routes.rb +4 -2
  32. data/db/migrate/20180321144021_move_images_to_user_level.rb +7 -0
  33. data/db/migrate/20180321170310_add_version_to_sibu_sites.rb +7 -0
  34. data/lib/sibu/version.rb +1 -1
  35. metadata +8 -3
  36. data/app/views/sibu/pages/_custom_styles.html.erb +0 -23
@@ -2,6 +2,7 @@
2
2
  //= require jquery_ujs
3
3
  //= require sibu/common
4
4
  //= require ../quill/quill
5
+ //= require ../cropper/cropper
5
6
  //= require_self
6
7
 
7
8
  var Inline = Quill.import('blots/inline');
@@ -77,3 +78,27 @@ function initQuillEditor(container) {
77
78
 
78
79
  return quill;
79
80
  }
81
+
82
+
83
+ function initCropper(imgId) {
84
+ var wrapper = $(".sibu_crop").first();
85
+ var srcImg = $("#content_panel").find(".sb-editing img[data-id='" + imgId + "']").first();
86
+ var srcContainer = srcImg.parent();
87
+ var ratio = parseFloat(srcContainer.css("width")) / parseFloat(wrapper.css("width"));
88
+ wrapper.css("height", (parseFloat(srcContainer.css("height")) / ratio) + "px");
89
+ var cropper = new Cropper(wrapper.find("img")[0], {
90
+ crop: function(event) {
91
+ var data = event.detail;
92
+ var cropper = this.cropper;
93
+ var imageData = cropper.getImageData();
94
+ var previewWidth = parseFloat(srcContainer.css("width"));
95
+ var imageScaledRatio = data.width / previewWidth;
96
+ var width = imageData.naturalWidth / imageScaledRatio + 'px';
97
+ var height = imageData.naturalHeight / imageScaledRatio + 'px';
98
+ var marginLeft = -data.x / imageScaledRatio + 'px';
99
+ var marginTop = -data.y / imageScaledRatio + 'px';
100
+
101
+ $("#element_style").val("width: " + width + "; height: " + height + "; margin-left: " + marginLeft + "; margin-top: " + marginTop +"; max-width: none; max-height: none;");
102
+ }
103
+ });
104
+ }
@@ -0,0 +1,305 @@
1
+ /*!
2
+ * Cropper.js v1.3.3
3
+ * https://github.com/fengyuanchen/cropperjs
4
+ *
5
+ * Copyright (c) 2015-2018 Chen Fengyuan
6
+ * Released under the MIT license
7
+ *
8
+ * Date: 2018-03-18T03:19:07.619Z
9
+ */
10
+
11
+ .cropper-container {
12
+ direction: ltr;
13
+ font-size: 0;
14
+ line-height: 0;
15
+ position: relative;
16
+ -ms-touch-action: none;
17
+ touch-action: none;
18
+ -webkit-user-select: none;
19
+ -moz-user-select: none;
20
+ -ms-user-select: none;
21
+ user-select: none;
22
+ }
23
+
24
+ .cropper-container img {/*Avoid margin top issue (Occur only when margin-top <= -height)
25
+ */
26
+ display: block;
27
+ height: 100%;
28
+ image-orientation: 0deg;
29
+ max-height: none !important;
30
+ max-width: none !important;
31
+ min-height: 0 !important;
32
+ min-width: 0 !important;
33
+ width: 100%;
34
+ }
35
+
36
+ .cropper-wrap-box,
37
+ .cropper-canvas,
38
+ .cropper-drag-box,
39
+ .cropper-crop-box,
40
+ .cropper-modal {
41
+ bottom: 0;
42
+ left: 0;
43
+ position: absolute;
44
+ right: 0;
45
+ top: 0;
46
+ }
47
+
48
+ .cropper-wrap-box,
49
+ .cropper-canvas {
50
+ overflow: hidden;
51
+ }
52
+
53
+ .cropper-drag-box {
54
+ background-color: #fff;
55
+ opacity: 0;
56
+ }
57
+
58
+ .cropper-modal {
59
+ background-color: #000;
60
+ opacity: .5;
61
+ }
62
+
63
+ .cropper-view-box {
64
+ display: block;
65
+ height: 100%;
66
+ outline-color: rgba(51, 153, 255, 0.75);
67
+ outline: 1px solid #39f;
68
+ overflow: hidden;
69
+ width: 100%;
70
+ }
71
+
72
+ .cropper-dashed {
73
+ border: 0 dashed #eee;
74
+ display: block;
75
+ opacity: .5;
76
+ position: absolute;
77
+ }
78
+
79
+ .cropper-dashed.dashed-h {
80
+ border-bottom-width: 1px;
81
+ border-top-width: 1px;
82
+ height: 33.33333%;
83
+ left: 0;
84
+ top: 33.33333%;
85
+ width: 100%;
86
+ }
87
+
88
+ .cropper-dashed.dashed-v {
89
+ border-left-width: 1px;
90
+ border-right-width: 1px;
91
+ height: 100%;
92
+ left: 33.33333%;
93
+ top: 0;
94
+ width: 33.33333%;
95
+ }
96
+
97
+ .cropper-center {
98
+ display: block;
99
+ height: 0;
100
+ left: 50%;
101
+ opacity: .75;
102
+ position: absolute;
103
+ top: 50%;
104
+ width: 0;
105
+ }
106
+
107
+ .cropper-center:before,
108
+ .cropper-center:after {
109
+ background-color: #eee;
110
+ content: ' ';
111
+ display: block;
112
+ position: absolute;
113
+ }
114
+
115
+ .cropper-center:before {
116
+ height: 1px;
117
+ left: -3px;
118
+ top: 0;
119
+ width: 7px;
120
+ }
121
+
122
+ .cropper-center:after {
123
+ height: 7px;
124
+ left: 0;
125
+ top: -3px;
126
+ width: 1px;
127
+ }
128
+
129
+ .cropper-face,
130
+ .cropper-line,
131
+ .cropper-point {
132
+ display: block;
133
+ height: 100%;
134
+ opacity: .1;
135
+ position: absolute;
136
+ width: 100%;
137
+ }
138
+
139
+ .cropper-face {
140
+ background-color: #fff;
141
+ left: 0;
142
+ top: 0;
143
+ }
144
+
145
+ .cropper-line {
146
+ background-color: #39f;
147
+ }
148
+
149
+ .cropper-line.line-e {
150
+ cursor: ew-resize;
151
+ right: -3px;
152
+ top: 0;
153
+ width: 5px;
154
+ }
155
+
156
+ .cropper-line.line-n {
157
+ cursor: ns-resize;
158
+ height: 5px;
159
+ left: 0;
160
+ top: -3px;
161
+ }
162
+
163
+ .cropper-line.line-w {
164
+ cursor: ew-resize;
165
+ left: -3px;
166
+ top: 0;
167
+ width: 5px;
168
+ }
169
+
170
+ .cropper-line.line-s {
171
+ bottom: -3px;
172
+ cursor: ns-resize;
173
+ height: 5px;
174
+ left: 0;
175
+ }
176
+
177
+ .cropper-point {
178
+ background-color: #39f;
179
+ height: 5px;
180
+ opacity: .75;
181
+ width: 5px;
182
+ }
183
+
184
+ .cropper-point.point-e {
185
+ cursor: ew-resize;
186
+ margin-top: -3px;
187
+ right: -3px;
188
+ top: 50%;
189
+ }
190
+
191
+ .cropper-point.point-n {
192
+ cursor: ns-resize;
193
+ left: 50%;
194
+ margin-left: -3px;
195
+ top: -3px;
196
+ }
197
+
198
+ .cropper-point.point-w {
199
+ cursor: ew-resize;
200
+ left: -3px;
201
+ margin-top: -3px;
202
+ top: 50%;
203
+ }
204
+
205
+ .cropper-point.point-s {
206
+ bottom: -3px;
207
+ cursor: s-resize;
208
+ left: 50%;
209
+ margin-left: -3px;
210
+ }
211
+
212
+ .cropper-point.point-ne {
213
+ cursor: nesw-resize;
214
+ right: -3px;
215
+ top: -3px;
216
+ }
217
+
218
+ .cropper-point.point-nw {
219
+ cursor: nwse-resize;
220
+ left: -3px;
221
+ top: -3px;
222
+ }
223
+
224
+ .cropper-point.point-sw {
225
+ bottom: -3px;
226
+ cursor: nesw-resize;
227
+ left: -3px;
228
+ }
229
+
230
+ .cropper-point.point-se {
231
+ bottom: -3px;
232
+ cursor: nwse-resize;
233
+ height: 20px;
234
+ opacity: 1;
235
+ right: -3px;
236
+ width: 20px;
237
+ }
238
+
239
+ @media (min-width: 768px) {
240
+ .cropper-point.point-se {
241
+ height: 15px;
242
+ width: 15px;
243
+ }
244
+ }
245
+
246
+ @media (min-width: 992px) {
247
+ .cropper-point.point-se {
248
+ height: 10px;
249
+ width: 10px;
250
+ }
251
+ }
252
+
253
+ @media (min-width: 1200px) {
254
+ .cropper-point.point-se {
255
+ height: 5px;
256
+ opacity: .75;
257
+ width: 5px;
258
+ }
259
+ }
260
+
261
+ .cropper-point.point-se:before {
262
+ background-color: #39f;
263
+ bottom: -50%;
264
+ content: ' ';
265
+ display: block;
266
+ height: 200%;
267
+ opacity: 0;
268
+ position: absolute;
269
+ right: -50%;
270
+ width: 200%;
271
+ }
272
+
273
+ .cropper-invisible {
274
+ opacity: 0;
275
+ }
276
+
277
+ .cropper-bg {
278
+ background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAAA3NCSVQICAjb4U/gAAAABlBMVEXMzMz////TjRV2AAAACXBIWXMAAArrAAAK6wGCiw1aAAAAHHRFWHRTb2Z0d2FyZQBBZG9iZSBGaXJld29ya3MgQ1M26LyyjAAAABFJREFUCJlj+M/AgBVhF/0PAH6/D/HkDxOGAAAAAElFTkSuQmCC');
279
+ }
280
+
281
+ .cropper-hide {
282
+ display: block;
283
+ height: 0;
284
+ position: absolute;
285
+ width: 0;
286
+ }
287
+
288
+ .cropper-hidden {
289
+ display: none !important;
290
+ }
291
+
292
+ .cropper-move {
293
+ cursor: move;
294
+ }
295
+
296
+ .cropper-crop {
297
+ cursor: crosshair;
298
+ }
299
+
300
+ .cropper-disabled .cropper-drag-box,
301
+ .cropper-disabled .cropper-face,
302
+ .cropper-disabled .cropper-line,
303
+ .cropper-disabled .cropper-point {
304
+ cursor: not-allowed;
305
+ }
@@ -1,5 +1,6 @@
1
1
  /*
2
2
  *= require ../quill/quill.snow
3
+ *= require ../cropper/cropper
3
4
  *= require_self
4
5
  */
5
6
 
@@ -2,5 +2,9 @@ module Sibu
2
2
  class ApplicationController < ActionController::Base
3
3
  protect_from_forgery with: :exception
4
4
  before_action Rails.application.config.sibu[:auth_filter]
5
+
6
+ def sibu_user
7
+ send(Rails.application.config.sibu[:current_user])
8
+ end
5
9
  end
6
10
  end
@@ -2,23 +2,23 @@ require_dependency "sibu/application_controller"
2
2
 
3
3
  module Sibu
4
4
  class ImagesController < ApplicationController
5
- before_action :set_site, only: [:index, :new, :create, :edit, :update, :destroy]
6
5
  before_action :set_image, only: [:edit, :update, :destroy]
7
6
  before_action :set_edition_context, only: [:new, :create]
8
7
 
9
8
  def index
10
- @images = Sibu::Image.where(site_id: params[:site_id])
9
+ @images = Sibu::Image.for_user(sibu_user)
11
10
  end
12
11
 
13
12
  def new
14
- @image = Sibu::Image.new(site_id: @site.id)
13
+ @image = Sibu::Image.new(user_id: send(Rails.application.config.sibu[:current_user]).id)
15
14
  end
16
15
 
17
16
  def create
18
17
  @image = Sibu::Image.new(image_params)
19
18
  if @image.save
20
19
  if !@page_id.blank? && !@section_id.blank? && !@element_id.blank? && !@size.blank?
21
- entity = @entity_type == 'site' ? @site : Sibu::Page.find(@page_id)
20
+ p = Sibu::Page.find(@page_id)
21
+ entity = @entity_type == 'site' ? p.site : p
22
22
  ids = (@section_id.split('|') + @element_id.split('|')).uniq[0...-1]
23
23
  elt = entity.update_element(*ids, {"id" => @img_id, "src" => @image.file_url(@size.to_sym), "alt" => @image.alt})
24
24
  if elt.nil?
@@ -28,7 +28,7 @@ module Sibu
28
28
  end
29
29
  redirect_to site_page_edit_content_path(@site.id, @page_id), msg
30
30
  else
31
- redirect_to site_images_url(@image.site_id), notice: "L'image a bien été téléchargée."
31
+ redirect_to images_url, notice: "L'image a bien été téléchargée."
32
32
  end
33
33
  else
34
34
  flash.now[:alert] = "Une erreur s'est produite lors du téléchargement de l'image."
@@ -44,7 +44,7 @@ module Sibu
44
44
 
45
45
  def update
46
46
  if @image.update(image_params)
47
- redirect_to site_images_url(@site.id), notice: "L'image a bien été mise à jour."
47
+ redirect_to images_url, notice: "L'image a bien été mise à jour."
48
48
  else
49
49
  flash.now[:alert] = "Une erreur s'est produite lors de l'enregistrement de l'image."
50
50
  render :index
@@ -53,15 +53,11 @@ module Sibu
53
53
 
54
54
  def destroy
55
55
  @image.destroy
56
- redirect_to site_images_url(@site.id), notice: "L'image a bien été supprimée."
56
+ redirect_to images_url, notice: "L'image a bien été supprimée."
57
57
  end
58
58
 
59
59
  private
60
60
 
61
- def set_site
62
- @site = Sibu::Site.find(params[:site_id])
63
- end
64
-
65
61
  def set_image
66
62
  @image = Sibu::Image.find(params[:id])
67
63
  end
@@ -2,7 +2,7 @@ require_dependency "sibu/application_controller"
2
2
 
3
3
  module Sibu
4
4
  class PagesController < ApplicationController
5
- before_action :set_page, only: [:edit, :update, :destroy, :edit_element, :update_element, :clone_element,
5
+ before_action :set_page, only: [:edit, :update, :destroy, :duplicate, :edit_element, :update_element, :clone_element,
6
6
  :delete_element, :child_element, :new_section, :create_section, :delete_section]
7
7
  before_action :set_site, only: [:index, :new]
8
8
  before_action :set_edit_context, only: [:edit_element, :update_element, :clone_element, :delete_element,
@@ -15,9 +15,9 @@ module Sibu
15
15
 
16
16
  def show
17
17
  if params[:site_id].blank?
18
- @site = Sibu::Site.find_by_domain(request.domain)
19
- if @site
20
- @page = @site.page(params[:path])
18
+ page = Page.lookup(request.domain, params[:path])
19
+ if page
20
+ @site = page.site
21
21
  @links = @site.pages_path_by_id
22
22
  view_template = @page ? 'show' : @site.not_found
23
23
  else
@@ -62,6 +62,16 @@ module Sibu
62
62
  def destroy
63
63
  end
64
64
 
65
+ def duplicate
66
+ new_page = @page.deep_copy
67
+ if new_page.save
68
+ redirect_to site_pages_url(@page.site_id), notice: "La page a bien été copiée."
69
+ else
70
+ flash.now[:alert] = "Une erreur s'est produite lors de la copie de la page."
71
+ render :index
72
+ end
73
+ end
74
+
65
75
  def edit_content
66
76
  @page = Sibu::Page.find(params[:page_id])
67
77
  @site = Sibu::Site.includes(:pages).find(@page.site_id) if @page
@@ -2,11 +2,11 @@ require_dependency "sibu/application_controller"
2
2
 
3
3
  module Sibu
4
4
  class SitesController < ApplicationController
5
- before_action :set_site, only: [:show, :edit, :update, :destroy]
5
+ before_action :set_site, only: [:show, :edit, :update, :destroy, :duplicate]
6
6
  skip_before_action Rails.application.config.sibu[:auth_filter], only: [:show]
7
7
 
8
8
  def index
9
- @sites = Sibu::Site.where(user_id: send(Rails.application.config.sibu[:current_user]).id)
9
+ @sites = Sibu::Site.for_user(sibu_user).order(:name, :version)
10
10
  end
11
11
 
12
12
  def show
@@ -15,7 +15,7 @@ module Sibu
15
15
  end
16
16
 
17
17
  def new
18
- @site = Sibu::Site.new(user_id: send(Rails.application.config.sibu[:current_user]).id)
18
+ @site = Sibu::Site.new(user_id: sibu_user.id, version: Sibu::Site::DEFAULT_VERSION)
19
19
  end
20
20
 
21
21
  def create
@@ -50,6 +50,16 @@ module Sibu
50
50
  redirect_to sites_url, notice: "Le site a bien été supprimé."
51
51
  end
52
52
 
53
+ def duplicate
54
+ new_site = @site.deep_copy
55
+ if new_site.save
56
+ redirect_to sites_url, notice: "Le site a bien été copié."
57
+ else
58
+ flash.now[:alert] = "Une erreur s'est produite lors de la copie du site."
59
+ render :index
60
+ end
61
+ end
62
+
53
63
  private
54
64
 
55
65
  def set_site
@@ -3,5 +3,9 @@ module Sibu
3
3
  def conf
4
4
  Rails.application.config.sibu
5
5
  end
6
+
7
+ def sibu_user
8
+ send(Rails.application.config.sibu[:current_user])
9
+ end
6
10
  end
7
11
  end
@@ -7,20 +7,12 @@ module Sibu
7
7
  p ? (@site.domain.blank? ? site_page_path(@site.id, p.id) : "/#{p.path}") : "#"
8
8
  end
9
9
 
10
- def page_templates
11
- [['Accueil', 'home'], ['Offre', 'offer'], ['Galerie', 'gallery'], ['Destination', 'destination'], ['Mentions légales', 'text']]
12
- end
13
-
14
10
  def sections_templates
15
11
  @site.site_template.available_templates
16
12
  end
17
13
 
18
- def page_languages
19
- [['Français', 'fr'], ['Anglais', 'en']]
20
- end
21
-
22
14
  def site_images
23
- Sibu::Image.shared + @site.images
15
+ ([Sibu::Image.empty] + Sibu::Image.shared + Sibu::Image.for_user(sibu_user)).uniq
24
16
  end
25
17
 
26
18
  def available_links
@@ -1,19 +1,23 @@
1
1
  module Sibu
2
2
  module SitesHelper
3
3
  def primary_colors
4
- Rails.application.config.sibu[:primary_colors]
4
+ ([@site.site_template.primary_color] + Rails.application.config.sibu[:primary_colors]).uniq
5
5
  end
6
6
 
7
7
  def secondary_colors
8
- Rails.application.config.sibu[:secondary_colors]
8
+ ([@site.site_template.secondary_color] + Rails.application.config.sibu[:secondary_colors]).uniq
9
9
  end
10
10
 
11
11
  def primary_fonts
12
- [''] + Rails.application.config.sibu[:primary_fonts]
12
+ ([@site.site_template.primary_font] + Rails.application.config.sibu[:primary_fonts]).uniq.map.each_with_index {|f, i| [i == 0 ? (f + ' (par défaut)') : f, f]}
13
13
  end
14
14
 
15
15
  def secondary_fonts
16
- [''] + Rails.application.config.sibu[:secondary_fonts]
16
+ ([@site.site_template.secondary_font] + Rails.application.config.sibu[:secondary_fonts]).uniq.map.each_with_index {|f, i| [i == 0 ? (f + ' (par défaut)') : f, f]}
17
+ end
18
+
19
+ def site_versions
20
+ [['Français (par défaut)', 'fr'], ['Anglais', 'en']]
17
21
  end
18
22
  end
19
23
  end
@@ -18,10 +18,10 @@ class Sibu::ImageUploader < Shrine
18
18
  end
19
19
 
20
20
  def generate_location(io, context)
21
- site_id = context[:record].site_id
21
+ user_id = context[:record].user_id
22
22
  style = context[:version] != :original ? "resized" : "originals"
23
23
  name = super
24
24
 
25
- [site_id, style, name].compact.join("/")
25
+ [user_id, style, name].compact.join("/")
26
26
  end
27
27
  end
@@ -0,0 +1,9 @@
1
+ module Sibu
2
+ module UserConcern
3
+ include ActiveSupport::Concern
4
+
5
+ def for_user(usr)
6
+ where(user_id: usr.id)
7
+ end
8
+ end
9
+ end
@@ -1,15 +1,23 @@
1
1
  module Sibu
2
2
  class Image < ApplicationRecord
3
3
  include ImageUploader::Attachment.new(:file)
4
+ extend Sibu::UserConcern
4
5
 
5
- belongs_to :site, :class_name => 'Sibu::Site', optional: true
6
-
7
- store :metadata, accessors: [:alt], coder: JSON
6
+ store :metadata, accessors: [:alt, :reference], coder: JSON
8
7
 
9
8
  validates_presence_of :file_data
10
9
 
11
10
  def self.shared
12
- where(site_id: nil)
11
+ where(user_id: nil)
12
+ end
13
+
14
+ def self.empty
15
+ empty_img = where("metadata ILIKE '%default_empty_image%'").first
16
+ if empty_img.nil?
17
+ empty_img = new(reference: 'default_empty_image', file: File.new('app/assets/images/empty.png'))
18
+ empty_img.save
19
+ end
20
+ empty_img
13
21
  end
14
22
  end
15
23
  end
@@ -7,7 +7,12 @@ module Sibu
7
7
  store :metadata, accessors: [:title, :description, :keywords], coder: JSON
8
8
 
9
9
  before_save :update_path
10
- validates_presence_of :name, :site, :language
10
+ validates_presence_of :name, :site
11
+
12
+ def self.lookup(domain_name, page_path)
13
+ joins(:site).where("sibu_sites.domain = ? AND ((sibu_sites.version = ? AND sibu_pages.path = ?) OR sibu_pages.path = LTRIM(REPLACE(?, sibu_sites.version, ''), '/'))",
14
+ domain_name, Sibu::Site::DEFAULT_VERSION, page_path, page_path).first
15
+ end
11
16
 
12
17
  def save_and_init
13
18
  if valid?
@@ -25,5 +30,11 @@ module Sibu
25
30
  def site_template
26
31
  site.site_template
27
32
  end
33
+
34
+ def deep_copy
35
+ new_page = deep_dup
36
+ new_page.name = name + ' - copie'
37
+ new_page
38
+ end
28
39
  end
29
40
  end
@@ -2,15 +2,17 @@ module Sibu
2
2
  class Site < ApplicationRecord
3
3
  include StyleUploader::Attachment.new(:style, cache: :styles_cache, store: :styles_store)
4
4
  include Sibu::SectionsConcern
5
+ extend Sibu::UserConcern
5
6
 
6
7
  store :custom_data, accessors: [:primary_font, :secondary_font, :primary_color, :secondary_color], coder: JSON
7
8
  store :metadata, accessors: [:analytics_id], coder: JSON
8
9
 
9
10
  belongs_to :site_template, :class_name => 'Sibu::SiteTemplate'
10
11
  has_many :pages, :class_name => 'Sibu::Page', dependent: :destroy
11
- has_many :images, :class_name => 'Sibu::Image', dependent: :destroy
12
12
 
13
- validates_presence_of :name, :site_template
13
+ validates_presence_of :name, :site_template, :version
14
+
15
+ DEFAULT_VERSION = 'fr'
14
16
 
15
17
  def style_url
16
18
  style ? style.url : site_template.path
@@ -54,6 +56,10 @@ module Sibu
54
56
  site_template.pages.each do |p|
55
57
  self.pages << Sibu::Page.new(p)
56
58
  end
59
+ self.primary_color = site_template.primary_color
60
+ self.secondary_color = site_template.secondary_color
61
+ self.primary_font = site_template.primary_font
62
+ self.secondary_font = site_template.secondary_font
57
63
  end
58
64
  save
59
65
  end
@@ -75,5 +81,16 @@ module Sibu
75
81
  self.sections = site_data.sections(self)
76
82
  save!
77
83
  end
84
+
85
+ def deep_copy
86
+ site_copy = deep_dup
87
+ pages.each do |p|
88
+ site_copy.name = name + ' - copie'
89
+ site_copy.domain = nil
90
+ site_copy.pages << p.deep_dup
91
+ end
92
+
93
+ site_copy
94
+ end
78
95
  end
79
96
  end