Class: Helpers::Tag
Instance Attribute Summary collapse
Attributes inherited from SelfCloseTag
#attrs, #name
Instance Method Summary
collapse
#[], #[]=, #data, #inspect
Constructor Details
#initialize(name, content = nil, attrs = Hash.new, &block) ⇒ Tag
Returns a new instance of Tag.
63
64
65
66
67
|
# File 'lib/helpers.rb', line 63
def initialize(name, content = nil, attrs = Hash.new, &block)
attrs, content = content, nil if content.is_a?(Hash) && attrs.empty?
self.content = ContentList.new(content, self.indentation + 1)
super(name, attrs, &block)
end
|
Instance Attribute Details
#content ⇒ Object
47
48
49
|
# File 'lib/helpers.rb', line 47
def content
@content ||= Array.new
end
|
#indentation ⇒ Object
52
53
54
|
# File 'lib/helpers.rb', line 52
def indentation
@indentation ||= 0
end
|
Instance Method Details
#each(&block) ⇒ Object
56
57
58
59
60
61
|
# File 'lib/helpers.rb', line 56
def each(&block)
self.to_s.split("\n").each do |item|
block.call("#{item}\n") end
end
|
#self_closing_tag(*args, &block) ⇒ Object
73
74
75
|
# File 'lib/helpers.rb', line 73
def self_closing_tag(*args, &block)
self.content.push(SelfCloseTag.new(*args, &block))
end
|
#tag(*args, &block) ⇒ Object
69
70
71
|
# File 'lib/helpers.rb', line 69
def tag(*args, &block)
self.content.push(Tag.new(*args, &block))
end
|
#to_s ⇒ Object
77
78
79
|
# File 'lib/helpers.rb', line 77
def to_s
"#{" " * self.indentation}<#{name}#{attrs.to_html_attrs}>\n#{" " * self.indentation}#{content}\n#{" " * self.indentation}</#{name}>"
end
|