active_admin-subnav 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c48d9e15942740b72a37b67dc9aa59a20687ad0f
4
+ data.tar.gz: 6df97455b50cc0015bde079189cc15e9b26095a4
5
+ SHA512:
6
+ metadata.gz: 14c65d77a8a5ee8af8a2a22b00d5d6f73a07448ace0abd68625ef907a5cee75e9cc7346e66edf3b70e1246a04667864edcd68525c4696d3bac39c88c0576b237
7
+ data.tar.gz: ce9920299f5832201c07aa03edf7788801a7d1a9f7b26f4338783333454f0603eb18b66fcc31bb1a68ee190bfc360f2f79f44a1528ab8b49edcfe0488738fc4e
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in activeadmin-subnav.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Charles Maresh
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,37 @@
1
+ # Activeadmin::Subnav
2
+
3
+ Provide sub-navigation menu for resources belonging to a parent resource.
4
+
5
+ Currently, ActiveAdmin 1.0pre resets the top navigation menu to display the sub
6
+ navigation menu for all resources related to that parent resource. This gem
7
+ provides a sub navigation menu for those resources.
8
+
9
+ NOTE: Optional belongs_to configurations are not supported!
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem 'activeadmin-subnav'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Add the subnav's styles to your `active_admin.css.scss` stylesheet:
22
+
23
+ //= require active_admin/subnav
24
+
25
+ // Align subnav with main navigation by padding the width of the site's
26
+ // titie.
27
+ #header div.subnav {
28
+ padding-left: 8.333em;
29
+ }
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it ( https://github.com/zorab47/activeadmin-subnav/fork )
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'active_admin/subnav/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "active_admin-subnav"
8
+ spec.version = Activeadmin::Subnav::VERSION
9
+ spec.authors = ["Charles Maresh"]
10
+ spec.email = ["charles.maresh@orm-tech.com"]
11
+ spec.summary = %q{Provide sub-navigation menu for resources belonging to a parent resource.}
12
+ spec.description = <<DESC
13
+ Currently, ActiveAdmin 1.0pre resets the top navigation menu to display the sub
14
+ navigation menu for all resources related to that parent resource. This gem
15
+ provides a sub navigation menu for those resources.
16
+ DESC
17
+ spec.homepage = ""
18
+ spec.license = "MIT"
19
+
20
+ spec.files = `git ls-files -z`.split("\x0")
21
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_dependency "activeadmin"
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.6"
28
+ spec.add_development_dependency "rake"
29
+ spec.add_development_dependency "minitest"
30
+ spec.add_development_dependency "minitest-spec-expect"
31
+ spec.add_development_dependency "sass-rails"
32
+ end
@@ -0,0 +1,21 @@
1
+ div.navigation.has_subnav {
2
+ margin-bottom: 5px;
3
+ }
4
+
5
+ div.subnav {
6
+ background-color: lighten(#53595D, 20%);
7
+ padding: 5px 20px 2px;
8
+ margin-bottom: -6px;
9
+
10
+ ul.tabs {
11
+ & > li {
12
+ &.has_nested > a {
13
+ z-index: 1009;
14
+ }
15
+ ul {
16
+ z-index: 1008;
17
+ }
18
+ }
19
+ }
20
+ }
21
+
@@ -0,0 +1,30 @@
1
+ require "active_admin"
2
+
3
+ require "active_admin/subnav/version"
4
+
5
+ require "active_admin/subnav/views/header_with_subnav"
6
+
7
+ require "active_admin/subnav/extensions/base_controller"
8
+ require "active_admin/subnav/extensions/namespace"
9
+ require "active_admin/subnav/extensions/page"
10
+ require "active_admin/subnav/extensions/resource"
11
+ require "active_admin/subnav/extensions/resource_menu"
12
+ require "active_admin/subnav/extensions/tabbed_navigation"
13
+
14
+ module ActiveAdmin
15
+ module Subnav
16
+ class Engine < ::Rails::Engine
17
+ end
18
+ end
19
+ end
20
+
21
+
22
+ # Register a TabbedNavigation view for the sub navigation.
23
+ ActiveAdmin::ViewFactory.register sub_navigation: ActiveAdmin::Views::TabbedNavigation,
24
+ header: ActiveAdmin::Views::HeaderWithSubnav
25
+
26
+ ActiveAdmin::Page.send :include, ActiveAdmin::Subnav::Page
27
+
28
+ ActiveAdmin.after_load do
29
+ ActiveAdmin::BaseController.send :include, ActiveAdmin::Subnav::MenuExtensions
30
+ end
@@ -0,0 +1,34 @@
1
+ module ActiveAdmin
2
+ module Subnav
3
+ module MenuExtensions
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ helper_method :sub_menu
8
+
9
+ # Facilitate AA submenus by providing the resource class's ID to
10
+ # sub-resources to generate URLs.
11
+ before_action do
12
+ if params[:id] && defined?(resource_class) && params[:"#{resource_class.name.underscore}_id"].nil?
13
+ params[:"#{resource_class.name.underscore}_id"] = params[:id]
14
+ end
15
+ end
16
+ end
17
+
18
+ def sub_menu
19
+ active_admin_config.sub_navigation_menu
20
+ end
21
+
22
+ # Delegates to super to set @current_tab. Also sets @current_sub_tab to
23
+ # be name of the sub menu tab to mark as current.
24
+ def set_current_tab
25
+ super
26
+
27
+ @current_sub_tab =
28
+ if active_admin_config.show_sub_menu?(params[:action])
29
+ active_admin_config.menu_item
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,40 @@
1
+ module ActiveAdmin
2
+ class Namespace
3
+
4
+ attr_reader :sub_menus
5
+
6
+ # Override reset_menu!
7
+ def reset_menu!
8
+ @menus.clear!
9
+ @sub_menus.clear!
10
+ end
11
+
12
+ # Override build_menu_collection
13
+ def build_menu_collection
14
+ @menus = MenuCollection.new
15
+ @sub_menus = MenuCollection.new
16
+
17
+ @menus.on_build do |menus|
18
+ build_default_utility_nav
19
+
20
+ resources.each do |resource|
21
+ resource.add_to_menu(@menus)
22
+ end
23
+
24
+ @sub_menus.send :build_menus!
25
+ end
26
+
27
+ @sub_menus.on_build do |menus|
28
+ resources.each do |resource|
29
+ if resource.belongs_to?
30
+ resource.belongs_to_config.target.nested_resources = true
31
+ end
32
+
33
+ resource.add_to_sub_menu(@sub_menus)
34
+ end
35
+ end
36
+ end
37
+
38
+ end
39
+ end
40
+
@@ -0,0 +1,11 @@
1
+ module ActiveAdmin
2
+ module Subnav
3
+ module Page
4
+ extend ActiveSupport::Concern
5
+
6
+ def show_sub_menu?(*)
7
+ false
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,23 @@
1
+ module ActiveAdmin
2
+ class Resource
3
+
4
+ # TODO: Support for optional belongs_to
5
+ def belongs_to(target, options = {})
6
+ @belongs_to = Resource::BelongsTo.new(self, target, options)
7
+ self.sub_navigation_menu_name = target
8
+ controller.send :belongs_to, target, options.dup
9
+ end
10
+
11
+ def nested_resources=(value)
12
+ @nested_resources = value
13
+ end
14
+
15
+ def has_nested_resources?
16
+ @nested_resources
17
+ end
18
+
19
+ def show_sub_menu?(action)
20
+ sub_menu_item? || (has_nested_resources? && ["show", "edit"].include?(action))
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,33 @@
1
+ module ActiveAdmin
2
+ class Resource
3
+ module Menu
4
+ attr_accessor :sub_navigation_menu_name
5
+
6
+ # Override add_to_menu
7
+ def add_to_menu(menu_collection)
8
+ if include_in_menu? && !sub_menu_item?
9
+ @menu_item = menu_collection.add navigation_menu_name, menu_item_options
10
+ end
11
+ end
12
+
13
+ def sub_navigation_menu
14
+ if has_nested_resources? && !sub_menu_item?
15
+ menu = resource_name.to_s.underscore.to_sym
16
+ namespace.sub_menus.fetch(menu)
17
+ else
18
+ namespace.sub_menus.fetch(sub_navigation_menu_name)
19
+ end
20
+ end
21
+
22
+ def add_to_sub_menu(menu_collection)
23
+ if include_in_menu? && sub_menu_item?
24
+ @menu_item = menu_collection.add sub_navigation_menu_name, menu_item_options
25
+ end
26
+ end
27
+
28
+ def sub_menu_item?
29
+ !sub_navigation_menu_name.nil?
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,23 @@
1
+
2
+ module ActiveAdmin
3
+ module Views
4
+ class TabbedNavigation
5
+
6
+ # Overridden
7
+ def build_menu_item(item)
8
+ li id: item.id do |li|
9
+ li.add_class "current" if item.current?(assigns[:current_tab]) || item.current?(assigns[:current_sub_tab])
10
+
11
+ text_node link_to item.label(self), item.url(self), item.html_options
12
+
13
+ if children = item.items(self).presence
14
+ li.add_class "has_nested"
15
+ ul do
16
+ children.each{ |child| build_menu_item child }
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,5 @@
1
+ module Activeadmin
2
+ module Subnav
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,55 @@
1
+ module ActiveAdmin
2
+ module Views
3
+ class HeaderWithSubnav < Component
4
+
5
+ def build(namespace, menu)
6
+ super(id: "header")
7
+
8
+ @namespace = namespace
9
+ @menu = menu
10
+ @utility_menu = @namespace.fetch_menu(:utility_navigation)
11
+
12
+ classes = Arbre::HTML::ClassList.new
13
+ classes << "navigation"
14
+ classes << "has_subnav" if has_sub_nav?
15
+
16
+ div class: classes do
17
+ build_site_title
18
+ build_global_navigation
19
+ build_utility_navigation
20
+ end
21
+
22
+ build_sub_navigation
23
+
24
+ end
25
+
26
+ def build_site_title
27
+ insert_tag view_factory.site_title, @namespace
28
+ end
29
+
30
+ def build_global_navigation
31
+ insert_tag view_factory.global_navigation, @menu, class: 'header-item tabs'
32
+ end
33
+
34
+ def build_sub_navigation
35
+ if has_sub_nav?
36
+ div class: "subnav" do
37
+ menu = active_admin_config.sub_navigation_menu
38
+ insert_tag view_factory.sub_navigation, menu, :class => "tabs"
39
+ end
40
+ end
41
+ end
42
+
43
+ def build_utility_navigation
44
+ insert_tag view_factory.utility_navigation, @utility_menu, id: "utility_nav", class: 'header-item tabs'
45
+ end
46
+
47
+ private
48
+
49
+ def has_sub_nav?
50
+ (active_admin_config.belongs_to? && !active_admin_config.has_nested_resources?) || active_admin_config.show_sub_menu?(params[:action])
51
+ end
52
+
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,67 @@
1
+ require 'bundler/setup'
2
+ require 'minitest/autorun'
3
+ require 'minitest/spec/expect'
4
+
5
+ require 'active_admin/subnav'
6
+ require 'sass-rails'
7
+
8
+ class Minitest::SharedExamples < Module
9
+ include Minitest::Spec::DSL
10
+ end
11
+
12
+ ResourceMenuSpec = Minitest::SharedExamples.new do
13
+ it "to have sub navigation menu name accessor" do
14
+ expect(resource).to_respond_to :sub_navigation_menu_name
15
+ expect(resource).to_respond_to :sub_navigation_menu_name=
16
+ end
17
+
18
+ it "is a sub menu item when sub_navigation_menu_name is set" do
19
+ expect(resource.sub_menu_item?).to_equal false
20
+ resource.sub_navigation_menu_name = "Dashboard"
21
+ expect(resource.sub_menu_item?).to_equal true
22
+ end
23
+ end
24
+
25
+ describe "activeadmin-subnav" do
26
+ it "registers a sub navigation view" do
27
+ expect(ActiveAdmin::ViewFactory.new.default_for(:sub_navigation)).to_equal ActiveAdmin::Views::TabbedNavigation
28
+ end
29
+
30
+ it "registers a header with subn navigation" do
31
+ expect(ActiveAdmin::ViewFactory.new.default_for(:header)).to_equal ActiveAdmin::Views::HeaderWithSubnav
32
+ end
33
+
34
+ def namespace
35
+ app = ActiveAdmin::Application.new
36
+ app.namespace(:admin)
37
+ end
38
+
39
+ describe "extends ActiveAdmin::Namespace" do
40
+ it "adds sub menus" do
41
+ expect(namespace).to_respond_to :sub_menus
42
+ end
43
+ end
44
+
45
+ describe "extends Page" do
46
+ let(:page) { ActiveAdmin::Page.new(namespace, "Dashboard", {}) }
47
+ alias_method :resource, :page
48
+
49
+ include ResourceMenuSpec
50
+
51
+ it "to never show sub menus" do
52
+ expect(page.show_sub_menu?).to_equal false
53
+ end
54
+ end
55
+
56
+ describe "extends Resource" do
57
+ class Post; end
58
+ let(:resource) { ActiveAdmin::Resource.new(namespace, Post) }
59
+
60
+ include ResourceMenuSpec
61
+
62
+ it "to assign nested resources" do
63
+ resource.nested_resources = "nested"
64
+ expect(resource.has_nested_resources?).to_equal "nested"
65
+ end
66
+ end
67
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_admin-subnav
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Charles Maresh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activeadmin
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest-spec-expect
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: sass-rails
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: |
98
+ Currently, ActiveAdmin 1.0pre resets the top navigation menu to display the sub
99
+ navigation menu for all resources related to that parent resource. This gem
100
+ provides a sub navigation menu for those resources.
101
+ email:
102
+ - charles.maresh@orm-tech.com
103
+ executables: []
104
+ extensions: []
105
+ extra_rdoc_files: []
106
+ files:
107
+ - ".gitignore"
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - active_admin-subnav.gemspec
113
+ - app/assets/stylesheets/active_admin/subnav.css.scss
114
+ - lib/active_admin/subnav.rb
115
+ - lib/active_admin/subnav/extensions/base_controller.rb
116
+ - lib/active_admin/subnav/extensions/namespace.rb
117
+ - lib/active_admin/subnav/extensions/page.rb
118
+ - lib/active_admin/subnav/extensions/resource.rb
119
+ - lib/active_admin/subnav/extensions/resource_menu.rb
120
+ - lib/active_admin/subnav/extensions/tabbed_navigation.rb
121
+ - lib/active_admin/subnav/version.rb
122
+ - lib/active_admin/subnav/views/header_with_subnav.rb
123
+ - specs/subnav_spec.rb
124
+ homepage: ''
125
+ licenses:
126
+ - MIT
127
+ metadata: {}
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.2.2
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: Provide sub-navigation menu for resources belonging to a parent resource.
148
+ test_files: []
149
+ has_rdoc: