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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag, node) ⇒ State

Returns a new instance of State.



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/utopia/middleware/content/node.rb', line 30

def initialize(tag, node)
	@node = node

	@buffer = StringIO.new
	@overrides = {}

	@tags = []
	@attributes = tag.to_hash

	@content = nil
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



42
43
44
# File 'lib/utopia/middleware/content/node.rb', line 42

def attributes
  @attributes
end

#contentObject (readonly)

Returns the value of attribute content.



44
45
46
# File 'lib/utopia/middleware/content/node.rb', line 44

def content
  @content
end

#nodeObject (readonly)

Returns the value of attribute node.



45
46
47
# File 'lib/utopia/middleware/content/node.rb', line 45

def node
  @node
end

#overridesObject (readonly)

Returns the value of attribute overrides.



43
44
45
# File 'lib/utopia/middleware/content/node.rb', line 43

def overrides
  @overrides
end

#tagsObject (readonly)

Returns the value of attribute tags.



46
47
48
# File 'lib/utopia/middleware/content/node.rb', line 46

def tags
  @tags
end

Instance Method Details

#[](key) ⇒ Object



48
49
50
# File 'lib/utopia/middleware/content/node.rb', line 48

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

#call(transaction) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/utopia/middleware/content/node.rb', line 52

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



79
80
81
# File 'lib/utopia/middleware/content/node.rb', line 79

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

#lookup(tag) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/utopia/middleware/content/node.rb', line 65

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



83
84
85
# File 'lib/utopia/middleware/content/node.rb', line 83

def markup(text)
	cdata(text)
end

#tag_begin(tag) ⇒ Object



91
92
93
94
# File 'lib/utopia/middleware/content/node.rb', line 91

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

#tag_complete(tag) ⇒ Object



87
88
89
# File 'lib/utopia/middleware/content/node.rb', line 87

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

#tag_end(tag) ⇒ Object



96
97
98
99
100
# File 'lib/utopia/middleware/content/node.rb', line 96

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

	tag.write_close_html(@buffer)
end