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,197 +1,197 @@
1
- require_dependency "sibu/application_controller"
2
-
3
- module Sibu
4
- class PagesController < ApplicationController
5
- before_action :set_page, only: [:edit, :update, :destroy, :duplicate, :edit_element, :update_element, :clone_element,
6
- :delete_element, :child_element, :new_section, :create_section, :edit_section,
7
- :update_section, :delete_section]
8
- before_action :set_site, only: [:index, :new]
9
- before_action :set_edit_context, only: [:edit_element, :update_element, :clone_element, :delete_element,
10
- :child_element, :new_section, :create_section, :edit_section,
11
- :update_section, :delete_section]
12
- before_action :set_online, only: [:show, :edit]
13
- skip_before_action Rails.application.config.sibu[:auth_filter], only: [:show]
14
-
15
- def index
16
- @pages = @site.pages.order(:created_at)
17
- end
18
-
19
- def show
20
- return_code = :ok
21
- if params[:site_id].blank?
22
- @page = Sibu::Page.lookup(request.host, params[:path])
23
- if @page
24
- @query_path = params[:path][@page.path.length + 1..-1] unless @page.path.blank?
25
- @query_params = show_params.except(:controller, :action, :path).to_h
26
- @site = @page.site
27
- @links = @site.pages_path_by_id
28
- view_template = 'show'
29
- else
30
- @site = Sibu::Site.where(domain: request.host).first
31
- view_template = Rails.application.config.sibu[:not_found]
32
- return_code = :not_found
33
- end
34
- else
35
- @site = Sibu::Site.find(params[:site_id])
36
- @page = Sibu::Page.find(params[:id])
37
- @links = @site.pages_path_by_id
38
- @query_path = params[:path]
39
- @query_params = show_params.except(:controller, :action, :path).to_h
40
- view_template = 'show'
41
- end
42
-
43
- render view_template, layout: 'sibu/site', status: return_code
44
- end
45
-
46
- def new
47
- @page = Sibu::Page.new(site_id: @site.id)
48
- end
49
-
50
- def create
51
- @page = Sibu::Page.new(page_params)
52
- if @page.save_and_init
53
- redirect_to site_pages_url(@page.site_id), notice: "La page a bien été créée."
54
- else
55
- flash.now[:alert] = "Une erreur s'est produite lors de la création de la page."
56
- render :new
57
- end
58
- end
59
-
60
- def edit
61
- end
62
-
63
- def update
64
- if @page.update(page_params)
65
- redirect_to site_pages_url(@page.site_id), notice: "La page a bien été mise à jour."
66
- else
67
- flash.now[:alert] = "Une erreur s'est produite lors de l'enregistrement de la page."
68
- render :edit
69
- end
70
- end
71
-
72
- def destroy
73
- site_id = @page.site_id
74
- if @page.destroy
75
- redirect_to site_pages_url(site_id), notice: "La page a bien été supprimée."
76
- else
77
- flash.now[:alert] = "Une erreur s'est produite lors de la suppression de la page."
78
- render :index
79
- end
80
- end
81
-
82
- def duplicate
83
- new_page = @page.deep_copy
84
- if new_page.save
85
- redirect_to site_pages_url(@page.site_id), notice: "La page a bien été copiée."
86
- else
87
- flash.now[:alert] = "Une erreur s'est produite lors de la copie de la page."
88
- render :index
89
- end
90
- end
91
-
92
- def edit_content
93
- @page = Sibu::Page.find(params[:page_id])
94
- @site = Sibu::Site.includes(:pages).find(@page.site_id) if @page
95
- @links = @site.pages_path_by_id if @site
96
- @edit_section = params[:edit_section]
97
- render :edit_content, layout: 'sibu/edit_content'
98
- end
99
-
100
- def edit_element
101
- @content_type = params[:content_type]
102
- @links = @site.pages_path_by_id if @site
103
- @element = @entity.element(*@section_id.split('|'), *@element_id.split('|'))
104
- @repeat = params[:repeat]
105
- @size = params[:size].blank? ? :medium : params[:size].to_sym
106
- @children = params[:children]
107
- end
108
-
109
- def update_element
110
- ids = (@section_id.split('|') + @element_id.split('|')).uniq[0...-1]
111
- @updated = @entity.update_element(*ids, element_params)
112
- @refresh = params[:refresh]
113
- end
114
-
115
- def clone_element
116
- @cloned = @entity.clone_element(*@section_id.split('|'), *@element_id.split('|'))
117
- end
118
-
119
- def delete_element
120
- @deleted = @entity.delete_element(*@section_id.split('|'), *@element_id.split('|'))
121
- end
122
-
123
- def child_element
124
- @added = @entity.child_element(*@section_id.split('|'), *@element_id.split('|'))
125
- end
126
-
127
- def new_section
128
- page = Sibu::Page.find(params[:id])
129
- @page = Page.new(id: page.id, sections: [])
130
- @site = Sibu::Site.includes(:pages).find(page.site_id)
131
- @after = params[:after]
132
- @links = @site.pages_path_by_id
133
-
134
- @site.site_template.available_sections.each do |t|
135
- template_defaults = @site.site_template.templates ? (@site.site_template.templates[t["template"]] || {}) : {}
136
- @page.sections << template_defaults.merge(t).to_h
137
- end
138
- end
139
-
140
- def create_section
141
- @created = @entity.create_section(*@section_id.split('|'), params[:after], section_params)
142
- end
143
-
144
- def edit_section
145
- @section = @entity.section(params[:section_id])
146
- end
147
-
148
- def update_section
149
- # {"utf8"=>"✓", "section"=>{"color"=>"#AFCA0B", "filters"=>"school_camps"}, "section_id"=>"cs1536301729", "refresh"=>"true", "commit"=>"Valider", "site_id"=>"3", "id"=>"1392"}
150
- @entity.section(params[:section_id]).merge!(section_params)
151
- logger.debug @entity.section(params[:section_id])
152
- @updated = @entity.save
153
- end
154
-
155
- def delete_section
156
- @deleted = @entity.delete_section(*@section_id.split('|'))
157
- end
158
-
159
- private
160
-
161
- def set_page
162
- @page = Sibu::Page.find(params[:id])
163
- @site = Sibu::Site.includes(:pages).find(@page.site_id) if @page
164
- end
165
-
166
- def set_site
167
- @site = Sibu::Site.find(params[:site_id])
168
- end
169
-
170
- def set_edit_context
171
- @entity_type = params[:entity]
172
- @section_id = params[:section_id]
173
- @element_id = params[:element_id]
174
- @entity = @entity_type == 'site' ? @site : @page
175
- end
176
-
177
- def set_online
178
- @online = request.host != conf[:host]
179
- end
180
-
181
- def page_params
182
- params.require(:page).permit!
183
- end
184
-
185
- def element_params
186
- params.require(:element).permit!
187
- end
188
-
189
- def section_params
190
- params.require(:section).permit!
191
- end
192
-
193
- def show_params
194
- params.permit!
195
- end
196
- end
197
- end
1
+ require_dependency "sibu/application_controller"
2
+
3
+ module Sibu
4
+ class PagesController < ApplicationController
5
+ before_action :set_page, only: [:edit, :update, :destroy, :duplicate, :edit_element, :update_element, :clone_element,
6
+ :delete_element, :child_element, :new_section, :create_section, :edit_section,
7
+ :update_section, :delete_section]
8
+ before_action :set_site, only: [:index, :new]
9
+ before_action :set_edit_context, only: [:edit_element, :update_element, :clone_element, :delete_element,
10
+ :child_element, :new_section, :create_section, :edit_section,
11
+ :update_section, :delete_section]
12
+ before_action :set_online, only: [:show, :edit]
13
+ skip_before_action Rails.application.config.sibu[:auth_filter], only: [:show]
14
+
15
+ def index
16
+ @pages = @site.pages.order(:created_at)
17
+ end
18
+
19
+ def show
20
+ return_code = :ok
21
+ if params[:site_id].blank?
22
+ @page = Sibu::Page.lookup(request.host, params[:path])
23
+ if @page
24
+ @query_path = params[:path][@page.path.length + 1..-1] unless @page.path.blank?
25
+ @query_params = show_params.except(:controller, :action, :path).to_h
26
+ @site = @page.site
27
+ @links = @site.pages_path_by_id
28
+ view_template = 'show'
29
+ else
30
+ @site = Sibu::Site.where(domain: request.host).first
31
+ view_template = Rails.application.config.sibu[:not_found]
32
+ return_code = :not_found
33
+ end
34
+ else
35
+ @site = Sibu::Site.find(params[:site_id])
36
+ @page = Sibu::Page.find(params[:id])
37
+ @links = @site.pages_path_by_id
38
+ @query_path = params[:path]
39
+ @query_params = show_params.except(:controller, :action, :path).to_h
40
+ view_template = 'show'
41
+ end
42
+
43
+ render view_template, layout: 'sibu/site', status: return_code
44
+ end
45
+
46
+ def new
47
+ @page = Sibu::Page.new(site_id: @site.id)
48
+ end
49
+
50
+ def create
51
+ @page = Sibu::Page.new(page_params)
52
+ if @page.save_and_init
53
+ redirect_to site_pages_url(@page.site_id), notice: "La page a bien été créée."
54
+ else
55
+ flash.now[:alert] = "Une erreur s'est produite lors de la création de la page."
56
+ render :new
57
+ end
58
+ end
59
+
60
+ def edit
61
+ end
62
+
63
+ def update
64
+ if @page.update(page_params)
65
+ redirect_to site_pages_url(@page.site_id), notice: "La page a bien été mise à jour."
66
+ else
67
+ flash.now[:alert] = "Une erreur s'est produite lors de l'enregistrement de la page."
68
+ render :edit
69
+ end
70
+ end
71
+
72
+ def destroy
73
+ site_id = @page.site_id
74
+ if @page.destroy
75
+ redirect_to site_pages_url(site_id), notice: "La page a bien été supprimée."
76
+ else
77
+ flash.now[:alert] = "Une erreur s'est produite lors de la suppression de la page."
78
+ render :index
79
+ end
80
+ end
81
+
82
+ def duplicate
83
+ new_page = @page.deep_copy
84
+ if new_page.save
85
+ redirect_to site_pages_url(@page.site_id), notice: "La page a bien été copiée."
86
+ else
87
+ flash.now[:alert] = "Une erreur s'est produite lors de la copie de la page."
88
+ render :index
89
+ end
90
+ end
91
+
92
+ def edit_content
93
+ @page = Sibu::Page.find(params[:page_id])
94
+ @site = Sibu::Site.includes(:pages).find(@page.site_id) if @page
95
+ @links = @site.pages_path_by_id if @site
96
+ @edit_section = params[:edit_section]
97
+ render :edit_content, layout: 'sibu/edit_content'
98
+ end
99
+
100
+ def edit_element
101
+ @content_type = params[:content_type]
102
+ @links = @site.pages_path_by_id if @site
103
+ @element = @entity.element(*@section_id.split('|'), *@element_id.split('|'))
104
+ @repeat = params[:repeat]
105
+ @size = params[:size].blank? ? :medium : params[:size].to_sym
106
+ @children = params[:children]
107
+ end
108
+
109
+ def update_element
110
+ ids = (@section_id.split('|') + @element_id.split('|')).uniq[0...-1]
111
+ @updated = @entity.update_element(*ids, element_params)
112
+ @refresh = params[:refresh]
113
+ end
114
+
115
+ def clone_element
116
+ @cloned = @entity.clone_element(*@section_id.split('|'), *@element_id.split('|'))
117
+ end
118
+
119
+ def delete_element
120
+ @deleted = @entity.delete_element(*@section_id.split('|'), *@element_id.split('|'))
121
+ end
122
+
123
+ def child_element
124
+ @added = @entity.child_element(*@section_id.split('|'), *@element_id.split('|'))
125
+ end
126
+
127
+ def new_section
128
+ page = Sibu::Page.find(params[:id])
129
+ @page = Page.new(id: page.id, sections: [])
130
+ @site = Sibu::Site.includes(:pages).find(page.site_id)
131
+ @after = params[:after]
132
+ @links = @site.pages_path_by_id
133
+
134
+ @site.site_template.available_sections.each do |t|
135
+ template_defaults = @site.site_template.templates ? (@site.site_template.templates[t["template"]] || {}) : {}
136
+ @page.sections << template_defaults.merge(t).to_h
137
+ end
138
+ end
139
+
140
+ def create_section
141
+ @created = @entity.create_section(*@section_id.split('|'), params[:after], section_params)
142
+ end
143
+
144
+ def edit_section
145
+ @section = @entity.section(params[:section_id])
146
+ end
147
+
148
+ def update_section
149
+ # {"utf8"=>"✓", "section"=>{"color"=>"#AFCA0B", "filters"=>"school_camps"}, "section_id"=>"cs1536301729", "refresh"=>"true", "commit"=>"Valider", "site_id"=>"3", "id"=>"1392"}
150
+ @entity.section(params[:section_id]).merge!(section_params)
151
+ logger.debug @entity.section(params[:section_id])
152
+ @updated = @entity.save
153
+ end
154
+
155
+ def delete_section
156
+ @deleted = @entity.delete_section(*@section_id.split('|'))
157
+ end
158
+
159
+ private
160
+
161
+ def set_page
162
+ @page = Sibu::Page.find(params[:id])
163
+ @site = Sibu::Site.includes(:pages).find(@page.site_id) if @page
164
+ end
165
+
166
+ def set_site
167
+ @site = Sibu::Site.find(params[:site_id])
168
+ end
169
+
170
+ def set_edit_context
171
+ @entity_type = params[:entity]
172
+ @section_id = params[:section_id]
173
+ @element_id = params[:element_id]
174
+ @entity = @entity_type == 'site' ? @site : @page
175
+ end
176
+
177
+ def set_online
178
+ @online = request.host != conf[:host]
179
+ end
180
+
181
+ def page_params
182
+ params.require(:page).permit!
183
+ end
184
+
185
+ def element_params
186
+ params.require(:element).permit!
187
+ end
188
+
189
+ def section_params
190
+ params.require(:section).permit!
191
+ end
192
+
193
+ def show_params
194
+ params.permit!
195
+ end
196
+ end
197
+ end
@@ -1,81 +1,81 @@
1
- require_dependency "sibu/application_controller"
2
-
3
- module Sibu
4
- class SitesController < ApplicationController
5
- before_action :set_site, only: [:show, :edit, :update, :destroy, :duplicate]
6
- skip_before_action Rails.application.config.sibu[:auth_filter], only: [:show]
7
-
8
- def index
9
- @sites = Sibu::Site.for_user(sibu_user).order(:name, :version)
10
- end
11
-
12
- def show
13
- @page = @site.page('')
14
- redirect_to site_page_path(@site.id, @page.id)
15
- end
16
-
17
- def new
18
- @site = Sibu::Site.new(user_id: sibu_user.id, version: Sibu::Site::DEFAULT_VERSION)
19
- end
20
-
21
- def create
22
- @site = Sibu::Site.new(site_params)
23
- if @site.save_and_init
24
- generate_styles(@site) if conf[:custom_styles]
25
- redirect_to sites_url, notice: "Le site a bien été créé."
26
- else
27
- flash.now[:alert] = "Une erreur s'est produite lors de la création du site."
28
- render :new
29
- end
30
- end
31
-
32
- def edit
33
- end
34
-
35
- def update
36
- if @site.update(site_params)
37
- if conf[:custom_styles] && @site.previous_changes.has_key?(:custom_data)
38
- generate_styles(@site)
39
- end
40
- redirect_to sites_url, notice: "Le site a bien été mis à jour."
41
- else
42
- flash.now[:alert] = "Une erreur s'est produite lors de l'enregistrement du site."
43
- render :edit
44
- end
45
- end
46
-
47
- def destroy
48
- @site.destroy
49
- redirect_to sites_url, notice: "Le site a bien été supprimé."
50
- end
51
-
52
- def duplicate
53
- new_site = @site.deep_copy
54
- if new_site.save
55
- if conf[:custom_styles]
56
- generate_styles(@site)
57
- generate_styles(new_site)
58
- end
59
- redirect_to sites_url, notice: "Le site a bien été copié."
60
- else
61
- flash.now[:alert] = "Une erreur s'est produite lors de la copie du site."
62
- render :index
63
- end
64
- end
65
-
66
- private
67
-
68
- def set_site
69
- @site = Sibu::Site.find(params[:id])
70
- end
71
-
72
- def site_params
73
- params.require(:site).permit!
74
- end
75
-
76
- def generate_styles(site)
77
- ds = Sibu::DynamicStyle.new(site.id)
78
- ds.compile
79
- end
80
- end
81
- end
1
+ require_dependency "sibu/application_controller"
2
+
3
+ module Sibu
4
+ class SitesController < ApplicationController
5
+ before_action :set_site, only: [:show, :edit, :update, :destroy, :duplicate]
6
+ skip_before_action Rails.application.config.sibu[:auth_filter], only: [:show]
7
+
8
+ def index
9
+ @sites = Sibu::Site.for_user(sibu_user).order(:name, :version)
10
+ end
11
+
12
+ def show
13
+ @page = @site.page('')
14
+ redirect_to site_page_path(@site.id, @page.id)
15
+ end
16
+
17
+ def new
18
+ @site = Sibu::Site.new(user_id: sibu_user.id, version: Sibu::Site::DEFAULT_VERSION)
19
+ end
20
+
21
+ def create
22
+ @site = Sibu::Site.new(site_params)
23
+ if @site.save_and_init
24
+ generate_styles(@site) if conf[:custom_styles]
25
+ redirect_to sites_url, notice: "Le site a bien été créé."
26
+ else
27
+ flash.now[:alert] = "Une erreur s'est produite lors de la création du site."
28
+ render :new
29
+ end
30
+ end
31
+
32
+ def edit
33
+ end
34
+
35
+ def update
36
+ if @site.update(site_params)
37
+ if conf[:custom_styles] && @site.previous_changes.has_key?(:custom_data)
38
+ generate_styles(@site)
39
+ end
40
+ redirect_to sites_url, notice: "Le site a bien été mis à jour."
41
+ else
42
+ flash.now[:alert] = "Une erreur s'est produite lors de l'enregistrement du site."
43
+ render :edit
44
+ end
45
+ end
46
+
47
+ def destroy
48
+ @site.destroy
49
+ redirect_to sites_url, notice: "Le site a bien été supprimé."
50
+ end
51
+
52
+ def duplicate
53
+ new_site = @site.deep_copy
54
+ if new_site.save
55
+ if conf[:custom_styles]
56
+ generate_styles(@site)
57
+ generate_styles(new_site)
58
+ end
59
+ redirect_to sites_url, notice: "Le site a bien été copié."
60
+ else
61
+ flash.now[:alert] = "Une erreur s'est produite lors de la copie du site."
62
+ render :index
63
+ end
64
+ end
65
+
66
+ private
67
+
68
+ def set_site
69
+ @site = Sibu::Site.find(params[:id])
70
+ end
71
+
72
+ def site_params
73
+ params.require(:site).permit!
74
+ end
75
+
76
+ def generate_styles(site)
77
+ ds = Sibu::DynamicStyle.new(site.id)
78
+ ds.compile
79
+ end
80
+ end
81
+ end