Class: LazyForm::Tag
- Inherits:
-
Object
- Object
- LazyForm::Tag
- Defined in:
- lib/lazy_form.rb
Constant Summary collapse
- BOOLEAN_ATTRIBUTES =
%i(autofocus checked disabled readonly required)
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(name, attributes = {}, &block) ⇒ Tag
constructor
A new instance of Tag.
- #to_s ⇒ Object
Constructor Details
#initialize(name, attributes = {}, &block) ⇒ Tag
Returns a new instance of Tag.
29 30 31 32 33 |
# File 'lib/lazy_form.rb', line 29 def initialize(name, attributes = {}, &block) @name = name @attributes = attributes @block = block end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
25 26 27 |
# File 'lib/lazy_form.rb', line 25 def attributes @attributes end |
#block ⇒ Object (readonly)
Returns the value of attribute block.
25 26 27 |
# File 'lib/lazy_form.rb', line 25 def block @block end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
25 26 27 |
# File 'lib/lazy_form.rb', line 25 def name @name end |
Instance Method Details
#to_s ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/lazy_form.rb', line 35 def to_s attrs = build_attributes attributes.reject { |k, v| v.nil? } attrs.unshift name if block.nil? "<#{attrs.reject(&:empty?).join ' '}/>" else "<#{attrs.reject(&:empty?).join ' '}>#{block.call}</#{name}>" end end |