sibu 1.0.11 → 1.0.16

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: ddad9d6305d71605c692e8dbdafadb0c6cce1d7a
4
- data.tar.gz: 91539711c089a4d111dede2965a554051c590dc5
3
+ metadata.gz: b93f3e95737adee12da11b924e22c4f04fbf32bb
4
+ data.tar.gz: 2e2f83ffda9d26834d8900c8a6b010a18af69a59
5
5
  SHA512:
6
- metadata.gz: e025dc9b575fedeb91471848f78487b4ba1e3e7fbb19e81822bc31576aae2cd764326ce75bd6e39dd2d2b9ea0901d30f5b33bcef1a26a354a62f90f3d3d74a05
7
- data.tar.gz: cb43b5c568dcd4c9323944645c2ab6935f81988d8a95fe3c47902115db8070bf8e2f10253174d8eaa73074f63348bce2acb724e0c69171e1ff8540355a8db827
6
+ metadata.gz: c4feb32b7552393945dbf01283555d8a2037d076c71dbc71fbc4a5806a35a132190043b87ad6e95dd2be4fdad6498bc6ba204f9b683309fea3e097c08a1cd281
7
+ data.tar.gz: 5155224fcf65a3e519ea91f2fbe87e52b8185f86dbefb459abe623902266b9959ed72eac609ecf41e21c081b895359209a4c992ef6f9d02f0c0efcfe4828653a
@@ -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,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
- @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?
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(*@sb_section, id)
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
- @sb_section = (@sb_section || []) + [t_id]
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
- @sb_section -= [t_id]
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 = [s['id']]
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 = [section_id]
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
- @sb_section = (@sb_section || []) + [t_id]
317
- 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'
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
- @sb_section -= [t_id]
350
+ pop_section_id
336
351
  html_output
337
352
  end
338
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| %>
data/lib/sibu/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sibu
2
- VERSION = '1.0.11'
2
+ VERSION = '1.0.16'
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.11
4
+ version: 1.0.16
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-10-02 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