Permalink
Browse files

add setup_development_environment

  • Loading branch information...
xdite committed Oct 7, 2012
1 parent 95c6f20 commit 0ec3a88dc27cf69b262e33bf163676d36c9b10bb
View
@@ -1,6 +1,7 @@
#!/usr/bin/env ruby
require File.expand_path(File.join('..', 'lib', 'bootstrapers', 'generators', 'app_generator'), File.dirname(__FILE__))
require File.expand_path(File.join('..', 'lib', 'bootstrapers', 'actions'), File.dirname(__FILE__))
require File.expand_path(File.join('..', 'lib', 'bootstrapers', 'app_builder'), File.dirname(__FILE__))
templates_root = File.expand_path(File.join("..", "templates"), File.dirname(__FILE__))
@@ -0,0 +1,35 @@
module Bootstrapers
module Actions
def concat_file(source, destination)
contents = IO.read(find_in_source_paths(source))
append_file destination, contents
end
def replace_in_file(relative_path, find, replace)
path = File.join(destination_root, relative_path)
contents = IO.read(path)
unless contents.gsub!(find, replace)
raise "#{find.inspect} not found in #{relative_path}"
end
File.open(path, "w") { |file| file.write(contents) }
end
def action_mailer_host(rails_env, host)
inject_into_file(
"config/environments/#{rails_env}.rb",
"\n\n config.action_mailer.default_url_options = { :host => '#{host}' }",
:before => "\nend"
)
end
def download_file(uri_string, destination)
uri = URI.parse(uri_string)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true if uri_string =~ /^https/
request = Net::HTTP::Get.new(uri.path)
contents = http.request(request).body
path = File.join(destination_root, destination)
File.open(path, "w") { |file| file.write(contents) }
end
end
end
@@ -0,0 +1,24 @@
module Bootstrapers
class AppBuilder < Rails::AppBuilder
include Bootstrapers::Actions
def readme
template 'README.md.erb', 'README.md'
end
def remove_public_index
remove_file 'public/index.html'
end
def remove_rails_logo_image
remove_file 'app/assets/images/rails.png'
end
def raise_delivery_errors
replace_in_file 'config/environments/development.rb',
'raise_delivery_errors = false', 'raise_delivery_errors = true'
end
end
end
@@ -4,14 +4,32 @@
module Bootstrapers
class AppGenerator < Rails::Generators::AppGenerator
def finish_template
invoke :bootstrapers_customization
super
end
def bootstrapers_customization
invoke :remove_files_we_dont_need
invoke :setup_development_environment
end
def remove_files_we_dont_need
build :remove_public_index
build :remove_rails_logo_image
end
def setup_development_environment
say 'Setting up the development environment'
build :raise_delivery_errors
end
protected
def get_builder_class
Bootstrapers::AppBuilder
end
end
end
View
@@ -0,0 +1,3 @@
* [Ruby Coding Style](https://github.com/bbatsov/ruby-style-guide)

0 comments on commit 0ec3a88

Please sign in to comment.