Class: Helpers::SelfCloseTag
- Inherits:
-
Object
- Object
- Helpers::SelfCloseTag
- Defined in:
- lib/helpers.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#attrs ⇒ Object
Returns the value of attribute attrs.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #[](attr) ⇒ Object
- #[]=(attr, value) ⇒ Object
-
#data ⇒ Object
Tag.new(:form) { |form| form.data = “Send it now?” }.
-
#initialize(name, attrs = Hash.new, &block) ⇒ SelfCloseTag
constructor
A new instance of SelfCloseTag.
-
#inspect ⇒ Object
NOTE: we can’t use aliasing because it just copy the method so inheritance doesn’t work as expected.
- #to_s ⇒ Object
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
#attrs ⇒ Object
Returns the value of attribute attrs.
14 15 16 |
# File 'lib/helpers.rb', line 14 def attrs @attrs end |
#name ⇒ Object
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 |
#data ⇒ Object
Tag.new(:form) { |form| form.data = “Send it now?” }
30 31 32 |
# File 'lib/helpers.rb', line 30 def data @attrs["data-"] end |
#inspect ⇒ Object
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_s ⇒ Object
34 35 36 |
# File 'lib/helpers.rb', line 34 def to_s "<#{name}#{attrs.to_html_attrs} />" end |