cypher-rack-dickbarblocker 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +29 -0
- data/Rakefile +55 -0
- data/VERSION.yml +4 -0
- data/lib/rack/contrib/dick_bar_blocker.rb +33 -0
- data/test/spec_rack_dick_bar_blocker.rb +28 -0
- metadata +57 -0
data/README.markdown
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# rack-dickbarblocker
|
2
|
+
|
3
|
+
A Rack middleware that displays a special page when the DiggBar is used.
|
4
|
+
|
5
|
+
Hat-tip to [rue](http://github.com/rue) for suggesting the name.
|
6
|
+
|
7
|
+
# Usage
|
8
|
+
|
9
|
+
* Put it somewhere were Ruby can find it (Rubygem coming soon)
|
10
|
+
* Add this to your rack config:
|
11
|
+
|
12
|
+
require 'rack/contrib/dick_bar_blocker'
|
13
|
+
|
14
|
+
use Rack::Contrib::DickBarBlocker
|
15
|
+
|
16
|
+
* Or, if you're on Rails, add this to your environment.rb:
|
17
|
+
|
18
|
+
require 'rack/contrib/dick_bar_blocker'
|
19
|
+
|
20
|
+
Rails::Initializer.run do |config|
|
21
|
+
config.middleware.use 'Rack::Contrib::DickBarBlocker'
|
22
|
+
|
23
|
+
# rest of your config
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
## Copyright
|
28
|
+
|
29
|
+
Copyright (c) 2009 Markus Prinz. See COPYING for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "rack-dickbarblocker"
|
8
|
+
gem.summary = %Q{Shows a special page to anyone using the DiggBar}
|
9
|
+
gem.email = "markus.prinz@nuclearsquid.com"
|
10
|
+
gem.homepage = "http://github.com/cypher/rack-dickbarblocker"
|
11
|
+
gem.authors = ["Markus Prinz"]
|
12
|
+
|
13
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
14
|
+
end
|
15
|
+
rescue LoadError
|
16
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'rake/testtask'
|
20
|
+
desc "Run all tests"
|
21
|
+
task :test do
|
22
|
+
sh "specrb -Ilib:test -w #{ENV['TEST'] || '-a'} #{ENV['TESTOPTS']}"
|
23
|
+
end
|
24
|
+
|
25
|
+
begin
|
26
|
+
require 'rcov/rcovtask'
|
27
|
+
Rcov::RcovTask.new do |test|
|
28
|
+
test.libs << 'test'
|
29
|
+
test.pattern = 'test/**/*_test.rb'
|
30
|
+
test.verbose = true
|
31
|
+
end
|
32
|
+
rescue LoadError
|
33
|
+
task :rcov do
|
34
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
task :default => :test
|
40
|
+
|
41
|
+
require 'rake/rdoctask'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
if File.exist?('VERSION.yml')
|
44
|
+
config = YAML.load(File.read('VERSION.yml'))
|
45
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
46
|
+
else
|
47
|
+
version = ""
|
48
|
+
end
|
49
|
+
|
50
|
+
rdoc.rdoc_dir = 'rdoc'
|
51
|
+
rdoc.title = "rack-dickbarblocker #{version}"
|
52
|
+
rdoc.rdoc_files.include('README*')
|
53
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
54
|
+
end
|
55
|
+
|
data/VERSION.yml
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
module Rack
|
2
|
+
module Contrib
|
3
|
+
class DickBarBlocker
|
4
|
+
def initialize(app)
|
5
|
+
@app = app
|
6
|
+
end
|
7
|
+
|
8
|
+
def call(env)
|
9
|
+
referrer = env['HTTP_REFERER']
|
10
|
+
# Regex courtesy of John Gruber: http://daringfireball.net/2009/04/how_to_block_the_diggbar
|
11
|
+
if referrer && referrer =~ %r{http://digg.com/\w{1,8}/*(\?.*)?$}
|
12
|
+
body = <<BODY
|
13
|
+
<!DOCTYPE html>
|
14
|
+
<html lang="en">
|
15
|
+
<head>
|
16
|
+
<meta charset="UTF-8" />
|
17
|
+
<title>Say no to the DiggBar</title>
|
18
|
+
</head>
|
19
|
+
<body>
|
20
|
+
Dear Digg<br />
|
21
|
+
Framing Sites is bullshit.<br />
|
22
|
+
</body>
|
23
|
+
</html>
|
24
|
+
BODY
|
25
|
+
|
26
|
+
[200, {'Content-Length' => body.size.to_s, 'Content-Type' => 'text/html'}, body]
|
27
|
+
else
|
28
|
+
@app.call(env)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'test/spec'
|
2
|
+
require 'rack/mock'
|
3
|
+
require 'rack/contrib/dick_bar_blocker'
|
4
|
+
|
5
|
+
context "Rack::Contrib::DickBarBlocker" do
|
6
|
+
app = lambda {|env| [200, {'Content-Type' => 'text/plain'}, "Hello, kitty"]}
|
7
|
+
|
8
|
+
context "non-digg-toolbar referrer" do
|
9
|
+
specify "returns unmodified response" do
|
10
|
+
status, headers, body = Rack::Contrib::DickBarBlocker.new(app).call({'HTTP_REFERER' => 'http://daringfireball.net'})
|
11
|
+
|
12
|
+
status.should.equal 200
|
13
|
+
headers['Content-Type'].should.equal 'text/plain'
|
14
|
+
body.should.equal "Hello, kitty"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "via digg bar" do
|
19
|
+
specify "return anti-digg-toolbar site" do
|
20
|
+
status, headers, body = Rack::Contrib::DickBarBlocker.new(app).call({'HTTP_REFERER' => 'http://digg.com/d1oNOZ'})
|
21
|
+
|
22
|
+
status.should.equal 200
|
23
|
+
headers['Content-Type'].should.equal 'text/html'
|
24
|
+
body.should =~ %r{<title>Say no to the DiggBar</title>}
|
25
|
+
body.should =~ %r{Dear Digg.*Framing Sites is bullshit\.}m
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cypher-rack-dickbarblocker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Markus Prinz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-04-11 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: markus.prinz@nuclearsquid.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.markdown
|
24
|
+
files:
|
25
|
+
- README.markdown
|
26
|
+
- Rakefile
|
27
|
+
- VERSION.yml
|
28
|
+
- lib/rack/contrib/dick_bar_blocker.rb
|
29
|
+
- test/spec_rack_dick_bar_blocker.rb
|
30
|
+
has_rdoc: true
|
31
|
+
homepage: http://github.com/cypher/rack-dickbarblocker
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options:
|
34
|
+
- --charset=UTF-8
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: "0"
|
42
|
+
version:
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: "0"
|
48
|
+
version:
|
49
|
+
requirements: []
|
50
|
+
|
51
|
+
rubyforge_project:
|
52
|
+
rubygems_version: 1.2.0
|
53
|
+
signing_key:
|
54
|
+
specification_version: 2
|
55
|
+
summary: Shows a special page to anyone using the DiggBar
|
56
|
+
test_files:
|
57
|
+
- test/spec_rack_dick_bar_blocker.rb
|