resources_nav 1.0.2 → 1.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a2d2c8167884fca9848b82a95da97e19f2bf7f966cea3da0d8919c001c7dd648
4
- data.tar.gz: aa9ca810689144e8cf2ae516de4d0944b6a82e906b763af3c9e688b004f7d5b1
3
+ metadata.gz: 75f0940b72e00489bd3888e7e7a04320479a7aa141fec83745d6819d047af38f
4
+ data.tar.gz: 2c9e23d262232f945de7b798b3cd1362f9308ac28de2329383608cc3791012ea
5
5
  SHA512:
6
- metadata.gz: f199ee3d01462b37ffc7e2c86faf29ff5f32cda0c03b05e11f0f7045f11db9ced4f77da0e384fef91fb0ecd52faf035fbdcb316472dafa7dad7936517bfb68fa
7
- data.tar.gz: 296b754362cbd2548ad9d850c49c11acd270faf56f21f3e4295f33bfa3b802468ed4a5c5515ab704745600e08cace2c5a23bd43ad66d9dc9b8ec9381724f3ca1
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, like so:
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
- irb(main):001:0> Rails.application.routes.resources_nav
17
- => [:purchase_invoice_lines, :purchase_invoices, :journal_entries, :accounts, :companies]
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
@@ -1,3 +1,3 @@
1
1
  module ResourcesNav
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
data/lib/resources_nav.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "resources_nav/version"
2
2
  require "resources_nav/railtie"
3
3
 
4
+ require "resources_nav/resource"
4
5
  require "resources_nav/route_set_extension"
5
6
  require "resources_nav/mapper_extension"
6
7
  module ResourcesNav
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.2
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-01 00:00:00.000000000 Z
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