sibu 1.0.8 → 1.0.13

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: 9be2c0e35af2b8d5bb5e9283434dff69b764aac6
4
- data.tar.gz: e83fbe2deb769b75efe13a4211cb9f88542d9c03
3
+ metadata.gz: dd539c6932c5892e902387c23af671662ef5e6f0
4
+ data.tar.gz: 3479e3686c6e4eb316c4717e720424ffa98175b3
5
5
  SHA512:
6
- metadata.gz: 593deedf3cecf0eae5c84ce825726d3889d4c9e4b4eba5d2733c0a8c02ba7d1c0fb1a366dfe9523710cb55962cdd7479095e6aac0703cda77282731522e3c851
7
- data.tar.gz: 7e46c8092624205af3b6506587c8a0de7f55fd406d49f2bfc5034455a2b7187c297baa35ee447982d3aeb74f4048102f457734378db1d729bb8282e4524e9fd5
6
+ metadata.gz: f1893df21c5e7b14cd4504744851ea2916bd0c4773245936899fafcc66832c8ebda987e93b24b07489eca3574a6d0c5a9f0584efe7daec8a53040b783d19f4aa
7
+ data.tar.gz: e152ccc9a2afc46648b5a53a9a5801e4f02fa6aba8a3feb79f41e036b424ff8592bd25859c812e67137322cdfcc538d0c445cd41181a936e5c2f99c312a7deda
@@ -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
@@ -118,6 +118,13 @@ module Sibu
118
118
  nested_elts.map {|e| e.merge({"data-id" => join_tokens(element_id_tokens[1..-1], e['id'])})}
119
119
  end
120
120
 
121
+ def each_element(elt_or_id)
122
+ element_id = elt_id(elt_or_id)
123
+ @sb_section = (@sb_section + element_id.split("|")).uniq unless element_id.blank?
124
+ (@sb_entity.elements(*@sb_section) || []).map {|el| yield(el)}
125
+ @sb_section -= [element_id] unless element_id.blank?
126
+ end
127
+
121
128
  def select_element(id)
122
129
  @sb_entity.element(*@sb_section, id)
123
130
  end
@@ -146,6 +153,22 @@ module Sibu
146
153
  html_output
147
154
  end
148
155
 
156
+ def svg_image(elt, opts = {})
157
+ size = opts.delete(:size)
158
+ t_id = elt.is_a?(Hash) ? elt["id"] : elt
159
+ defaults = {"id" => t_id, "xlink:href" => Sibu::DEFAULT_IMG}
160
+ content = defaults.merge((elt.is_a?(Hash) ? elt : (select_element(elt) || {})).transform_keys {|k| k == 'src' ? 'xlink:href' : k})
161
+ @sb_section = (@sb_section || []) + [t_id]
162
+ if action_name == 'show'
163
+ content["xlink:href"] = ("/#{conf[:deployment_path]}" + content["xlink:href"]) if @online && conf[:deployment_path]
164
+ else
165
+ opts.merge!({data: {id: @sb_section[1..-1].join('|'), type: "media", repeat: false, size: size}})
166
+ end
167
+ html_output = content_tag(:image, nil, content.except("id").merge(opts.stringify_keys) {|k, old, new| k == 'class' ? [old, new].join(' ') : new})
168
+ @sb_section -= [t_id]
169
+ html_output
170
+ end
171
+
149
172
  def grp(elt, opts = {}, &block)
150
173
  wrapper = opts.delete(:wrapper) || :div
151
174
  repeat = opts.delete(:repeat)
@@ -169,10 +192,14 @@ module Sibu
169
192
  end
170
193
 
171
194
  def form_label(elt, html_opts = {}, &block)
172
- defaults = {"id" => elt.is_a?(Hash) ? elt["id"] : elt, "text" => Sibu::DEFAULT_TEXT}
195
+ t_id = elt.is_a?(Hash) ? elt["id"] : elt
196
+ defaults = {"id" => t_id, "text" => Sibu::DEFAULT_TEXT}
173
197
  content = defaults.merge(elt.is_a?(Hash) ? elt : (select_element(elt) || {}))
174
- html_opts.merge!({data: {id: elt_id(elt), type: "text"}}) if action_name != 'show'
175
- content_tag(:label, raw(content["text"]).html_safe, html_opts)
198
+ @sb_section = (@sb_section || []) + [t_id]
199
+ html_opts.merge!({data: {id: @sb_section[1..-1].join('|'), type: "text"}}) if action_name != 'show'
200
+ html_output = content_tag(:label, raw(content["text"]).html_safe, html_opts)
201
+ @sb_section -= [t_id]
202
+ html_output
176
203
  end
177
204
 
178
205
  def form_input(elt, html_opts = {})
@@ -238,16 +265,17 @@ module Sibu
238
265
 
239
266
  alias site sb_site
240
267
 
241
- def render_page_section(s)
268
+ def render_page_section(s, set_id = false)
242
269
  @sb_section = [s['id']]
243
270
  @sb_entity = @page
244
271
  render partial: "shared/#{@site.section_template(s)}",
245
- locals: {sibu: self, sibu_section: s, sibu_attrs: sibu_attributes(s).html_safe}
272
+ locals: {sibu: self, sibu_section: s, sibu_attrs: sibu_attributes(s, set_id).html_safe}
246
273
  end
247
274
 
248
275
  # Page sections attrs
249
- def sibu_attributes(section)
250
- action_name != 'show' ? ('data-sb-id="' + section['id'] + '" data-sb-entity="page"') : ''
276
+ def sibu_attributes(section, set_id)
277
+ attrs = set_id ? ('id="' + section['id'] + '" ') : ''
278
+ attrs + (action_name != 'show' ? ('data-sb-id="' + section['id'] + '" data-sb-entity="page"') : '')
251
279
  end
252
280
 
253
281
  # Site sections attrs
@@ -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.8'
2
+ VERSION = '1.0.13'
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.8
4
+ version: 1.0.13
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-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails