Class: HtmlToHaml::Html::AttributeHandler
- Inherits:
-
Object
- Object
- HtmlToHaml::Html::AttributeHandler
- Defined in:
- lib/html_to_haml/tools/html/attribute_handler.rb
Constant Summary collapse
- HTML_ONLY_ATTRIBUTE_REGEX =
/=['"][^#\{]*['"]/
Instance Method Summary collapse
- #add_attribute(attr:) ⇒ Object
- #attributes_string ⇒ Object
-
#initialize ⇒ AttributeHandler
constructor
A new instance of AttributeHandler.
Constructor Details
#initialize ⇒ AttributeHandler
Returns a new instance of AttributeHandler.
6 7 8 9 10 |
# File 'lib/html_to_haml/tools/html/attribute_handler.rb', line 6 def initialize @ids = [] @classes = [] @plain_attributes = [] end |
Instance Method Details
#add_attribute(attr:) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/html_to_haml/tools/html/attribute_handler.rb', line 12 def add_attribute(attr:) if use_id_syntax?(attr: attr) @ids += extract_attribute_value(attr: attr).split(' ') elsif use_class_syntax?(attr: attr) @classes += extract_attribute_value(attr: attr).split(' ') else @plain_attributes << attr.strip.gsub(/=/, ': ') end end |
#attributes_string ⇒ Object
22 23 24 |
# File 'lib/html_to_haml/tools/html/attribute_handler.rb', line 22 def attributes_string "#{format_ids}#{format_classes}#{format_attributes}" end |