Skip to content

Instantly share code, notes, and snippets.

@yannski
Forked from bscofield/gist:181842
Created December 19, 2009 14:14
Show Gist options
  • Save yannski/260092 to your computer and use it in GitHub Desktop.
Save yannski/260092 to your computer and use it in GitHub Desktop.
# mongo_template.rb
# remove unneeded defaults
run "rm public/index.html"
run "rm public/images/rails.png"
run "rm public/javascripts/controls.js"
run "rm public/javascripts/dragdrop.js"
run "rm public/javascripts/effects.js"
run "rm public/javascripts/prototype.js"
# add basic layout to start
file 'app/views/layouts/application.html.erb', <<-ERB
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Application!</title>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js" type="text/javascript"></script>
<%= stylesheet_link_tag 'global' %>
</head>
<body>
<%= yield %>
</body>
</html>
ERB
# MongoDB FTW!
db_name = ask('What should I call the database? ')
initializer 'mongo.rb', <<-CODE
config = YAML.load_file(Rails.root + 'config' + 'database.yml')[Rails.env]
MongoMapper.connection = Mongo::Connection.new(config['host'], config['port'], {
:logger => Rails.logger
})
MongoMapper.database = config['database']
if config['username'].present?
MongoMapper.database.authenticate(config['username'], config['password'])
end
Dir[Rails.root + 'app/models/**/*.rb'].each do |model_path|
File.basename(model_path, '.rb').classify.constantize
end
MongoMapper.ensure_indexes!
if defined?(PhusionPassenger)
PhusionPassenger.on_event(:starting_worker_process) do |forked|
# if using older than 0.6.5 of MM then you want database instead of connection
# MongoMapper.database.connect_to_master if forked
MongoMapper.connection.connect_to_master if forked
end
end
CODE
file 'config/database.yml', <<-CODE
development: &global_settings
database: #{db_name}_dev
host: 127.0.0.1
port: 27017
test:
database: #{db_name}_test
<<: *global_settings
production:
host: hostname
database: #{db_name}_prod
username: username
password: password
<<: *global_settings
CODE
environment 'config.frameworks -= [:active_record]'
gem 'mongo_mapper'
gem 'haml'
gem 'will_paginate'
# Testing and Cucumber
gem 'rspec', :lib => false
gem 'rspec-rails', :lib => false
gem 'factory_girl'
gem 'shoulda'
gem 'cucumber'
gem 'webrat'
# Finish RSpec
run './script/generate rspec'
# Finish Cucumber
run './script/generate cucumber'
# source control
file '.gitignore', <<-FILES
.DS_Store
**/.DS_Store
log/*
tmp/*
tmp/**/*
config/database.yml
coverage/*
coverage/**/*
*swp
*~
FILES
git :init
git :add => '.'
git :commit => '-a -m "Initial commit"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment