module Bootstrap::ActiveLinkTo
Public Instance Methods
active_link_to(*args, &block)
click to toggle source
Wrapper around link_to. Accepts following params:
:active => Boolean | Symbol | Regex | Controller/Action Pair :class_active => String :class_inactive => String :disable_active => Boolean :wrap_tag => Symbol
Example usage:
active_link_to('/users', :class_active => 'enabled') active_link_to(users_path, :active => :exclusive, :wrap_tag => :li)
# File lib/bootstrap/active_link_to.rb, line 89 def active_link_to(*args, &block) ActiveLink.new(self).render(*args, &block) end
active_link_to_class(url, options={}, is_active=nil)
click to toggle source
Returns css class name. Takes the link’s URL and its params Example usage:
active_link_to_class('/root', :class_active => 'on', :class_inactive => 'off')
# File lib/bootstrap/active_link_to.rb, line 97 def active_link_to_class(url, options={}, is_active=nil) is_active = is_active_link?(url, options[:active]) if is_active.nil? is_active ? (options[:class_active] ||= 'active') : options[:class_inactive] end
is_active_link?(url, condition = nil)
click to toggle source
Returns true or false based on the provided path and condition Possible condition values are:
Boolean -> true | false Symbol -> :exclusive | :inclusive Regex -> /regex/ Controller/Action Pair -> [[:controller], [:action_a, :action_b]]
Example usage:
is_active_link?('/root', true) is_active_link?('/root', :exclusive) is_active_link?('/root', /^\/root/) is_active_link?('/root', ['users', ['show', 'edit']])
# File lib/bootstrap/active_link_to.rb, line 114 def is_active_link?(url, condition = nil) url = url_for(url).sub(/\?.*/, '') # ignore GET params case condition when :inclusive, nil !request.fullpath.match(/^#{Regexp.escape(url)}(\/.*|\?.*)?$/).blank? when :exclusive !request.fullpath.match(/^#{Regexp.escape(url)}\/?(\?.*)?$/).blank? when Regexp !request.fullpath.match(condition).blank? when Array controllers = [*condition[0]] actions = [*condition[1]] (controllers.blank? || controllers.member?(params[:controller])) && (actions.blank? || actions.member?(params[:action])) when TrueClass true when FalseClass false end end