Class: Helpers::SelfCloseTag

Inherits:
Object
  • Object
show all
Defined in:
lib/helpers.rb

Direct Known Subclasses

Tag

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, attrs = Hash.new, &block) ⇒ SelfCloseTag

Returns a new instance of SelfCloseTag.



15
16
17
18
19
# File 'lib/helpers.rb', line 15

def initialize(name, attrs = Hash.new, &block)
  attrs.extend(HtmlAttrsMixin)
  @name, @attrs = name, attrs
  block.call(self) unless block.nil?
end

Instance Attribute Details

#attrsObject

Returns the value of attribute attrs.



14
15
16
# File 'lib/helpers.rb', line 14

def attrs
  @attrs
end

#nameObject

Returns the value of attribute name.



14
15
16
# File 'lib/helpers.rb', line 14

def name
  @name
end

Instance Method Details

#[](attr) ⇒ Object



21
22
23
# File 'lib/helpers.rb', line 21

def [](attr)
  self.attrs[attr]
end

#[]=(attr, value) ⇒ Object



25
26
27
# File 'lib/helpers.rb', line 25

def []=(attr, value)
  self.attrs[attr] = value
end

#dataObject

Tag.new(:form) { |form| form.data = “Send it now?” }



30
31
32
# File 'lib/helpers.rb', line 30

def data
  @attrs["data-"]
end

#inspectObject

NOTE: we can’t use aliasing because it just copy the method so inheritance doesn’t work as expected



39
40
41
# File 'lib/helpers.rb', line 39

def inspect
  self.to_s
end

#to_sObject



34
35
36
# File 'lib/helpers.rb', line 34

def to_s
  "<#{name}#{attrs.to_html_attrs} />"
end