# File lib/active_link_to/active_link_to.rb, line 12
  def active_link_to(*args, &block)
    name = block_given? ? capture(&block) : args.shift
    options = args.shift || {}
    html_options = args.shift || {}
    
    url = url_for(options)

    active_options  = { }
    link_options    = { }
    html_options.each do |k, v|
      if [:active, :class_active, :class_inactive, :active_disable, :wrap_tag, :wrap_class].member?(k)
        active_options[k] = v
      else
        link_options[k] = v
      end
    end

    css_class = link_options.delete(:class).to_s + ' '

    wrap_tag    = active_options[:wrap_tag].present? ? active_options[:wrap_tag] : nil
    wrap_class  = active_options[:wrap_class].present? ? active_options[:wrap_class] + ' ' : ''

    if wrap_tag.present?
      wrap_class << active_link_to_class(url, active_options)
      wrap_class.strip!
    else
      css_class << active_link_to_class(url, active_options)
      css_class.strip!
    end

    link_options[:class] = css_class if css_class.present?
    link_options['aria-current'] = 'page' if is_active_link?(url, active_options[:active])

    link = if active_options[:active_disable] === true && is_active_link?(url, active_options[:active])
      content_tag(:span, name, link_options)
    else
      link_to(name, url, link_options)
    end

    wrap_tag ? content_tag(wrap_tag, link, class: (wrap_class if wrap_class.present?)) : link
  end