Class: TagStatement
- Defined in:
- lib/emerald/nodes/tag_statement.rb
Overview
A tag
Constant Summary collapse
- VOID_TAGS =
( "area base br col embed hr img input link " + "menuitem meta param source track wbr" ).split(/\s+/)
Instance Method Summary collapse
- #class_attribute ⇒ Object
- #closing_tag(_context) ⇒ Object
- #id_attribute ⇒ Object
- #opening_tag(context) ⇒ Object
- #to_html(context) ⇒ Object
- #void_tag? ⇒ Boolean
Instance Method Details
#class_attribute ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/emerald/nodes/tag_statement.rb', line 31 def class_attribute unless classes.empty? class_names = classes .elements .map{ |c| c.name.text_value } .join(' ') " class=\"#{class_names}\"" else '' end end |
#closing_tag(_context) ⇒ Object
75 76 77 |
# File 'lib/emerald/nodes/tag_statement.rb', line 75 def closing_tag(_context) "</#{tag.text_value}>" end |
#id_attribute ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/emerald/nodes/tag_statement.rb', line 44 def id_attribute unless identifier.empty? " id=\"#{identifier.name.text_value}\"" else '' end end |
#opening_tag(context) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/emerald/nodes/tag_statement.rb', line 52 def opening_tag(context) "<#{tag.text_value}" + id_attribute + class_attribute + ( if !attributes.empty? ' ' + attributes.to_html(context) else '' end ) + ( if void_tag? ' />' else '>' end ) end |
#to_html(context) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/emerald/nodes/tag_statement.rb', line 15 def to_html(context) if void_tag? opening_tag(context) else opening_tag(context) + ( if !body.empty? body.to_html(context) else '' end ) + closing_tag(context) end end |
#void_tag? ⇒ Boolean
71 72 73 |
# File 'lib/emerald/nodes/tag_statement.rb', line 71 def void_tag? VOID_TAGS.include? tag.text_value end |