goose 0.6.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.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.md +100 -0
- data/Rakefile +51 -0
- data/VERSION +1 -0
- data/lib/generators/goose/USAGE +4 -0
- data/lib/generators/goose/install_generator.rb +18 -0
- data/lib/generators/goose/templates/goose.rb +13 -0
- data/lib/goose/config.rb +22 -0
- data/lib/goose/ext/action_view.rb +2 -0
- data/lib/goose/helper.rb +28 -0
- data/lib/goose/state.rb +29 -0
- data/lib/goose.rb +22 -0
- data/test/helper.rb +10 -0
- data/test/test_goose.rb +7 -0
- metadata +81 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Bruce Williams
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
Goose
|
2
|
+
=====
|
3
|
+
|
4
|
+
Goose is a navigation plugin for Rails whose aim it is to make adding
|
5
|
+
smart, context-aware navigation to your application as easy as
|
6
|
+
possible.
|
7
|
+
|
8
|
+
Installing it
|
9
|
+
-------------
|
10
|
+
|
11
|
+
First of all, install it with bundler.
|
12
|
+
|
13
|
+
In your `Gemfile`:
|
14
|
+
|
15
|
+
gem 'goose'
|
16
|
+
|
17
|
+
Then:
|
18
|
+
|
19
|
+
$ bundle install
|
20
|
+
|
21
|
+
Now, install the Goose configuration:
|
22
|
+
|
23
|
+
$ rails generate goose:install
|
24
|
+
|
25
|
+
Adding your navigation
|
26
|
+
----------------------
|
27
|
+
|
28
|
+
Create a partial for each navigation menu in the [now present]
|
29
|
+
`app/views/nav` directory. You can have as many as you like.
|
30
|
+
|
31
|
+
We add one in `app/views/nav/_main.html.erb`:
|
32
|
+
|
33
|
+
<nav>
|
34
|
+
<ul>
|
35
|
+
</ul>
|
36
|
+
</nav>
|
37
|
+
|
38
|
+
You'll notice this example uses HTML5 `<nav>` tags. You don't have to
|
39
|
+
(but you probably should).
|
40
|
+
|
41
|
+
In your `<ul>`, use `nav_to` in place of your `<li>`s. `nav_to` is
|
42
|
+
invoked the same way as the `link_to` helper you already know and love:
|
43
|
+
|
44
|
+
<nav>
|
45
|
+
<ul>
|
46
|
+
<%= nav_to 'People', people_path %>
|
47
|
+
<%= nav_to 'Places', places_path %>
|
48
|
+
<%= nav_to 'Things', things_path %>
|
49
|
+
</ul>
|
50
|
+
</nav>
|
51
|
+
|
52
|
+
Now, in each action template, just tell Goose where you are.
|
53
|
+
|
54
|
+
<%= nav_at 'People' %>
|
55
|
+
|
56
|
+
By default, Goose guesses your location is in reference to a `"main"`
|
57
|
+
nav. You can tell it to use something else easily enough; for
|
58
|
+
instance, if we also had a `app/views/nav/_people.html.erb` that we
|
59
|
+
were using as secondary navigation:
|
60
|
+
|
61
|
+
<%= nav_at 'Address Information', in: 'people' %>
|
62
|
+
|
63
|
+
The navigation partial will be inserted (as you might expect), exactly
|
64
|
+
where you put your `nav_at`. If you want to place your navigation
|
65
|
+
somewhere else (as you probably want to do with your main navigation),
|
66
|
+
just wrap your navigation partial in a `content_for`:
|
67
|
+
|
68
|
+
<% content_for :main_navigation do %>
|
69
|
+
<nav>
|
70
|
+
<ul>
|
71
|
+
<%= nav_to 'People', people_path %>
|
72
|
+
<%= nav_to 'Places', places_path %>
|
73
|
+
<%= nav_to 'Things', things_path %>
|
74
|
+
</ul>
|
75
|
+
</nav>
|
76
|
+
<% end %>
|
77
|
+
|
78
|
+
And use `yield` wherever it makes sense in your layout:
|
79
|
+
|
80
|
+
<!DOCTYPE html>
|
81
|
+
<html>
|
82
|
+
...
|
83
|
+
<header>
|
84
|
+
<h1>Great balls of fire!</h1>
|
85
|
+
<%= yield :main_navigation %>
|
86
|
+
</header>
|
87
|
+
...
|
88
|
+
</html>
|
89
|
+
|
90
|
+
It's that simple.
|
91
|
+
|
92
|
+
Customizing Goose
|
93
|
+
-----------------
|
94
|
+
|
95
|
+
See `config/initializers/goose.rb` for options.
|
96
|
+
|
97
|
+
Copyright
|
98
|
+
---------
|
99
|
+
|
100
|
+
Copyright (c) 2010 Bruce Williams. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "goose"
|
8
|
+
gem.summary = %Q{Top Gun navigation for your Rails application}
|
9
|
+
gem.description = %Q{Flexible, simple support for multiple navigation views}
|
10
|
+
gem.email = "bruce@codefluency.com"
|
11
|
+
gem.homepage = "http://github.com/bruce/goose"
|
12
|
+
gem.authors = ["Bruce Williams"]
|
13
|
+
end
|
14
|
+
Jeweler::GemcutterTasks.new
|
15
|
+
rescue LoadError
|
16
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'rake/testtask'
|
20
|
+
Rake::TestTask.new(:test) do |test|
|
21
|
+
test.libs << 'lib' << 'test'
|
22
|
+
test.pattern = 'test/**/test_*.rb'
|
23
|
+
test.verbose = true
|
24
|
+
end
|
25
|
+
|
26
|
+
begin
|
27
|
+
require 'rcov/rcovtask'
|
28
|
+
Rcov::RcovTask.new do |test|
|
29
|
+
test.libs << 'test'
|
30
|
+
test.pattern = 'test/**/test_*.rb'
|
31
|
+
test.verbose = true
|
32
|
+
end
|
33
|
+
rescue LoadError
|
34
|
+
task :rcov do
|
35
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
task :test => :check_dependencies
|
40
|
+
|
41
|
+
task :default => :test
|
42
|
+
|
43
|
+
require 'rake/rdoctask'
|
44
|
+
Rake::RDocTask.new do |rdoc|
|
45
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
46
|
+
|
47
|
+
rdoc.rdoc_dir = 'rdoc'
|
48
|
+
rdoc.title = "goose #{version}"
|
49
|
+
rdoc.rdoc_files.include('README*')
|
50
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
51
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.6.0
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Goose
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
desc "Copy Goose default files"
|
5
|
+
source_root File.expand_path('../templates', __FILE__)
|
6
|
+
|
7
|
+
def copy_initializers
|
8
|
+
copy_file 'goose.rb', 'config/initializers/goose.rb'
|
9
|
+
end
|
10
|
+
|
11
|
+
def create_nav_directory
|
12
|
+
empty_directory "app/views/nav"
|
13
|
+
create_file "app/views/nav/.gitkeep", "\n"
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# Use this setup block to configure all options available in Goose.
|
2
|
+
Goose.setup do |config|
|
3
|
+
|
4
|
+
# Default tag used by nav_to
|
5
|
+
# config.wrapper_tag = :li
|
6
|
+
|
7
|
+
# Default options added to nav_to wrapper when current location
|
8
|
+
# config.active_options = {:class => 'active'}
|
9
|
+
|
10
|
+
# Default options added to nav_to wrapper when not current location
|
11
|
+
# config.inactive_options = {}
|
12
|
+
|
13
|
+
end
|
data/lib/goose/config.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Goose
|
2
|
+
|
3
|
+
class Config
|
4
|
+
|
5
|
+
attr_writer :wrapper_tag, :active_options, :inactive_options
|
6
|
+
|
7
|
+
def wrapper_tag
|
8
|
+
@wrapper_tag ||= :li
|
9
|
+
end
|
10
|
+
|
11
|
+
def active_options
|
12
|
+
@active_options ||= {:class => 'active'}
|
13
|
+
end
|
14
|
+
|
15
|
+
def inactive_options
|
16
|
+
@inactive_options ||= {}
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
end
|
data/lib/goose/helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
module Goose
|
2
|
+
|
3
|
+
module Helper
|
4
|
+
|
5
|
+
def goose
|
6
|
+
@goose ||= State.new(self)
|
7
|
+
end
|
8
|
+
|
9
|
+
def nav_to(place, url, options = {}, &block)
|
10
|
+
if goose.at?(place)
|
11
|
+
options.update(Goose.config.active_options)
|
12
|
+
end
|
13
|
+
content = link_to(place, url) if url
|
14
|
+
content_tag(Goose.config.wrapper_tag, content, options, &block)
|
15
|
+
end
|
16
|
+
|
17
|
+
def nav_at(place, options = {})
|
18
|
+
nav = options[:in] || :main
|
19
|
+
goose.render(nav, place)
|
20
|
+
end
|
21
|
+
|
22
|
+
def nav(name = nil)
|
23
|
+
nav_at(nil, :in => name)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
data/lib/goose/state.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module Goose
|
2
|
+
|
3
|
+
class State
|
4
|
+
|
5
|
+
def initialize(view)
|
6
|
+
@view = view
|
7
|
+
@stack ||= []
|
8
|
+
end
|
9
|
+
|
10
|
+
def render(nav, place)
|
11
|
+
at(nav, place) { @view.render(:partial => "nav/#{nav}") }
|
12
|
+
end
|
13
|
+
|
14
|
+
def at?(place)
|
15
|
+
@stack.last == place
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def at(nav, place, &block)
|
21
|
+
@stack << place
|
22
|
+
result = yield
|
23
|
+
@stack.pop
|
24
|
+
result
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
data/lib/goose.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Goose
|
2
|
+
|
3
|
+
autoload :Config, 'goose/config'
|
4
|
+
autoload :Helper, 'goose/helper'
|
5
|
+
autoload :State, 'goose/state'
|
6
|
+
|
7
|
+
def self.config
|
8
|
+
@config ||= Config.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.setup(&block)
|
12
|
+
yield config
|
13
|
+
end
|
14
|
+
|
15
|
+
# Not recommended for production use.
|
16
|
+
def self.eject! #:nodoc:
|
17
|
+
raise NotImplementedError, "BOOM...Crunch"
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'goose/ext/action_view'
|
data/test/helper.rb
ADDED
data/test/test_goose.rb
ADDED
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: goose
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 6
|
8
|
+
- 0
|
9
|
+
version: 0.6.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Bruce Williams
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-11-03 00:00:00 -07:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: Flexible, simple support for multiple navigation views
|
22
|
+
email: bruce@codefluency.com
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files:
|
28
|
+
- LICENSE
|
29
|
+
- README.md
|
30
|
+
files:
|
31
|
+
- .document
|
32
|
+
- .gitignore
|
33
|
+
- LICENSE
|
34
|
+
- README.md
|
35
|
+
- Rakefile
|
36
|
+
- VERSION
|
37
|
+
- lib/generators/goose/USAGE
|
38
|
+
- lib/generators/goose/install_generator.rb
|
39
|
+
- lib/generators/goose/templates/goose.rb
|
40
|
+
- lib/goose.rb
|
41
|
+
- lib/goose/config.rb
|
42
|
+
- lib/goose/ext/action_view.rb
|
43
|
+
- lib/goose/helper.rb
|
44
|
+
- lib/goose/state.rb
|
45
|
+
- test/helper.rb
|
46
|
+
- test/test_goose.rb
|
47
|
+
has_rdoc: true
|
48
|
+
homepage: http://github.com/bruce/goose
|
49
|
+
licenses: []
|
50
|
+
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options:
|
53
|
+
- --charset=UTF-8
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
version: "0"
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
requirements: []
|
73
|
+
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.3.7
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: Top Gun navigation for your Rails application
|
79
|
+
test_files:
|
80
|
+
- test/helper.rb
|
81
|
+
- test/test_goose.rb
|