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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag, node) ⇒ State

Returns a new instance of State.



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/utopia/content/transaction.rb', line 39

def initialize(tag, node)
	@node = node

	@buffer = StringIO.new
	@overrides = {}

	@tags = []
	@attributes = tag.to_hash

	@content = nil
	@deferred = []
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



52
53
54
# File 'lib/utopia/content/transaction.rb', line 52

def attributes
  @attributes
end

#contentObject (readonly)

Returns the value of attribute content.



54
55
56
# File 'lib/utopia/content/transaction.rb', line 54

def content
  @content
end

#deferredObject (readonly)

Returns the value of attribute deferred.



58
59
60
# File 'lib/utopia/content/transaction.rb', line 58

def deferred
  @deferred
end

#nodeObject (readonly)

Returns the value of attribute node.



55
56
57
# File 'lib/utopia/content/transaction.rb', line 55

def node
  @node
end

#overridesObject (readonly)

Returns the value of attribute overrides.



53
54
55
# File 'lib/utopia/content/transaction.rb', line 53

def overrides
  @overrides
end

#tagsObject (readonly)

Returns the value of attribute tags.



56
57
58
# File 'lib/utopia/content/transaction.rb', line 56

def tags
  @tags
end

Instance Method Details

#[](key) ⇒ Object



66
67
68
# File 'lib/utopia/content/transaction.rb', line 66

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

#call(transaction) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/utopia/content/transaction.rb', line 70

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

	return @buffer.string
end

#cdata(text) ⇒ Object



97
98
99
# File 'lib/utopia/content/transaction.rb', line 97

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

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



60
61
62
63
64
# File 'lib/utopia/content/transaction.rb', line 60

def defer(value = nil, &block)
	@deferred << block

	Tag.closed("deferred", :id => @deferred.size - 1).to_html
end

#lookup(tag) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/utopia/content/transaction.rb', line 83

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



101
102
103
# File 'lib/utopia/content/transaction.rb', line 101

def markup(text)
	cdata(text)
end

#tag_begin(tag) ⇒ Object



109
110
111
112
# File 'lib/utopia/content/transaction.rb', line 109

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

#tag_complete(tag) ⇒ Object



105
106
107
# File 'lib/utopia/content/transaction.rb', line 105

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

#tag_end(tag) ⇒ Object



114
115
116
117
118
# File 'lib/utopia/content/transaction.rb', line 114

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

	tag.write_close_html(@buffer)
end