heroku-nav 0.1.6 → 0.1.7
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/Rakefile +1 -1
- data/heroku-nav.gemspec +2 -2
- data/lib/heroku/nav.rb +29 -19
- data/spec/api_spec.rb +5 -5
- data/spec/nav_spec.rb +7 -11
- metadata +3 -3
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.7'
|
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,11 +5,11 @@
|
|
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.7"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Todd Matthews", "Pedro Belo"]
|
12
|
-
s.date = %q{2010-03-
|
12
|
+
s.date = %q{2010-03-19}
|
13
13
|
s.description = %q{}
|
14
14
|
s.email = %q{pedro@heroku.com}
|
15
15
|
s.files = [
|
data/lib/heroku/nav.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'rest_client'
|
2
2
|
require 'json'
|
3
|
+
require 'timeout'
|
3
4
|
|
4
5
|
module Heroku
|
5
6
|
module Nav
|
@@ -29,35 +30,44 @@ module Heroku
|
|
29
30
|
end
|
30
31
|
|
31
32
|
def refresh
|
32
|
-
@html = fetch
|
33
|
+
@html = self.class.fetch
|
33
34
|
end
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
36
|
+
class << self
|
37
|
+
def fetch
|
38
|
+
Timeout.timeout(4) do
|
39
|
+
raw = RestClient.get(resource_url, :accept => :json)
|
40
|
+
attrs = JSON.parse(raw)
|
41
|
+
return attrs['html']
|
42
|
+
end
|
43
|
+
rescue => e
|
44
|
+
STDERR.puts "Failed to fetch the Heroku #{resource}: #{e.class.name} - #{e.message}"
|
45
|
+
nil
|
46
|
+
end
|
43
47
|
|
44
|
-
|
45
|
-
|
46
|
-
|
48
|
+
def resource
|
49
|
+
name.split('::').last.downcase
|
50
|
+
end
|
47
51
|
|
48
|
-
|
49
|
-
|
50
|
-
|
52
|
+
def resource_url
|
53
|
+
[api_url, '/', resource].join
|
54
|
+
end
|
55
|
+
|
56
|
+
def api_url
|
57
|
+
ENV['API_URL'] || "http://nav.heroku.com"
|
58
|
+
end
|
51
59
|
|
52
|
-
|
53
|
-
|
60
|
+
# for non-rack use
|
61
|
+
def html
|
62
|
+
@@body ||= fetch
|
63
|
+
end
|
54
64
|
end
|
55
65
|
end
|
56
66
|
|
57
67
|
class Header < Base
|
58
68
|
def insert!
|
59
69
|
if @html
|
60
|
-
@body.send(@body_accessor).gsub!(/(<head>)/i, "\\1<link href='#{api_url}/header.css' media='all' rel='stylesheet' type='text/css' />")
|
70
|
+
@body.send(@body_accessor).gsub!(/(<head>)/i, "\\1<link href='#{self.class.api_url}/header.css' media='all' rel='stylesheet' type='text/css' />")
|
61
71
|
@body.send(@body_accessor).gsub!(/(<body.*?>\s*(<div .*?class=["'].*?container.*?["'].*?>)?)/i, "\\1#{@html}")
|
62
72
|
end
|
63
73
|
@headers['Content-Length'] = @body.send(@body_accessor).size.to_s
|
@@ -67,7 +77,7 @@ module Heroku
|
|
67
77
|
class Footer < Base
|
68
78
|
def insert!
|
69
79
|
if @html
|
70
|
-
@body.send(@body_accessor).gsub!(/(<head>)/i, "\\1<link href='#{api_url}/footer.css' media='all' rel='stylesheet' type='text/css' />")
|
80
|
+
@body.send(@body_accessor).gsub!(/(<head>)/i, "\\1<link href='#{self.class.api_url}/footer.css' media='all' rel='stylesheet' type='text/css' />")
|
71
81
|
@body.send(@body_accessor).gsub!(/(<\/body>)/i, "#{@html}\\1")
|
72
82
|
end
|
73
83
|
@headers['Content-Length'] = @body.send(@body_accessor).size.to_s
|
data/spec/api_spec.rb
CHANGED
@@ -3,23 +3,23 @@ require File.dirname(__FILE__) + '/base'
|
|
3
3
|
describe "Api" do
|
4
4
|
before do
|
5
5
|
RestClient.stubs(:get).returns({ :html => '<!-- header -->' }.to_json)
|
6
|
-
@header = Heroku::Nav::Header.new(:app)
|
7
6
|
end
|
8
7
|
|
9
8
|
it "has a resource based on the class name" do
|
10
|
-
|
9
|
+
Heroku::Nav::Header.resource.should == 'header'
|
10
|
+
Heroku::Nav::Footer.resource.should == 'footer'
|
11
11
|
end
|
12
12
|
|
13
13
|
it "has a resource url based on the api url" do
|
14
|
-
|
14
|
+
Heroku::Nav::Header.resource_url.should == 'http://nav.heroku.com/header'
|
15
15
|
end
|
16
16
|
|
17
17
|
it "doesn't raise" do
|
18
18
|
RestClient.stubs(:get).raises("error")
|
19
|
-
lambda {
|
19
|
+
lambda { Heroku::Nav::Header.fetch }.should.not.raise
|
20
20
|
end
|
21
21
|
|
22
22
|
it "parses the JSON response, returning the html and css" do
|
23
|
-
|
23
|
+
Heroku::Nav::Header.fetch.should == '<!-- header -->'
|
24
24
|
end
|
25
25
|
end
|
data/spec/nav_spec.rb
CHANGED
@@ -1,18 +1,10 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/base'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
'<!-- header -->'
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
class Heroku::Nav::Footer
|
10
|
-
def fetch
|
11
|
-
'<!-- footer -->'
|
3
|
+
describe Heroku::Nav::Header do
|
4
|
+
before do
|
5
|
+
Heroku::Nav::Header.stubs(:fetch).returns('<!-- header -->')
|
12
6
|
end
|
13
|
-
end
|
14
7
|
|
15
|
-
describe Heroku::Nav::Header do
|
16
8
|
def app
|
17
9
|
make_app { use Heroku::Nav::Header }
|
18
10
|
end
|
@@ -76,6 +68,10 @@ describe Heroku::Nav::Header do
|
|
76
68
|
end
|
77
69
|
|
78
70
|
describe Heroku::Nav::Footer do
|
71
|
+
before do
|
72
|
+
Heroku::Nav::Footer.stubs(:fetch).returns('<!-- footer -->')
|
73
|
+
end
|
74
|
+
|
79
75
|
def app
|
80
76
|
make_app { use Heroku::Nav::Footer }
|
81
77
|
end
|
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
|
+
- 7
|
9
|
+
version: 0.1.7
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Todd Matthews
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-03-
|
18
|
+
date: 2010-03-19 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|