Class: Keynote::Rumble::Tag
- Inherits:
-
Object
- Object
- Keynote::Rumble::Tag
show all
- Defined in:
- lib/keynote/rumble.rb
Instance Method Summary
collapse
Constructor Details
#initialize(context, instance, name, sc) ⇒ Tag
Returns a new instance of Tag.
226
227
228
229
230
231
232
|
# File 'lib/keynote/rumble.rb', line 226
def initialize(context, instance, name, sc)
@context = context
@instance = instance
@name = name
@sc = sc
@done, @content = nil
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, content = nil, attrs = nil, &blk) ⇒ Object
250
251
252
253
254
255
256
257
258
259
260
261
262
|
# File 'lib/keynote/rumble.rb', line 250
def method_missing(name, content = nil, attrs = nil, &blk)
name = name.to_s
if name[-1] == "!"
attributes[:id] = name[0..-2]
elsif attributes.has_key?(:class)
attributes[:class] += " #{name}"
else
attributes[:class] = name
end
insert(content, attrs, &blk)
end
|
Instance Method Details
#attributes ⇒ Object
234
235
236
|
# File 'lib/keynote/rumble.rb', line 234
def attributes
@attributes ||= {}
end
|
#html_safe? ⇒ Boolean
305
306
307
|
# File 'lib/keynote/rumble.rb', line 305
def html_safe?
true
end
|
#insert(content = nil, attrs = nil, &blk) ⇒ Object
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
|
# File 'lib/keynote/rumble.rb', line 264
def insert(content = nil, attrs = nil, &blk)
raise Error, "This tag is already closed" if @done
if content.is_a?(Hash)
attrs = content
content = nil
end
attrs = flatten_attr_hash(attrs, :aria)
attrs = flatten_attr_hash(attrs, :data)
merge_attributes(attrs) if attrs
if block_given?
raise Error, "`#{@name}` is not allowed to have content" if @sc
@done = :block
before = @context.size
res = yield
@content = Rumble.html_escape(res) if @context.size == before
@context << "</#{@name}>"
elsif content
raise Error, "`#{@name}` is not allowed to have content" if @sc
@done = true
@content = Rumble.html_escape(content)
elsif attrs
@done = true
end
self
rescue
@instance.rumble_cleanup
raise $!
end
|
#inspect ⇒ Object
323
324
325
|
# File 'lib/keynote/rumble.rb', line 323
def inspect
to_s.inspect
end
|
#merge_attributes(attrs) ⇒ Object
238
239
240
241
242
243
244
|
# File 'lib/keynote/rumble.rb', line 238
def merge_attributes(attrs)
if defined?(@attributes)
@attributes.merge!(attrs)
else
@attributes = attrs
end
end
|
#respond_to_missing?(name, include_private = false) ⇒ Boolean
246
247
248
|
# File 'lib/keynote/rumble.rb', line 246
def respond_to_missing?(name, include_private = false)
true
end
|
#to_ary ⇒ Object
297
298
299
|
# File 'lib/keynote/rumble.rb', line 297
def to_ary
nil
end
|
#to_s ⇒ Object
309
310
311
312
313
314
315
316
317
318
319
320
321
|
# File 'lib/keynote/rumble.rb', line 309
def to_s
if @instance.rumble_context.eql?(@context)
@instance.rumble_cleanup
@context.to_s
else
@result ||= begin
res = "<#{@name}#{attrs_to_s}>"
res << @content if @content
res << "</#{@name}>" if !@sc && @done != :block
res.html_safe
end
end
end
|
#to_str ⇒ Object
301
302
303
|
# File 'lib/keynote/rumble.rb', line 301
def to_str
to_s
end
|