sickill-rack_revision_info 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,8 +11,9 @@ module Rack
11
11
  @revision_info << " (#{date.strftime(DATETIME_FORMAT)})" if date
12
12
  @action = (opts.keys & INJECT_ACTIONS).first
13
13
  if @action
14
- require 'hpricot'
14
+ require File.join(File.dirname(__FILE__), 'rack_revision_info', 'nokogiri_backend')
15
15
  @selector = opts[@action]
16
+ @action = :inner_html= if @action == :inner_html
16
17
  end
17
18
  end
18
19
 
@@ -24,11 +25,10 @@ module Rack
24
25
  body = html
25
26
  begin
26
27
  if @action
27
- doc = Hpricot(body)
28
- elements = doc.search(@selector).compact
28
+ doc = Nokogiri.parse(body)
29
+ elements = doc.css(@selector)
29
30
  if elements.size > 0
30
- elements = elements.first if @action == :swap
31
- elements.send(@action, @revision_info)
31
+ elements.each { |e| e.send(@action, @revision_info) }
32
32
  body = doc.to_s
33
33
  end
34
34
  end
@@ -67,4 +67,4 @@ module Rack
67
67
  end
68
68
 
69
69
  end
70
- end
70
+ end
@@ -0,0 +1,14 @@
1
+ require 'nokogiri'
2
+
3
+ # extending Nokogiri with 'append' and 'prepend' methods
4
+
5
+ class Nokogiri::XML::Element
6
+ def append(data)
7
+ self.inner_html = inner_html + data
8
+ end
9
+
10
+ def prepend(data)
11
+ self.inner_html = data + inner_html
12
+ end
13
+ end
14
+
@@ -20,7 +20,7 @@ describe "Rack::RevisionInfo" do
20
20
  run lambda { |env| [200, { 'Content-Type' => 'text/html' }, ["<html><head></head><body>Hello, World!</body></html>"]] }
21
21
  end
22
22
  response = Rack::MockRequest.new(app).get('/')
23
- response.body.should match(/#{Regexp.escape("<!-- Revision #{REV} (#{DATE.strftime(Rack::RevisionInfo::DATETIME_FORMAT)}) -->")}/)
23
+ response.body.should match(/#{Regexp.escape("<!-- Revision #{REV} (#{DATE.strftime(Rack::RevisionInfo::DATETIME_FORMAT)}) -->")}/m)
24
24
  end
25
25
 
26
26
  it "shouldn't append revision info for non-html content-types" do
@@ -29,7 +29,7 @@ describe "Rack::RevisionInfo" do
29
29
  run lambda { |env| [200, { 'Content-Type' => 'text/plain' }, ["Hello, World!"]] }
30
30
  end
31
31
  response = Rack::MockRequest.new(app).get('/')
32
- response.body.should_not match(/#{Regexp.escape('<!-- Revision ')}/)
32
+ response.body.should_not match(/#{Regexp.escape('<!-- Revision ')}/m)
33
33
  end
34
34
 
35
35
  it "shouldn't append revision info for xhr requests" do
@@ -38,7 +38,7 @@ describe "Rack::RevisionInfo" do
38
38
  run lambda { |env| [200, { 'Content-Type' => 'text/html' }, ["<html><head></head><body>Hello, World!</body></html>"]] }
39
39
  end
40
40
  response = Rack::MockRequest.new(app).get('/', "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest")
41
- response.body.should_not match(/#{Regexp.escape('<!-- Revision ')}/)
41
+ response.body.should_not match(/#{Regexp.escape('<!-- Revision ')}/m)
42
42
  end
43
43
 
44
44
  it "should raise exeption when no path given" do
@@ -55,19 +55,28 @@ describe "Rack::RevisionInfo" do
55
55
  Rack::RevisionInfo::INJECT_ACTIONS.each do |action|
56
56
  app = Rack::Builder.new do
57
57
  use Rack::RevisionInfo, :path => "/some/path/to/repo", action => "#footer"
58
- run lambda { |env| [200, { 'Content-Type' => 'text/html' }, ["<html><head></head><body>Hello, World!<div id='footer'>Foota</div></body></html>"]] }
58
+ run lambda { |env| [200, { 'Content-Type' => 'text/html' }, [%q{<html><head></head><body>Hello, World!<div id="footer">Foota</div></body></html>}]] }
59
59
  end
60
60
  response = Rack::MockRequest.new(app).get('/')
61
- response.body.should match(/#{Regexp.escape("Revision #{REV} (#{DATE.strftime(Rack::RevisionInfo::DATETIME_FORMAT)})")}.*#{Regexp.escape("</body>")}/)
61
+ response.body.should match(/#{Regexp.escape("Revision #{REV} (#{DATE.strftime(Rack::RevisionInfo::DATETIME_FORMAT)})")}.*#{Regexp.escape("</body>")}/m)
62
62
  end
63
63
  end
64
64
 
65
65
  it "shouldn't inject revision info into DOM if unknown action" do
66
66
  app = Rack::Builder.new do
67
67
  use Rack::RevisionInfo, :path => "/some/path/to/repo", :what_what => "#footer"
68
- run lambda { |env| [200, { 'Content-Type' => 'text/html' }, ["<html><head></head><body>Hello, World!<div id='footer'>Foota</div></body></html>"]] }
68
+ run lambda { |env| [200, { 'Content-Type' => 'text/html' }, [%q{<html><head></head><body>Hello, World!<div id="footer">Foota</div></body></html>}]] }
69
69
  end
70
70
  response = Rack::MockRequest.new(app).get('/')
71
- response.body.should_not match(/#{Regexp.escape("Revision #{REV} (#{DATE.strftime(Rack::RevisionInfo::DATETIME_FORMAT)})")}.*#{Regexp.escape("</body>")}/)
71
+ response.body.should_not match(/#{Regexp.escape("Revision #{REV} (#{DATE.strftime(Rack::RevisionInfo::DATETIME_FORMAT)})")}.*#{Regexp.escape("</body>")}/m)
72
+ end
73
+
74
+ it "shouldn't escape backslashes" do # hpricot was doing this :|
75
+ app = Rack::Builder.new do
76
+ use Rack::RevisionInfo, :path => "/some/path/to/repo", :inner_html => "#footer"
77
+ run lambda { |env| [200, { 'Content-Type' => 'text/html' }, [%q{<html><head></head><body><input type="text" name="foo" value="\" /><div id="footer">Foota</div></body></html>}]] }
78
+ end
79
+ response = Rack::MockRequest.new(app).get('/')
80
+ response.body.should_not match(/value="\\\\"/m)
72
81
  end
73
82
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sickill-rack_revision_info
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcin Kulik
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-18 00:00:00 -07:00
12
+ date: 2009-08-31 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -23,9 +23,11 @@ extra_rdoc_files: []
23
23
 
24
24
  files:
25
25
  - lib/rack_revision_info.rb
26
+ - lib/rack_revision_info/nokogiri_backend.rb
26
27
  - spec/spec_rack_revision_info.rb
27
28
  has_rdoc: false
28
29
  homepage: http://sickill.net
30
+ licenses:
29
31
  post_install_message:
30
32
  rdoc_options: []
31
33
 
@@ -46,7 +48,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
46
48
  requirements: []
47
49
 
48
50
  rubyforge_project:
49
- rubygems_version: 1.2.0
51
+ rubygems_version: 1.3.5
50
52
  signing_key:
51
53
  specification_version: 2
52
54
  summary: Rack middleware showing current git (or svn) revision number of application