Class: Utopia::Content::Document::State
- Inherits:
-
Object
- Object
- Utopia::Content::Document::State
- Defined in:
- lib/utopia/content/document.rb
Overview
The state of a single tag being rendered within a document 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.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#tags ⇒ Object
readonly
A list of all tags in order of rendering them, which have not been finished yet.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #call(document) ⇒ Object
- #defer(value = nil, &block) ⇒ Object
-
#empty? ⇒ Boolean
Whether this state has any nested tags.
-
#initialize(parent, tag, node, attributes = tag.to_hash) ⇒ State
constructor
A new instance of State.
- #tag_begin(tag) ⇒ Object
- #tag_complete(tag) ⇒ Object
- #tag_end(tag) ⇒ Object
- #text(string) ⇒ Object
- #write(string) ⇒ Object
Constructor Details
#initialize(parent, tag, node, attributes = tag.to_hash) ⇒ State
Returns a new instance of State.
230 231 232 233 234 235 236 237 238 239 240 241 242 |
# 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 |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
245 246 247 |
# File 'lib/utopia/content/document.rb', line 245 def attributes @attributes end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
246 247 248 |
# File 'lib/utopia/content/document.rb', line 246 def content @content end |
#deferred ⇒ Object (readonly)
Returns the value of attribute deferred.
252 253 254 |
# File 'lib/utopia/content/document.rb', line 252 def deferred @deferred end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
247 248 249 |
# File 'lib/utopia/content/document.rb', line 247 def node @node end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
244 245 246 |
# File 'lib/utopia/content/document.rb', line 244 def parent @parent end |
#tags ⇒ Object (readonly)
A list of all tags in order of rendering them, which have not been finished yet.
250 251 252 |
# File 'lib/utopia/content/document.rb', line 250 def @tags end |
Instance Method Details
#[](key) ⇒ Object
260 261 262 |
# File 'lib/utopia/content/document.rb', line 260 def [](key) @attributes[key] end |
#call(document) ⇒ Object
264 265 266 267 268 269 270 271 272 273 274 275 |
# 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) ⇒ Object
254 255 256 257 258 |
# 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? ⇒ Boolean
Whether this state has any nested tags.
290 291 292 |
# File 'lib/utopia/content/document.rb', line 290 def empty? @tags.empty? end |
#tag_begin(tag) ⇒ Object
294 295 296 297 298 299 |
# 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) ⇒ Object
285 286 287 |
# File 'lib/utopia/content/document.rb', line 285 def tag_complete(tag) tag.write(@buffer) end |
#tag_end(tag) ⇒ Object
301 302 303 304 |
# 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) ⇒ Object
281 282 283 |
# File 'lib/utopia/content/document.rb', line 281 def text(string) Trenni::Markup.append(@buffer, string) end |
#write(string) ⇒ Object
277 278 279 |
# File 'lib/utopia/content/document.rb', line 277 def write(string) @buffer << string end |