rails-menu-manager 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 97e4b3ac41b5c44a7bb06f2c9ace21b8b06fdda7
4
+ data.tar.gz: 100a97a6bca11df0e7a00bd60c504a9a50ea7d58
5
+ SHA512:
6
+ metadata.gz: 0627a35bdb1fd148460f9cfd4d43d21ac88115159adff14ed7f6b09753c491c46a355e0c9f2215475bce491f63ea8c080d991befbf547a8c6ffd0a431c837b47
7
+ data.tar.gz: d85ccb31346215e2eee1637e3618183c00378f8594fed84783825a2981299f0551af6939844b7a69f3b1e646284277aed445a0114440e889c6340b49ccb31bc0
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.1.5
5
+ - 2.2.2
6
+
7
+ gemfile:
8
+ - gemfiles/rails40
9
+ - gemfiles/rails41
10
+ - gemfiles/rails42
11
+
12
+ script: bundle exec rake spec
13
+
14
+ before_install:
15
+ - gem install bundler -v '~> 1.9'
@@ -0,0 +1,3 @@
1
+ # Change Log
2
+
3
+ ## 0.1.0 (2015-04-20) (initial release)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rails-menu-manager.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Florian Schwab
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.
@@ -0,0 +1,57 @@
1
+ [![Gem Version](https://img.shields.io/gem/v/rails-menu-manager.svg)](https://rubygems.org/gems/rails-menu-manager)
2
+ [![Dependencies](https://img.shields.io/gemnasium/ydkn/rails-menu-manager.svg)](https://gemnasium.com/ydkn/rails-menu-manager)
3
+ [![Travis CI](https://img.shields.io/travis/ydkn/rails-menu-manager.svg)](https://travis-ci.org/ydkn/rails-menu-manager)
4
+ [![Code Climate](https://img.shields.io/codeclimate/github/ydkn/rails-menu-manager.svg)](https://codeclimate.com/github/ydkn/rails-menu-manager)
5
+
6
+ # Rails::Menu::Manager
7
+
8
+ Simple menu manager for Rails.
9
+ Besides a flat menu structure it supports multiple navigation menus and nested menus as well.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'rails-menu-manager'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install rails-menu-manager
26
+
27
+ ## Usage
28
+
29
+ Set menu path in controller:
30
+
31
+ ```ruby
32
+ class FooController < ApplicationController
33
+ menu :main, :users, except: [:index]
34
+
35
+ def index
36
+ menu :sidebar, :users
37
+ end
38
+ end
39
+ ```
40
+
41
+ Highlight current navigation link(s):
42
+
43
+ ```ruby
44
+ content_tag :li, 'Menu', class: in_menu?(:main) ? 'active' : nil
45
+
46
+ link_to 'users', users_path, class: in_menu?(:main, :users) ? 'active' : nil
47
+
48
+ link_to 'users', users_path, class: in_menu?(:sidebar, :users) ? 'active' : nil
49
+ ```
50
+
51
+ ## Contributing
52
+
53
+ 1. Fork it ( https://github.com/ydkn/rails-menu-manager/fork )
54
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
55
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
56
+ 4. Push to the branch (`git push origin my-new-feature`)
57
+ 5. Create a new Pull Request
@@ -0,0 +1,4 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rails-menu-manager.gemspec
4
+ gemspec path: '..'
5
+
6
+
7
+ gem 'railties', '~> 4.0'
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rails-menu-manager.gemspec
4
+ gemspec path: '..'
5
+
6
+
7
+ gem 'railties', '~> 4.1'
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rails-menu-manager.gemspec
4
+ gemspec path: '..'
5
+
6
+
7
+ gem 'railties', '~> 4.2'
@@ -0,0 +1,2 @@
1
+ require 'rails/menu/manager/version'
2
+ require 'rails/menu/manager/railtie'
@@ -0,0 +1,59 @@
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
@@ -0,0 +1,21 @@
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
@@ -0,0 +1,14 @@
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
@@ -0,0 +1,7 @@
1
+ module Rails
2
+ module Menu
3
+ module Manager
4
+ VERSION = '0.1.0'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rails/menu/manager/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'rails-menu-manager'
8
+ spec.version = Rails::Menu::Manager::VERSION
9
+ spec.authors = ['Florian Schwab']
10
+ spec.email = ['me@ydkn.de']
11
+
12
+ spec.summary = %q{Simple menu manager for Rails.}
13
+ spec.description = %q{Simple menu manager for Rails.}
14
+ spec.homepage = 'https://github.com/ydkn/rails-menu-manager'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = 'bin'
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'railties', '>= 4.0', '< 5.0'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.9'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec', '~> 3.2'
26
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails-menu-manager
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Florian Schwab
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '4.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.9'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.9'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '10.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '10.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.2'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.2'
75
+ description: Simple menu manager for Rails.
76
+ email:
77
+ - me@ydkn.de
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - ".gitignore"
83
+ - ".rspec"
84
+ - ".travis.yml"
85
+ - CHANGELOG.md
86
+ - Gemfile
87
+ - LICENSE.txt
88
+ - README.md
89
+ - Rakefile
90
+ - gemfiles/rails40
91
+ - gemfiles/rails41
92
+ - 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
98
+ - rails-menu-manager.gemspec
99
+ homepage: https://github.com/ydkn/rails-menu-manager
100
+ licenses: []
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.4.6
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: Simple menu manager for Rails.
122
+ test_files: []