Created
May 20, 2010 07:13
-
-
Save slawosz/407296 to your computer and use it in GitHub Desktop.
template files for rails3 application with mongoid and devise with simple css, usage: rails app_name -m http://gist.github.com/raw/407296/edge-mongoid-devise.rb
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
puts "Setting up Devise" | |
# Install devise | |
run "rails generate devise_install" | |
gsub_file "config/initializers/devise.rb", "require 'devise/orm/active_record'", "require 'devise/orm/mongoid'" | |
# Install mongoid | |
# Disable activerecord framework | |
frameworks = <<-FRAMEWORKS | |
# Pick the frameworks you want: | |
# We use mongoid | |
# require "active_record/railtie" | |
require "action_controller/railtie" | |
require "action_mailer/railtie" | |
require "active_resource/railtie" | |
require "rails/test_unit/railtie" | |
FRAMEWORKS | |
gsub_file 'config/application.rb', "require 'rails/all'", frameworks | |
file 'app/models/user.rb', <<-USER | |
class User | |
include Mongoid::Document | |
devise :database_authenticatable, | |
:registerable, | |
#:confirmable, | |
:recoverable, | |
:rememberable, | |
:trackable, | |
:validatable | |
end | |
USER | |
inject_into_file 'config/routes.rb', "\ndevise_for :users", :after => "Application.routes.draw do |map|\n", :verbose => true |
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 is for drying end easy maintain template for creating rails application with devise, mongoid and haml | |
# Inspiration from http://gist.github.com/383499/ | |
# To use this template, you need rails3, then run: | |
# rails app_name -m http://gist.github.com/raw/407296/edge-mongoid-devise.rb | |
#Gemfile | |
apply "http://gist.github.com/raw/407296/edge-template-Gemfile.rb" | |
# Bundle | |
run 'bundle install --relock' | |
# Initialize testing suite | |
run 'script/rails g rspec:install' | |
run 'script/rails g cucumber:skeleton --rspec --capybara' | |
run 'script/rails g mongoid:config' | |
#change layout to haml | |
#apply "http://gist.github.com/raw/407296/haml-html5-layout.rb" | |
#you can also use a bit more usefull layout, with user navigation for devise and css: | |
apply "http://gist.github.com/raw/407296/haml-html5-layout-with-devise-and-css.rb" | |
run "rm public/javascripts/*.js" | |
run "curl -L http://github.com/rails/jquery-ujs/raw/master/src/rails.js > public/javascripts/rails.js" | |
#generators config | |
config = <<-CONFIG | |
config.generators do |g| | |
g.orm :mongoid | |
g.template_engine :haml | |
g.test_framework :rspec, :fixture => false | |
end | |
CONFIG | |
file 'lib/tasks/mongo.rake', <<-RAKE | |
namespace :db do | |
namespace :test do | |
task :prepare do | |
# Stub out for MongoDB | |
end | |
end | |
end | |
RAKE | |
inject_into_file 'config/application.rb', "#{config}", :after => "# end\n", :verbose => true | |
database_flushing = <<-RSPEC | |
config.before(:each) do | |
Mongoid.master.collections.each(&:drop) | |
end | |
RSPEC | |
inject_into_file 'spec/spec_helper', database_flushing, :after => "Rspec.configure do |config|\n", :verbose => true | |
#devise config | |
apply "http://gist.github.com/raw/407296/devise-with-mongoid-configuration.rb" | |
# Remove index.html, application.html.erb and rails.png | |
run "rm public/index.html" | |
run "rm public/images/rails.png" | |
run "rm app/views/layouts/application.html.erb" | |
# Remove test directory since we're not using test/unit | |
run "rm -rf test" | |
# Creates Main controller with route root | |
apply "http://gist.github.com/raw/407296/main-controller.rb" | |
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
gemfile = <<-GEMS | |
source 'http://rubygems.org' | |
gem "bundler", "0.9.25" | |
gem 'rails', '3.0.0.beta3' | |
gem "compass" | |
gem "haml" | |
gem "bundler", ">=0.9.25" | |
gem "rails3-generators" | |
#works with devise | |
gem "mongoid", :git => "http://github.com/dbackeus/mongoid.git" | |
#gem "mongoid", :git => "git://github.com/durran/mongoid.git" | |
gem "mongo" | |
gem "bson_ext" | |
gem "devise", :git => "git://github.com/plataformatec/devise.git", :ref => "9291ab55b895724" | |
#gem "devise", :git => "git://github.com/plataformatec/devise.git" | |
gem "will_paginate", "3.0.pre" | |
gem "yard", :require => nil | |
group :cucumber do | |
gem "culerity", :require => nil | |
gem "capybara" | |
gem "thin", :require => nil | |
end | |
group :cucumber, :test do | |
gem "rspec", ">= 2.0.0.beta.4", :require => false | |
gem "rspec-rails", ">= 2.0.0.beta.4", :require => false | |
gem "factory_girl", :git => "git://github.com/drogus/factory_girl.git" | |
gem "faker" | |
end | |
group :metrics do | |
gem "metric_fu" | |
gem "reek" # code smells | |
gem "flay" # duplicates | |
gem "churn" # how often is file, method or class changes? if it's changed too often it means it is probably not encapsulated enough | |
gem "rcov" # test coverage | |
gem "flog" # code complexity | |
gem "roodi" # design issues | |
end | |
GEMS | |
run 'rm Gemfile' | |
file 'Gemfile', gemfile |
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
#layout with very simple styling | |
file "app/views/layouts/application.haml", <<-HAML | |
!!! 5 | |
%html | |
%head | |
%title | |
New Rails App! | |
= stylesheet_link_tag :all | |
= csrf_meta_tag | |
%body | |
#container | |
#user_navigation | |
- if user_signed_in? | |
== Signed in as \#{ current_user.email }. \#{ link_to "Sign out", destroy_user_session_path } | |
- else | |
== \#{link_to "Sign in", new_user_session_path } or \#{ link_to "sign up", new_user_registration_path } | |
- flash.each do |name, msg| | |
= content_tag :div, msg, :id => "flash_\#{name}" | |
#content | |
= yield | |
HAML | |
#and stylesheet | |
file 'public/stylesheets/style.css', <<-CSS | |
body { | |
font-size: 13px; | |
font-family: Consolas, 'Lucida Console', Monaco, monospace; | |
background: #efefef; | |
} | |
#container { | |
width: 940px; | |
padding: 10px; | |
margin: 11px auto; | |
background: #fff; | |
} | |
#user_navigation { | |
text-align: left; | |
} | |
#flash_notice, #flash_alert { | |
margin: 10px; | |
padding: 10px; | |
text-align: center; | |
} | |
#flash_notice { | |
background-color: #79e077; | |
border: 1px solid #049f00; | |
} | |
#flash_alert { | |
background-color: #fd8588; | |
border: 1px solid #d40404; | |
} | |
CSS |
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
# Add a haml layout with google's jQuery | |
file "app/views/layouts/application.haml", <<-HAML | |
!!! 5 | |
%html | |
%head | |
= csrf_meta_tag | |
= stylesheet_link_tag 'screen.css', :media => 'screen, projection' | |
= stylesheet_link_tag 'print.css', :media => 'print' | |
/[if lt IE 8] | |
= stylesheet_link_tag 'ie.css', :media => 'screen, projection' | |
= javascript_include_tag 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js' | |
= javascript_include_tag 'application.js' | |
%body | |
= yield | |
HAML |
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
file 'app/controllers/main_controller.rb', <<-MAIN | |
class MainController < ApplicationController | |
def index | |
end | |
end | |
MAIN | |
file 'app/views/main/index.html.haml', <<-INDEX | |
%h1 New Rails Application | |
edit app/views/main/index.html.haml | |
INDEX | |
inject_into_file 'config/routes.rb', "resource :main\n", :after =>"# root :to => \"welcome#index\"\n", :verbose => true | |
inject_into_file 'config/routes.rb', "root :to => \"main#index\"", :after =>"resource :main\n", :verbose => true | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment