lib/hexp/builder.rb
def tag!(tag, *args, &block)
      text, attributes = nil, {}
      args.each do |arg|
        case arg
        when ::Hash
          attributes.merge!(arg)
        when ::String
          text ||= ''
          text << arg
        end
      end
      @stack << [tag, attributes, text ? [text] : []]
      if block
        _process(&block)
      end
      if @stack.length > 1
        node = @stack.pop
        @stack.last[2] << node
        NodeBuilder.new(node, self)
      else
        NodeBuilder.new(@stack.last, self)
      end
    end
def tag!(tag, *args, &block)
      text, attributes = nil, {}
      args.each do |arg|
        case arg
        when ::Hash
          attributes.merge!(arg)
        when ::String
          text ||= ''
          text << arg
        end
      end
      @stack << [tag, attributes, text ? [text] : []]
      if block
        _process(&block)
      end
      if @stack.length > 1
        node = @stack.pop
        @stack.last[2] << node
        NodeBuilder.new(node, self)
      else
        NodeBuilder.new(@stack.last, self)
      end
    end
Construct a new builder, and start building

 The recommended way to call this is through `Hexp.build`. If the block
 takes an argument, then builder methods need to be called on that variable.

 @example With an explicit builder
   hi = Hexp.build {|html| html.span "Hello" ; html.span " World"}

 @example Without a builder object
   hi = Hexp.build { span "Hello" ; span " World"}

 @param [Symbol] tag
   The tag of the outermost element (optional)
 @param [Array<Hash,String>] args
   Extra arguments, a String for a text node, a Hash for attributes

 @yieldparam [Hexp::Builder]
   If the block takes an argument it will receive the builder object

 @api private

 Add a tag (HTML element)

 Typically this is called implicitly through method missing, but in case of
 name clashes or dynamically generated tags you can call this directly.

 @example
   hexp = Hexp.build :div do
     tag!(:p, "Oh the code, such sweet joy it brings")
   end
   hexp.to_html #=> "<div><p>Oh the code, such sweet joy it brings</p></div>"

 @param [Symbol] tag
   The tag name, like 'div' or 'head'
 @param [Array<Hash|String>] args
   A hash of attributes, or a string to use inside the tag, or both. Multiple
   occurences of each can be specified
 @param [Proc] block
   Builder directives for the contents of the tag

 @return [nil]

 @api public