Class: Utopia::Content::Tag
- Inherits:
-
Object
- Object
- Utopia::Content::Tag
- Defined in:
- lib/utopia/content/tag.rb
Overview
This represents an individual SGML tag, e.g. , or , with attributes. Attribute values must be escaped.
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#closed ⇒ Object
Returns the value of attribute closed.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](key) ⇒ Object
- #freeze ⇒ Object
-
#initialize(name, attributes = {}) ⇒ Tag
constructor
A new instance of Tag.
- #to_hash ⇒ Object
- #to_s(content = nil) ⇒ Object (also: #to_html)
- #write_close_html(buffer) ⇒ Object
- #write_full_html(buffer, content = nil) ⇒ Object
- #write_open_html(buffer, terminate = false) ⇒ Object
Constructor Details
#initialize(name, attributes = {}) ⇒ Tag
Returns a new instance of Tag.
38 39 40 41 42 |
# File 'lib/utopia/content/tag.rb', line 38 def initialize(name, attributes = {}) @name = name @attributes = attributes @closed = false end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
53 54 55 |
# File 'lib/utopia/content/tag.rb', line 53 def attributes @attributes end |
#closed ⇒ Object
Returns the value of attribute closed.
54 55 56 |
# File 'lib/utopia/content/tag.rb', line 54 def closed @closed end |
#name ⇒ Object
Returns the value of attribute name.
52 53 54 |
# File 'lib/utopia/content/tag.rb', line 52 def name @name end |
Class Method Details
Instance Method Details
#==(other) ⇒ Object
25 26 27 28 29 |
# File 'lib/utopia/content/tag.rb', line 25 def == other if Tag === other [@name, @attributes, @closed] == [other.name, other.attributes, other.closed] end end |
#[](key) ⇒ Object
56 57 58 |
# File 'lib/utopia/content/tag.rb', line 56 def [](key) @attributes[key] end |
#freeze ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/utopia/content/tag.rb', line 44 def freeze @name.freeze @attributes.freeze @closed.freeze super end |
#to_hash ⇒ Object
60 61 62 |
# File 'lib/utopia/content/tag.rb', line 60 def to_hash @attributes end |
#to_s(content = nil) ⇒ Object Also known as: to_html
64 65 66 67 68 69 70 |
# File 'lib/utopia/content/tag.rb', line 64 def to_s(content = nil) buffer = String.new write_full_html(buffer, content) return buffer end |
#write_close_html(buffer) ⇒ Object
92 93 94 |
# File 'lib/utopia/content/tag.rb', line 92 def write_close_html(buffer) buffer << "</#{name}>" end |
#write_full_html(buffer, content = nil) ⇒ Object
96 97 98 99 100 101 102 103 104 |
# File 'lib/utopia/content/tag.rb', line 96 def write_full_html(buffer, content = nil) if @closed and content.nil? write_open_html(buffer, true) else write_open_html(buffer) buffer << content if content write_close_html(buffer) end end |
#write_open_html(buffer, terminate = false) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/utopia/content/tag.rb', line 74 def write_open_html(buffer, terminate = false) buffer << "<#{name}" @attributes.each do |key, value| if value buffer << " #{key}=\"#{value}\"" else buffer << " #{key}" end end if terminate buffer << "/>" else buffer << ">" end end |