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 +4 -4
- data/app/helpers/inplace_editing_helper.rb +62 -1
- data/lib/inplace_editing/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6eb5a3fd084d87825995b0a62aa3db86694227a2
|
4
|
+
data.tar.gz: 4fc5e702322f481f0e2f45106ff823c013c63d0b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 =
|
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
|