Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from menkel/master
[feature] add generator for install roboto
- Loading branch information
Showing
8 changed files
with
101 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,6 @@ spec/dummy/db/*.sqlite3 | |
spec/dummy/log/*.log | ||
spec/dummy/tmp/ | ||
|
||
|
||
.DS_Store | ||
spec/dummy_generator/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module Roboto | ||
module Generators | ||
class InstallGenerator < Rails::Generators::Base | ||
source_root File.expand_path("../../templates", __FILE__) | ||
|
||
desc "Creates a Roboto locale files to your application." | ||
|
||
def copy_locale | ||
empty_directory "config/robots" | ||
env_list = Dir.glob("#{destination_root}/config/environments/*") | ||
env_list.each do |env_file| | ||
env_name = File.basename(env_file, ".rb") | ||
unless (env_name == "production" && FileTest.exists?("public/robots.txt")) | ||
copy_file "robots.txt", "config/robots/#{env_name}.txt" | ||
end | ||
end | ||
if FileTest.exists?("public/robots.txt") | ||
copy_file File.join(destination_root + "/public/robots.txt"), "config/robots/production.txt" | ||
remove_file "public/robots.txt" | ||
end | ||
end | ||
|
||
def add_roboto_route | ||
route "mount_roboto" | ||
end | ||
|
||
def show_readme | ||
readme "README" if behavior == :invoke | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
=============================================================================== | ||
Disallow crawlers from accessing your site has been made for all | ||
your environments. | ||
|
||
If you had a robots.txt in public, | ||
it was moved to config/robots/production.txt | ||
|
||
You can now specify environment specific robots.txt files in config/robots. | ||
=============================================================================== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
User-Agent: * | ||
Disallow: / |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
require 'spec_helper' | ||
require 'generators/roboto/install_generator' | ||
|
||
describe Roboto::Generators::InstallGenerator do | ||
destination File.expand_path("../../../dummy_generator", __FILE__) | ||
|
||
before {prepare_destination} | ||
|
||
describe 'presence of roboto configuration file' do | ||
before do | ||
@env_availabe = ["roboto_env", "staging", "production"] | ||
create_fake_env | ||
create_routes_rb | ||
run_generator | ||
end | ||
|
||
["roboto_env", "staging", "production"].each do |env| | ||
describe 'config/robots/#{env}.txt' do | ||
subject { file("config/robots/#{env}.txt") } | ||
it { should exist } | ||
it { should contain "User-Agent: *" } | ||
it { should contain "Disallow: /" } | ||
end | ||
end | ||
|
||
describe 'config/routes.rb' do | ||
subject { file('config/routes.rb') } | ||
it { should exist } | ||
it { should contain "mount_roboto" } | ||
end | ||
end | ||
|
||
def create_routes_rb | ||
routes = File.expand_path("../../../dummy/config/routes.rb", __FILE__) | ||
destination = File.join(destination_root, "config") | ||
FileUtils.mkdir_p(destination) | ||
FileUtils.cp routes, destination | ||
end | ||
|
||
def create_fake_env | ||
destination = File.join(destination_root, "config/environments") | ||
FileUtils.mkdir_p(destination) | ||
@env_availabe.each {|env| FileUtils.touch(destination_root + "/config/environments/#{env}.rb")} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters