roboto 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -22,3 +22,6 @@ spec/dummy/db/*.sqlite3
22
22
  spec/dummy/log/*.log
23
23
  spec/dummy/tmp/
24
24
 
25
+
26
+ .DS_Store
27
+ spec/dummy_generator/
data/README.md CHANGED
@@ -7,36 +7,21 @@ Roboto is a Rails Engine that gives you the ability to specify enviornment speci
7
7
  Don't let crawlers access your staging environment. This is [bad for SEO](http://www.seomoz.org/learn-seo/duplicate-content).
8
8
 
9
9
  ## Installing
10
-
11
- First, remove the default, generate robots.txt in your Rails App
10
+ You can add it to your Gemfile with:
12
11
 
13
12
  ```
14
- #> rm public/robots.txt
13
+ gem 'roboto'
15
14
  ```
16
15
 
17
- Next, add roboto to your gemfile:
18
-
16
+ After you need to run the generator:
19
17
  ```
20
- gem 'roboto'
18
+ #> rails generate roboto:install
21
19
  ```
22
20
 
23
- Then, add robot to your routes (config/routes.rb):
24
-
25
- ```
26
- Rails.application.routes.draw do
27
- mount_roboto
28
- end
29
- ```
21
+ If you already have robots.txt, it will be kept for your production environment in config/robots/production.txt
30
22
 
31
- You can now specify environment specific robots.txt files in config/robots.
32
-
33
- It's recommended for staging that you do disallow crawlers from accessing your site. Once you've created a separate Rails environment for staging, define a config/robots/staging.txt file like so:
34
-
35
- ```
36
- #place this in config/robots/staging.txt
37
- User-Agent: *
38
- Disallow: /
39
- ```
23
+ You can now specify environment specific robots.txt files in config/robots/.
24
+ By default crawlers are disallow from accessing your site has been made for all your environments.
40
25
 
41
26
  ## Contributing
42
27
 
@@ -8,7 +8,8 @@ module Roboto
8
8
 
9
9
  protected
10
10
  def robot_contents
11
- Roboto::ContentProvider.new.contents
11
+ # process erb template in the context of this controller request
12
+ Roboto::ContentProvider.new.contents(binding)
12
13
  end
13
14
 
14
15
  def robots_path
data/config/routes.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  Roboto::Engine.routes.draw do
2
- get '/robots.txt' => 'Robots#show'
2
+ get '/' => 'Robots#show'
3
3
  end
4
4
 
@@ -0,0 +1,32 @@
1
+ module Roboto
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path("../../templates", __FILE__)
5
+
6
+ desc "Creates a Roboto locale files to your application."
7
+
8
+ def copy_locale
9
+ empty_directory "config/robots"
10
+ env_list = Dir.glob("#{destination_root}/config/environments/*")
11
+ env_list.each do |env_file|
12
+ env_name = File.basename(env_file, ".rb")
13
+ unless (env_name == "production" && FileTest.exists?("public/robots.txt"))
14
+ copy_file "robots.txt", "config/robots/#{env_name}.txt"
15
+ end
16
+ end
17
+ if FileTest.exists?("public/robots.txt")
18
+ copy_file File.join(destination_root + "/public/robots.txt"), "config/robots/production.txt"
19
+ remove_file "public/robots.txt"
20
+ end
21
+ end
22
+
23
+ def add_roboto_route
24
+ route "mount_roboto"
25
+ end
26
+
27
+ def show_readme
28
+ readme "README" if behavior == :invoke
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,11 @@
1
+ ===============================================================================
2
+ Disallow crawlers from accessing your site has been made for all
3
+ your environments.
4
+
5
+ If you had a robots.txt in public,
6
+ it was moved to config/robots/production.txt
7
+
8
+ You can now specify environment specific robots.txt files in config/robots.
9
+
10
+ Domo arigato!
11
+ ===============================================================================
@@ -0,0 +1,2 @@
1
+ User-Agent: *
2
+ Disallow: /
@@ -1,10 +1,18 @@
1
+ require 'erb'
2
+
1
3
  module Roboto
2
4
  #provides the content of effective robots.txt file
3
5
  class ContentProvider
4
6
  # Reads the contents of the effective robots.txt file
5
7
  # @return [String] the contents of the effective robots.txt file
6
- def contents
7
- @contents ||= File.read(path)
8
+ def contents(custom_binding = nil)
9
+ return @contents unless @contents.nil?
10
+
11
+ @contents = File.read(path)
12
+ if path.extname == '.erb'
13
+ @contents = ERB.new(@contents).result(custom_binding ? custom_binding : binding)
14
+ end
15
+ @contents
8
16
  end
9
17
 
10
18
  # Determines the most relevant robots.txt file.
@@ -30,7 +38,9 @@ module Roboto
30
38
  def lookup_paths
31
39
  [
32
40
  Rails.root.join("config/robots/#{Rails.env}.txt"),
41
+ Rails.root.join("config/robots/#{Rails.env}.txt.erb"),
33
42
  Rails.root.join(relative_path_to_default),
43
+ Rails.root.join("#{relative_path_to_default}.erb"),
34
44
  Roboto::Engine.root.join(relative_path_to_default)
35
45
  ]
36
46
  end
@@ -3,7 +3,7 @@ module Roboto
3
3
  module Routing
4
4
  # convenience function for mounting the roboto rails engine to root
5
5
  def mount_roboto
6
- mount Roboto::Engine => "/"
6
+ mount Roboto::Engine => "/robots.txt"
7
7
  end
8
8
  end
9
9
  end
@@ -1,4 +1,4 @@
1
1
  module Roboto
2
2
  #The effective version of roboto
3
- VERSION = "0.0.2"
3
+ VERSION = "0.1.0"
4
4
  end
data/roboto.gemspec CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |gem|
6
6
  gem.email = ['dan.pickett@launchware.com']
7
7
  gem.description = %q{A Rails Engine to help with robots.txt}
8
8
  gem.summary = %q{A Rails Engine to help with robots.txt}
9
- gem.homepage = ""
9
+ gem.homepage = "https://github.com/LaunchWare/roboto"
10
10
 
11
11
  gem.files = `git ls-files`.split($\)
12
12
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -19,11 +19,13 @@ Gem::Specification.new do |gem|
19
19
  gem.add_dependency 'actionpack', '>= 3.0.0'
20
20
 
21
21
  gem.add_development_dependency 'rspec-rails', '~> 2.9.0'
22
+ gem.add_development_dependency 'ammeter'
22
23
  gem.add_development_dependency 'capybara'
23
24
  gem.add_development_dependency 'fakefs'
24
25
  gem.add_development_dependency 'yard'
25
26
  gem.add_development_dependency 'redcarpet'
26
27
 
28
+
27
29
  #we need this for the dummy app
28
30
  gem.add_development_dependency 'sqlite3'
29
31
  end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+ require 'generators/roboto/install_generator'
3
+
4
+ describe Roboto::Generators::InstallGenerator do
5
+ destination File.expand_path("../../../dummy_generator", __FILE__)
6
+
7
+ before {prepare_destination}
8
+
9
+ describe 'presence of roboto configuration file' do
10
+ before do
11
+ @env_availabe = ["roboto_env", "staging", "production"]
12
+ create_fake_env
13
+ create_routes_rb
14
+ run_generator
15
+ end
16
+
17
+ ["roboto_env", "staging", "production"].each do |env|
18
+ describe 'config/robots/#{env}.txt' do
19
+ subject { file("config/robots/#{env}.txt") }
20
+ it { should exist }
21
+ it { should contain "User-Agent: *" }
22
+ it { should contain "Disallow: /" }
23
+ end
24
+ end
25
+
26
+ describe 'config/routes.rb' do
27
+ subject { file('config/routes.rb') }
28
+ it { should exist }
29
+ it { should contain "mount_roboto" }
30
+ end
31
+ end
32
+
33
+ def create_routes_rb
34
+ routes = File.expand_path("../../../dummy/config/routes.rb", __FILE__)
35
+ destination = File.join(destination_root, "config")
36
+ FileUtils.mkdir_p(destination)
37
+ FileUtils.cp routes, destination
38
+ end
39
+
40
+ def create_fake_env
41
+ destination = File.join(destination_root, "config/environments")
42
+ FileUtils.mkdir_p(destination)
43
+ @env_availabe.each {|env| FileUtils.touch(destination_root + "/config/environments/#{env}.rb")}
44
+ end
45
+ end
@@ -17,8 +17,16 @@ describe Roboto::ContentProvider do
17
17
 
18
18
  it 'uses the environment specific file if found' do
19
19
  path = Rails.root.join("config/robots/test.txt")
20
- FileUtils.touch(path)
20
+ File.open(path, 'wb') { |f| f.write(Rails.env) }
21
+ content_provider.path.should eql(path)
22
+ content_provider.contents.should eql(Rails.env)
23
+ end
24
+
25
+ it 'supports erb pre-processing' do
26
+ path = Rails.root.join("config/robots/test.txt.erb")
27
+ File.open(path, 'wb') { |f| f.write('<%= Rails.env %>') }
21
28
  content_provider.path.should eql(path)
29
+ content_provider.contents.should eql(Rails.env)
22
30
  end
23
31
 
24
32
  it 'uses the default robots file if found in the rails root' do
data/spec/spec_helper.rb CHANGED
@@ -6,6 +6,7 @@ require "rails/test_help"
6
6
 
7
7
  require 'capybara/rspec'
8
8
  require 'rspec/rails'
9
+ require 'ammeter/init'
9
10
 
10
11
  Rails.backtrace_cleaner.remove_silencers!
11
12
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roboto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-21 00:00:00.000000000 Z
12
+ date: 2012-08-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &2156478460 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: 3.1.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2156478460
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 3.1.0
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: actionpack
27
- requirement: &2156471600 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: 3.0.0
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *2156471600
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 3.0.0
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: rspec-rails
38
- requirement: &2156470840 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ~>
@@ -43,10 +53,31 @@ dependencies:
43
53
  version: 2.9.0
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *2156470840
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.9.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: ammeter
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
47
78
  - !ruby/object:Gem::Dependency
48
79
  name: capybara
49
- requirement: &2156469740 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
50
81
  none: false
51
82
  requirements:
52
83
  - - ! '>='
@@ -54,10 +85,15 @@ dependencies:
54
85
  version: '0'
55
86
  type: :development
56
87
  prerelease: false
57
- version_requirements: *2156469740
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
58
94
  - !ruby/object:Gem::Dependency
59
95
  name: fakefs
60
- requirement: &2156467660 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
61
97
  none: false
62
98
  requirements:
63
99
  - - ! '>='
@@ -65,10 +101,15 @@ dependencies:
65
101
  version: '0'
66
102
  type: :development
67
103
  prerelease: false
68
- version_requirements: *2156467660
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
69
110
  - !ruby/object:Gem::Dependency
70
111
  name: yard
71
- requirement: &2156466460 !ruby/object:Gem::Requirement
112
+ requirement: !ruby/object:Gem::Requirement
72
113
  none: false
73
114
  requirements:
74
115
  - - ! '>='
@@ -76,10 +117,15 @@ dependencies:
76
117
  version: '0'
77
118
  type: :development
78
119
  prerelease: false
79
- version_requirements: *2156466460
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
80
126
  - !ruby/object:Gem::Dependency
81
127
  name: redcarpet
82
- requirement: &2156456000 !ruby/object:Gem::Requirement
128
+ requirement: !ruby/object:Gem::Requirement
83
129
  none: false
84
130
  requirements:
85
131
  - - ! '>='
@@ -87,10 +133,15 @@ dependencies:
87
133
  version: '0'
88
134
  type: :development
89
135
  prerelease: false
90
- version_requirements: *2156456000
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
91
142
  - !ruby/object:Gem::Dependency
92
143
  name: sqlite3
93
- requirement: &2156454860 !ruby/object:Gem::Requirement
144
+ requirement: !ruby/object:Gem::Requirement
94
145
  none: false
95
146
  requirements:
96
147
  - - ! '>='
@@ -98,7 +149,12 @@ dependencies:
98
149
  version: '0'
99
150
  type: :development
100
151
  prerelease: false
101
- version_requirements: *2156454860
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
102
158
  description: A Rails Engine to help with robots.txt
103
159
  email:
104
160
  - dan.pickett@launchware.com
@@ -126,6 +182,9 @@ files:
126
182
  - bin/tmux.sh
127
183
  - config/robots/default.txt
128
184
  - config/routes.rb
185
+ - lib/generators/roboto/install_generator.rb
186
+ - lib/generators/templates/README
187
+ - lib/generators/templates/robots.txt
129
188
  - lib/roboto.rb
130
189
  - lib/roboto/content_provider.rb
131
190
  - lib/roboto/engine.rb
@@ -165,11 +224,12 @@ files:
165
224
  - spec/dummy/public/500.html
166
225
  - spec/dummy/public/favicon.ico
167
226
  - spec/dummy/script/rails
227
+ - spec/generators/roboto/install_generator_spec.rb
168
228
  - spec/requests/user_visits_robots_spec.rb
169
229
  - spec/roboto/content_provider_spec.rb
170
230
  - spec/spec_helper.rb
171
231
  - spec/support/fakefs.rb
172
- homepage: ''
232
+ homepage: https://github.com/LaunchWare/roboto
173
233
  licenses: []
174
234
  post_install_message:
175
235
  rdoc_options: []
@@ -183,7 +243,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
183
243
  version: '0'
184
244
  segments:
185
245
  - 0
186
- hash: -2852200819852454992
246
+ hash: -3061485289554401182
187
247
  required_rubygems_version: !ruby/object:Gem::Requirement
188
248
  none: false
189
249
  requirements:
@@ -192,10 +252,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
192
252
  version: '0'
193
253
  segments:
194
254
  - 0
195
- hash: -2852200819852454992
255
+ hash: -3061485289554401182
196
256
  requirements: []
197
257
  rubyforge_project:
198
- rubygems_version: 1.8.17
258
+ rubygems_version: 1.8.23
199
259
  signing_key:
200
260
  specification_version: 3
201
261
  summary: A Rails Engine to help with robots.txt
@@ -231,6 +291,7 @@ test_files:
231
291
  - spec/dummy/public/500.html
232
292
  - spec/dummy/public/favicon.ico
233
293
  - spec/dummy/script/rails
294
+ - spec/generators/roboto/install_generator_spec.rb
234
295
  - spec/requests/user_visits_robots_spec.rb
235
296
  - spec/roboto/content_provider_spec.rb
236
297
  - spec/spec_helper.rb