rails-menu-manager 0.1.0 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 97e4b3ac41b5c44a7bb06f2c9ace21b8b06fdda7
4
- data.tar.gz: 100a97a6bca11df0e7a00bd60c504a9a50ea7d58
3
+ metadata.gz: 4e581b735d3ae2594071364e8a3d4bc9e61ff41b
4
+ data.tar.gz: d032d81ae6a24718579a8534f6b841e562f610a3
5
5
  SHA512:
6
- metadata.gz: 0627a35bdb1fd148460f9cfd4d43d21ac88115159adff14ed7f6b09753c491c46a355e0c9f2215475bce491f63ea8c080d991befbf547a8c6ffd0a431c837b47
7
- data.tar.gz: d85ccb31346215e2eee1637e3618183c00378f8594fed84783825a2981299f0551af6939844b7a69f3b1e646284277aed445a0114440e889c6340b49ccb31bc0
6
+ metadata.gz: 34fb992a4bb146cc75543e4f34c71fb22925e508a5cc4aeadbcb21d13f6b6be54b67a0548efcebd689eb8d4d52e7a413ee6679c910f9279f67a844ef549777e2
7
+ data.tar.gz: 48f8d6f2e67b154833a93f1962c3463eb386cc56bca4c2284c73658fe9e0176778fc398b1c60ae0e69485d8904283ad9c4635446c40029428394c73e3ea0cd3b
@@ -1,3 +1,7 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.2.0 (2015-04-20) (initial release)
4
+ ### Changes
5
+ - Renamed namespace from Rails::Menu::Manager to RailsMenuManager
6
+
3
7
  ## 0.1.0 (2015-04-20) (initial release)
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![Travis CI](https://img.shields.io/travis/ydkn/rails-menu-manager.svg)](https://travis-ci.org/ydkn/rails-menu-manager)
4
4
  [![Code Climate](https://img.shields.io/codeclimate/github/ydkn/rails-menu-manager.svg)](https://codeclimate.com/github/ydkn/rails-menu-manager)
5
5
 
6
- # Rails::Menu::Manager
6
+ # Rails Menu Manager
7
7
 
8
8
  Simple menu manager for Rails.
9
9
  Besides a flat menu structure it supports multiple navigation menus and nested menus as well.
@@ -0,0 +1,2 @@
1
+ require 'rails_menu_manager/version'
2
+ require 'rails_menu_manager/railtie'
@@ -0,0 +1,63 @@
1
+ require 'active_support/concern'
2
+ require 'rails_menu_manager/menu_item'
3
+
4
+ module RailsMenuManager
5
+ module ActionController
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ helper_method :'in_menu?'
10
+ end
11
+
12
+ # Checks if a at least one defined and active menu is in given path
13
+ #
14
+ # @param [Array] Menu path to check
15
+ # @return [Boolean] Boolean indicating if at least one menu item is in path
16
+ def in_menu?(*args)
17
+ _menu_items.each do |menu|
18
+ return true if menu.in?(*args)
19
+ end
20
+
21
+ false
22
+ end
23
+
24
+ # Adds a menu
25
+ # Supports before_action options: if, only, unless, except
26
+ #
27
+ # @param [Array/Hash] Menu path and options.
28
+ def menu(*args)
29
+ _add_menu_setting(*args)
30
+ end
31
+
32
+ private
33
+
34
+ def _menu_items
35
+ @_menu_items ||= []
36
+ end
37
+
38
+ def _add_menu_setting(*args)
39
+ opts = args.extract_options!
40
+
41
+ path = args.map { |p| p.to_sym }
42
+
43
+ _menu_items << MenuItem.new(path, opts)
44
+ end
45
+
46
+ module ClassMethods
47
+ def menu(*args)
48
+ opts = args.extract_options!
49
+
50
+ before_action_opts = {
51
+ only: opts.delete(:only),
52
+ if: opts.delete(:if),
53
+ except: opts.delete(:except),
54
+ unless: opts.delete(:unless)
55
+ }
56
+
57
+ before_action before_action_opts do
58
+ _add_menu_setting(*args, opts)
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,17 @@
1
+ module RailsMenuManager
2
+ class MenuItem
3
+ attr_reader :path, :options
4
+
5
+ def initialize(path, options = {})
6
+ @path = path
7
+ @path_str = path.join('#')
8
+ @options = options
9
+ end
10
+
11
+ def in?(*args)
12
+ return false if path.nil?
13
+
14
+ !!(@path_str =~ /\A#{args.join('#')}/i)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,10 @@
1
+ require 'rails/railtie'
2
+ require 'rails_menu_manager/action_controller'
3
+
4
+ module RailsMenuManager
5
+ class Railtie < Rails::Railtie
6
+ initializer 'rails-menu-manager' do
7
+ ::ActionController::Base.send(:include, RailsMenuManager::ActionController)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module RailsMenuManager
2
+ VERSION = '0.2.0'
3
+ end
@@ -1,11 +1,11 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'rails/menu/manager/version'
4
+ require 'rails_menu_manager/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'rails-menu-manager'
8
- spec.version = Rails::Menu::Manager::VERSION
8
+ spec.version = RailsMenuManager::VERSION
9
9
  spec.authors = ['Florian Schwab']
10
10
  spec.email = ['me@ydkn.de']
11
11
 
@@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency 'bundler', '~> 1.9'
24
24
  spec.add_development_dependency 'rake', '~> 10.0'
25
25
  spec.add_development_dependency 'rspec', '~> 3.2'
26
+ spec.add_development_dependency 'yard', '~> 0.8'
26
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-menu-manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Schwab
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-20 00:00:00.000000000 Z
11
+ date: 2015-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -72,6 +72,20 @@ dependencies:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
74
  version: '3.2'
75
+ - !ruby/object:Gem::Dependency
76
+ name: yard
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '0.8'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '0.8'
75
89
  description: Simple menu manager for Rails.
76
90
  email:
77
91
  - me@ydkn.de
@@ -90,11 +104,11 @@ files:
90
104
  - gemfiles/rails40
91
105
  - gemfiles/rails41
92
106
  - gemfiles/rails42
93
- - lib/rails/menu/manager.rb
94
- - lib/rails/menu/manager/concern.rb
95
- - lib/rails/menu/manager/menu_item.rb
96
- - lib/rails/menu/manager/railtie.rb
97
- - lib/rails/menu/manager/version.rb
107
+ - lib/rails-menu-manager.rb
108
+ - lib/rails_menu_manager/action_controller.rb
109
+ - lib/rails_menu_manager/menu_item.rb
110
+ - lib/rails_menu_manager/railtie.rb
111
+ - lib/rails_menu_manager/version.rb
98
112
  - rails-menu-manager.gemspec
99
113
  homepage: https://github.com/ydkn/rails-menu-manager
100
114
  licenses: []
@@ -120,3 +134,4 @@ signing_key:
120
134
  specification_version: 4
121
135
  summary: Simple menu manager for Rails.
122
136
  test_files: []
137
+ has_rdoc:
@@ -1,2 +0,0 @@
1
- require 'rails/menu/manager/version'
2
- require 'rails/menu/manager/railtie'
@@ -1,59 +0,0 @@
1
- require 'active_support/concern'
2
- require 'rails/menu/manager/menu_item'
3
-
4
- module Rails
5
- module Menu
6
- module Manager
7
- module Concern
8
- extend ActiveSupport::Concern
9
-
10
- included do
11
- helper_method :'in_menu?'
12
- end
13
-
14
- def in_menu?(*args)
15
- _menu_items.each do |menu|
16
- return true if menu.in?(*args)
17
- end
18
-
19
- false
20
- end
21
-
22
- def menu(*args)
23
- _add_menu_setting(*args)
24
- end
25
-
26
- private
27
-
28
- def _menu_items
29
- @_menu_items ||= []
30
- end
31
-
32
- def _add_menu_setting(*args)
33
- opts = args.extract_options!
34
-
35
- path = args.map { |p| p.to_sym }
36
-
37
- _menu_items << MenuItem.new(path, opts)
38
- end
39
-
40
- module ClassMethods
41
- def menu(*args)
42
- opts = args.extract_options!
43
-
44
- before_action_opts = {
45
- only: opts.delete(:only),
46
- if: opts.delete(:if),
47
- except: opts.delete(:except),
48
- unless: opts.delete(:unless)
49
- }
50
-
51
- before_action before_action_opts do
52
- _add_menu_setting(*args, opts)
53
- end
54
- end
55
- end
56
- end
57
- end
58
- end
59
- end
@@ -1,21 +0,0 @@
1
- module Rails
2
- module Menu
3
- module Manager
4
- class MenuItem
5
- attr_reader :path, :options
6
-
7
- def initialize(path, options = {})
8
- @path = path
9
- @path_str = path.join('#')
10
- @options = options
11
- end
12
-
13
- def in?(*args)
14
- return false if path.nil?
15
-
16
- !!(@path_str =~ /\A#{args.join('#')}/i)
17
- end
18
- end
19
- end
20
- end
21
- end
@@ -1,14 +0,0 @@
1
- require 'rails/railtie'
2
- require 'rails/menu/manager/concern'
3
-
4
- module Rails
5
- module Menu
6
- module Manager
7
- class Railtie < Rails::Railtie
8
- initializer 'rails-menu-manager' do
9
- ActionController::Base.send(:include, Rails::Menu::Manager::Concern)
10
- end
11
- end
12
- end
13
- end
14
- end
@@ -1,7 +0,0 @@
1
- module Rails
2
- module Menu
3
- module Manager
4
- VERSION = '0.1.0'
5
- end
6
- end
7
- end