class Nav::Link
Attributes
active[RW]
args[RW]
compute_active[RW]
config[RW]
content[RW]
controller[RW]
default[RW]
options[RW]
pattern[RW]
slug[RW]
weight[RW]
Public Class Methods
default_active_block_for(pattern)
click to toggle source
# File lib/rails_nav.rb, line 337 def Link.default_active_block_for(pattern) proc do |link| path_info = link.path_info depth = -1 matched = false path_info.each{|path| depth += 1; break if(matched = path =~ pattern)} weight = matched ? depth : nil end end
default_active_pattern_for(content)
click to toggle source
# File lib/rails_nav.rb, line 332 def Link.default_active_pattern_for(content) path_info = Slug.for(content.to_s.split('/').first, :join => '[_-]*') %r/\b#{ path_info }\b/i end
new(*args, &block)
click to toggle source
# File lib/rails_nav.rb, line 257 def initialize(*args, &block) # @options = if args.last.is_a?(Hash) args.extract_options!.to_options! else {} end # args.each{|arg| @nav = arg if arg.is_a?(Nav)} args.delete_if{|arg| arg.is_a?(Nav)} unless @nav @nav = Nav.new @nav.controller = Current.mock_controller end # @content = getopt!(:content){ args.shift || 'Slash' } @url = getopt!(:url){ args.shift || {} } @pattern = getopt!(:pattern){ args.shift || Link.default_active_pattern_for(@content) } @compute_active = getopt!(:active){ block || Link.default_active_block_for(@pattern) } @default = getopt!(:default){ nil } # @slug = Slug.for(@content, :join => '-') @already_computed_active = nil @config = Map.new end
Public Instance Methods
compute_active!()
click to toggle source
# File lib/rails_nav.rb, line 292 def compute_active! @active = if @compute_active.respond_to?(:call) @nav.evaluate(@compute_active, link = self) else !!@compute_active end ensure @already_computed_active = true end
default?()
click to toggle source
# File lib/rails_nav.rb, line 307 def default? !!@default end
getopt!(key, &block)
click to toggle source
# File lib/rails_nav.rb, line 288 def getopt!(key, &block) @options.has_key?(key) ? @options.delete(key) : (block && block.call) end
inspect()
click to toggle source
Calls superclass method
# File lib/rails_nav.rb, line 328 def inspect super end
to_s()
click to toggle source
# File lib/rails_nav.rb, line 324 def to_s content.to_s end
url()
click to toggle source
# File lib/rails_nav.rb, line 319 def url controller.send(:url_for, *@url) end
Also aliased as: href