sibu 1.0.12 → 1.0.17

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: d80e0d86c6b0ae3ee81f45775acf1c021fe15a17
4
- data.tar.gz: 712c3383c6bb99034f988e9ecd45933f7cd60957
3
+ metadata.gz: '0881050b04d182c65eeffbad03d9685873c0c19d'
4
+ data.tar.gz: 596ab4805391210194ff4ca5ee3526eb535cf175
5
5
  SHA512:
6
- metadata.gz: a51aca986aff80d8a5c0341aa6081bf464f66ee74eacae47aedf730035a123d19edf9219e4d3df56e00b3adf56dfb2aff72841677b2459ceec37a1892f09ccb5
7
- data.tar.gz: 79751582c4674b13b2d7da12cd50224d2073f695bdb746d2d222457eb97c5a4ccb01fb9962777ff71c95313c4c4f554b26a5da8d47661f4200469f9236cf0fe5
6
+ metadata.gz: 33e03744ade338a03c6b16fb327d2675163abe23f4d3ee2f5b3fe58c301fb6573c8409c6007dbf787c58a9d20e7e24391d07f52d8b6ca69912222681d40ce2b8
7
+ data.tar.gz: c653ca08088170f1c076d793e1bf14dc7adf62ae849e18a899b9a3cd3ed162b98e1d00958be7ab05865486e7e7c80fe0ba89e848efadb70daee21036602c5db9
@@ -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
 
@@ -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
@@ -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.12'
2
+ VERSION = '1.0.17'
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.12
4
+ version: 1.0.17
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-12-22 00:00:00.000000000 Z
11
+ date: 2021-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails