inplace_editing 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 14d4af4297d80751b6dd9c94bc5907b149f2b3a1
4
- data.tar.gz: df9554b5d67b72dc7e3774a884c2bb75e76fd96d
3
+ metadata.gz: 6eb5a3fd084d87825995b0a62aa3db86694227a2
4
+ data.tar.gz: 4fc5e702322f481f0e2f45106ff823c013c63d0b
5
5
  SHA512:
6
- metadata.gz: 3b20cb1f7b60dfc8913a9cc570b65bc7527697da7a41648a6eca96d38ce473c1601f4ad25b3871bfba0aae87c2f1b28c9dd0ec431264592b2ac0da0c015b15f8
7
- data.tar.gz: 3f755c7bf752975c36e330b4ed6ea1c03c6f2870ac4e7dae00454fd0d0220d9ec0c8f5c57f57794fae2bd3b3b1c52a1896cc8c1d4947e33092da3a141df9ccc8
6
+ metadata.gz: 05a3684dda2bf7c514ece856c77f9f36036ecaa398bb0aa079c4b5ed9e0708caf778530736a7f7303e525cf10bbba6a6c12218de449164803e13d88d26060b31
7
+ data.tar.gz: 4a600b62027bfff60c3bf22de0880ef2c7472c813780c32c22e39cd20c2cfb3b156071063ea33536f8fd0c959258a6e81068511cd0d9a9eb1539be70ffc9c759
@@ -99,7 +99,7 @@ module InplaceEditingHelper
99
99
 
100
100
  def empty_content_tag(*args)
101
101
  if block_given?
102
- tag = Tag.new(args[0], args[1] || {})
102
+ tag = EmptyTag.new(args[0], args[1] || {})
103
103
  old_buf = @output_buffer
104
104
  @output_buffer = ActionView::OutputBuffer.new
105
105
  content = tag.render(@output_buffer.presence)
@@ -170,6 +170,67 @@ module InplaceEditingHelper
170
170
  end
171
171
  end
172
172
  end
173
+
174
+ class EmptyTag
175
+ include ActionView::Helpers::CaptureHelper
176
+ attr_accessor :id
177
+ attr_reader :name, :css
178
+
179
+ def initialize(name, attributes = {})
180
+ @name = name
181
+ @attributes = attributes.with_indifferent_access
182
+ @attributes[:class] = Tag::CSS.new(attributes[:class])
183
+ end
184
+
185
+ def []=(k,v)
186
+ @attributes[k] = v
187
+ end
188
+
189
+ def [](k)
190
+ @attributes[k]
191
+ end
192
+
193
+ def render(content)
194
+ "<#{name}#{render_attributes} />".html_safe
195
+ end
196
+
197
+ def render_attributes
198
+ attrs = @attributes.dup
199
+ if self[:class].empty?
200
+ attrs.delete :class
201
+ else
202
+ attrs[:class] = self[:class].to_s
203
+ end
204
+
205
+ attrs.keys.map do |k|
206
+ "#{k}='#{ERB::Util.html_escape(attrs[k])}'".html_safe
207
+ end.join(' ').prepend(' ')
208
+ end
209
+
210
+ class CSS
211
+
212
+ def initialize(css)
213
+ if css.is_a? String
214
+ @internals = css.split(' ')
215
+ else
216
+ @internals = css.to_a
217
+ end
218
+ end
219
+
220
+ def to_s
221
+ @internals.uniq.join(' ')
222
+ end
223
+
224
+ def empty?
225
+ @internals.empty?
226
+ end
227
+
228
+ def <<(name)
229
+ @internals << name
230
+ nil
231
+ end
232
+ end
233
+ end
173
234
  end
174
235
 
175
236
  # @inplace_editing_mode = tem que ser setado no after_action usando o @can_edit
@@ -1,3 +1,3 @@
1
1
  module InplaceEditing
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inplace_editing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henrique Rangel