sibu 1.0.9 → 1.0.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a342b61a67c0e4b5181984f617ab47635611dd6a
4
- data.tar.gz: 545735764452344e08b8c66845e948d4d569447f
3
+ metadata.gz: 269f3881e2c48664a07b538764e527e174a8ae39
4
+ data.tar.gz: 8ec378a884b7d26ff5b400241cd6333ac0177aa1
5
5
  SHA512:
6
- metadata.gz: 18fddf4a252bf6243e3020c4082c10da885f343881dc4abbc4c0c05d894dc4885c0ad21970bc002eba918c73a25029fec34cc863df165530303dfbca512b1633
7
- data.tar.gz: 48d28a56d1a239fda2b8ea17ba654ebff2f2ec5c6dd4181c7080ffda0bdc58d6102b198c2c024ce9e80e58b17dfbf01b6f50cc9f454eff99196a397c770d50f4
6
+ metadata.gz: db8306822fca5383613540b03d8e2e26ba0a511aa4e0c5ae62e30a6ada43778a442551cb8b9a1b11a9d6c79417ec60d24ddb53750acafd7fa0f11cd92419402e
7
+ data.tar.gz: 59f03f99a1920ae2a406ae657a043e8f216c952514ff3e8a4488023ae9a1bf8b7da89d81782821c5776780ef9fb54c12604b07302203c2242fd25c8f3b9e32ab
@@ -38,8 +38,8 @@ module Sibu
38
38
 
39
39
  def update
40
40
  if @site.update(site_params)
41
- if conf[:custom_styles] && @site.previous_changes.has_key?(:custom_data)
42
- generate_styles(@site)
41
+ if conf[:custom_styles]
42
+ generate_styles(@site, @site.previous_changes.has_key?(:custom_data))
43
43
  end
44
44
  if @site.previous_changes.has_key?(:version)
45
45
  @site.update_paths
@@ -61,7 +61,7 @@ module Sibu
61
61
  if new_site.save
62
62
  if conf[:custom_styles]
63
63
  generate_styles(@site)
64
- generate_styles(new_site)
64
+ generate_styles(new_site, true)
65
65
  end
66
66
  redirect_to sites_url, notice: "Le site a bien été copié."
67
67
  else
@@ -81,8 +81,8 @@ module Sibu
81
81
  params.require(:site).permit!
82
82
  end
83
83
 
84
- def generate_styles(site)
85
- ds = Sibu::DynamicStyle.new(site.id)
84
+ def generate_styles(site, force_styles = false)
85
+ ds = Sibu::DynamicStyle.new(site.id, force_styles)
86
86
  ds.compile
87
87
  end
88
88
  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,11 @@ 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
- @sb_section = (@sb_section || []) + [t_id]
56
+ instance_variable_set("@sb_section", (instance_variable_get("@sb_section") || []) + [t_id])
57
+ Rails.logger.info("s : #{instance_variable_get("@sb_section")} - t : #{t_id} - content: #{content}")
56
58
  if action_name != 'show'
57
59
  html_opts.merge!({
58
- "data-id" => @sb_section[1..-1].join('|'),
60
+ "data-id" => instance_variable_get("@sb_section")[1..-1].join('|'),
59
61
  "data-type" => (t == :p ? "paragraph" : "text"),
60
62
  "data-repeat" => opts.delete(:repeat),
61
63
  "data-children" => opts.delete(:children)
@@ -74,7 +76,7 @@ module Sibu
74
76
  html_output = content_tag(t, raw(content["text"]).html_safe, html_opts)
75
77
  end
76
78
  end
77
- @sb_section -= [t_id]
79
+ instance_variable_set("@sb_section", instance_variable_get("@sb_section")[0..-2])
78
80
  html_output
79
81
  end
80
82
  end
@@ -82,18 +84,18 @@ module Sibu
82
84
  [:div, :section, :article, :aside, :header, :footer, :nav, :main, :ul, :ol, :wrapper].each do |t|
83
85
  define_method(t) do |elt, opts = {}, &block|
84
86
  t_id = elt.is_a?(Hash) ? elt["id"] : elt
85
- @sb_section = (@sb_section || []) + [t_id]
87
+ instance_variable_set("@sb_section", (instance_variable_get("@sb_section") || []) + [t_id])
86
88
  html_opts = {"id" => t_id}.merge(opts.except(:repeat, :children).stringify_keys)
87
89
  if action_name != 'show'
88
90
  html_opts.merge!({
89
- "data-id" => @sb_section[1..-1].join('|'),
91
+ "data-id" => instance_variable_get("@sb_section")[1..-1].join('|'),
90
92
  "data-type" => "group",
91
93
  "data-repeat" => opts.delete(:repeat),
92
94
  "data-children" => opts.delete(:children)
93
95
  })
94
96
  end
95
97
  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
- @sb_section -= [t_id]
98
+ instance_variable_set("@sb_section", instance_variable_get("@sb_section")[0..-2])
97
99
  html_output
98
100
  end
99
101
  end
@@ -118,8 +120,15 @@ module Sibu
118
120
  nested_elts.map {|e| e.merge({"data-id" => join_tokens(element_id_tokens[1..-1], e['id'])})}
119
121
  end
120
122
 
123
+ def each_element(elt_or_id)
124
+ element_id = elt_id(elt_or_id)
125
+ @sb_section = (@sb_section + element_id.split("|")).uniq unless element_id.blank?
126
+ (@sb_entity.elements(*@sb_section) || []).map {|el| yield(el)}
127
+ @sb_section -= [element_id] unless element_id.blank?
128
+ end
129
+
121
130
  def select_element(id)
122
- @sb_entity.element(*@sb_section, id)
131
+ @sb_entity.element(*instance_variable_get("@sb_section"), id)
123
132
  end
124
133
 
125
134
  def elements(id = nil)
@@ -146,6 +155,22 @@ module Sibu
146
155
  html_output
147
156
  end
148
157
 
158
+ def svg_image(elt, opts = {})
159
+ size = opts.delete(:size)
160
+ t_id = elt.is_a?(Hash) ? elt["id"] : elt
161
+ defaults = {"id" => t_id, "xlink:href" => Sibu::DEFAULT_IMG}
162
+ content = defaults.merge((elt.is_a?(Hash) ? elt : (select_element(elt) || {})).transform_keys {|k| k == 'src' ? 'xlink:href' : k})
163
+ @sb_section = (@sb_section || []) + [t_id]
164
+ if action_name == 'show'
165
+ content["xlink:href"] = ("/#{conf[:deployment_path]}" + content["xlink:href"]) if @online && conf[:deployment_path]
166
+ else
167
+ opts.merge!({data: {id: @sb_section[1..-1].join('|'), type: "media", repeat: false, size: size}})
168
+ end
169
+ html_output = content_tag(:image, nil, content.except("id").merge(opts.stringify_keys) {|k, old, new| k == 'class' ? [old, new].join(' ') : new})
170
+ @sb_section -= [t_id]
171
+ html_output
172
+ end
173
+
149
174
  def grp(elt, opts = {}, &block)
150
175
  wrapper = opts.delete(:wrapper) || :div
151
176
  repeat = opts.delete(:repeat)
@@ -242,16 +267,17 @@ module Sibu
242
267
 
243
268
  alias site sb_site
244
269
 
245
- def render_page_section(s)
270
+ def render_page_section(s, set_id = false)
246
271
  @sb_section = [s['id']]
247
272
  @sb_entity = @page
248
273
  render partial: "shared/#{@site.section_template(s)}",
249
- locals: {sibu: self, sibu_section: s, sibu_attrs: sibu_attributes(s).html_safe}
274
+ locals: {sibu: self, sibu_section: s, sibu_attrs: sibu_attributes(s, set_id).html_safe}
250
275
  end
251
276
 
252
277
  # Page sections attrs
253
- def sibu_attributes(section)
254
- action_name != 'show' ? ('data-sb-id="' + section['id'] + '" data-sb-entity="page"') : ''
278
+ def sibu_attributes(section, set_id)
279
+ attrs = set_id ? ('id="' + section['id'] + '" ') : ''
280
+ attrs + (action_name != 'show' ? ('data-sb-id="' + section['id'] + '" data-sb-entity="page"') : '')
255
281
  end
256
282
 
257
283
  # Site sections attrs
@@ -289,8 +315,9 @@ module Sibu
289
315
  content = defaults.merge(link_elt)
290
316
  val = content.delete("value") || ""
291
317
  text = content.delete("text")
292
- @sb_section = (@sb_section || []) + [t_id]
293
- html_opts.merge!({data: {id: @sb_section[1..-1].join('|'), type: "link", repeat: repeat, children: children}}) if action_name != 'show'
318
+ instance_variable_set("@sb_section", (instance_variable_get("@sb_section") || []) + [t_id])
319
+ # @sb_section = (@sb_section || []) + [t_id]
320
+ html_opts.merge!({data: {id: instance_variable_get("@sb_section")[1..-1].join('|'), type: "link", repeat: repeat, children: children}}) if action_name != 'show'
294
321
  if val.to_s.start_with?('http')
295
322
  content["href"] = val
296
323
  elsif val.to_s.start_with?('#')
@@ -308,7 +335,8 @@ module Sibu
308
335
  else
309
336
  html_output = content_tag(:a, raw(text), content.merge(html_opts).except("elements"))
310
337
  end
311
- @sb_section -= [t_id]
338
+ instance_variable_set("@sb_section", instance_variable_get("@sb_section") - [t_id])
339
+ # @sb_section -= [t_id]
312
340
  html_output
313
341
  end
314
342
 
@@ -3,9 +3,9 @@ module Sibu
3
3
 
4
4
  attr_reader :site, :body, :env, :filename, :scss_file, :styles_changed
5
5
 
6
- def initialize(site_id)
6
+ def initialize(site_id, force_styles = false)
7
7
  @site = Sibu::Site.find(site_id)
8
- @styles_changed = styles_changed?(@site.style_url)
8
+ @styles_changed = @site.style.nil? || force_styles || styles_changed?(@site.style_url)
9
9
  if @styles_changed
10
10
  @filename = "#{site_id}_#{Time.current.to_i}"
11
11
  @scss_file = File.new(scss_file_path, 'w')
@@ -14,6 +14,12 @@
14
14
  <%= javascript_include_tag "#{conf[:javascript]}-edit" %>
15
15
  <%= csrf_meta_tags %>
16
16
  <%= yield :styles %>
17
+ <% if @site && !@site.header_code.blank? %>
18
+ <%= raw @site.header_code %>
19
+ <% end %>
20
+ <% if @page && !@page.header_code.blank? %>
21
+ <%= raw @page.header_code %>
22
+ <% end %>
17
23
  </head>
18
24
  <body class="sibu_edit_content">
19
25
  <% [:top_panel, :side_panel, :content_panel, :bottom_panel].each do |panel| %>
@@ -65,7 +71,7 @@
65
71
  rightOverlay.style.height = height + "px";
66
72
  rightOverlay.style.left = left + width + "px";
67
73
  rightOverlay.style.top = top + "px";
68
- editModeActions.style.top = (top <= 120 ? (top + height) : (top - 40 - 20)) + "px";
74
+ editModeActions.style.top = (top + height) + "px";
69
75
  editModeActions.style.left = left + "px";
70
76
  editModeActions.style.width = width + "px";
71
77
  editMode.querySelector("#edit_section_msg").innerText = "Modifier la section";
@@ -79,8 +85,6 @@
79
85
  editMode.querySelector("#new_section_after").style.display = "block";
80
86
  editMode.querySelector("#delete_section").style.display = "block";
81
87
  }
82
- var topPadding = top <= 120 ? 60 : 120;
83
- window.scrollTo(0, top - topPadding);
84
88
  section.classList.add('sb-editing');
85
89
  initInnerOverlays(section);
86
90
  document.querySelector("#edit_overlays").innerHTML = "";
@@ -49,11 +49,11 @@ setTimeout(function() {
49
49
  editPanel.querySelector('.sibu_image.selected').classList.remove('selected');
50
50
  }
51
51
  evt.currentTarget.classList.add('selected');
52
- var imgElt = evt.currentTarget.querySelector("img");
53
- document.querySelector("#element_src").value = imgElt.getAttribute("data-src");
52
+ var imgElt = evt.currentTarget.querySelector("img"), eltSrc = document.querySelector("#element_src");
53
+ eltSrc.value = imgElt.getAttribute("data-src");
54
54
  document.querySelector("#element_alt").value = imgElt.getAttribute("data-alt");
55
55
  editPanel.querySelector(".sibu_center").innerHTML =
56
- '<img src="' + $("#element_src").val() + '"/>' +
56
+ '<img src="' + eltSrc.value + '"/>' +
57
57
  '<div id="sibu_center_pos" style="display: none;">✕</div>' +
58
58
  '<div id="sibu_center_desc" style="display: none;"><em>Cliquez sur l\'image pour la recentrer sur un point donné (à utiliser lorsque l\'image est tronquée car la zone d\'affichage est trop petite)</em></div>';
59
59
  if (editPanel.querySelector(".sibu_selected_image > p:first-child")) {
data/lib/sibu/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sibu
2
- VERSION = '1.0.9'
2
+ VERSION = '1.0.14'
3
3
  end
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.9
4
+ version: 1.0.14
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: 2020-09-07 00:00:00.000000000 Z
11
+ date: 2021-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails