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
# File 'lib/utopia/content/transaction.rb', line 207

def initialize(tag, node, attributes = tag.to_hash)
	@node = node

	@buffer = StringIO.new
	@overrides = {}

	@tags = []
	@attributes = attributes

	@content = nil
	@deferred = []
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



220
221
222
# File 'lib/utopia/content/transaction.rb', line 220

def attributes
  @attributes
end

#contentObject (readonly)

Returns the value of attribute content.



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

def content
  @content
end

#deferredObject (readonly)

Returns the value of attribute deferred.



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

def deferred
  @deferred
end

#nodeObject (readonly)

Returns the value of attribute node.



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

def node
  @node
end

#overridesObject (readonly)

Returns the value of attribute overrides.



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

def overrides
  @overrides
end

#tagsObject (readonly)

Returns the value of attribute tags.



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

def tags
  @tags
end

Instance Method Details

#[](key) ⇒ Object



234
235
236
# File 'lib/utopia/content/transaction.rb', line 234

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

#call(transaction) ⇒ Object



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

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

#cdata(text) ⇒ Object



265
266
267
# File 'lib/utopia/content/transaction.rb', line 265

def cdata(text)
	@buffer.write(text)
end

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



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

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

#lookup(tag) ⇒ Object



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

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



269
270
271
# File 'lib/utopia/content/transaction.rb', line 269

def markup(text)
	cdata(text)
end

#tag_begin(tag) ⇒ Object



277
278
279
280
# File 'lib/utopia/content/transaction.rb', line 277

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

#tag_complete(tag) ⇒ Object



273
274
275
# File 'lib/utopia/content/transaction.rb', line 273

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

#tag_end(tag) ⇒ Object



282
283
284
285
286
# File 'lib/utopia/content/transaction.rb', line 282

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

	tag.write_close_html(@buffer)
end