sibu 1.0.10 → 1.0.15

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: 81b1a892357b7809824ea579fe32219a9cc864c1
4
- data.tar.gz: 121e9d7cec8dd2790bafc8d152aeff2f667d2014
3
+ metadata.gz: c73b880e87681d9f20c0f5b0a7fe505e226d2cf2
4
+ data.tar.gz: c9032cab8cb4a7365c5988c43a7e4686485b9e77
5
5
  SHA512:
6
- metadata.gz: 481e3ce5022276de19aa596d15da11c99638a3b06fb9cb1eeac5ad8e38699810ece60c46a1cfeff01725dd2f5a5e5bd24dc1965d343325af161b1f1b76e1133d
7
- data.tar.gz: c6dcd079e5672c7a702db7d9e117aa87cb90cc687171ad6d2110f51ba1fb6b5d8de4cdff7f1c3cb884da391bb64653910067b75998c3a7631804065cf31c3a0a
6
+ metadata.gz: 29087a80f2f64240a12c975dc1faf82eb810541b408b839f60181997bcc294b25b79edb8a6b1c8a05e2f6c89db83af445ab896297e617fa5bab71dafbadaac22
7
+ data.tar.gz: f76234b3d79658d30f120c9a0bd11b4e5d6a8aee814400d29748f43709b4ed3eec86f5d9f903d39c516b25467c49e0d575ddf4db8dc33d9b8fc25c0ea91555b5
@@ -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,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
- @sb_section = (@sb_section || []) + [t_id]
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
- @sb_section -= [t_id]
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
- @sb_section = (@sb_section || []) + [t_id]
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
- @sb_section -= [t_id]
97
+ pop_section_id
97
98
  html_output
98
99
  end
99
100
  end
@@ -112,14 +113,21 @@ 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'])})}
119
120
  end
120
121
 
122
+ def each_element(elt_or_id)
123
+ element_id = elt_id(elt_or_id)
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?
127
+ end
128
+
121
129
  def select_element(id)
122
- @sb_entity.element(*@sb_section, id)
130
+ @sb_entity.element(*instance_variable_get("@sb_section"), id)
123
131
  end
124
132
 
125
133
  def elements(id = nil)
@@ -127,6 +135,16 @@ module Sibu
127
135
  items.blank? ? [{"id" => "el#{Time.current.to_i}"}] : items
128
136
  end
129
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
+
130
148
  def img(elt, opts = {})
131
149
  wrapper = opts.delete(:wrapper)
132
150
  repeat = opts.delete(:repeat)
@@ -134,14 +152,30 @@ module Sibu
134
152
  t_id = elt.is_a?(Hash) ? elt["id"] : elt
135
153
  defaults = {"id" => t_id, "src" => Sibu::DEFAULT_IMG}
136
154
  content = defaults.merge(elt.is_a?(Hash) ? elt : (select_element(elt) || {}))
137
- @sb_section = (@sb_section || []) + [t_id]
155
+ push_section_ids(t_id)
138
156
  if action_name == 'show'
139
157
  content["src"] = ("/#{conf[:deployment_path]}" + content["src"]) if @online && conf[:deployment_path]
140
158
  else
141
- 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}})
142
160
  end
143
161
  html_output = wrapper ? content_tag(wrapper, content_tag(:img, nil, content.except("id")), opts)
144
162
  : content_tag(:img, nil, content.except("id").merge(opts.stringify_keys) {|k, old, new| k == 'class' ? [old, new].join(' ') : new})
163
+ pop_section_id
164
+ html_output
165
+ end
166
+
167
+ def svg_image(elt, opts = {})
168
+ size = opts.delete(:size)
169
+ t_id = elt.is_a?(Hash) ? elt["id"] : elt
170
+ defaults = {"id" => t_id, "xlink:href" => Sibu::DEFAULT_IMG}
171
+ content = defaults.merge((elt.is_a?(Hash) ? elt : (select_element(elt) || {})).transform_keys {|k| k == 'src' ? 'xlink:href' : k})
172
+ @sb_section = (@sb_section || []) + [t_id]
173
+ if action_name == 'show'
174
+ content["xlink:href"] = ("/#{conf[:deployment_path]}" + content["xlink:href"]) if @online && conf[:deployment_path]
175
+ else
176
+ opts.merge!({data: {id: @sb_section[1..-1].join('|'), type: "media", repeat: false, size: size}})
177
+ end
178
+ html_output = content_tag(:image, nil, content.except("id").merge(opts.stringify_keys) {|k, old, new| k == 'class' ? [old, new].join(' ') : new})
145
179
  @sb_section -= [t_id]
146
180
  html_output
147
181
  end
@@ -242,21 +276,25 @@ module Sibu
242
276
 
243
277
  alias site sb_site
244
278
 
245
- def render_page_section(s)
246
- @sb_section = [s['id']]
279
+ # Resets section ids to clean up remaining ids
280
+ def render_page_section(s, set_id = false)
281
+ instance_variable_set("@sb_section", [])
282
+ push_section_ids(s['id'])
247
283
  @sb_entity = @page
248
284
  render partial: "shared/#{@site.section_template(s)}",
249
- locals: {sibu: self, sibu_section: s, sibu_attrs: sibu_attributes(s).html_safe}
285
+ locals: {sibu: self, sibu_section: s, sibu_attrs: sibu_attributes(s, set_id).html_safe}
250
286
  end
251
287
 
252
288
  # Page sections attrs
253
- def sibu_attributes(section)
254
- action_name != 'show' ? ('data-sb-id="' + section['id'] + '" data-sb-entity="page"') : ''
289
+ def sibu_attributes(section, set_id)
290
+ attrs = set_id ? ('id="' + section['id'] + '" ') : ''
291
+ attrs + (action_name != 'show' ? ('data-sb-id="' + section['id'] + '" data-sb-entity="page"') : '')
255
292
  end
256
293
 
257
- # Site sections attrs
294
+ # Site sections attrs - resets section ids
258
295
  def sibu_attrs(section_id)
259
- @sb_section = [section_id]
296
+ instance_variable_set("@sb_section", [])
297
+ push_section_ids(section_id)
260
298
  @sb_entity = @site
261
299
  action_name != 'show' ? ('data-sb-id="' + section_id + '" data-sb-entity="site"').html_safe : ''
262
300
  end
@@ -289,8 +327,9 @@ module Sibu
289
327
  content = defaults.merge(link_elt)
290
328
  val = content.delete("value") || ""
291
329
  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'
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'
294
333
  if val.to_s.start_with?('http')
295
334
  content["href"] = val
296
335
  elsif val.to_s.start_with?('#')
@@ -308,7 +347,7 @@ module Sibu
308
347
  else
309
348
  html_output = content_tag(:a, raw(text), content.merge(html_opts).except("elements"))
310
349
  end
311
- @sb_section -= [t_id]
350
+ pop_section_id
312
351
  html_output
313
352
  end
314
353
 
@@ -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 = @site.style.nil? || 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.10'
2
+ VERSION = '1.0.15'
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.10
4
+ version: 1.0.15
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-08 00:00:00.000000000 Z
11
+ date: 2021-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails