cypher-rack-dickbarblocker 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -18,7 +18,7 @@ Hat-tip to [rue](http://github.com/rue) for suggesting the name.
18
18
 
19
19
  require 'rack/contrib/dick_bar_blocker'
20
20
 
21
- use Rack::Contrib::DickBarBlocker
21
+ use Rack::Contrib::DickBarBlocker, 'name or initials here'
22
22
 
23
23
  * Or, if you're on Rails, add this to your environment.rb:
24
24
 
@@ -26,23 +26,23 @@ Hat-tip to [rue](http://github.com/rue) for suggesting the name.
26
26
 
27
27
  Rails::Initializer.run do |config|
28
28
  config.gem 'cypher-rack-dickbarblocker', :lib => 'rack/contrib/dick_bar_blocker', :source => 'http://gems.github.com'
29
- config.middleware.use 'Rack::Contrib::DickBarBlocker'
29
+ config.middleware.use 'Rack::Contrib::DickBarBlocker', 'name or initials here'
30
30
 
31
31
  # rest of your config
32
32
  end
33
33
 
34
34
  By default, it shows the following text (sans markup):
35
35
 
36
- > Dear Digg,
36
+ > Dear Digg,
37
37
  > Framing sites is bullshit.
38
38
  >
39
- > Your pal,
40
- > —J.G.
39
+ > Your pal,
40
+ > —(here are the supplied initals or name)
41
41
  >
42
- > p.s. Firefox users may enjoy the<br>
42
+ > p.s. Firefox users may enjoy the
43
43
  > DiggBar Killer script for Greasemonkey.
44
44
  >
45
- > p.p.s. Digg users can disable the DiggBar under
45
+ > p.p.s. Digg users can disable the DiggBar under
46
46
  > My Profile → Settings → Viewing Preferences.
47
47
 
48
48
  You can override this by supplying the middleware with a block that returns whatever you want it to display:
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 2
4
- :patch: 0
4
+ :patch: 1
@@ -1,8 +1,11 @@
1
1
  module Rack
2
2
  module Contrib
3
3
  class DickBarBlocker
4
- def initialize(app, &block)
4
+ def initialize(app, name = nil, &block)
5
+ raise ArgumentError, "You need to supply a name or a block" if name.nil? and block.nil?
6
+
5
7
  @app = app
8
+ @name = name
6
9
  @block = block
7
10
  end
8
11
 
@@ -41,7 +44,7 @@ module Rack
41
44
  Framing sites is bullshit.<br>
42
45
  <br>
43
46
  Your pal,<br>
44
- —J.G.
47
+ —#{@name}
45
48
  </p>
46
49
  <p>
47
50
  p.s. Firefox users may enjoy the<br>
@@ -7,7 +7,7 @@ context "Rack::Contrib::DickBarBlocker" do
7
7
 
8
8
  context "non-digg-toolbar referrer" do
9
9
  specify "returns unmodified response" do
10
- status, headers, body = Rack::Contrib::DickBarBlocker.new(app).call({'HTTP_REFERER' => 'http://daringfireball.net'})
10
+ status, headers, body = Rack::Contrib::DickBarBlocker.new(app, 'J.G.').call({'HTTP_REFERER' => 'http://daringfireball.net'})
11
11
 
12
12
  status.should.equal 200
13
13
  headers['Content-Type'].should.equal 'text/plain'
@@ -17,12 +17,36 @@ context "Rack::Contrib::DickBarBlocker" do
17
17
 
18
18
  context "via digg bar" do
19
19
  specify "return anti-digg-toolbar site" do
20
- status, headers, body = Rack::Contrib::DickBarBlocker.new(app).call({'HTTP_REFERER' => 'http://digg.com/d1oNOZ'})
20
+ status, headers, body = Rack::Contrib::DickBarBlocker.new(app, 'J.G.').call({'HTTP_REFERER' => 'http://digg.com/d1oNOZ'})
21
21
 
22
22
  status.should.equal 200
23
23
  headers['Content-Type'].should.equal 'text/html'
24
24
  body.should =~ %r{<title>Don't be a dick, say no to the DiggBar</title>}i
25
- body.should =~ %r{Dear Digg,.*Framing sites is bullshit\.}mi
25
+ body.should =~ %r{Dear Digg,<br>\s+Framing sites is bullshit\.<br>\s+<br>\s+Your pal,<br>\s+—J.G.}mi
26
+ end
27
+
28
+ specify "uses the given name" do
29
+ name = "test name"
30
+ status, headers, body = Rack::Contrib::DickBarBlocker.new(app, name).call({'HTTP_REFERER' => 'http://digg.com/d1oNOZ'})
31
+
32
+ status.should.equal 200
33
+ headers['Content-Type'].should.equal 'text/html'
34
+ body.should =~ %r{Your pal,<br>\s+—#{name}}i
35
+ end
36
+
37
+ specify "raises an error when no name or block is supplied" do
38
+ lambda {
39
+ Rack::Contrib::DickBarBlocker.new(app).call({'HTTP_REFERER' => 'http://digg.com/d1oNOZ'})
40
+ }.should.raise ArgumentError
41
+ end
42
+
43
+ specify "returns custom content when supplied with a block" do
44
+ block = lambda { "Here be kittens." }
45
+ status, headers, body = Rack::Contrib::DickBarBlocker.new(app, &block).call({'HTTP_REFERER' => 'http://digg.com/d1oNOZ'})
46
+
47
+ status.should.equal 200
48
+ headers['Content-Type'].should.equal 'text/html'
49
+ body.should.equal "Here be kittens."
26
50
  end
27
51
  end
28
52
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cypher-rack-dickbarblocker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Markus Prinz