module LinkToActiveState::ViewHelpers::UrlHelper

Public Class Methods

included(base) click to toggle source
# File lib/link_to_active_state/view_helpers/url_helper.rb, line 7
def self.included(base)
  base.send(:alias_method, :link_to_without_active_state, :link_to)
  base.send(:alias_method, :link_to, :link_to_with_active_state)
end

Public Instance Methods

Private Instance Methods

is_active?(active_on, link_options = {}, html_options = {}) click to toggle source
# File lib/link_to_active_state/view_helpers/url_helper.rb, line 53
def is_active?(active_on, link_options = {}, html_options = {})
  if html_options.present? && html_options[:ignore_query]
    path = request.fullpath.gsub( /\?.*/, "" )
  else
    path = request.fullpath
  end

  case active_on
  when String
    path == active_on
  when Array
    active_on.include?(path)
  when Regexp
    path =~ active_on
  when Proc
    active_on.arity == 1 ? active_on.call(request) : active_on.call
  else
    # Anything else we'll take as a true argument, and match the link's URL (including any query string)
    url = url_for(link_options)
    path == url
  end
end
merge_class(original, new) click to toggle source
# File lib/link_to_active_state/view_helpers/url_helper.rb, line 76
def merge_class(original, new)
  original ||= ""
  [original, new].delete_if(&:blank?).join(" ")
end
render_with_wrapper(element_or_proc, wrapper_options, &block) click to toggle source
# File lib/link_to_active_state/view_helpers/url_helper.rb, line 81
def render_with_wrapper(element_or_proc, wrapper_options, &block)
  content = block.call

  case element_or_proc
  when Proc
    element_or_proc.call(content, wrapper_options)
  when Symbol || String
    content_tag(element_or_proc, content, wrapper_options)
  end
end