heroku-nav 0.1.18 → 0.1.19
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +31 -0
- data/Rakefile +1 -1
- data/heroku-nav.gemspec +6 -2
- data/lib/heroku/nav.rb +16 -2
- data/spec/nav_spec.rb +11 -0
- metadata +6 -5
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
Heroku Nav
|
2
|
+
==========
|
3
|
+
|
4
|
+
This is a Ruby gem providing a Rack middleware to help Heroku add-on providers
|
5
|
+
displaying a customized header for users coming from a single sign-on session.
|
6
|
+
|
7
|
+
|
8
|
+
## Usage ######################################################################
|
9
|
+
|
10
|
+
Use it just like any Rack middleware:
|
11
|
+
|
12
|
+
require 'heroku/nav'
|
13
|
+
use Heroku::Nav::Provider
|
14
|
+
|
15
|
+
That will fetch the latest header from our API and insert it as the first
|
16
|
+
element inside the body tag when the cookie "heroku-nav-data" is defined.
|
17
|
+
|
18
|
+
For Rails apps, add it to your Gemfile:
|
19
|
+
|
20
|
+
gem 'heroku-nav', :require => 'heroku/nav'
|
21
|
+
|
22
|
+
And add the middleware like:
|
23
|
+
|
24
|
+
config.middleware.use Heroku::Nav::Provider
|
25
|
+
|
26
|
+
|
27
|
+
## Meta #######################################################################
|
28
|
+
|
29
|
+
Maintained by Pedro Belo, contributions by Todd Matthews and David Dollar.
|
30
|
+
|
31
|
+
Released under the MIT license. http://github.com/heroku/heroku-nav
|
data/Rakefile
CHANGED
@@ -21,7 +21,7 @@ begin
|
|
21
21
|
gemspec.add_dependency(%q<rest-client>, [">= 1.0"])
|
22
22
|
gemspec.add_dependency(%q<json>, [">= 0"])
|
23
23
|
|
24
|
-
gemspec.version = '0.1.
|
24
|
+
gemspec.version = '0.1.19'
|
25
25
|
end
|
26
26
|
rescue LoadError
|
27
27
|
puts "Jeweler not available. Install it with: gem install jeweler"
|
data/heroku-nav.gemspec
CHANGED
@@ -5,15 +5,19 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{heroku-nav}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.19"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["David Dollar", "Pedro Belo", "Todd Matthews"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-10-21}
|
13
13
|
s.description = %q{}
|
14
14
|
s.email = ["david@heroku.com", "pedro@heroku.com", "todd@heroku.com"]
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.md"
|
17
|
+
]
|
15
18
|
s.files = [
|
16
19
|
".gitignore",
|
20
|
+
"README.md",
|
17
21
|
"Rakefile",
|
18
22
|
"heroku-nav.gemspec",
|
19
23
|
"lib/heroku/nav.rb",
|
data/lib/heroku/nav.rb
CHANGED
@@ -8,7 +8,8 @@ module Heroku
|
|
8
8
|
def initialize(app, options={})
|
9
9
|
@app = app
|
10
10
|
@options = options
|
11
|
-
@options[:
|
11
|
+
@options[:only] = [@options[:only]].compact unless @options[:only].is_a?(Array)
|
12
|
+
@options[:except] = [@options[:except]].compact unless @options[:except].is_a?(Array)
|
12
13
|
@options[:status] ||= [200]
|
13
14
|
refresh
|
14
15
|
end
|
@@ -24,10 +25,23 @@ module Heroku
|
|
24
25
|
def can_insert?(env)
|
25
26
|
return unless @options[:status].include?(@status)
|
26
27
|
return unless @headers['Content-Type'] =~ /text\/html/
|
27
|
-
return if
|
28
|
+
return if !@options[:only].empty? && !@options[:only].any? { |route| match_route(route, env['PATH_INFO']) }
|
29
|
+
return if @options[:except].any? { |route| match_route(route, env['PATH_INFO']) }
|
28
30
|
true
|
29
31
|
end
|
30
32
|
|
33
|
+
def match_route(route, path)
|
34
|
+
return unless route
|
35
|
+
case route.class.name
|
36
|
+
when 'Regexp'
|
37
|
+
path =~ route
|
38
|
+
when 'String'
|
39
|
+
path.chomp('/') == route.chomp('/')
|
40
|
+
else
|
41
|
+
raise "Don't know how to match the route: #{route} (#{route.class.name})"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
31
45
|
def refresh
|
32
46
|
@nav = self.class.fetch
|
33
47
|
end
|
data/spec/nav_spec.rb
CHANGED
@@ -65,6 +65,17 @@ describe Heroku::Nav::Header do
|
|
65
65
|
last_response.body.should.not =~ /<!-- header -->/
|
66
66
|
end
|
67
67
|
end
|
68
|
+
|
69
|
+
describe "only including certain paths" do
|
70
|
+
def app
|
71
|
+
make_app { use Heroku::Nav::Header, :only => /x/ }
|
72
|
+
end
|
73
|
+
|
74
|
+
it "respects the :only option" do
|
75
|
+
get '/alternate', :body => '<html><body>hi'
|
76
|
+
last_response.body.should.not =~ /<!-- header -->/
|
77
|
+
end
|
78
|
+
end
|
68
79
|
end
|
69
80
|
|
70
81
|
describe Heroku::Nav::Footer do
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 19
|
9
|
+
version: 0.1.19
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- David Dollar
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2010-
|
19
|
+
date: 2010-10-21 00:00:00 -07:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -89,10 +89,11 @@ executables: []
|
|
89
89
|
|
90
90
|
extensions: []
|
91
91
|
|
92
|
-
extra_rdoc_files:
|
93
|
-
|
92
|
+
extra_rdoc_files:
|
93
|
+
- README.md
|
94
94
|
files:
|
95
95
|
- .gitignore
|
96
|
+
- README.md
|
96
97
|
- Rakefile
|
97
98
|
- heroku-nav.gemspec
|
98
99
|
- lib/heroku/nav.rb
|