rails_nav 2.5.7 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +8 -8
  2. data/lib/rails_nav.rb +36 -20
  3. data/rails_nav.gemspec +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YTRiNzBkYTQzOWVlNTE4MWY2OTVkNDEzMDI4NjAxMjQxOGZhZmE1Nw==
4
+ NjAwZWFiOWZiYjJlMDJmODU0MTcxMzdhMjJlZjdjNzBhMmUzNTY4YQ==
5
5
  data.tar.gz: !binary |-
6
- ODdmMGU5ZWE1NGFjMzAyYmI4ODlmZDU3NWQ2MzVlOThmYTAxNzJmYg==
6
+ MGMxOTdiOGMzNGUxODhhNzUyYmMzODBkYmU2MGJlODE3OGFjNzBlNg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- OTMwYzFkYzI5NGYzOGQ4ZGMyNmJhNjJiMDU3ZmE2NjUyMTVmOTgyMTNiZDIy
10
- ZDdmMjljNmE2NTQyYTVhNmZkMGRmYmIxOTgwYzk4Njk1ZTgzMjE0NWY3MmY1
11
- MDhlMGYzMDE5YjQ3OTY3NGNiZDhkZTk5N2I5NTA0YjIwMmE5ZTQ=
9
+ MDA0MDZlYzdlMjZhOGIzNjhlNjUzYTk2ZTJmMGJkMzBlOTI3YjdmMmZhNDBm
10
+ ZGYzYWU0ZTVmNmJhNTVkZGE5NzFmYTgyZmQyMjc5NWNkYTU2YTQ0MTIyYzc0
11
+ NTkwOGU4YjRjNjIyNGJiNzFiM2UwNjcwYTZkZWZkMWY3OTA1ODc=
12
12
  data.tar.gz: !binary |-
13
- ZjI4MzkwMTEwYjM2YjY0NWFiZTI0NGY3NWFmMDI2ZTBhMWViZGRlNjMzMGY4
14
- M2Q2YTNjODIxYTBlYzFmNTgyZGNjOTA3N2U2ZWFjYjMyNmU1ODI5OWEzN2Uw
15
- YzFkYmYzM2UyYmMyMjE5ZmZhZTNhMGViNzVhMWI5MTlkMTkyOWU=
13
+ NmQ0ZjBiM2RmZjJiYzNjM2ZiZDdjMzEwZGE1YzAzNjZjZDJhNTUzMWZmYzIz
14
+ MzU0YThiNzM0OTk5OTI5ZGIwMDg1OTM0NDAxYThiNDMzMzMzYTNhZDc3N2Ew
15
+ MGJkNmVjNjIxMGY4ZjVlYzQ1YzMzYTJkMTJlZmNiNDlhOWU3MGE=
data/lib/rails_nav.rb CHANGED
@@ -7,7 +7,7 @@
7
7
  ##
8
8
  #
9
9
  def Nav.version()
10
- '2.5.7'
10
+ '2.6.0'
11
11
  end
12
12
 
13
13
  def Nav.dependencies
@@ -146,9 +146,15 @@
146
146
  link.active = false
147
147
  end
148
148
 
149
- no_clear_winner =
149
+ more_than_one_link =
150
+ size > 1
151
+
152
+ equivalently_active =
150
153
  weights.uniq.size < 2
151
154
 
155
+ no_clear_winner =
156
+ more_than_one_link && equivalently_active
157
+
152
158
  active_link =
153
159
  if no_clear_winner
154
160
  detect{|link| link.default}
@@ -239,51 +245,61 @@
239
245
  attr_accessor(:content)
240
246
  attr_accessor(:options)
241
247
  attr_accessor(:pattern)
242
- attr_accessor(:active)
243
248
  attr_accessor(:compute_active)
249
+ attr_accessor(:active)
244
250
  attr_accessor(:default)
245
251
  attr_accessor(:weight)
246
252
  attr_accessor(:slug)
247
253
  attr_accessor(:config)
248
254
 
249
- def initialize(nav, *args, &block)
250
- @nav = nav
251
-
252
- options =
255
+ def initialize(*args, &block)
256
+ #
257
+ @options =
253
258
  if args.last.is_a?(Hash)
254
259
  args.extract_options!.to_options!
255
260
  else
256
261
  {}
257
262
  end
263
+ #
264
+ args.each{|arg| @nav = arg if arg.is_a?(Nav)}
265
+ args.delete_if{|arg| arg.is_a?(Nav)}
258
266
 
259
- @content = options.delete(:content) || args.shift || 'Slash'
260
- @url = options.delete(:url) || args.shift || {}
261
- @pattern = options.delete(:pattern) || args.shift || Link.default_active_pattern_for(@content)
262
- @compute_active = options.delete(:active) || block || Link.default_active_block_for(@pattern)
263
- @default = options.delete(:default)
267
+ unless @nav
268
+ @nav = Nav.new
269
+ @nav.controller = Current.mock_controller
270
+ end
264
271
 
265
- @options = options
272
+ #
273
+ @content = getopt!(:content){ args.shift || 'Slash' }
274
+ @url = getopt!(:url){ args.shift || {} }
275
+ @pattern = getopt!(:pattern){ args.shift || Link.default_active_pattern_for(@content) }
276
+ @compute_active = getopt!(:active){ block || Link.default_active_block_for(@pattern) }
277
+ @default = getopt!(:default){ nil }
266
278
 
279
+ #
267
280
  @slug = Slug.for(@content, :join => '-')
268
281
  @already_computed_active = nil
269
- @active = nil
270
282
 
271
283
  @config = Map.new
272
284
  end
273
285
 
286
+ def getopt!(key, &block)
287
+ @options.has_key?(key) ? @options.delete(key) : (block && block.call)
288
+ end
289
+
274
290
  def compute_active!
275
- @active = (@compute_active.respond_to?(:call) ? @nav.evaluate(@compute_active, link = self) : !!@compute_active)
291
+ @active =
292
+ if @compute_active.respond_to?(:call)
293
+ @nav.evaluate(@compute_active, link = self)
294
+ else
295
+ !!@compute_active
296
+ end
276
297
  ensure
277
298
  @already_computed_active = true
278
299
  end
279
300
 
280
301
  def compute_active
281
302
  compute_active! unless @already_computed_active
282
- @active
283
- end
284
-
285
- def active?
286
- !!@active
287
303
  end
288
304
 
289
305
  def default?
data/rails_nav.gemspec CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  Gem::Specification::new do |spec|
5
5
  spec.name = "rails_nav"
6
- spec.version = "2.5.7"
6
+ spec.version = "2.6.0"
7
7
  spec.platform = Gem::Platform::RUBY
8
8
  spec.summary = "rails_nav"
9
9
  spec.description = "declarative navigation for rails applications"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_nav
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.7
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ara T. Howard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-12 00:00:00.000000000 Z
11
+ date: 2015-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails_current