Class: Utopia::Content::Transaction::State

Inherits:
Object
  • Object
show all
Defined in:
lib/utopia/content/transaction.rb

Overview

The state of a single tag being rendered within a Transaction instance.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag, node, attributes = tag.to_hash) ⇒ State

Returns a new instance of State.



207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/utopia/content/transaction.rb', line 207

def initialize(tag, node, attributes = tag.to_hash)
  @node = node
  
  # The contents of the output
  @buffer = String.new
  
  @overrides = {}

  @tags = []
  @attributes = attributes

  @content = nil
  @deferred = []
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



222
223
224
# File 'lib/utopia/content/transaction.rb', line 222

def attributes
  @attributes
end

#contentObject (readonly)

Returns the value of attribute content.



224
225
226
# File 'lib/utopia/content/transaction.rb', line 224

def content
  @content
end

#deferredObject (readonly)

Returns the value of attribute deferred.



228
229
230
# File 'lib/utopia/content/transaction.rb', line 228

def deferred
  @deferred
end

#nodeObject (readonly)

Returns the value of attribute node.



225
226
227
# File 'lib/utopia/content/transaction.rb', line 225

def node
  @node
end

#overridesObject (readonly)

Returns the value of attribute overrides.



223
224
225
# File 'lib/utopia/content/transaction.rb', line 223

def overrides
  @overrides
end

#tagsObject (readonly)

Returns the value of attribute tags.



226
227
228
# File 'lib/utopia/content/transaction.rb', line 226

def tags
  @tags
end

Instance Method Details

#[](key) ⇒ Object



236
237
238
# File 'lib/utopia/content/transaction.rb', line 236

def [](key)
  @attributes[key]
end

#call(transaction) ⇒ Object



254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/utopia/content/transaction.rb', line 254

def call(transaction)
  @content = @buffer
  @buffer = String.new
  
  if node.respond_to? :call
    node.call(transaction, self)
  else
    transaction.parse_markup(@content)
  end
  
  return @buffer
end

#cdata(text) ⇒ Object



267
268
269
# File 'lib/utopia/content/transaction.rb', line 267

def cdata(text)
  @buffer << text
end

#defer(value = nil, &block) ⇒ Object



230
231
232
233
234
# File 'lib/utopia/content/transaction.rb', line 230

def defer(value = nil, &block)
  @deferred << block
  
  Tag.closed(DEFERRED_TAG_NAME, :id => @deferred.size - 1).to_s
end

#lookup(tag) ⇒ Object



240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'lib/utopia/content/transaction.rb', line 240

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



271
272
273
# File 'lib/utopia/content/transaction.rb', line 271

def markup(text)
  cdata(text)
end

#tag_begin(tag) ⇒ Object



279
280
281
282
# File 'lib/utopia/content/transaction.rb', line 279

def tag_begin(tag)
  @tags << tag
  tag.write_open_html(@buffer)
end

#tag_complete(tag) ⇒ Object



275
276
277
# File 'lib/utopia/content/transaction.rb', line 275

def tag_complete(tag)
  tag.write_full_html(@buffer)
end

#tag_end(tag) ⇒ Object



284
285
286
287
288
# File 'lib/utopia/content/transaction.rb', line 284

def tag_end(tag)
  raise UnbalancedTagError(tag) unless @tags.pop.name == tag.name

  tag.write_close_html(@buffer)
end