bad_bot 0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 Tiago Scolari
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,53 @@
1
+ = BadBot
2
+
3
+ This gem simply gives you the ability to avoid certain pieces of your view from being indexed by search bots.
4
+
5
+ Even if this is generally not recommended, there are situations that you really don't want parts to be indexed. Instead of loading all this stuff from a javascript, BadBot simply gives you an option for doing this instead:
6
+
7
+ <%= no_bot do %>
8
+ stuff i dont wat to be indexed
9
+ <% end %>
10
+
11
+ in case of a search bot request, the content of the block won't be rendered.
12
+
13
+
14
+ == Configuration
15
+
16
+ Include the gem in your gemfile: `gem 'bad_bot'`. And load it in a controller, for example `ApplicationController`:
17
+
18
+ class ApplicationController < ActionController::Base
19
+ include BadBot::Detector
20
+ end
21
+
22
+ == Usage
23
+
24
+ Once your controller is configured, you can call on you views/controller the `no_bot` and `is_bot?` methods:
25
+
26
+ Stories
27
+ <% no_bot do %>
28
+ 1 of 10 pages
29
+ <% end %>
30
+ ...
31
+
32
+
33
+ Stories
34
+ <% unless is_bot? %>
35
+ 1 of 10 pages
36
+ <% end %>
37
+
38
+ == Customization
39
+
40
+ By default it will only trigger for Google, Yahoo and Bing.
41
+
42
+ You can add new user-agents to the robots list by using the `BadBot::Bots.setup` method.
43
+
44
+ # some_initializer.rb
45
+ BadBot::Bots.instance.setup do |robots|
46
+ robots << 'otherbot'
47
+ robots << 'otherbot2'
48
+ end
49
+
50
+ == Caution
51
+
52
+ How you will use this is entirely up to you. You can get punished by search engines if you make bad use of it.
53
+ My intent on creating this was to remove some useless words that kept showing as the highest keywords in webmasters tool.
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'BadBot'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
data/lib/bad_bot.rb ADDED
@@ -0,0 +1,4 @@
1
+ module BadBot
2
+ require 'bad_bot/detector'
3
+ require 'bad_bot/bots'
4
+ end
@@ -0,0 +1,39 @@
1
+ module BadBot
2
+ require 'singleton'
3
+
4
+ # Bots list
5
+ #
6
+ #
7
+ class Bots
8
+ include Singleton
9
+
10
+ def initialize
11
+ @bots = ['msnbot', 'googlebot', 'slurp', 'yahoo']
12
+ end
13
+
14
+ # Public: Configures the search robots array:
15
+ # Example
16
+ # BadBot.Bot.insance.setup do |bots|
17
+ # bots << 'googlebot'
18
+ # bots << 'yahoo'
19
+ # bots << 'custom stuff'
20
+ # end
21
+ #
22
+ def setup
23
+ yield(@bots)
24
+ end
25
+
26
+ # Public: Returns the array of bots
27
+ #
28
+ def bots
29
+ @bots
30
+ end
31
+
32
+ # Public: Convert the array of bots into a regular
33
+ # expression for searching
34
+ def bots_to_regexp
35
+ Regexp.union(bots)
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,48 @@
1
+ module BadBot
2
+ # Detector
3
+ # Gives the controller the ability to detect and behave
4
+ # different for requests that come from search bots.
5
+ #
6
+ # Example:
7
+ # class ApplicationController < ...
8
+ # include BadBot::Detector
9
+ # end
10
+ # ...
11
+ # <div>
12
+ # <% no_bot do %>
13
+ # stuff that is not worth to crawl
14
+ # <% end %>
15
+ # </div>
16
+ #
17
+ #
18
+ module Detector
19
+ extend ActiveSupport::Concern
20
+
21
+ included do
22
+ before_filter :detect_search_bots
23
+ helper_method :no_bot, :is_bot?
24
+ end
25
+
26
+ # Public: Helper that only executes the block in case
27
+ # this is not a request made by a search bot
28
+ #
29
+ def no_bot(&block)
30
+ block.call unless(is_bot?)
31
+ end
32
+
33
+ # Public: Helper that returns true or false, if the the
34
+ # request if from a search bot or not.
35
+ #
36
+ def is_bot?
37
+ @search_bot
38
+ end
39
+
40
+ private
41
+
42
+ # Private: Detects if the request comes from a search bot or not
43
+ #
44
+ def detect_search_bots
45
+ @search_bot ||= (request.user_agent =~ BadBot::Bots.instance.bots_to_regexp ? true : false)
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,3 @@
1
+ module BadBot
2
+ VERSION = "0.9"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :bad_bot do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bad_bot
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.9'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tiago Scolari
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: &70109398068500 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.3
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70109398068500
25
+ - !ruby/object:Gem::Dependency
26
+ name: sqlite3
27
+ requirement: &70109398067600 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70109398067600
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec-rails
38
+ requirement: &70109398066260 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70109398066260
47
+ - !ruby/object:Gem::Dependency
48
+ name: turnip
49
+ requirement: &70109398065160 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70109398065160
58
+ - !ruby/object:Gem::Dependency
59
+ name: capybara
60
+ requirement: &70109398063960 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70109398063960
69
+ - !ruby/object:Gem::Dependency
70
+ name: debugger
71
+ requirement: &70109398062880 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70109398062880
80
+ - !ruby/object:Gem::Dependency
81
+ name: simplecov
82
+ requirement: &70109398062380 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70109398062380
91
+ description: Avoid bad keywords from being indexed by google and other robots.
92
+ email:
93
+ - tscolari@gmail.com
94
+ executables: []
95
+ extensions: []
96
+ extra_rdoc_files: []
97
+ files:
98
+ - lib/bad_bot/bots.rb
99
+ - lib/bad_bot/detector.rb
100
+ - lib/bad_bot/version.rb
101
+ - lib/bad_bot.rb
102
+ - lib/tasks/bad_bot_tasks.rake
103
+ - MIT-LICENSE
104
+ - Rakefile
105
+ - README.rdoc
106
+ homepage: http://github.com/tscolari/bad_bot
107
+ licenses: []
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ segments:
119
+ - 0
120
+ hash: -496881733477053487
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ segments:
128
+ - 0
129
+ hash: -496881733477053487
130
+ requirements: []
131
+ rubyforge_project:
132
+ rubygems_version: 1.8.17
133
+ signing_key:
134
+ specification_version: 3
135
+ summary: Get better ranking on search engines, by preventing bad stuff from being
136
+ indexed.
137
+ test_files: []