nav 0.7.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 58149015afffa5b2d9cce232ffb836775bdf9e9d
4
+ data.tar.gz: fc210ea775bf73be81d64aa03be9319694b0ccf6
5
+ SHA512:
6
+ metadata.gz: 40597ec1fa97d6142182eda7cfc040fc0c90fbf80b3f1b35c3f3dfcacd1cdcdd24fa827c7b2aabb274560730bcc9995553883da3e618ef97cd58492dc7e9dcdc
7
+ data.tar.gz: 1e96cdeaa67b15632c76dcd3e6c0ac96f6498364ca3f6091df7beb2d0beb5fd2ddd6c4193c8ccc1c387544d7d57bcd75bcb56c977d235b80a997ca7ce4243bff
data/Gemfile CHANGED
@@ -2,3 +2,9 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in nav.gemspec
4
4
  gemspec
5
+
6
+ group :development, :test do
7
+ gem 'minitest'
8
+ gem 'rr'
9
+
10
+ end
@@ -1,5 +1,6 @@
1
1
  module Nav
2
2
  class Builder
3
+
3
4
  def initialize( template, options = {} )
4
5
  @template, @options = template, options
5
6
  @actions = []
@@ -9,7 +10,7 @@ module Nav
9
10
 
10
11
  # @example A basic action
11
12
  # action "Home", home_url
12
- # action "Tome, home_url, :current => true
13
+ # action "Home, home_url, :current => true
13
14
  #
14
15
  # @example Given a block
15
16
  # action do
@@ -19,86 +20,88 @@ module Nav
19
20
  # action :current => true do
20
21
  # content_tag :span, "A simple text""
21
22
  # end
22
- def action( name = nil, options = {}, html_options = {}, &block )
23
- @actions << if block
24
- [ @template.capture(&block), name || {}, {} ]
23
+ def action( name = nil, url_for_options = {}, html_options = {}, &block )
24
+ @actions << if block_given?
25
+ [@template.capture(&block), name || {}, {}]
25
26
  else
26
27
  wrapper_options = {
27
28
  :current => html_options.delete(:current),
28
29
  :disabled => html_options.delete(:disabled),
29
30
  }
30
31
 
31
- [ link_to(name, options, html_options), wrapper_options, options ]
32
+ [link_to(name, url_for_options, html_options), wrapper_options, url_for_options]
32
33
  end
33
34
  end
34
35
 
35
36
  def to_s
36
- content_tag( :ul, actions.html_safe, @options ).html_safe if actions?
37
+ content_tag(:ul, actions.join.html_safe, @options).html_safe
37
38
  end
38
39
 
39
40
 
40
41
  private
41
42
 
42
43
  def actions
43
- @actions.collect { |a| action_wrapper(*a) }.join
44
+ @actions.map { |content, options, url_for_options| action_wrapper(content, options, url_for_options) }
44
45
  end
45
46
 
46
47
  def actions?
47
48
  @actions.any?
48
49
  end
49
50
 
50
- def action_wrapper( contents, options = {}, url_for_options = {} )
51
- present = [contents, options, url_for_options] # the one we're dealing with
52
- present_index = @actions.index( present )
51
+ def action_wrapper( content, options = {}, url_for_options = {} )
52
+ present = [content, options, url_for_options] # the one we're dealing with
53
+ present_index = @actions.index(present)
53
54
 
54
- before_present = @actions.at( present_index - 1 ) if present_index > 0
55
- after_present = @actions.at( present_index + 1 ) if present_index < @actions.size
55
+ before_present = @actions.at(present_index - 1) if present_index > 0
56
+ after_present = @actions.at(present_index + 1) if present_index < @actions.size
56
57
 
57
- classes = []
58
- classes << options[:class] if options.key?(:class)
58
+ classes = [ *options[:class] ]
59
59
  classes << "first" if present == @actions.first
60
60
  classes << "after_first" if present_index == 1
61
61
  classes << "before_last" if present == @actions[-2]
62
- classes << "last" if present == @actions.last
63
- classes << "current" if current?( *present )
62
+ classes << "last" if present == @actions.last
63
+ classes << "current" if current?(*present)
64
64
  classes << "disabled" if options[:disabled]
65
- classes << "before_current" if after_present && current?( *after_present )
66
- classes << "after_current" if before_present && current?( *before_present )
65
+ classes << "before_current" if after_present && current?(*after_present)
66
+ classes << "after_current" if before_present && current?(*before_present)
67
67
 
68
- content_tag :li, contents.html_safe, :class => classes.join(" ")
68
+ content_tag(:li, content.html_safe, :class => classes.join(" "))
69
69
  end
70
70
 
71
- def current?( contents, options = {}, url_for_options = {} )
72
- current = options[:current]
71
+ def current?( content, options = {}, url_for_options = {} )
72
+ return false if !!options[:disabled]
73
73
 
74
- is_current = case current
75
- when TrueClass then true
76
- when Regexp then request_uri.match(current).nil? ? false : true
77
- when Proc then current.call
78
- else false
79
- end
74
+ current = options[:current] || url_for_options
80
75
 
81
- return true if is_current && !options[:disabled]
82
- return true if is_current || !url_for_options.is_a?(Symbol) && @template.current_page?(url_for_options) && url_for_options != {} && !options[:disabled]
76
+ case current
77
+ when TrueClass, FalseClass then current
78
+ when Regexp then request_uri.match(current)
79
+ when Proc then current.call
80
+ when Array then current.map { |c| current?(content, options.merge(current: c), url_for_options) }.any?
81
+ else current_page?(current)
82
+ end
83
+ end
83
84
 
84
- false
85
+ def current_page?( options )
86
+ @template.current_page?(options)
85
87
  end
86
88
 
87
89
  def content_tag( *args )
88
- @template.content_tag( *args ).html_safe
90
+ @template.content_tag(*args).html_safe
89
91
  end
90
92
 
91
93
  def link_to( *args )
92
- @template.link_to( *args ).html_safe
94
+ @template.link_to(*args).html_safe
93
95
  end
94
96
 
95
97
  def request_uri
96
- @request_uri or @request_uri = request.respond_to?(:request_uri) ? request.request_uri : request.url
98
+ request.respond_to?(:request_uri) ? request.request_uri : request.url
97
99
  end
98
100
 
99
101
  def request
100
102
  @template.request
101
103
  end
104
+
102
105
  end
103
106
  end
104
107
 
@@ -1,5 +1,4 @@
1
1
  module Nav
2
-
3
- VERSION = "0.7.0"
2
+ VERSION = "0.9.0"
4
3
 
5
4
  end
@@ -18,6 +18,5 @@ Gem::Specification.new do |s|
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
20
 
21
- s.add_dependency 'actionpack', '~> 3'
22
- s.add_development_dependency 'rr'
21
+ s.add_dependency 'actionpack', '>= 3'
23
22
  end
@@ -1,13 +1,14 @@
1
- require 'rubygems'
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+
4
+ require 'nav'
2
5
  require 'minitest/autorun'
6
+ require 'rr'
3
7
 
4
8
  begin
5
9
  require 'action_view'
6
- require 'rr'
7
10
  rescue LoadError
8
11
  STDERR.puts "Unable to run Nav tests."
9
- else
10
- require File.dirname(__FILE__) + "/../lib/nav"
11
12
  end
12
13
 
13
14
 
metadata CHANGED
@@ -1,38 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nav
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
5
- prerelease:
4
+ version: 0.9.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Rudolf Schmidt
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-02-29 00:00:00.000000000 Z
11
+ date: 2013-10-18 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: actionpack
16
- requirement: &70286083358500 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ~>
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '3'
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *70286083358500
25
- - !ruby/object:Gem::Dependency
26
- name: rr
27
- requirement: &70286083357760 !ruby/object:Gem::Requirement
28
- none: false
22
+ version_requirements: !ruby/object:Gem::Requirement
29
23
  requirements:
30
- - - ! '>='
24
+ - - '>='
31
25
  - !ruby/object:Gem::Version
32
- version: '0'
33
- type: :development
34
- prerelease: false
35
- version_requirements: *70286083357760
26
+ version: '3'
36
27
  description: Simple nagivation builder
37
28
  email:
38
29
  executables: []
@@ -52,28 +43,28 @@ files:
52
43
  - test/test_helper.rb
53
44
  homepage: http://rubygems.org/gems/nav
54
45
  licenses: []
46
+ metadata: {}
55
47
  post_install_message:
56
48
  rdoc_options: []
57
49
  require_paths:
58
50
  - lib
59
51
  required_ruby_version: !ruby/object:Gem::Requirement
60
- none: false
61
52
  requirements:
62
- - - ! '>='
53
+ - - '>='
63
54
  - !ruby/object:Gem::Version
64
55
  version: '0'
65
56
  required_rubygems_version: !ruby/object:Gem::Requirement
66
- none: false
67
57
  requirements:
68
- - - ! '>='
58
+ - - '>='
69
59
  - !ruby/object:Gem::Version
70
60
  version: '0'
71
61
  requirements: []
72
62
  rubyforge_project: nav
73
- rubygems_version: 1.8.17
63
+ rubygems_version: 2.0.6
74
64
  signing_key:
75
- specification_version: 3
65
+ specification_version: 4
76
66
  summary: Simple nagivation builder
77
67
  test_files:
78
68
  - test/nav_test.rb
79
69
  - test/test_helper.rb
70
+ has_rdoc: