resources_nav 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -4
- data/lib/resources_nav/mapper_extension.rb +1 -1
- data/lib/resources_nav/resource.rb +29 -0
- data/lib/resources_nav/version.rb +1 -1
- data/lib/resources_nav.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75f0940b72e00489bd3888e7e7a04320479a7aa141fec83745d6819d047af38f
|
4
|
+
data.tar.gz: 2c9e23d262232f945de7b798b3cd1362f9308ac28de2329383608cc3791012ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f2089efdce357e8fd615125d7b4a85cbad10d9d3c9ff4bf101c0fdcb491ab075f207a3f8e90564cb935bb574441ebc12f4a6f5169b27bdfc4a882a0110df991
|
7
|
+
data.tar.gz: 3bc7649d711cb9756a578f325c15696e0e84aad88a0adba6032642880a84080979b60bad19d62a79e485d8064fddd1ce2f6cc96e6feb056d5aaa1944e9cff653
|
data/README.md
CHANGED
@@ -3,20 +3,30 @@ Add a :nav option to Rails routes mapper 'resources' method, that adds the resou
|
|
3
3
|
It's convenient to populate a navigation menu.
|
4
4
|
|
5
5
|
## Usage
|
6
|
-
Just add a nav option to your resources route in config/routes.rb
|
6
|
+
Just add a nav option to your resources route in config/routes.rb. The nav option can take a hash,
|
7
|
+
containing an icon name.
|
8
|
+
|
7
9
|
```ruby
|
8
10
|
Rails.application.routes.draw do
|
9
11
|
resources :apples, nav: true
|
10
12
|
resources :oranges, nav: true
|
13
|
+
resources :apricots, nav: { icon: 'fruit' }
|
11
14
|
end
|
12
15
|
```
|
13
16
|
|
14
17
|
The resources array will then be accessible from Rails.application.routes.resources_nav:
|
15
18
|
```ruby
|
16
|
-
|
17
|
-
=> [:
|
18
|
-
|
19
|
+
Rails.application.routes.resources_nav.map(&:name)
|
20
|
+
=> [:apples, :oranges, :apricots]
|
21
|
+
|
22
|
+
resource = Rails.application.routes.resources_nav.detect { |r| r == :apricots }
|
19
23
|
|
24
|
+
resource.name
|
25
|
+
=> :apricots
|
26
|
+
|
27
|
+
resource.icon
|
28
|
+
=> 'fruit'
|
29
|
+
```
|
20
30
|
|
21
31
|
## Installation
|
22
32
|
Add this line to your application's Gemfile:
|
@@ -9,7 +9,7 @@ module ResourcesNav
|
|
9
9
|
if options[:nav]
|
10
10
|
@set.resources_nav ||= []
|
11
11
|
resources.each do |resource|
|
12
|
-
@set.resources_nav << resource unless @set.resources_nav.include?(resource)
|
12
|
+
@set.resources_nav << ResourcesNav::Resource.new(resource, options[:nav]) unless @set.resources_nav.include?(resource)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
resources_orig(*resources, &block)
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module ResourcesNav
|
2
|
+
class Resource
|
3
|
+
attr_accessor :name, :icon
|
4
|
+
def initialize(_name, options={})
|
5
|
+
@name = _name
|
6
|
+
@icon = options[:icon] if options.is_a?(Hash)
|
7
|
+
end
|
8
|
+
|
9
|
+
def ==(other)
|
10
|
+
if other.is_a?(Symbol)
|
11
|
+
name == other
|
12
|
+
elsif other.is_a?(String)
|
13
|
+
to_s == other
|
14
|
+
elsif other.is_a?(self.class)
|
15
|
+
name == other.name
|
16
|
+
else
|
17
|
+
false
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_s
|
22
|
+
to_sym.to_s
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_sym
|
26
|
+
name
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/resources_nav.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resources_nav
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bruno Enten
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-07-
|
11
|
+
date: 2022-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -44,6 +44,7 @@ files:
|
|
44
44
|
- lib/resources_nav.rb
|
45
45
|
- lib/resources_nav/mapper_extension.rb
|
46
46
|
- lib/resources_nav/railtie.rb
|
47
|
+
- lib/resources_nav/resource.rb
|
47
48
|
- lib/resources_nav/route_set_extension.rb
|
48
49
|
- lib/resources_nav/version.rb
|
49
50
|
- lib/tasks/resources_nav_tasks.rake
|