cypher-rack-dickbarblocker 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +31 -0
- data/VERSION.yml +2 -2
- data/lib/rack/contrib/dick_bar_blocker.rb +11 -4
- data/test/spec_rack_dick_bar_blocker.rb +1 -1
- metadata +1 -1
data/README.markdown
CHANGED
@@ -31,6 +31,37 @@ Hat-tip to [rue](http://github.com/rue) for suggesting the name.
|
|
31
31
|
# rest of your config
|
32
32
|
end
|
33
33
|
|
34
|
+
By default, it shows the following text (sans markup):
|
35
|
+
|
36
|
+
> Dear Digg,
|
37
|
+
> Framing sites is bullshit.
|
38
|
+
>
|
39
|
+
> Your pal,
|
40
|
+
> —J.G.
|
41
|
+
>
|
42
|
+
> p.s. Firefox users may enjoy the<br>
|
43
|
+
> DiggBar Killer script for Greasemonkey.
|
44
|
+
>
|
45
|
+
> p.p.s. Digg users can disable the DiggBar under
|
46
|
+
> My Profile → Settings → Viewing Preferences.
|
47
|
+
|
48
|
+
You can override this by supplying the middleware with a block that returns whatever you want it to display:
|
49
|
+
|
50
|
+
use Rack::Contrib::DickBarBlocker do
|
51
|
+
<<-HTML
|
52
|
+
<html>
|
53
|
+
<body>
|
54
|
+
Kittens are fun!
|
55
|
+
</body>
|
56
|
+
</html>
|
57
|
+
HTML
|
58
|
+
end
|
59
|
+
|
60
|
+
This would return an HTML page with "Kittens are fun!" on it instead.
|
61
|
+
|
62
|
+
DickBarBlocker expects the return value of the body to respond to `to_s`.
|
63
|
+
It also currently hardcodes the content type to `text/html`, so your response should
|
64
|
+
be HTML.
|
34
65
|
|
35
66
|
## Copyright
|
36
67
|
|
data/VERSION.yml
CHANGED
@@ -1,25 +1,31 @@
|
|
1
1
|
module Rack
|
2
2
|
module Contrib
|
3
3
|
class DickBarBlocker
|
4
|
-
def initialize(app)
|
4
|
+
def initialize(app, &block)
|
5
5
|
@app = app
|
6
|
+
@block = block
|
6
7
|
end
|
7
8
|
|
8
9
|
def call(env)
|
9
10
|
referrer = env['HTTP_REFERER']
|
10
11
|
# Regex courtesy of John Gruber: http://daringfireball.net/2009/04/how_to_block_the_diggbar
|
11
12
|
if referrer && referrer =~ %r{http://digg.com/\w{1,8}/*(\?.*)?$}
|
12
|
-
|
13
|
+
if @block
|
14
|
+
body = @block.call.to_s
|
15
|
+
else
|
16
|
+
body = <<BODY
|
13
17
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
|
14
18
|
<html lang="en">
|
15
19
|
<head>
|
16
|
-
<meta
|
17
|
-
<title>
|
20
|
+
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
|
21
|
+
<title>Don't be a dick, say no to the DiggBar</title>
|
18
22
|
<style type="text/css">
|
19
23
|
body {
|
20
24
|
font-family: "Lucida Grande";
|
21
25
|
font-size: 12px;
|
22
26
|
line-height: 1.8em;
|
27
|
+
/* So it doesn't stick to the top of the page */
|
28
|
+
margin-top: 12em;
|
23
29
|
}
|
24
30
|
/* I am no CSS master, but this seems to center the text on the page */
|
25
31
|
p {
|
@@ -48,6 +54,7 @@ module Rack
|
|
48
54
|
</body>
|
49
55
|
</html>
|
50
56
|
BODY
|
57
|
+
end
|
51
58
|
|
52
59
|
[200, {'Content-Length' => body.size.to_s, 'Content-Type' => 'text/html'}, body]
|
53
60
|
else
|
@@ -21,7 +21,7 @@ context "Rack::Contrib::DickBarBlocker" do
|
|
21
21
|
|
22
22
|
status.should.equal 200
|
23
23
|
headers['Content-Type'].should.equal 'text/html'
|
24
|
-
body.should =~ %r{<title>
|
24
|
+
body.should =~ %r{<title>Don't be a dick, say no to the DiggBar</title>}i
|
25
25
|
body.should =~ %r{Dear Digg,.*Framing sites is bullshit\.}mi
|
26
26
|
end
|
27
27
|
end
|