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

Inherits:
Object
  • Object
show all
Defined in:
lib/utopia/content/node.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.



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/utopia/content/node.rb', line 42

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.



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

def attributes
  @attributes
end

#contentObject (readonly)

Returns the value of attribute content.



57
58
59
# File 'lib/utopia/content/node.rb', line 57

def content
  @content
end

#deferredObject (readonly)

Returns the value of attribute deferred.



61
62
63
# File 'lib/utopia/content/node.rb', line 61

def deferred
  @deferred
end

#nodeObject (readonly)

Returns the value of attribute node.



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

def node
  @node
end

#overridesObject (readonly)

Returns the value of attribute overrides.



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

def overrides
  @overrides
end

#tagsObject (readonly)

Returns the value of attribute tags.



59
60
61
# File 'lib/utopia/content/node.rb', line 59

def tags
  @tags
end

Instance Method Details

#[](key) ⇒ Object



69
70
71
# File 'lib/utopia/content/node.rb', line 69

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

#call(transaction) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/utopia/content/node.rb', line 73

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



100
101
102
# File 'lib/utopia/content/node.rb', line 100

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

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



63
64
65
66
67
# File 'lib/utopia/content/node.rb', line 63

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

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

#lookup(tag) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/utopia/content/node.rb', line 86

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



104
105
106
# File 'lib/utopia/content/node.rb', line 104

def markup(text)
	cdata(text)
end

#tag_begin(tag) ⇒ Object



112
113
114
115
# File 'lib/utopia/content/node.rb', line 112

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

#tag_complete(tag) ⇒ Object



108
109
110
# File 'lib/utopia/content/node.rb', line 108

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

#tag_end(tag) ⇒ Object



117
118
119
120
121
# File 'lib/utopia/content/node.rb', line 117

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

	tag.write_close_html(@buffer)
end