class Utopia::Content::Document::State
The state of a single tag being rendered within a document instance.
Attributes
attributes[R]
content[R]
deferred[R]
node[R]
parent[R]
Public Class Methods
new(parent, tag, node, attributes = tag.to_hash)
click to toggle source
# File lib/utopia/content/document.rb, line 230 def initialize(parent, tag, node, attributes = tag.to_hash) @parent = parent @tag = tag @node = node @attributes = attributes @buffer = Trenni::MarkupString.new.force_encoding(Encoding::UTF_8) @content = nil @deferred = [] @tags = [] end
Public Instance Methods
[](key)
click to toggle source
# File lib/utopia/content/document.rb, line 260 def [](key) @attributes[key] end
call(document)
click to toggle source
# File lib/utopia/content/document.rb, line 264 def call(document) @content = @buffer @buffer = Trenni::MarkupString.new.force_encoding(Encoding::UTF_8) if node.respond_to? :call node.call(document, self) else document.parse_markup(@content) end return @buffer end
defer(value = nil, &block)
click to toggle source
# File lib/utopia/content/document.rb, line 254 def defer(value = nil, &block) @deferred << block Tag.closed(DEFERRED_TAG_NAME, :id => @deferred.size - 1) end
empty?()
click to toggle source
Whether this state has any nested tags.
# File lib/utopia/content/document.rb, line 290 def empty? @tags.empty? end
tag_begin(tag)
click to toggle source
# File lib/utopia/content/document.rb, line 294 def tag_begin(tag) # raise ArgumentError.new("tag_begin: #{tag} is tag.self_closed?") if tag.self_closed? @tags << tag tag.write_opening_tag(@buffer) end
tag_complete(tag)
click to toggle source
# File lib/utopia/content/document.rb, line 285 def tag_complete(tag) tag.write(@buffer) end
tag_end(tag)
click to toggle source
# File lib/utopia/content/document.rb, line 301 def tag_end(tag) raise UnbalancedTagError.new(tag) unless @tags.pop.name == tag.name tag.write_closing_tag(@buffer) end
text(string)
click to toggle source
# File lib/utopia/content/document.rb, line 281 def text(string) Trenni::Markup.append(@buffer, string) end
write(string)
click to toggle source
# File lib/utopia/content/document.rb, line 277 def write(string) @buffer << string end