sibu 1.0.13 → 1.0.18
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.
- checksums.yaml +4 -4
- data/app/controllers/sibu/images_controller.rb +8 -4
- data/app/controllers/sibu/pages_controller.rb +9 -0
- data/app/helpers/sibu/pages_helper.rb +35 -20
- data/app/models/concerns/sibu/image_uploader.rb +1 -1
- data/app/models/concerns/sibu/sections_concern.rb +4 -0
- data/lib/sibu/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e913afa40651591876a68f2f23dade0fb309c410
|
4
|
+
data.tar.gz: bca620a625fdbc2cfd19a536e387f1841587af4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 492a6fda285b61ed431cbb30c8f61ec9b55e98bb15d69f5671b5c9520bf260caec02b44834a15323650111075d96b0826e76e76ce3df0f18e281ab3f379c212f
|
7
|
+
data.tar.gz: 859ccb722dd7fe498ec580bdd3ccb76a7a22c0831865c25299fe3c6af04f8658aa29670b3e839e2c0a9151061dd26ca3e8d4fb5ef911b52c2e59873cf30854d8
|
@@ -20,11 +20,15 @@ module Sibu
|
|
20
20
|
p = Sibu::Page.find(@page_id)
|
21
21
|
entity = @entity_type == 'site' ? p.site : p
|
22
22
|
ids = (@section_id.split('|') + @element_id.split('|')).uniq[0...-1]
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
if entity.has_section?(ids.first)
|
24
|
+
elt = entity.update_element(*ids, {"id" => @img_id, "src" => @image.file_url(@size.to_sym), "alt" => @image.alt})
|
25
|
+
if elt.nil?
|
26
|
+
msg = {alert: "Une erreur s'est produite lors de la mise à jour de l'image."}
|
27
|
+
else
|
28
|
+
msg = {notice: "L'image a bien été mise à jour."}
|
29
|
+
end
|
26
30
|
else
|
27
|
-
msg = {
|
31
|
+
msg = {alert: "L'image n'a pas pu être ajoutée à la section."}
|
28
32
|
end
|
29
33
|
redirect_to site_page_edit_content_path(p.site_id, @page_id), msg
|
30
34
|
else
|
@@ -11,6 +11,8 @@ module Sibu
|
|
11
11
|
:child_element, :new_section, :create_section, :edit_section,
|
12
12
|
:update_section, :delete_section]
|
13
13
|
before_action :set_online, only: [:show, :edit]
|
14
|
+
before_action :check_section, only: [:edit_element, :update_element, :clone_element, :delete_element,
|
15
|
+
:child_element, :edit_section, :update_section, :delete_section]
|
14
16
|
|
15
17
|
skip_before_action Rails.application.config.sibu[:auth_filter], only: [:show]
|
16
18
|
|
@@ -197,6 +199,13 @@ module Sibu
|
|
197
199
|
params.permit!
|
198
200
|
end
|
199
201
|
|
202
|
+
def check_section
|
203
|
+
section_id = params[:section_id]
|
204
|
+
unless @entity && @entity.has_section?(section_id)
|
205
|
+
redirect_to main_app.root_url, alert: "L'opération n'a pas pu aboutir."
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
200
209
|
def compile_assets
|
201
210
|
Sibu::DynamicStyle.new(params[:site_id]).compile if Rails.env.development? && conf[:custom_styles] && !params[:site_id].blank?
|
202
211
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# Note : methods defined here are included in ActionView::Base
|
1
2
|
module Sibu
|
2
3
|
module PagesHelper
|
3
4
|
include Sibu::Engine.routes.url_helpers
|
@@ -52,10 +53,10 @@ module Sibu
|
|
52
53
|
defaults = {"id" => t_id, "text" => (t == :p ? Sibu::DEFAULT_PARAGRAPH : Sibu::DEFAULT_TEXT)}
|
53
54
|
content = defaults.merge(elt.is_a?(Hash) ? elt : (select_element(elt) || {}))
|
54
55
|
html_opts = {"id" => t_id}.merge(opts.except(:repeat, :children).stringify_keys)
|
55
|
-
|
56
|
+
push_section_ids(t_id)
|
56
57
|
if action_name != 'show'
|
57
58
|
html_opts.merge!({
|
58
|
-
"data-id" => @sb_section[1..-1].join('|'),
|
59
|
+
"data-id" => instance_variable_get("@sb_section")[1..-1].join('|'),
|
59
60
|
"data-type" => (t == :p ? "paragraph" : "text"),
|
60
61
|
"data-repeat" => opts.delete(:repeat),
|
61
62
|
"data-children" => opts.delete(:children)
|
@@ -74,7 +75,7 @@ module Sibu
|
|
74
75
|
html_output = content_tag(t, raw(content["text"]).html_safe, html_opts)
|
75
76
|
end
|
76
77
|
end
|
77
|
-
|
78
|
+
pop_section_id
|
78
79
|
html_output
|
79
80
|
end
|
80
81
|
end
|
@@ -82,18 +83,18 @@ module Sibu
|
|
82
83
|
[:div, :section, :article, :aside, :header, :footer, :nav, :main, :ul, :ol, :wrapper].each do |t|
|
83
84
|
define_method(t) do |elt, opts = {}, &block|
|
84
85
|
t_id = elt.is_a?(Hash) ? elt["id"] : elt
|
85
|
-
|
86
|
+
push_section_ids(t_id)
|
86
87
|
html_opts = {"id" => t_id}.merge(opts.except(:repeat, :children).stringify_keys)
|
87
88
|
if action_name != 'show'
|
88
89
|
html_opts.merge!({
|
89
|
-
"data-id" => @sb_section[1..-1].join('|'),
|
90
|
+
"data-id" => instance_variable_get("@sb_section")[1..-1].join('|'),
|
90
91
|
"data-type" => "group",
|
91
92
|
"data-repeat" => opts.delete(:repeat),
|
92
93
|
"data-children" => opts.delete(:children)
|
93
94
|
})
|
94
95
|
end
|
95
96
|
html_output = t == :wrapper ? capture(current_elt(elt), nested_elements(t_id), &block) : content_tag(t, capture(current_elt(elt), nested_elements(t_id), &block), html_opts)
|
96
|
-
|
97
|
+
pop_section_id
|
97
98
|
html_output
|
98
99
|
end
|
99
100
|
end
|
@@ -112,7 +113,7 @@ module Sibu
|
|
112
113
|
# Note : add "each_with_elements" and "elements" on section/elts enumerables
|
113
114
|
def nested_elements(elt_or_id)
|
114
115
|
element_id = elt_id(elt_or_id)
|
115
|
-
element_id_tokens = (@sb_section + element_id.split("|")).uniq
|
116
|
+
element_id_tokens = (instance_variable_get("@sb_section") + element_id.split("|")).uniq
|
116
117
|
nested_elts = @sb_entity.elements(*element_id_tokens)
|
117
118
|
nested_elts.blank? ? [{"id" => element_id.split("|").last, "data-id" => join_tokens(element_id_tokens[1..-1], "#{element_id}0")}] :
|
118
119
|
nested_elts.map {|e| e.merge({"data-id" => join_tokens(element_id_tokens[1..-1], e['id'])})}
|
@@ -120,13 +121,13 @@ module Sibu
|
|
120
121
|
|
121
122
|
def each_element(elt_or_id)
|
122
123
|
element_id = elt_id(elt_or_id)
|
123
|
-
|
124
|
-
(@sb_entity.elements(
|
125
|
-
|
124
|
+
push_section_ids(*element_id.split("|")) unless element_id.blank?
|
125
|
+
(@sb_entity.elements(*instance_variable_get("@sb_section")) || []).map {|el| yield(el)}
|
126
|
+
pop_section_id unless element_id.blank?
|
126
127
|
end
|
127
128
|
|
128
129
|
def select_element(id)
|
129
|
-
@sb_entity.element(
|
130
|
+
@sb_entity.element(*instance_variable_get("@sb_section"), id)
|
130
131
|
end
|
131
132
|
|
132
133
|
def elements(id = nil)
|
@@ -134,6 +135,16 @@ module Sibu
|
|
134
135
|
items.blank? ? [{"id" => "el#{Time.current.to_i}"}] : items
|
135
136
|
end
|
136
137
|
|
138
|
+
def push_section_ids(*section_ids)
|
139
|
+
# Rails.logger.debug "push section ids #{section_ids}"
|
140
|
+
instance_variable_set("@sb_section", (instance_variable_get("@sb_section") || []) + section_ids)
|
141
|
+
end
|
142
|
+
|
143
|
+
def pop_section_id
|
144
|
+
instance_variable_set("@sb_section", instance_variable_get("@sb_section")[0..-2])
|
145
|
+
# Rails.logger.debug "popped section - now #{instance_variable_get("@sb_section")}"
|
146
|
+
end
|
147
|
+
|
137
148
|
def img(elt, opts = {})
|
138
149
|
wrapper = opts.delete(:wrapper)
|
139
150
|
repeat = opts.delete(:repeat)
|
@@ -141,15 +152,15 @@ module Sibu
|
|
141
152
|
t_id = elt.is_a?(Hash) ? elt["id"] : elt
|
142
153
|
defaults = {"id" => t_id, "src" => Sibu::DEFAULT_IMG}
|
143
154
|
content = defaults.merge(elt.is_a?(Hash) ? elt : (select_element(elt) || {}))
|
144
|
-
|
155
|
+
push_section_ids(t_id)
|
145
156
|
if action_name == 'show'
|
146
157
|
content["src"] = ("/#{conf[:deployment_path]}" + content["src"]) if @online && conf[:deployment_path]
|
147
158
|
else
|
148
|
-
opts.merge!({data: {id: @sb_section[1..-1].join('|'), type: "media", repeat: repeat, size: size}})
|
159
|
+
opts.merge!({data: {id: instance_variable_get("@sb_section")[1..-1].join('|'), type: "media", repeat: repeat, size: size}})
|
149
160
|
end
|
150
161
|
html_output = wrapper ? content_tag(wrapper, content_tag(:img, nil, content.except("id")), opts)
|
151
162
|
: content_tag(:img, nil, content.except("id").merge(opts.stringify_keys) {|k, old, new| k == 'class' ? [old, new].join(' ') : new})
|
152
|
-
|
163
|
+
pop_section_id
|
153
164
|
html_output
|
154
165
|
end
|
155
166
|
|
@@ -265,8 +276,10 @@ module Sibu
|
|
265
276
|
|
266
277
|
alias site sb_site
|
267
278
|
|
279
|
+
# Resets section ids to clean up remaining ids
|
268
280
|
def render_page_section(s, set_id = false)
|
269
|
-
@sb_section
|
281
|
+
instance_variable_set("@sb_section", [])
|
282
|
+
push_section_ids(s['id'])
|
270
283
|
@sb_entity = @page
|
271
284
|
render partial: "shared/#{@site.section_template(s)}",
|
272
285
|
locals: {sibu: self, sibu_section: s, sibu_attrs: sibu_attributes(s, set_id).html_safe}
|
@@ -278,9 +291,10 @@ module Sibu
|
|
278
291
|
attrs + (action_name != 'show' ? ('data-sb-id="' + section['id'] + '" data-sb-entity="page"') : '')
|
279
292
|
end
|
280
293
|
|
281
|
-
# Site sections attrs
|
294
|
+
# Site sections attrs - resets section ids
|
282
295
|
def sibu_attrs(section_id)
|
283
|
-
@sb_section
|
296
|
+
instance_variable_set("@sb_section", [])
|
297
|
+
push_section_ids(section_id)
|
284
298
|
@sb_entity = @site
|
285
299
|
action_name != 'show' ? ('data-sb-id="' + section_id + '" data-sb-entity="site"').html_safe : ''
|
286
300
|
end
|
@@ -313,8 +327,9 @@ module Sibu
|
|
313
327
|
content = defaults.merge(link_elt)
|
314
328
|
val = content.delete("value") || ""
|
315
329
|
text = content.delete("text")
|
316
|
-
|
317
|
-
|
330
|
+
push_section_ids(t_id)
|
331
|
+
|
332
|
+
html_opts.merge!({data: {id: instance_variable_get("@sb_section")[1..-1].join('|'), type: "link", repeat: repeat, children: children}}) if action_name != 'show'
|
318
333
|
if val.to_s.start_with?('http')
|
319
334
|
content["href"] = val
|
320
335
|
elsif val.to_s.start_with?('#')
|
@@ -332,7 +347,7 @@ module Sibu
|
|
332
347
|
else
|
333
348
|
html_output = content_tag(:a, raw(text), content.merge(html_opts).except("elements"))
|
334
349
|
end
|
335
|
-
|
350
|
+
pop_section_id
|
336
351
|
html_output
|
337
352
|
end
|
338
353
|
|
@@ -25,7 +25,7 @@ class Sibu::ImageUploader < Shrine
|
|
25
25
|
def generate_location(io, context)
|
26
26
|
user_id = context[:record] ? context[:record].user_id : nil
|
27
27
|
style = context[:version] != :original ? "resized" : "originals"
|
28
|
-
name = super
|
28
|
+
name = "#{context.dig(:metadata, 'filename') ? context.dig(:metadata, 'filename').gsub(/\.\w+$/, '').parameterize : 'image'}-#{super}"
|
29
29
|
|
30
30
|
[user_id, style, name].compact.join("/")
|
31
31
|
end
|
data/lib/sibu/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sibu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jean-Baptiste Vilain
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|