rails_navigation 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/Guardfile +11 -0
- data/LICENSE.txt +22 -0
- data/README.md +55 -0
- data/Rakefile +10 -0
- data/app/helpers/rails_navigation_helper.rb +5 -0
- data/lib/rails_navigation.rb +4 -0
- data/lib/rails_navigation/matcher.rb +33 -0
- data/lib/rails_navigation/railtie.rb +4 -0
- data/lib/rails_navigation/version.rb +3 -0
- data/rails_navigation.gemspec +30 -0
- data/spec/rails_navigation_spec.rb +68 -0
- data/spec/spec_helper.rb +8 -0
- metadata +188 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: aae613c2e8f7248f1dafd41a9b6f18785b3ace6b
|
4
|
+
data.tar.gz: b6a32d1b639ec4145de44cd67c55a1af829a16a5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f80224ce1656d606479c1d6ff61606b8148a4aad4b783981172b1825c704c74b1cb32f53153b3d8b0e13713e17d413631ad2b038323d9f619af3f7993b228e44
|
7
|
+
data.tar.gz: 3938909fcae239fce32fb82bc1d0f6903995544d92870c3edb0a0fe935951ec9ca25cf26e45779a483aeccfbf679d0b98fbfb67d12e755e1cebc31f827a8f9fd
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Sascha Brink
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# rails_navigation
|
2
|
+
|
3
|
+
Simplify matching of Rails routes. Did you ever hate the link_to_if helper? E.g.:
|
4
|
+
|
5
|
+
<%= link_to_if(@current_user.nil?, "Login", { controller: "sessions", action: "new" }) %>
|
6
|
+
|
7
|
+
Then try this gem! You can now match controllers and actions like defined in the routes.rb.
|
8
|
+
|
9
|
+
## Examples
|
10
|
+
|
11
|
+
Matching controllers:
|
12
|
+
|
13
|
+
{ controller: "pages", action: "new" } becomes 'pages'
|
14
|
+
|
15
|
+
Matching controllers and actions:
|
16
|
+
|
17
|
+
{ controller: "pages", action: "new" } becomes 'pages#new'
|
18
|
+
|
19
|
+
Matching controllers, actions and params:
|
20
|
+
|
21
|
+
{ controller: "pages", action: "show", params: { id: 'homepage' } } becomes 'pages#new?id=homepage'
|
22
|
+
|
23
|
+
Or even simpler (id is the default):
|
24
|
+
|
25
|
+
{ controller: "pages", action: "show", params: { id: 'homepage' } } becomes 'pages#new?homepage'
|
26
|
+
|
27
|
+
|
28
|
+
## Installation
|
29
|
+
|
30
|
+
Add this line to your application's Gemfile:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
gem 'rails_navigation'
|
34
|
+
```
|
35
|
+
|
36
|
+
And then execute:
|
37
|
+
|
38
|
+
$ bundle
|
39
|
+
|
40
|
+
## Usage
|
41
|
+
|
42
|
+
TODO: Write usage instructions here
|
43
|
+
|
44
|
+
|
45
|
+
## TODO
|
46
|
+
|
47
|
+
* Match multiple conditions
|
48
|
+
|
49
|
+
## Contributing
|
50
|
+
|
51
|
+
1. Fork it ( https://github.com/sbrink/rails_navigation/fork )
|
52
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
53
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
54
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
55
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'rspec/core/rake_task'
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
|
4
|
+
# Default directory to look in is `/specs`
|
5
|
+
# Run with `rake spec`
|
6
|
+
RSpec::Core::RakeTask.new(:spec) do |task|
|
7
|
+
task.rspec_opts = ['--color', '--format', 'nested']
|
8
|
+
end
|
9
|
+
|
10
|
+
task default: :spec
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module RailsNavigation
|
2
|
+
class Matcher
|
3
|
+
def initialize(controller_name, action_name, params)
|
4
|
+
@controller_name = controller_name
|
5
|
+
@action_name = action_name
|
6
|
+
@params = params
|
7
|
+
end
|
8
|
+
|
9
|
+
def check_controller(str)
|
10
|
+
result = Array(str.match(/^([a-z_\-]+)/))[1]
|
11
|
+
result ? (result == @controller_name) : true
|
12
|
+
end
|
13
|
+
|
14
|
+
def check_action(str)
|
15
|
+
result = Array(str.match(/#([a-z_\-]+)/))[1]
|
16
|
+
result ? (result == @action_name) : true
|
17
|
+
end
|
18
|
+
|
19
|
+
def check_parameters(str)
|
20
|
+
result = Array(str.match(/\?([!a-z0-9&_\-=]+)/))[1]
|
21
|
+
if result
|
22
|
+
key, value = result.split('=')
|
23
|
+
result.include?('=') ? value == @params[key.to_sym] : result == @params[:id]
|
24
|
+
else
|
25
|
+
true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def active?(str)
|
30
|
+
check_controller(str) && check_action(str) && check_parameters(str)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rails_navigation/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'rails_navigation'
|
8
|
+
spec.version = RailsNavigation::VERSION
|
9
|
+
spec.authors = ['Sascha Brink', 'Martin Schurig']
|
10
|
+
spec.email = ['sascha.brink@gmail.com', 'martin@schurig.pw']
|
11
|
+
spec.summary = %q{Simplified navigation helper for Rails.}
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = 'https://github.com/sbrink/rails_navigation'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
spec.add_development_dependency 'rspec'
|
24
|
+
spec.add_development_dependency 'rspec-nc'
|
25
|
+
spec.add_development_dependency 'guard'
|
26
|
+
spec.add_development_dependency 'guard-rspec'
|
27
|
+
spec.add_development_dependency 'pry'
|
28
|
+
spec.add_development_dependency 'pry-remote'
|
29
|
+
spec.add_development_dependency 'pry-nav'
|
30
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RailsNavigation::Matcher do
|
4
|
+
|
5
|
+
describe 'with a controller' do
|
6
|
+
it 'matches a controller' do
|
7
|
+
condition = 'pages'
|
8
|
+
controller_name, action_name, params = 'pages', 'edit', {}
|
9
|
+
matcher = RailsNavigation::Matcher.new(controller_name, action_name, params)
|
10
|
+
expect(matcher.active?(condition)).to be_truthy
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'with a controller and action' do
|
15
|
+
it 'matches a controller with action' do
|
16
|
+
condition = 'pages#edit'
|
17
|
+
controller_name, action_name, params = 'pages', 'edit', {}
|
18
|
+
matcher = RailsNavigation::Matcher.new(controller_name, action_name, params)
|
19
|
+
expect(matcher.active?(condition)).to be_truthy
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'does not match a controller with a wrong action' do
|
23
|
+
condition = 'pages#show'
|
24
|
+
controller_name, action_name, params = 'pages', 'edit', {}
|
25
|
+
matcher = RailsNavigation::Matcher.new(controller_name, action_name, params)
|
26
|
+
expect(matcher.active?(condition)).to be_falsey
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'with controller, action and a single parameter' do
|
31
|
+
it 'matches a controller, action and param id as default' do
|
32
|
+
condition = 'pages#edit?about'
|
33
|
+
controller_name, action_name, params = 'pages', 'edit', { id: 'about' }
|
34
|
+
matcher = RailsNavigation::Matcher.new(controller_name, action_name, params)
|
35
|
+
expect(matcher.active?(condition)).to be_truthy
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'does not match a controller, action and param id as default' do
|
39
|
+
condition = 'pages#edit?about'
|
40
|
+
controller_name, action_name, params = 'pages', 'edit', { id: 'imprint' }
|
41
|
+
matcher = RailsNavigation::Matcher.new(controller_name, action_name, params)
|
42
|
+
expect(matcher.active?(condition)).to be_falsy
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'matches a controller, action and param' do
|
46
|
+
condition = 'pages#edit?from=homepage'
|
47
|
+
controller_name, action_name, params = 'pages', 'edit', { from: 'homepage' }
|
48
|
+
matcher = RailsNavigation::Matcher.new(controller_name, action_name, params)
|
49
|
+
expect(matcher.active?(condition)).to be_truthy
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'does not match a wrong controller, action and param' do
|
53
|
+
condition = 'pages#edit?from=start'
|
54
|
+
controller_name, action_name, params = 'pages', 'edit', { from: 'homepage' }
|
55
|
+
matcher = RailsNavigation::Matcher.new(controller_name, action_name, params)
|
56
|
+
expect(matcher.active?(condition)).to be_falsy
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe 'with array of conditions' do
|
61
|
+
# it 'matches one of multiple conditions' do
|
62
|
+
# conditions = ['pages#edit', 'recipes#show']
|
63
|
+
# controller_name, action_name, params = 'pages', 'edit', { }
|
64
|
+
# matcher = RailsNavigation::Matcher.new(controller_name, action_name, params)
|
65
|
+
# expect(matcher.active?(conditions)).to be_truthy
|
66
|
+
# end
|
67
|
+
end
|
68
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,188 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails_navigation
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sascha Brink
|
8
|
+
- Martin Schurig
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-01-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.7'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.7'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '10.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '10.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rspec-nc
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: guard
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: guard-rspec
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: pry
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: pry-remote
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: pry-nav
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
type: :development
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
description: Simplified navigation helper for Rails.
|
141
|
+
email:
|
142
|
+
- sascha.brink@gmail.com
|
143
|
+
- martin@schurig.pw
|
144
|
+
executables: []
|
145
|
+
extensions: []
|
146
|
+
extra_rdoc_files: []
|
147
|
+
files:
|
148
|
+
- ".gitignore"
|
149
|
+
- Gemfile
|
150
|
+
- Guardfile
|
151
|
+
- LICENSE.txt
|
152
|
+
- README.md
|
153
|
+
- Rakefile
|
154
|
+
- app/helpers/rails_navigation_helper.rb
|
155
|
+
- lib/rails_navigation.rb
|
156
|
+
- lib/rails_navigation/matcher.rb
|
157
|
+
- lib/rails_navigation/railtie.rb
|
158
|
+
- lib/rails_navigation/version.rb
|
159
|
+
- rails_navigation.gemspec
|
160
|
+
- spec/rails_navigation_spec.rb
|
161
|
+
- spec/spec_helper.rb
|
162
|
+
homepage: https://github.com/sbrink/rails_navigation
|
163
|
+
licenses:
|
164
|
+
- MIT
|
165
|
+
metadata: {}
|
166
|
+
post_install_message:
|
167
|
+
rdoc_options: []
|
168
|
+
require_paths:
|
169
|
+
- lib
|
170
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
171
|
+
requirements:
|
172
|
+
- - ">="
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: '0'
|
175
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
176
|
+
requirements:
|
177
|
+
- - ">="
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
version: '0'
|
180
|
+
requirements: []
|
181
|
+
rubyforge_project:
|
182
|
+
rubygems_version: 2.2.2
|
183
|
+
signing_key:
|
184
|
+
specification_version: 4
|
185
|
+
summary: Simplified navigation helper for Rails.
|
186
|
+
test_files:
|
187
|
+
- spec/rails_navigation_spec.rb
|
188
|
+
- spec/spec_helper.rb
|