navbar 0.0.1
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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +40 -0
- data/Rakefile +8 -0
- data/lib/navbar.rb +5 -0
- data/lib/navbar/builder.rb +21 -0
- data/lib/navbar/configurator.rb +44 -0
- data/lib/navbar/renderer.rb +13 -0
- data/lib/navbar/version.rb +3 -0
- data/navbar.gemspec +27 -0
- data/spec/navbar/builder_spec.rb +33 -0
- data/spec/navbar/configurator_spec.rb +87 -0
- data/spec/navbar/renderer_spec.rb +13 -0
- data/spec/rails_integration_spec.rb +26 -0
- data/spec/support/app.rb +22 -0
- data/spec/support/welcome_controller.rb +10 -0
- metadata +165 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Dmitry Larkin
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# Navbar
|
2
|
+
|
3
|
+
Rails Navigation Bar Renderer
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'navbar'
|
10
|
+
|
11
|
+
Or install it yourself as:
|
12
|
+
|
13
|
+
$ gem install navbar
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
In rails view
|
18
|
+
|
19
|
+
= navbar class: "navbar" do |tab|
|
20
|
+
= tab.first "First", first_path
|
21
|
+
= tab.second "Second", second_path
|
22
|
+
= tab.third "Third", third_path
|
23
|
+
|
24
|
+
In rails controller
|
25
|
+
|
26
|
+
class ItemsController < ApplicationController
|
27
|
+
nav_tab :first, class: "bold"
|
28
|
+
nav_tab :second, active: true
|
29
|
+
|
30
|
+
...
|
31
|
+
end
|
32
|
+
|
33
|
+
Will render
|
34
|
+
|
35
|
+
<ul class="navbar">
|
36
|
+
<li class="bold"><a href="/first">First</a></li>
|
37
|
+
<li class="active"><a href="/second">Second</a></li>
|
38
|
+
<li><a href="/third">Third</a></li>
|
39
|
+
</ul>
|
40
|
+
|
data/Rakefile
ADDED
data/lib/navbar.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'navbar/configurator'
|
2
|
+
require 'navbar/renderer'
|
3
|
+
|
4
|
+
module Navbar
|
5
|
+
module Builder
|
6
|
+
def self.extended(base)
|
7
|
+
base.class_eval do
|
8
|
+
class_attribute :navbar
|
9
|
+
self.navbar ||= Configurator.new do |c|
|
10
|
+
c.scope = :default
|
11
|
+
c.class = nil
|
12
|
+
c.tabs = []
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def nav_tab(name, options = {})
|
18
|
+
navbar.register(name, options)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
3
|
+
module Navbar
|
4
|
+
class Configurator
|
5
|
+
|
6
|
+
DEFAULT_SCOPE = :default
|
7
|
+
|
8
|
+
attr_reader :tabs
|
9
|
+
|
10
|
+
def initialize(*args, &block)
|
11
|
+
@configuration = OpenStruct.new
|
12
|
+
@tabs = OpenStruct.new(DEFAULT_SCOPE => [])
|
13
|
+
|
14
|
+
yield(@configuration) if block_given?
|
15
|
+
end
|
16
|
+
|
17
|
+
def register(name, options = {})
|
18
|
+
scope = options.fetch(:scope, DEFAULT_SCOPE)
|
19
|
+
active = options.fetch(:active, nil)
|
20
|
+
css = [options.fetch(:class, nil)]
|
21
|
+
css << (active.is_a?(String) ? active : "active") if active
|
22
|
+
bar(scope) << OpenStruct.new({
|
23
|
+
name: name,
|
24
|
+
html_class: css.compact.flatten.join(" "),
|
25
|
+
"active?" => active
|
26
|
+
})
|
27
|
+
end
|
28
|
+
|
29
|
+
def tab(name, scope = DEFAULT_SCOPE)
|
30
|
+
tabs.send(scope) && tabs.send(scope).find{ |item| item.name == name }
|
31
|
+
end
|
32
|
+
|
33
|
+
def size(scope = DEFAULT_SCOPE)
|
34
|
+
bar(scope).is_a?(Array) and bar(scope).size
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def bar(scope)
|
40
|
+
tabs.send(scope) or tabs.send("#{scope}=", [])
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
data/navbar.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'navbar/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "navbar"
|
8
|
+
spec.version = Navbar::VERSION
|
9
|
+
spec.authors = ["Dmitry Larkin"]
|
10
|
+
spec.email = ["dmitry.larkin@gmail.com"]
|
11
|
+
spec.description = %q{Rails Navigation Bar Builder}
|
12
|
+
spec.summary = %q{Rails Navigation Bar Builder}
|
13
|
+
spec.homepage = "http://github.com/dml/navbar"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency 'rspec', '~> 2.13'
|
24
|
+
spec.add_development_dependency 'rspec-rails', '~> 2.13'
|
25
|
+
spec.add_development_dependency 'actionpack', '>= 3.1.0'
|
26
|
+
spec.add_development_dependency 'activesupport', '>= 3.1.0'
|
27
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "navbar/builder"
|
2
|
+
require "action_controller"
|
3
|
+
|
4
|
+
class TargetsController < ActionController::Base
|
5
|
+
extend Navbar::Builder
|
6
|
+
end
|
7
|
+
|
8
|
+
describe Navbar::Builder do
|
9
|
+
|
10
|
+
describe ".navbar" do
|
11
|
+
|
12
|
+
let(:controller) { TargetsController.new }
|
13
|
+
|
14
|
+
subject { controller }
|
15
|
+
|
16
|
+
it { should respond_to(:navbar) }
|
17
|
+
it { respond_to(:nav_tab) }
|
18
|
+
|
19
|
+
context "defatult scope" do
|
20
|
+
|
21
|
+
context "assign current tab as active" do
|
22
|
+
before { subject.nav_tab(:test, active: true) }
|
23
|
+
end
|
24
|
+
|
25
|
+
context "highligt tab with a css class" do
|
26
|
+
before { subject.nav_tab(:test, class: "permanent") }
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'navbar/configurator'
|
2
|
+
|
3
|
+
describe Navbar::Configurator do
|
4
|
+
|
5
|
+
let(:configurator) { described_class.new }
|
6
|
+
|
7
|
+
subject { configurator }
|
8
|
+
|
9
|
+
it { should respond_to(:tabs) }
|
10
|
+
it { should respond_to(:size) }
|
11
|
+
|
12
|
+
context ".register" do
|
13
|
+
|
14
|
+
context "scope" do
|
15
|
+
context "default scope" do
|
16
|
+
before { subject.register(:test) }
|
17
|
+
its(:size) { should == 1 }
|
18
|
+
end
|
19
|
+
|
20
|
+
context "named scope as symbol" do
|
21
|
+
before { subject.register(:test, scope: :wizard) }
|
22
|
+
specify { subject.size(:wizard).should == 1 }
|
23
|
+
specify { subject.size('wizard').should == 1 }
|
24
|
+
end
|
25
|
+
|
26
|
+
context "named scope as string" do
|
27
|
+
before { subject.register(:test, scope: 'wizard') }
|
28
|
+
specify { subject.size(:wizard).should == 1 }
|
29
|
+
specify { subject.size('wizard').should == 1 }
|
30
|
+
end
|
31
|
+
|
32
|
+
context "scopes mix" do
|
33
|
+
before do
|
34
|
+
subject.register(:test)
|
35
|
+
subject.register(:test, scope: 'wizard')
|
36
|
+
end
|
37
|
+
its(:size) { should == 1 }
|
38
|
+
specify { subject.size(:wizard).should == 1 }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "html class" do
|
43
|
+
context "defatult scope" do
|
44
|
+
before { configurator.register(:test, class: 'highlighted') }
|
45
|
+
subject { configurator.tab(:test) }
|
46
|
+
its(:html_class) { should == 'highlighted' }
|
47
|
+
end
|
48
|
+
|
49
|
+
context "named scope" do
|
50
|
+
before { configurator.register(:test, scope: "wizard", class: 'highlighted') }
|
51
|
+
subject { configurator.tab(:test, :wizard) }
|
52
|
+
its(:html_class) { should == 'highlighted' }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "active" do
|
57
|
+
context "by default" do
|
58
|
+
before { configurator.register(:test) }
|
59
|
+
subject { configurator.tab(:test) }
|
60
|
+
specify { subject.should_not be_active }
|
61
|
+
end
|
62
|
+
|
63
|
+
context "acvite true" do
|
64
|
+
before { configurator.register(:test, active: true) }
|
65
|
+
subject { configurator.tab(:test) }
|
66
|
+
specify { subject.should be_active }
|
67
|
+
specify { subject.html_class.should == "active" }
|
68
|
+
end
|
69
|
+
|
70
|
+
context "acvite is a html class name" do
|
71
|
+
before { configurator.register(:test, active: "current") }
|
72
|
+
subject { configurator.tab(:test) }
|
73
|
+
specify { subject.should be_active }
|
74
|
+
specify { subject.html_class.should == "current" }
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context "css classes mix" do
|
79
|
+
before { configurator.register(:test, active: "current", class: "colorful") }
|
80
|
+
subject { configurator.tab(:test) }
|
81
|
+
specify { subject.html_class.should =~ /current/ }
|
82
|
+
specify { subject.html_class.should =~ /colorful/ }
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rspec/rails'
|
2
|
+
require 'support/app'
|
3
|
+
require 'support/welcome_controller'
|
4
|
+
|
5
|
+
require 'navbar'
|
6
|
+
|
7
|
+
describe TargetsController do
|
8
|
+
|
9
|
+
context "tabs configuration" do
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
context "tabs rendering" do
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
__END__
|
20
|
+
|
21
|
+
= navbar do
|
22
|
+
= tab.external, "Non target action", root_path
|
23
|
+
= tab.home, "Target index", targets_path
|
24
|
+
= tab.edit, "Content"
|
25
|
+
= tab.preview, "Preview"
|
26
|
+
|
data/spec/support/app.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'active_support/all'
|
2
|
+
require 'action_controller'
|
3
|
+
require 'action_dispatch'
|
4
|
+
|
5
|
+
require 'navbar'
|
6
|
+
|
7
|
+
module Rails
|
8
|
+
class App
|
9
|
+
def env_config; {} end
|
10
|
+
def routes
|
11
|
+
return @routes if defined?(@routes)
|
12
|
+
@routes = ActionDispatch::Routing::RouteSet.new
|
13
|
+
@routes.draw do
|
14
|
+
root to: 'welcome#index'
|
15
|
+
end
|
16
|
+
@routes
|
17
|
+
end
|
18
|
+
end
|
19
|
+
def self.application
|
20
|
+
@app ||= App.new
|
21
|
+
end
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: navbar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dmitry Larkin
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '2.13'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.13'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec-rails
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '2.13'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '2.13'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: actionpack
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 3.1.0
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 3.1.0
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: activesupport
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 3.1.0
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 3.1.0
|
110
|
+
description: Rails Navigation Bar Builder
|
111
|
+
email:
|
112
|
+
- dmitry.larkin@gmail.com
|
113
|
+
executables: []
|
114
|
+
extensions: []
|
115
|
+
extra_rdoc_files: []
|
116
|
+
files:
|
117
|
+
- .gitignore
|
118
|
+
- Gemfile
|
119
|
+
- LICENSE.txt
|
120
|
+
- README.md
|
121
|
+
- Rakefile
|
122
|
+
- lib/navbar.rb
|
123
|
+
- lib/navbar/builder.rb
|
124
|
+
- lib/navbar/configurator.rb
|
125
|
+
- lib/navbar/renderer.rb
|
126
|
+
- lib/navbar/version.rb
|
127
|
+
- navbar.gemspec
|
128
|
+
- spec/navbar/builder_spec.rb
|
129
|
+
- spec/navbar/configurator_spec.rb
|
130
|
+
- spec/navbar/renderer_spec.rb
|
131
|
+
- spec/rails_integration_spec.rb
|
132
|
+
- spec/support/app.rb
|
133
|
+
- spec/support/welcome_controller.rb
|
134
|
+
homepage: http://github.com/dml/navbar
|
135
|
+
licenses:
|
136
|
+
- MIT
|
137
|
+
post_install_message:
|
138
|
+
rdoc_options: []
|
139
|
+
require_paths:
|
140
|
+
- lib
|
141
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
142
|
+
none: false
|
143
|
+
requirements:
|
144
|
+
- - ! '>='
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
|
+
none: false
|
149
|
+
requirements:
|
150
|
+
- - ! '>='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
requirements: []
|
154
|
+
rubyforge_project:
|
155
|
+
rubygems_version: 1.8.24
|
156
|
+
signing_key:
|
157
|
+
specification_version: 3
|
158
|
+
summary: Rails Navigation Bar Builder
|
159
|
+
test_files:
|
160
|
+
- spec/navbar/builder_spec.rb
|
161
|
+
- spec/navbar/configurator_spec.rb
|
162
|
+
- spec/navbar/renderer_spec.rb
|
163
|
+
- spec/rails_integration_spec.rb
|
164
|
+
- spec/support/app.rb
|
165
|
+
- spec/support/welcome_controller.rb
|