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

Version Path
radiant-shop-extension-0.94.8 spec/helpers/nested_tag_helper.rb
radiant-shop-extension-0.94.7 spec/helpers/nested_tag_helper.rb
radiant-shop-extension-0.94.6 spec/helpers/nested_tag_helper.rb
radiant-shop-extension-0.94.5 spec/helpers/nested_tag_helper.rb
radiant-shop-extension-0.94.4 spec/helpers/nested_tag_helper.rb
radiant-shop-extension-0.94.3 spec/helpers/nested_tag_helper.rb
radiant-shop-extension-0.94.2 spec/helpers/nested_tag_helper.rb
radiant-shop-extension-0.94.1 spec/helpers/nested_tag_helper.rb
radiant-shop-extension-0.94.0 spec/helpers/nested_tag_helper.rb
radiant-shop-extension-0.93.3 spec/helpers/nested_tag_helper.rb
radiant-shop-extension-0.93.2 spec/helpers/nested_tag_helper.rb
radiant-shop-extension-0.93.1 spec/helpers/nested_tag_helper.rb
radiant-shop-extension-0.93.0 spec/helpers/nested_tag_helper.rb
radiant-shop-extension-0.92.11 spec/helpers/nested_tag_helper.rb
radiant-shop-extension-0.92.10 spec/helpers/nested_tag_helper.rb
radiant-shop-extension-0.92.9 spec/helpers/nested_tag_helper.rb
radiant-shop-extension-0.92.8 spec/helpers/nested_tag_helper.rb
radiant-shop-extension-0.92.7 spec/helpers/nested_tag_helper.rb
radiant-shop-extension-0.92.6 spec/helpers/nested_tag_helper.rb
radiant-shop-extension-0.92.3 spec/helpers/nested_tag_helper.rb