Class: Utopia::Middleware::Content::Transaction::State
- Inherits:
-
Object
- Object
- Utopia::Middleware::Content::Transaction::State
- Defined in:
- lib/utopia/middleware/content/node.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#overrides ⇒ Object
readonly
Returns the value of attribute overrides.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #call(transaction) ⇒ Object
- #cdata(text) ⇒ Object
-
#initialize(tag, node) ⇒ State
constructor
A new instance of State.
- #lookup(tag) ⇒ Object
- #markup(text) ⇒ Object
- #tag_begin(tag) ⇒ Object
- #tag_complete(tag) ⇒ Object
- #tag_end(tag) ⇒ Object
Constructor Details
#initialize(tag, node) ⇒ State
Returns a new instance of State.
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/utopia/middleware/content/node.rb', line 30 def initialize(tag, node) @node = node @buffer = StringIO.new @overrides = {} @tags = [] @attributes = tag.to_hash @content = nil end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
42 43 44 |
# File 'lib/utopia/middleware/content/node.rb', line 42 def attributes @attributes end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
44 45 46 |
# File 'lib/utopia/middleware/content/node.rb', line 44 def content @content end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
45 46 47 |
# File 'lib/utopia/middleware/content/node.rb', line 45 def node @node end |
#overrides ⇒ Object (readonly)
Returns the value of attribute overrides.
43 44 45 |
# File 'lib/utopia/middleware/content/node.rb', line 43 def overrides @overrides end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
46 47 48 |
# File 'lib/utopia/middleware/content/node.rb', line 46 def @tags end |
Instance Method Details
#[](key) ⇒ Object
48 49 50 |
# File 'lib/utopia/middleware/content/node.rb', line 48 def [](key) @attributes[key.to_s] end |
#call(transaction) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/utopia/middleware/content/node.rb', line 52 def call(transaction) @content = @buffer.string @buffer = StringIO.new if node.respond_to? :call node.call(transaction, self) else transaction.parse_xml(@content) end return @buffer.string end |
#cdata(text) ⇒ Object
79 80 81 |
# File 'lib/utopia/middleware/content/node.rb', line 79 def cdata(text) @buffer.write(text) end |
#lookup(tag) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/utopia/middleware/content/node.rb', line 65 def lookup(tag) if override = @overrides[tag.name] if override.respond_to? :call return override.call(tag) elsif String === override return Tag.new(override, tag.attributes) else return override end else return tag end end |
#markup(text) ⇒ Object
83 84 85 |
# File 'lib/utopia/middleware/content/node.rb', line 83 def markup(text) cdata(text) end |
#tag_begin(tag) ⇒ Object
91 92 93 94 |
# File 'lib/utopia/middleware/content/node.rb', line 91 def tag_begin(tag) @tags << tag tag.write_open_html(@buffer) end |
#tag_complete(tag) ⇒ Object
87 88 89 |
# File 'lib/utopia/middleware/content/node.rb', line 87 def tag_complete(tag) tag.write_full_html(@buffer) end |
#tag_end(tag) ⇒ Object
96 97 98 99 100 |
# File 'lib/utopia/middleware/content/node.rb', line 96 def tag_end(tag) raise UnbalancedTagError(tag) unless @tags.pop.name == tag.name tag.write_close_html(@buffer) end |