Class: Nav::Link
- Inherits:
-
Object
- Object
- Nav::Link
- Defined in:
- lib/rails_nav.rb
Instance Attribute Summary collapse
-
#active ⇒ Object
Returns the value of attribute active.
-
#args ⇒ Object
Returns the value of attribute args.
-
#compute_active ⇒ Object
Returns the value of attribute compute_active.
-
#config ⇒ Object
Returns the value of attribute config.
-
#content ⇒ Object
Returns the value of attribute content.
-
#controller ⇒ Object
Returns the value of attribute controller.
-
#default ⇒ Object
Returns the value of attribute default.
-
#nav ⇒ Object
Returns the value of attribute nav.
-
#options ⇒ Object
Returns the value of attribute options.
-
#pattern ⇒ Object
Returns the value of attribute pattern.
-
#slug ⇒ Object
Returns the value of attribute slug.
-
#weight ⇒ Object
Returns the value of attribute weight.
Class Method Summary collapse
Instance Method Summary collapse
- #compute_active! ⇒ Object
- #default? ⇒ Boolean
- #getopt!(key, &block) ⇒ Object
-
#initialize(*args, &block) ⇒ Link
constructor
A new instance of Link.
- #inspect ⇒ Object
- #to_s ⇒ Object
- #url ⇒ Object (also: #href)
Constructor Details
#initialize(*args, &block) ⇒ Link
Returns a new instance of Link.
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 |
# File 'lib/rails_nav.rb', line 257 def initialize(*args, &block) # @options = if args.last.is_a?(Hash) args.. 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 |
Instance Attribute Details
#active ⇒ Object
Returns the value of attribute active.
251 252 253 |
# File 'lib/rails_nav.rb', line 251 def active @active end |
#args ⇒ Object
Returns the value of attribute args.
244 245 246 |
# File 'lib/rails_nav.rb', line 244 def args @args end |
#compute_active ⇒ Object
Returns the value of attribute compute_active.
250 251 252 |
# File 'lib/rails_nav.rb', line 250 def compute_active @compute_active end |
#config ⇒ Object
Returns the value of attribute config.
255 256 257 |
# File 'lib/rails_nav.rb', line 255 def config @config end |
#content ⇒ Object
Returns the value of attribute content.
247 248 249 |
# File 'lib/rails_nav.rb', line 247 def content @content end |
#controller ⇒ Object
Returns the value of attribute controller.
246 247 248 |
# File 'lib/rails_nav.rb', line 246 def controller @controller end |
#default ⇒ Object
Returns the value of attribute default.
252 253 254 |
# File 'lib/rails_nav.rb', line 252 def default @default end |
#nav ⇒ Object
Returns the value of attribute nav.
243 244 245 |
# File 'lib/rails_nav.rb', line 243 def nav @nav end |
#options ⇒ Object
Returns the value of attribute options.
245 246 247 |
# File 'lib/rails_nav.rb', line 245 def @options end |
#pattern ⇒ Object
Returns the value of attribute pattern.
249 250 251 |
# File 'lib/rails_nav.rb', line 249 def pattern @pattern end |
#slug ⇒ Object
Returns the value of attribute slug.
254 255 256 |
# File 'lib/rails_nav.rb', line 254 def slug @slug end |
#weight ⇒ Object
Returns the value of attribute weight.
253 254 255 |
# File 'lib/rails_nav.rb', line 253 def weight @weight end |
Class Method Details
.default_active_block_for(pattern) ⇒ Object
337 338 339 340 341 342 343 344 345 |
# 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 |
Instance Method Details
#compute_active! ⇒ Object
292 293 294 295 296 297 298 299 300 301 |
# 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? ⇒ Boolean
307 308 309 |
# File 'lib/rails_nav.rb', line 307 def default? !!@default end |
#getopt!(key, &block) ⇒ Object
288 289 290 |
# File 'lib/rails_nav.rb', line 288 def getopt!(key, &block) @options.has_key?(key) ? @options.delete(key) : (block && block.call) end |
#inspect ⇒ Object
328 329 330 |
# File 'lib/rails_nav.rb', line 328 def inspect super end |
#to_s ⇒ Object
324 325 326 |
# File 'lib/rails_nav.rb', line 324 def to_s content.to_s end |
#url ⇒ Object Also known as: href
319 320 321 |
# File 'lib/rails_nav.rb', line 319 def url controller.send(:url_for, *@url) end |