heroku-nav 0.1.5 → 0.1.6
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 +1 -1
- data/lib/heroku/nav.rb +10 -6
- data/spec/api_spec.rb +2 -2
- data/spec/nav_spec.rb +2 -2
- metadata +2 -2
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.6'
|
25
25
|
end
|
26
26
|
rescue LoadError
|
27
27
|
puts "Jeweler not available. Install it with: gem install jeweler"
|
data/heroku-nav.gemspec
CHANGED
data/lib/heroku/nav.rb
CHANGED
@@ -29,13 +29,13 @@ module Heroku
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def refresh
|
32
|
-
@html
|
32
|
+
@html = fetch
|
33
33
|
end
|
34
34
|
|
35
35
|
def fetch
|
36
36
|
raw = RestClient.get(resource_url, :accept => :json)
|
37
37
|
attrs = JSON.parse(raw)
|
38
|
-
|
38
|
+
attrs['html']
|
39
39
|
rescue => e
|
40
40
|
STDERR.puts "Failed to fetch the Heroku #{resource}: #{e.class.name} - #{e.message}"
|
41
41
|
nil
|
@@ -56,16 +56,20 @@ module Heroku
|
|
56
56
|
|
57
57
|
class Header < Base
|
58
58
|
def insert!
|
59
|
-
|
60
|
-
|
59
|
+
if @html
|
60
|
+
@body.send(@body_accessor).gsub!(/(<head>)/i, "\\1<link href='#{api_url}/header.css' media='all' rel='stylesheet' type='text/css' />")
|
61
|
+
@body.send(@body_accessor).gsub!(/(<body.*?>\s*(<div .*?class=["'].*?container.*?["'].*?>)?)/i, "\\1#{@html}")
|
62
|
+
end
|
61
63
|
@headers['Content-Length'] = @body.send(@body_accessor).size.to_s
|
62
64
|
end
|
63
65
|
end
|
64
66
|
|
65
67
|
class Footer < Base
|
66
68
|
def insert!
|
67
|
-
|
68
|
-
|
69
|
+
if @html
|
70
|
+
@body.send(@body_accessor).gsub!(/(<head>)/i, "\\1<link href='#{api_url}/footer.css' media='all' rel='stylesheet' type='text/css' />")
|
71
|
+
@body.send(@body_accessor).gsub!(/(<\/body>)/i, "#{@html}\\1")
|
72
|
+
end
|
69
73
|
@headers['Content-Length'] = @body.send(@body_accessor).size.to_s
|
70
74
|
end
|
71
75
|
end
|
data/spec/api_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/base'
|
|
2
2
|
|
3
3
|
describe "Api" do
|
4
4
|
before do
|
5
|
-
RestClient.stubs(:get).returns({ :html => '<!-- header -->'
|
5
|
+
RestClient.stubs(:get).returns({ :html => '<!-- header -->' }.to_json)
|
6
6
|
@header = Heroku::Nav::Header.new(:app)
|
7
7
|
end
|
8
8
|
|
@@ -20,6 +20,6 @@ describe "Api" do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
it "parses the JSON response, returning the html and css" do
|
23
|
-
@header.fetch.should ==
|
23
|
+
@header.fetch.should == '<!-- header -->'
|
24
24
|
end
|
25
25
|
end
|
data/spec/nav_spec.rb
CHANGED
@@ -2,13 +2,13 @@ require File.dirname(__FILE__) + '/base'
|
|
2
2
|
|
3
3
|
class Heroku::Nav::Header
|
4
4
|
def fetch
|
5
|
-
|
5
|
+
'<!-- header -->'
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
9
|
class Heroku::Nav::Footer
|
10
10
|
def fetch
|
11
|
-
|
11
|
+
'<!-- footer -->'
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|