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 within a Transaction instance.
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
- #defer(value = nil, &block) ⇒ Object
-
#initialize(tag, node, attributes = tag.to_hash) ⇒ State
constructor
A new instance of State.
- #lookup(tag) ⇒ Object
- #tag_begin(tag) ⇒ Object
- #tag_complete(tag) ⇒ Object
- #tag_end(tag) ⇒ Object
- #text(string) ⇒ Object
- #write(string) ⇒ Object
Constructor Details
#initialize(tag, node, attributes = tag.to_hash) ⇒ State
Returns a new instance of State.
215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/utopia/content/transaction.rb', line 215 def initialize(tag, node, attributes = tag.to_hash) @node = node @buffer = Trenni::MarkupString.new.force_encoding(Encoding::UTF_8) @overrides = {} @tags = [] @attributes = attributes @content = nil @deferred = [] end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
229 230 231 |
# File 'lib/utopia/content/transaction.rb', line 229 def attributes @attributes end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
231 232 233 |
# File 'lib/utopia/content/transaction.rb', line 231 def content @content end |
#deferred ⇒ Object (readonly)
Returns the value of attribute deferred.
235 236 237 |
# File 'lib/utopia/content/transaction.rb', line 235 def deferred @deferred end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
232 233 234 |
# File 'lib/utopia/content/transaction.rb', line 232 def node @node end |
#overrides ⇒ Object (readonly)
Returns the value of attribute overrides.
230 231 232 |
# File 'lib/utopia/content/transaction.rb', line 230 def overrides @overrides end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
233 234 235 |
# File 'lib/utopia/content/transaction.rb', line 233 def @tags end |
Instance Method Details
#[](key) ⇒ Object
243 244 245 |
# File 'lib/utopia/content/transaction.rb', line 243 def [](key) @attributes[key] end |
#call(transaction) ⇒ Object
261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'lib/utopia/content/transaction.rb', line 261 def call(transaction) @content = @buffer @buffer = Trenni::MarkupString.new.force_encoding(Encoding::UTF_8) if node.respond_to? :call node.call(transaction, self) else transaction.parse_markup(@content) end return @buffer end |
#defer(value = nil, &block) ⇒ Object
237 238 239 240 241 |
# File 'lib/utopia/content/transaction.rb', line 237 def defer(value = nil, &block) @deferred << block Tag.closed(DEFERRED_TAG_NAME, :id => @deferred.size - 1) end |
#lookup(tag) ⇒ Object
247 248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'lib/utopia/content/transaction.rb', line 247 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 |
#tag_begin(tag) ⇒ Object
286 287 288 289 |
# File 'lib/utopia/content/transaction.rb', line 286 def tag_begin(tag) @tags << tag tag.write_opening_tag(@buffer) end |
#tag_complete(tag) ⇒ Object
282 283 284 |
# File 'lib/utopia/content/transaction.rb', line 282 def tag_complete(tag) tag.write(@buffer) end |
#tag_end(tag) ⇒ Object
291 292 293 294 |
# File 'lib/utopia/content/transaction.rb', line 291 def tag_end(tag) raise UnbalancedTagError(tag) unless @tags.pop.name == tag.name tag.write_closing_tag(@buffer) end |
#text(string) ⇒ Object
278 279 280 |
# File 'lib/utopia/content/transaction.rb', line 278 def text(string) @buffer << Trenni::MarkupString(string) end |
#write(string) ⇒ Object
274 275 276 |
# File 'lib/utopia/content/transaction.rb', line 274 def write(string) @buffer << string end |