Class: Utopia::Content::Transaction::State
- Inherits:
-
Object
- Object
- Utopia::Content::Transaction::State
- Defined in:
- lib/utopia/content/transaction.rb
Overview
The state of a single tag being rendered.
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#deferred ⇒ Object
readonly
Returns the value of attribute deferred.
-
#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
- #defer(value = nil, &block) ⇒ 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.
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/utopia/content/transaction.rb', line 39 def initialize(tag, node) @node = node @buffer = StringIO.new @overrides = {} = [] @attributes = tag.to_hash @content = nil @deferred = [] end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
52 53 54 |
# File 'lib/utopia/content/transaction.rb', line 52 def attributes @attributes end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
54 55 56 |
# File 'lib/utopia/content/transaction.rb', line 54 def content @content end |
#deferred ⇒ Object (readonly)
Returns the value of attribute deferred.
58 59 60 |
# File 'lib/utopia/content/transaction.rb', line 58 def deferred @deferred end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
55 56 57 |
# File 'lib/utopia/content/transaction.rb', line 55 def node @node end |
#overrides ⇒ Object (readonly)
Returns the value of attribute overrides.
53 54 55 |
# File 'lib/utopia/content/transaction.rb', line 53 def overrides @overrides end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
56 57 58 |
# File 'lib/utopia/content/transaction.rb', line 56 def end |
Instance Method Details
#[](key) ⇒ Object
66 67 68 |
# File 'lib/utopia/content/transaction.rb', line 66 def [](key) @attributes[key.to_s] end |
#call(transaction) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/utopia/content/transaction.rb', line 70 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
97 98 99 |
# File 'lib/utopia/content/transaction.rb', line 97 def cdata(text) @buffer.write(text) end |
#defer(value = nil, &block) ⇒ Object
60 61 62 63 64 |
# File 'lib/utopia/content/transaction.rb', line 60 def defer(value = nil, &block) @deferred << block Tag.closed("deferred", :id => @deferred.size - 1).to_html end |
#lookup(tag) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/utopia/content/transaction.rb', line 83 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
101 102 103 |
# File 'lib/utopia/content/transaction.rb', line 101 def markup(text) cdata(text) end |
#tag_begin(tag) ⇒ Object
109 110 111 112 |
# File 'lib/utopia/content/transaction.rb', line 109 def tag_begin(tag) << tag tag.write_open_html(@buffer) end |
#tag_complete(tag) ⇒ Object
105 106 107 |
# File 'lib/utopia/content/transaction.rb', line 105 def tag_complete(tag) tag.write_full_html(@buffer) end |
#tag_end(tag) ⇒ Object
114 115 116 117 118 |
# File 'lib/utopia/content/transaction.rb', line 114 def tag_end(tag) raise UnbalancedTagError(tag) unless .pop.name == tag.name tag.write_close_html(@buffer) end |