heroku-nav 0.1.7 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
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.7'
24
+ gemspec.version = '0.1.9'
25
25
  end
26
26
  rescue LoadError
27
27
  puts "Jeweler not available. Install it with: gem install jeweler"
data/heroku-nav.gemspec CHANGED
@@ -1,15 +1,15 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in rakefile, and run the gemspec command
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{heroku-nav}
8
- s.version = "0.1.7"
8
+ s.version = "0.1.9"
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-19}
12
+ s.date = %q{2010-04-13}
13
13
  s.description = %q{}
14
14
  s.email = %q{pedro@heroku.com}
15
15
  s.files = [
data/lib/heroku/nav.rb CHANGED
@@ -30,15 +30,14 @@ module Heroku
30
30
  end
31
31
 
32
32
  def refresh
33
- @html = self.class.fetch
33
+ @nav = self.class.fetch
34
34
  end
35
35
 
36
36
  class << self
37
37
  def fetch
38
38
  Timeout.timeout(4) do
39
- raw = RestClient.get(resource_url, :accept => :json)
40
- attrs = JSON.parse(raw)
41
- return attrs['html']
39
+ raw = RestClient.get(resource_url, :accept => :json)
40
+ return JSON.parse(raw)
42
41
  end
43
42
  rescue => e
44
43
  STDERR.puts "Failed to fetch the Heroku #{resource}: #{e.class.name} - #{e.message}"
@@ -54,31 +53,46 @@ module Heroku
54
53
  end
55
54
 
56
55
  def api_url
57
- ENV['API_URL'] || "http://nav.heroku.com"
56
+ ENV['API_URL'] || ENV['HEROKU_NAV_URL'] || "http://nav.heroku.com"
58
57
  end
59
58
 
60
59
  # for non-rack use
61
60
  def html
62
- @@body ||= fetch
61
+ @@body ||= fetch['html']
63
62
  end
64
63
  end
65
64
  end
66
65
 
67
66
  class Header < Base
68
67
  def insert!
69
- if @html
68
+ if @nav['html']
70
69
  @body.send(@body_accessor).gsub!(/(<head>)/i, "\\1<link href='#{self.class.api_url}/header.css' media='all' rel='stylesheet' type='text/css' />")
71
- @body.send(@body_accessor).gsub!(/(<body.*?>\s*(<div .*?class=["'].*?container.*?["'].*?>)?)/i, "\\1#{@html}")
70
+ @body.send(@body_accessor).gsub!(/(<body.*?>\s*(<div .*?class=["'].*?container.*?["'].*?>)?)/i, "\\1#{@nav['html']}")
71
+ @headers['Content-Length'] = @body.send(@body_accessor).size.to_s
72
72
  end
73
- @headers['Content-Length'] = @body.send(@body_accessor).size.to_s
74
73
  end
75
74
  end
76
75
 
77
76
  class Footer < Base
78
77
  def insert!
79
- if @html
78
+ if @nav['html']
80
79
  @body.send(@body_accessor).gsub!(/(<head>)/i, "\\1<link href='#{self.class.api_url}/footer.css' media='all' rel='stylesheet' type='text/css' />")
81
- @body.send(@body_accessor).gsub!(/(<\/body>)/i, "#{@html}\\1")
80
+ @body.send(@body_accessor).gsub!(/(<\/body>)/i, "#{@nav['html']}\\1")
81
+ @headers['Content-Length'] = @body.send(@body_accessor).size.to_s
82
+ end
83
+ end
84
+ end
85
+
86
+ class Internal < Base
87
+ def self.resource
88
+ "internal.json"
89
+ end
90
+ def insert!
91
+ if @nav['head']
92
+ @body.send(@body_accessor).gsub!(/(<head>)/i, "\\1#{@nav['head']}")
93
+ end
94
+ if @nav['body'] && @options[:development]
95
+ @body.send(@body_accessor).gsub!(/(<body.*?>)/i, "\\1#{@nav['body']}")
82
96
  end
83
97
  @headers['Content-Length'] = @body.send(@body_accessor).size.to_s
84
98
  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 -->' }.to_json)
5
+ RestClient.stubs(:get).returns({ 'html' => '<!-- header -->' }.to_json)
6
6
  end
7
7
 
8
8
  it "has a resource based on the class name" do
@@ -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
- Heroku::Nav::Header.fetch.should == '<!-- header -->'
23
+ Heroku::Nav::Header.fetch.should == { 'html' => '<!-- header -->' }
24
24
  end
25
25
  end
data/spec/nav_spec.rb CHANGED
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/base'
2
2
 
3
3
  describe Heroku::Nav::Header do
4
4
  before do
5
- Heroku::Nav::Header.stubs(:fetch).returns('<!-- header -->')
5
+ Heroku::Nav::Header.stubs(:fetch).returns('html' => '<!-- header -->')
6
6
  end
7
7
 
8
8
  def app
@@ -69,7 +69,7 @@ end
69
69
 
70
70
  describe Heroku::Nav::Footer do
71
71
  before do
72
- Heroku::Nav::Footer.stubs(:fetch).returns('<!-- footer -->')
72
+ Heroku::Nav::Footer.stubs(:fetch).returns('html' => '<!-- footer -->')
73
73
  end
74
74
 
75
75
  def app
@@ -86,3 +86,35 @@ describe Heroku::Nav::Footer do
86
86
  last_response.body.should.equal "<html><head><link href='http://nav.heroku.com/footer.css' media='all' rel='stylesheet' type='text/css' />... <body>"
87
87
  end
88
88
  end
89
+
90
+ describe Heroku::Nav::Internal do
91
+ before do
92
+ Heroku::Nav::Internal.stubs(:fetch).returns('head' => '<!-- head -->', 'body' => '<!-- body -->')
93
+ end
94
+
95
+ def app
96
+ make_app { use Heroku::Nav::Internal }
97
+ end
98
+
99
+ it "adds the head" do
100
+ get '/', :body => '<head><title /></head><body>'
101
+ last_response.body.should.equal '<head><!-- head --><title /></head><body>'
102
+ end
103
+
104
+ it "doesn't add the body" do
105
+ get '/', :body => '<html><body>hi'
106
+ last_response.body.should.equal '<html><body>hi'
107
+ end
108
+
109
+ describe "development mode" do
110
+ def app
111
+ make_app { use Heroku::Nav::Internal, :development => true }
112
+ end
113
+
114
+ it "adds the body" do
115
+ get '/', :body => '<html><body>hi'
116
+ last_response.body.should.equal '<html><body><!-- body -->hi'
117
+ end
118
+ end
119
+
120
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 7
9
- version: 0.1.7
8
+ - 9
9
+ version: 0.1.9
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-19 00:00:00 -07:00
18
+ date: 2010-04-13 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency