rack-revision-info 0.3.7 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rack-revision-info.rb +5 -1
- data/spec/spec-rack-revision-info.rb +21 -2
- metadata +18 -9
data/lib/rack-revision-info.rb
CHANGED
@@ -9,6 +9,7 @@ module Rack
|
|
9
9
|
@revision_info = "#{get_revision_label(opts)} #{revision || 'unknown'}"
|
10
10
|
@revision_info << " (#{date.strftime(get_date_format(opts))})" if date
|
11
11
|
@action = (opts.keys & INJECT_ACTIONS).first
|
12
|
+
@into_header = opts[:header]
|
12
13
|
if @action
|
13
14
|
require ::File.join(::File.dirname(__FILE__), 'rack-revision-info', 'nokogiri_backend')
|
14
15
|
@selector = opts[@action]
|
@@ -18,7 +19,10 @@ module Rack
|
|
18
19
|
|
19
20
|
def call(env)
|
20
21
|
status, headers, body = @app.call(env)
|
21
|
-
if
|
22
|
+
if @into_header
|
23
|
+
h = @into_header == true ? 'X-Revision-Info' : @into_header
|
24
|
+
headers[h] = @revision_info
|
25
|
+
elsif headers['Content-Type'].to_s.include?('text/html') && !Rack::Request.new(env).xhr?
|
22
26
|
new_body = ""
|
23
27
|
body.each { |line| new_body << line }
|
24
28
|
body = new_body
|
@@ -2,7 +2,8 @@ require 'rubygems'
|
|
2
2
|
require 'spec'
|
3
3
|
require 'rack/builder'
|
4
4
|
require 'rack/mock'
|
5
|
-
require
|
5
|
+
require 'date'
|
6
|
+
require File.expand_path File.join(File.dirname(__FILE__), '..', 'lib', 'rack-revision-info.rb')
|
6
7
|
|
7
8
|
class Rack::RevisionInfo
|
8
9
|
DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S %Z"
|
@@ -79,7 +80,7 @@ describe "Rack::RevisionInfo" do
|
|
79
80
|
response = Rack::MockRequest.new(app).get('/')
|
80
81
|
end.should raise_error(ArgumentError)
|
81
82
|
end
|
82
|
-
|
83
|
+
|
83
84
|
it "should inject revision info into DOM" do
|
84
85
|
Rack::RevisionInfo::INJECT_ACTIONS.each do |action|
|
85
86
|
app = Rack::Builder.new do
|
@@ -100,6 +101,24 @@ describe "Rack::RevisionInfo" do
|
|
100
101
|
response.body.should_not match(/#{Regexp.escape("Revision #{REV} (#{DATE.strftime(Rack::RevisionInfo::DATETIME_FORMAT)})")}.*#{Regexp.escape("</body>")}/m)
|
101
102
|
end
|
102
103
|
|
104
|
+
it "should put revision info into X-Revision-Info header" do
|
105
|
+
app = Rack::Builder.new do
|
106
|
+
use Rack::RevisionInfo, :path => "/some/path/to/repo", :header => true
|
107
|
+
run lambda { |env| [200, { 'Content-Type' => 'application/xml' }, ['<response><some_xml></some_xml></response>']] }
|
108
|
+
end
|
109
|
+
response = Rack::MockRequest.new(app).get('/')
|
110
|
+
response.headers['X-Revision-Info'].should match(/#{Regexp.escape("#{REV} (#{DATE.strftime(Rack::RevisionInfo::DATETIME_FORMAT)})")}/m)
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should put revision info into My-Custom-Header header" do
|
114
|
+
app = Rack::Builder.new do
|
115
|
+
use Rack::RevisionInfo, :path => "/some/path/to/repo", :header => 'My-Custom-Header'
|
116
|
+
run lambda { |env| [200, { 'Content-Type' => 'application/xml' }, ['<response><some_xml></some_xml></response>']] }
|
117
|
+
end
|
118
|
+
response = Rack::MockRequest.new(app).get('/')
|
119
|
+
response.headers['My-Custom-Header'].should match(/#{Regexp.escape("#{REV} (#{DATE.strftime(Rack::RevisionInfo::DATETIME_FORMAT)})")}/m)
|
120
|
+
end
|
121
|
+
|
103
122
|
it "shouldn't escape backslashes" do # hpricot was doing this :|
|
104
123
|
app = Rack::Builder.new do
|
105
124
|
use Rack::RevisionInfo, :path => "/some/path/to/repo", :inner_html => "#footer"
|
metadata
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-revision-info
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 4
|
8
|
+
version: "0.4"
|
5
9
|
platform: ruby
|
6
10
|
authors:
|
7
11
|
- Marcin Kulik
|
@@ -9,19 +13,22 @@ autorequire:
|
|
9
13
|
bindir: bin
|
10
14
|
cert_chain: []
|
11
15
|
|
12
|
-
date:
|
16
|
+
date: 2010-04-10 00:00:00 +02:00
|
13
17
|
default_executable:
|
14
18
|
dependencies:
|
15
19
|
- !ruby/object:Gem::Dependency
|
16
20
|
name: nokogiri
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
prerelease: false
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
23
|
requirements:
|
21
24
|
- - ">="
|
22
25
|
- !ruby/object:Gem::Version
|
26
|
+
segments:
|
27
|
+
- 1
|
28
|
+
- 2
|
23
29
|
version: "1.2"
|
24
|
-
|
30
|
+
type: :runtime
|
31
|
+
version_requirements: *id001
|
25
32
|
description:
|
26
33
|
email: marcin.kulik@gmail.com
|
27
34
|
executables: []
|
@@ -47,18 +54,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
47
54
|
requirements:
|
48
55
|
- - ">="
|
49
56
|
- !ruby/object:Gem::Version
|
57
|
+
segments:
|
58
|
+
- 0
|
50
59
|
version: "0"
|
51
|
-
version:
|
52
60
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
61
|
requirements:
|
54
62
|
- - ">="
|
55
63
|
- !ruby/object:Gem::Version
|
64
|
+
segments:
|
65
|
+
- 0
|
56
66
|
version: "0"
|
57
|
-
version:
|
58
67
|
requirements: []
|
59
68
|
|
60
69
|
rubyforge_project:
|
61
|
-
rubygems_version: 1.3.
|
70
|
+
rubygems_version: 1.3.6
|
62
71
|
signing_key:
|
63
72
|
specification_version: 3
|
64
73
|
summary: Rack middleware showing current git (or svn) revision number of application
|