def haml_tag(name, *rest, &block)
      ret = ErrorReturn.new("haml_tag")

      text = rest.shift.to_s unless [Symbol, Hash, NilClass].any? {|t| rest.first.is_a? t}
      flags = []
      flags << rest.shift while rest.first.is_a? Symbol
      attrs = (rest.shift || {})
      attrs.keys.each {|key| attrs[key.to_s] = attrs.delete(key)} unless attrs.empty?
      name, attrs = merge_name_and_attributes(name.to_s, attrs)

      attributes = Haml::AttributeBuilder.build_attributes(haml_buffer.html?,
        haml_buffer.options[:attr_wrapper],
        haml_buffer.options[:escape_attrs],
        haml_buffer.options[:hyphenate_data_attrs],
        attrs)

      if text.nil? && block.nil? && (haml_buffer.options[:autoclose].include?(name) || flags.include?(:/))
        haml_internal_concat_raw "<#{name}#{attributes}#{' /' if haml_buffer.options[:format] == :xhtml}>"
        return ret
      end

      if flags.include?(:/)
        raise Error.new(Error.message(:self_closing_content)) if text
        raise Error.new(Error.message(:illegal_nesting_self_closing)) if block
      end

      tag = "<#{name}#{attributes}>"
      end_tag = "</#{name}>"
      if block.nil?
        text = text.to_s
        if text.include?("\n")
          haml_internal_concat_raw tag
          tab_up
          haml_internal_concat text
          tab_down
          haml_internal_concat_raw end_tag
        else
          haml_internal_concat_raw tag, false
          haml_internal_concat text, false, false
          haml_internal_concat_raw end_tag, true, false
        end
        return ret
      end

      if text
        raise Error.new(Error.message(:illegal_nesting_line, name))
      end

      if flags.include?(:<)
        haml_internal_concat_raw tag, false
        haml_internal_concat "#{capture_haml(&block).strip}", false, false
        haml_internal_concat_raw end_tag, true, false
        return ret
      end

      haml_internal_concat_raw tag
      tab_up
      block.call
      tab_down
      haml_internal_concat_raw end_tag

      ret
    end
def haml_tag(name, *rest, &block)
      ret = ErrorReturn.new("haml_tag")

      text = rest.shift.to_s unless [Symbol, Hash, NilClass].any? {|t| rest.first.is_a? t}
      flags = []
      flags << rest.shift while rest.first.is_a? Symbol
      attrs = (rest.shift || {})
      attrs.keys.each {|key| attrs[key.to_s] = attrs.delete(key)} unless attrs.empty?
      name, attrs = merge_name_and_attributes(name.to_s, attrs)

      attributes = Haml::AttributeBuilder.build_attributes(haml_buffer.html?,
        haml_buffer.options[:attr_wrapper],
        haml_buffer.options[:escape_attrs],
        haml_buffer.options[:hyphenate_data_attrs],
        attrs)

      if text.nil? && block.nil? && (haml_buffer.options[:autoclose].include?(name) || flags.include?(:/))
        haml_internal_concat_raw "<#{name}#{attributes}#{' /' if haml_buffer.options[:format] == :xhtml}>"
        return ret
      end

      if flags.include?(:/)
        raise Error.new(Error.message(:self_closing_content)) if text
        raise Error.new(Error.message(:illegal_nesting_self_closing)) if block
      end

      tag = "<#{name}#{attributes}>"
      end_tag = "</#{name}>"
      if block.nil?
        text = text.to_s
        if text.include?("\n")
          haml_internal_concat_raw tag
          tab_up
          haml_internal_concat text
          tab_down
          haml_internal_concat_raw end_tag
        else
          haml_internal_concat_raw tag, false
          haml_internal_concat text, false, false
          haml_internal_concat_raw end_tag, true, false
        end
        return ret
      end

      if text
        raise Error.new(Error.message(:illegal_nesting_line, name))
      end

      if flags.include?(:<)
        haml_internal_concat_raw tag, false
        haml_internal_concat "#{capture_haml(&block).strip}", false, false
        haml_internal_concat_raw end_tag, true, false
        return ret
      end

      haml_internal_concat_raw tag
      tab_up
      block.call
      tab_down
      haml_internal_concat_raw end_tag

      ret
    end
Creates an HTML tag with the given name and optionally text and attributes.
 Can take a block that will run between the opening and closing tags.
 If the block is a Haml block or outputs text using \{#haml\_concat},
 the text will be properly indented.

 `name` can be a string using the standard Haml class/id shorthand
 (e.g. "span#foo.bar", "#foo").
 Just like standard Haml tags, these class and id values
 will be merged with manually-specified attributes.

 `flags` is a list of symbol flags
 like those that can be put at the end of a Haml tag
 (`:/`, `:<`, and `:>`).
 Currently, only `:/` and `:<` are supported.

 `haml_tag` outputs directly to the buffer;
 its return value should not be used.
 If you need to get the results as a string,
 use \{#capture\_haml\}.

 For example,

     haml_tag :table do
       haml_tag :tr do
         haml_tag 'td.cell' do
           haml_tag :strong, "strong!"
           haml_concat "data"
         end
         haml_tag :td do
           haml_concat "more_data"
         end
       end
     end

 outputs

     <table>
       <tr>
         <td class='cell'>
           <strong>
             strong!
           </strong>
           data
         </td>
         <td>
           more_data
         </td>
       </tr>
     </table>

 @param name [#to_s] The name of the tag

 @overload haml_tag(name, *rest, attributes = {})
   @yield The block of Haml code within the tag
 @overload haml_tag(name, text, *flags, attributes = {})
   @param text [#to_s] The text within the tag
   @param flags [Array<Symbol>] Haml end-of-tag flags