def buffer_attributes(attributes, extension)
      # Proc for setting class attribute extension, used as DRY closure
      #
      buffer_class_attribute_type_check = proc do |variable, escape = true|
        class_variable = buffer_set_variable :local, variable

        # Check if we need to add the class attribute
        buffer_eval "unless #{class_variable} and true === #{class_variable}"

        # Check if class attribute has array value
        buffer_eval "if Array === #{class_variable}"
        ruby_code = "#{class_variable}.join ' '"
        if escape
          buffer_escape ruby_code
        else
          buffer ruby_code
        end

        # Check if class attribute has hash value
        buffer_eval "elsif Hash === #{class_variable}"
        ruby_code = "#{class_variable}.to_a.join ' '"
        if escape
          buffer_escape ruby_code
        else
          buffer ruby_code
        end

        # Other values
        buffer_eval 'else'
        ruby_code = "#{class_variable}"
        if escape
          buffer_escape ruby_code
        else
          buffer ruby_code
        end

        # End cases
        buffer_eval 'end'

        # End
        buffer_eval 'end'
      end

      # Handle class attributes by checking if they're simple, noninterpolated
      # strings or not and extend them if needed
      #
      buffer_class_attribute = proc do |attribute|
        if attribute[@value] =~ Tokens[:exp_string_match]
          buffer_split_by_interpolation attribute[@value][1..-2],
                                        attribute[@options][:escaped]
        else
          buffer_class_attribute_type_check[
            attribute[@value],
            attribute[@options][:escaped]
          ]
        end
      end

      # If we have class attributes, process each one and check if we have an
      # extension for them
      if attributes[:class]
        buffer_freeze " class=\""

        # Process every class attribute
        attributes[:class].each do |node_class|
          buffer_class_attribute[node_class]
          buffer_freeze ' '
        end

        # Remove trailing whitespace from the buffer
        buffer_remove_last_character

        # Check for extension with :class key
        if extension
          buffer_eval "if #{extension[:name]}.has_key? :class"
          buffer_freeze ' '
          buffer_class_attribute_type_check[
            "#{extension[:name]}.delete(:class)"
          ]
          buffer_eval 'end'
        end

        buffer_freeze '"'
      elsif extension
        # If we do not have class attributes but we do have an extension, try to
        # see if the extension contains a class attribute
        buffer_eval "if #{extension[:name]}.has_key? :class"
        buffer_freeze " class=\""
        buffer_class_attribute_type_check["#{extension[:name]}.delete(:class)"]
        buffer_freeze '"'
        buffer_eval 'end'
      end

      # Proc for setting class attribute extension, used as DRY closure
      #
      buffer_data_attribute_type_check = proc do |key, variable, escape = true, dynamic = false|
        # Check if variable is set
        buffer_eval "if #{variable}"

        # @Array
        buffer_eval "if Array === #{variable}"
        dynamic ? buffer("\" #{key}=\\\"\"") : buffer_freeze(" #{key}=\"")

        ruby_code = "#{variable}.join '_'"
        if escape
          buffer_escape ruby_code
        else
          buffer ruby_code
        end

        buffer_freeze '"'

        # @Hash
        buffer_eval "elsif Hash === #{variable}"
        buffer_eval "#{variable}.each do |#{OPULENT_KEY}, #{OPULENT_VALUE}|"
        # key-hashkey
        dynamic ? buffer("\" #{key}-\"") : buffer_freeze(" #{key}-")
        buffer "#{OPULENT_KEY}.to_s"
        #="value"
        buffer_freeze "=\""
        escape ? buffer_escape(OPULENT_VALUE) : buffer(OPULENT_VALUE)
        buffer_freeze '"'
        buffer_eval 'end'

        # @TrueClass
        buffer_eval "elsif true === #{variable}"
        dynamic ? buffer("\" #{key}\"") : buffer_freeze(" #{key}")

        # @Object
        buffer_eval 'else'
        dynamic ? buffer("\" #{key}=\\\"\"") : buffer_freeze(" #{key}=\"")
        escape ? buffer_escape("#{variable}") : buffer("#{variable}")
        buffer_freeze '"'

        # End Cases
        buffer_eval 'end'

        # End
        buffer_eval 'end'
      end

      # Handle data (normal) attributes by checking if they're simple, noninterpolated
      # strings and extend them if needed
      #
      buffer_data_attribute = proc do |key, attribute|
        # When we have an extension for our attributes, check current key.
        # If it exists, check it's type and generate everything dynamically
        if extension
          buffer_eval "if #{extension[:name]}.has_key? :\"#{key}\""
          variable = buffer_set_variable :local,
                                         "#{extension[:name]}" \
                                         ".delete(:\"#{key}\")"
          buffer_data_attribute_type_check[
            key,
            variable,
            attribute[@options][:escaped]
          ]
          buffer_eval 'else'
        end

        # Check if the set attribute is a simple string. If it is, freeze it or
        # escape it. Otherwise, evaluate and initialize the type check.
        if attribute[@value] =~ Tokens[:exp_string_match]
          buffer_freeze " #{key}=\""
          buffer_split_by_interpolation attribute[@value][1..-2],
                                        attribute[@options][:escaped]
          buffer_freeze "\""
        else
          # Evaluate and type check
          variable = buffer_set_variable :local, attribute[@value]
          buffer_data_attribute_type_check[
            key,
            variable,
            attribute[@options][:escaped]
          ]
        end

        # Extension end
        buffer_eval 'end' if extension
      end

      # Process the remaining, non-class related attributes
      attributes.each do |key, attribute|
        next if key == :class
        buffer_data_attribute[key, attribute]
      end

      # Process remaining extension keys if there are any
      return unless extension

      buffer_eval "#{extension[:name]}.each do " \
                  "|ext#{OPULENT_KEY}, ext#{OPULENT_VALUE}|"

      buffer_data_attribute_type_check[
        "\#{ext#{OPULENT_KEY}}",
        "ext#{OPULENT_VALUE}",
        extension[:escaped],
        true
      ]
      buffer_eval 'end'
    end
def buffer_attributes(attributes, extension)
      # Proc for setting class attribute extension, used as DRY closure
      #
      buffer_class_attribute_type_check = proc do |variable, escape = true|
        class_variable = buffer_set_variable :local, variable

        # Check if we need to add the class attribute
        buffer_eval "unless #{class_variable} and true === #{class_variable}"

        # Check if class attribute has array value
        buffer_eval "if Array === #{class_variable}"
        ruby_code = "#{class_variable}.join ' '"
        if escape
          buffer_escape ruby_code
        else
          buffer ruby_code
        end

        # Check if class attribute has hash value
        buffer_eval "elsif Hash === #{class_variable}"
        ruby_code = "#{class_variable}.to_a.join ' '"
        if escape
          buffer_escape ruby_code
        else
          buffer ruby_code
        end

        # Other values
        buffer_eval 'else'
        ruby_code = "#{class_variable}"
        if escape
          buffer_escape ruby_code
        else
          buffer ruby_code
        end

        # End cases
        buffer_eval 'end'

        # End
        buffer_eval 'end'
      end

      # Handle class attributes by checking if they're simple, noninterpolated
      # strings or not and extend them if needed
      #
      buffer_class_attribute = proc do |attribute|
        if attribute[@value] =~ Tokens[:exp_string_match]
          buffer_split_by_interpolation attribute[@value][1..-2],
                                        attribute[@options][:escaped]
        else
          buffer_class_attribute_type_check[
            attribute[@value],
            attribute[@options][:escaped]
          ]
        end
      end

      # If we have class attributes, process each one and check if we have an
      # extension for them
      if attributes[:class]
        buffer_freeze " class=\""

        # Process every class attribute
        attributes[:class].each do |node_class|
          buffer_class_attribute[node_class]
          buffer_freeze ' '
        end

        # Remove trailing whitespace from the buffer
        buffer_remove_last_character

        # Check for extension with :class key
        if extension
          buffer_eval "if #{extension[:name]}.has_key? :class"
          buffer_freeze ' '
          buffer_class_attribute_type_check[
            "#{extension[:name]}.delete(:class)"
          ]
          buffer_eval 'end'
        end

        buffer_freeze '"'
      elsif extension
        # If we do not have class attributes but we do have an extension, try to
        # see if the extension contains a class attribute
        buffer_eval "if #{extension[:name]}.has_key? :class"
        buffer_freeze " class=\""
        buffer_class_attribute_type_check["#{extension[:name]}.delete(:class)"]
        buffer_freeze '"'
        buffer_eval 'end'
      end

      # Proc for setting class attribute extension, used as DRY closure
      #
      buffer_data_attribute_type_check = proc do |key, variable, escape = true, dynamic = false|
        # Check if variable is set
        buffer_eval "if #{variable}"

        # @Array
        buffer_eval "if Array === #{variable}"
        dynamic ? buffer("\" #{key}=\\\"\"") : buffer_freeze(" #{key}=\"")

        ruby_code = "#{variable}.join '_'"
        if escape
          buffer_escape ruby_code
        else
          buffer ruby_code
        end

        buffer_freeze '"'

        # @Hash
        buffer_eval "elsif Hash === #{variable}"
        buffer_eval "#{variable}.each do |#{OPULENT_KEY}, #{OPULENT_VALUE}|"
        # key-hashkey
        dynamic ? buffer("\" #{key}-\"") : buffer_freeze(" #{key}-")
        buffer "#{OPULENT_KEY}.to_s"
        #="value"
        buffer_freeze "=\""
        escape ? buffer_escape(OPULENT_VALUE) : buffer(OPULENT_VALUE)
        buffer_freeze '"'
        buffer_eval 'end'

        # @TrueClass
        buffer_eval "elsif true === #{variable}"
        dynamic ? buffer("\" #{key}\"") : buffer_freeze(" #{key}")

        # @Object
        buffer_eval 'else'
        dynamic ? buffer("\" #{key}=\\\"\"") : buffer_freeze(" #{key}=\"")
        escape ? buffer_escape("#{variable}") : buffer("#{variable}")
        buffer_freeze '"'

        # End Cases
        buffer_eval 'end'

        # End
        buffer_eval 'end'
      end

      # Handle data (normal) attributes by checking if they're simple, noninterpolated
      # strings and extend them if needed
      #
      buffer_data_attribute = proc do |key, attribute|
        # When we have an extension for our attributes, check current key.
        # If it exists, check it's type and generate everything dynamically
        if extension
          buffer_eval "if #{extension[:name]}.has_key? :\"#{key}\""
          variable = buffer_set_variable :local,
                                         "#{extension[:name]}" \
                                         ".delete(:\"#{key}\")"
          buffer_data_attribute_type_check[
            key,
            variable,
            attribute[@options][:escaped]
          ]
          buffer_eval 'else'
        end

        # Check if the set attribute is a simple string. If it is, freeze it or
        # escape it. Otherwise, evaluate and initialize the type check.
        if attribute[@value] =~ Tokens[:exp_string_match]
          buffer_freeze " #{key}=\""
          buffer_split_by_interpolation attribute[@value][1..-2],
                                        attribute[@options][:escaped]
          buffer_freeze "\""
        else
          # Evaluate and type check
          variable = buffer_set_variable :local, attribute[@value]
          buffer_data_attribute_type_check[
            key,
            variable,
            attribute[@options][:escaped]
          ]
        end

        # Extension end
        buffer_eval 'end' if extension
      end

      # Process the remaining, non-class related attributes
      attributes.each do |key, attribute|
        next if key == :class
        buffer_data_attribute[key, attribute]
      end

      # Process remaining extension keys if there are any
      return unless extension

      buffer_eval "#{extension[:name]}.each do " \
                  "|ext#{OPULENT_KEY}, ext#{OPULENT_VALUE}|"

      buffer_data_attribute_type_check[
        "\#{ext#{OPULENT_KEY}}",
        "ext#{OPULENT_VALUE}",
        extension[:escaped],
        true
      ]
      buffer_eval 'end'
    end
Go through the node attributes and apply extension where needed

 @param attributes [Array] Array of node attributes, from parser
 @param extension [String] Extension identifier