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.92.2 spec/helpers/nested_tag_helper.rb
radiant-shop-extension-0.92.1 spec/helpers/nested_tag_helper.rb
radiant-shop-extension-0.92.0 spec/helpers/nested_tag_helper.rb
radiant-shop-extension-0.91.7 spec/helpers/nested_tag_helper.rb
radiant-shop-extension-0.91.4 spec/helpers/nested_tag_helper.rb
radiant-shop-extension-0.91.3 spec/helpers/nested_tag_helper.rb
radiant-shop-extension-0.91.2 spec/helpers/nested_tag_helper.rb
radiant-shop-extension-0.90.4 spec/helpers/nested_tag_helper.rb
radiant-shop-extension-0.90.2 spec/helpers/nested_tag_helper.rb
radiant-shop-extension-0.90.1 spec/helpers/nested_tag_helper.rb
radiant-shop-extension-0.90.0 spec/helpers/nested_tag_helper.rb
radiant-shop-extension-0.11.6 spec/helpers/nested_tag_helper.rb
radiant-shop-extension-0.11.5 spec/helpers/nested_tag_helper.rb
radiant-shop-extension-0.11.4 spec/helpers/nested_tag_helper.rb
radiant-shop-extension-0.11.3 spec/helpers/nested_tag_helper.rb
radiant-shop-extension-0.11.1 spec/helpers/nested_tag_helper.rb
radiant-shop-extension-0.11.0 spec/helpers/nested_tag_helper.rb
radiant-shop-extension-0.10.0 spec/helpers/nested_tag_helper.rb
radiant-shop-extension-0.9.3 spec/helpers/nested_tag_helper.rb
radiant-shop-extension-0.9.2 spec/helpers/nested_tag_helper.rb