Skip to content

Instantly share code, notes, and snippets.

@hamin
Created January 20, 2011 22:41
Show Gist options
  • Save hamin/788845 to your computer and use it in GitHub Desktop.
Save hamin/788845 to your computer and use it in GitHub Desktop.
A Rails 3 Application template for MongoMapper
# Some basic flags
use_mongomapper = false
use_compass = false
use_simplenavigation = false
rails3_branch = false
run "cp config/database.yml config/database.example.yml"
# Remove redundant files
remove_file "public/index.html"
remove_file "public/favicon.ico"
remove_file "public/robots.txt"
remove_file "README"
remove_file "doc/README_FOR_APP"
remove_dir "public/javascripts"
empty_directory "public/javascripts"
# Create some files
create_file "README.markdown"
create_file "public/stylesheets/application.css"
create_file "public/javascripts/application.js"
# Grab jQuery files
get "http://code.jquery.com/jquery-1.4.2.min.js", "public/javascripts/jquery.js"
get "https://github.com/rails/jquery-ujs/raw/master/src/rails.js", "public/javascripts/rails.js"
if yes?('Use MongoMapper Rails 3 branch?')
rails3_branch = true
end
if yes?('Use Machinist 2')
use_machinist2 = true
elsif yes?('Use Machinist 1')
use_machinist1 = true
end
if yes?('Use Compass for stylesheets?')
use_compass = true
end
if yes?('Use simple-navigation gem for easy navigation?')
use_simplenavigation = true
end
gem "unicorn"
gem "wirble", :group => :development
gem "hirb", :group => :development
gem "awesome_print", :group => :development
gem "rails3-generators", :group => :development
gem "rspec", :group => :test
gem "rspec-rails", :group => :test
gem "bson_ext"
if use_simplenavigation
gem "simple_navigation"
generate "navigation_config"
end
if use_compass
gem "compass"
run "compass init rails . --sass-dir app/stylesheets --css-dir public/stylesheets --images-dir public/images --javascripts-dir public/javascripts --output-style compressed"
end
if rails3_branch
gem 'mongo_mapper', :git => 'git://github.com/jnunemaker/mongomapper', :branch => 'rails3'
else
gem 'mongo_mapper', :git => 'git://github.com/jnunemaker/mongomapper', :branch => 'rails3'
end
if use_machinist2
gem 'machinist2_mongomapper', :require => "machinist_mongomapper"
gem 'machinist_mongo', :require => 'machinist/mongo_mapper', :git => 'https://github.com/nmerouze/machinist_mongo.git', :branch => 'machinist2'
generators = <<-GENERATORS
config.generators do |g|
g.orm :mongo_mapper
g.template_engine :erb
g.test_framework :rspec
g.fixture_replacement :machinist
end
GENERATORS
end
if use_machinist1
gem 'machinist_mongo', :require => 'machinist/mongo_mapper'
generators = <<-GENERATORS
config.generators do |g|
g.orm :mongo_mapper
g.template_engine :erb
g.test_framework :rspec
end
GENERATORS
end
# bundle install
run "bundle install"
application generators
generate 'rspec:install'
generate 'simple_form:install'
if use_machinist2
generate 'machinist:install'
end
if use_machinist1
create_file 'spec/blueprints.rb', <<-CODE
require 'machinist/mongo_mapper'
require 'sham'
CODE
end
initializer 'asset_default.rb', <<-END
module ActionView::Helpers::AssetTagHelper
register_javascript_expansion :jquery => ["http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"]
remove_const :JAVASCRIPT_DEFAULT_SOURCES
JAVASCRIPT_DEFAULT_SOURCES = %w(jquery.js rails.js)
reset_javascript_include_default
end
END
# Configure mongo.yml amd mongo.rb
create_file 'config/initializers/mongo.rb', <<-CODE
config = YAML.load_file(Rails.root + 'config' + 'mongo.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
CODE
create_file 'config/mongo.yml'
remove_file 'app/views/layouts/application.html.erb'
create_file 'app/views/layouts/application.html.erb', <<-CODE
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Rails</title>
<%= stylesheet_link_tag :all %>
<%= javascript_include_tag :defaults %>
</head>
<body>
<header>
<h1>Hello World</h1>
<nav>
<%= render_navigation %>
</nav>
</header>
<section>
<% flash.each do |name, message| %>
content_tag :div, message, :class => 'flash-notice'
<% end %>
<%= yield %>
</section>
<footer>
<p>Powered by Ruby On Rails</p>
</footer>
</body>
</html>
CODE
file 'public/stylesheets/applicationcss', <<-CODE
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,font,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td{border:0;outline:0;font-size:100%;vertical-align:baseline;background:transparent;margin:0;padding:0;}body{line-height:1;font-size:62.5%;}ol,ul{list-style:none;}blockquote,q{quotes:none;}blockquote:before,blockquote:after,q:before,q:after{content:none;}:focus{outline:0;}ins{text-decoration:none;}del{text-decoration:line-through;}table{border-collapse:collapse;border-spacing:0;text-align:left;}* p:last-child{margin-bottom:0;}code,pre,samp,kbd{font-family:monospace;}input,textarea,select{font-family:sans-serif;font-size:12px;}section,header,nav,article,aside,figure,footer,label{display:block;}
body {
font-family: Palatino, Georgia, serif;
font-size: 16px;
color: #333;
background: #fff;
}
h1, h2, h3, h4, h5, h6 {
font-weight: 400;
}
h2 {
margin-bottom: 10px;
font-size: 1.6em;
}
.flash-notice {
border: 1px solid #FFD324;
background: ##FFF6BF;
}
.field_with_errors {
padding: 2px;
background-color: red;
display: table;
}
#error_explanation {
width: 450px;
border: 2px solid red;
padding: 7px;
padding-bottom: 0;
margin-bottom: 20px;
background-color: #f0f0f0;
}
#error_explanation h2 {
text-align: left;
font-weight: bold;
padding: 5px 5px 5px 15px;
font-size: 12px;
margin: -7px;
margin-bottom: 0px;
background-color: #c00;
color: #fff;
}
#error_explanation ul li {
font-size: 12px;
list-style: square;
}
CODE
# Initialize the git repository and make the first commit
git :init
git :add => '.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment