Sha256: 2d6e0f7cfcbcff60360fcdd92bd42149f385f4379372e19ddab44504a55486f9
Contents?: true
Size: 703 Bytes
Versions: 40
Compression:
Stored size: 703 Bytes
Contents
# # Nested tag helper is used to test tags that can be declared inside other tags. # # @example # tag = NestedTagHelper.new # tag.push '<div>', '</div>' # tag.push '<h1>', '</h1>' # tag.push 'Title' # tag.to_s => '<div><h1>Title</h1></div>' # class NestedTagHelper def initialize @tag_stack = [] end def push(opening, closing = nil) @tag_stack.push Tag.new(opening, closing) end def to_s closing_tags = [] @tag_stack.collect do |tag| closing_tags.unshift tag.closing tag.opening end.join('') + closing_tags.join('') end private ####################################################################### Tag = Struct.new(:opening, :closing) end
Version data entries
40 entries across 40 versions & 1 rubygems