Created
December 26, 2009 12:36
-
-
Save tejo/263939 to your computer and use it in GitHub Desktop.
bootstrap
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
# require webrat , responders & database_cleaner gems | |
############## plugin commands ################# | |
plugin 'paperclip', :git => "git://github.com/thoughtbot/paperclip.git" | |
plugin 'rails_indexes', :git => 'git://github.com/eladmeidar/rails_indexes.git' | |
plugin 'formtastic', :git => 'git://github.com/justinfrench/formtastic.git' | |
plugin 'scrooge', :git => 'git://github.com/methodmissing/scrooge.git' | |
plugin 'web-app-theme', :git => 'git://github.com/pilu/web-app-theme.git' | |
plugin 'admin_section', :git => 'git://github.com/tejo/admin_section.git' | |
############## gem commands ################# | |
gem 'shoulda', :source => 'http://gemcutter.org' | |
gem 'factory_girl', :source => 'http://gemcutter.org' | |
gem 'cucumber-rails', :lib => 'cucumber' | |
gem 'will_paginate', :version => '~> 2.3.11', :source => 'http://gemcutter.org' | |
gem 'searchlogic' | |
gem 'authlogic' | |
gem 'paperclip', :source => 'http://gemcutter.org' | |
gem "inherited_resources", :version => "1.0.0" | |
gem "responders", :version => "0.4.0" | |
################ routing #################### | |
route 'map.connect "*page", :controller => "pages", :action => "show"' | |
route 'map.resources :pages, :collection => {:home => :get}' | |
route 'map.root :controller => "pages", :action => "home"' | |
route 'end' | |
route 'admin.resources :users' | |
route 'admin.resources :user_sessions' | |
route 'admin.resources :news_items' | |
route 'admin.resources :homes' | |
route 'map.namespace :admin do |admin|' | |
route 'map.logout "logout", :namespace => "admin", :controller => "user_sessions", :action => "destroy"' | |
route 'map.login "login", :namespace => "admin", :controller => "user_sessions", :action => "new"' | |
############# generate files ########### | |
#controller pages - home page | |
file 'app/controllers/pages_controller.rb', <<-CODE | |
class PagesController < ApplicationController | |
#lista pagine statiche | |
PAGES = %w(home).freeze | |
def show | |
page = params[:id] || params[:page].first | |
if PAGES.include?(page) | |
render :action => page | |
else | |
raise ActiveRecord::RecordNotFound, | |
"No such static page: \#{params[:id].inspect}" | |
end | |
end | |
def index | |
redirect_to root_path | |
end | |
end | |
CODE | |
file 'app/views/pages/home.html.erb', <<-CODE | |
home | |
CODE | |
file 'features/step_definitions/homepage_steps.rb', <<-CODE | |
Given /^I am at the home page$/ do | |
visit home_pages_url | |
end | |
When /^I point the browser to home page$/ do | |
visit home_pages_url | |
pending # express the regexp above with the code you wish you had | |
end | |
Then /^I should see '(.*)' in the body of the page$/ do | |
response_body.should include(title) | |
end | |
CODE | |
file 'features/homepage.feature', <<-CODE | |
Scenario: Default home page | |
Given I am at the home page | |
When I point the browser to home page | |
Then I should see 'home' in the body of the page | |
CODE | |
#authlogic stuff | |
file 'app/models/user_session.rb', <<-CODE | |
class UserSession < Authlogic::Session::Base | |
end | |
CODE | |
file 'app/controllers/application_controller.rb', <<-CODE | |
class ApplicationController < ActionController::Base | |
helper :all # include all helpers, all the time | |
protect_from_forgery # See ActionController::RequestForgeryProtection for details | |
helper_method :current_user, :admin_required | |
# Scrub sensitive parameters from your log | |
# filter_parameter_logging :password | |
private | |
def current_user_session | |
return @current_user_session if defined?(@current_user_session) | |
@current_user_session = UserSession.find | |
end | |
def current_user | |
@current_user = current_user_session && current_user_session.record | |
end | |
def admin_required | |
unless current_user | |
store_location | |
flash[:notice] = "You must be logged in to access this page" | |
redirect_to login_path | |
return false | |
end | |
end | |
def store_location | |
session[:return_to] = request.request_uri | |
end | |
def redirect_back_or_default(default) | |
redirect_to(session[:return_to] || default) | |
session[:return_to] = nil | |
end | |
end | |
CODE | |
file 'app/controllers/admin/user_sessions_controller.rb', <<-CODE | |
class Admin::UserSessionsController < ApplicationController | |
layout 'admin/application' | |
def new | |
@user_session = UserSession.new | |
end | |
def create | |
@user_session = UserSession.new(params[:user_session]) | |
if @user_session.save | |
flash[:notice] = "Succesfully logged in" | |
redirect_back_or_default admin_homes_path | |
else | |
render :action => 'new' | |
end | |
end | |
def destroy | |
@user_session = UserSession.find | |
@user_session.destroy | |
flash[:notice] = "Succesfully logged out" | |
redirect_to root_url | |
end | |
end | |
CODE | |
file 'app/views/admin/user_sessions/new.html.erb', <<-CODE | |
<% form_for [:admin, @user_session] do |f| %> | |
<%= f.error_messages %> | |
<p> | |
<%= f.label :username %><br/> | |
<%= f.text_field :username %> | |
</p> | |
<p> | |
<%= f.label :password %><br/> | |
<%= f.password_field :password %> | |
</p> | |
<p><%= f.submit "Submit" %></p> | |
<%end%> | |
CODE | |
file 'app/controllers/admin/homes_controller.rb', <<-CODE | |
class Admin::HomesController < InheritedResources::Base | |
before_filter :admin_required | |
layout 'admin/application' | |
def index | |
end | |
end | |
CODE | |
file 'app/views/layouts/admin/application.html.erb',<<-CODE | |
<!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" lang="en"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
<title>Admin Panel</title> | |
<%= stylesheet_link_tag 'admin/web_app_theme', "admin/themes/drastic-dark/style" %> | |
<%= stylesheet_link_tag 'admin/formtastic'%> | |
<%= javascript_include_tag 'jquery' %> | |
<%= javascript_include_tag 'application' %> | |
<%= yield(:head) %> | |
</head> | |
<body> | |
<div id="container"> | |
<div id="header"> | |
<h1><a href="/">Admin Panel</a></h1> | |
<div id="user-navigation"> | |
<ul> | |
<!-- <li><a href="#">Profile</a></li> | |
<li><a href="#">Settings</a></li> --> | |
<li><a href="/logout" class="logout">Logout</a></li> | |
</ul> | |
<div class="clear"></div> | |
</div> | |
<div id="main-navigation"> | |
<ul> | |
<li class="<%= controller.controller_path == 'admin/homes' ? 'active' : '' %>"><a href="<%= admin_homes_path%>">Homepage</a></li> | |
<li class="<%= controller.controller_path == 'admin/news_items' ? 'active' : '' %>"><a href="<%= admin_news_items_path%>">News</a></li> | |
</ul> | |
<div class="clear"></div> | |
</div> | |
</div> | |
<div id="wrapper"> | |
<div class="flash"> | |
<% flash.each do |type, message| -%> | |
<div class="message <%= type %>"> | |
<p><%= message %></p> | |
</div> | |
<% end -%> | |
</div> | |
<div id="main"> | |
<%= yield %> | |
<div id="footer"> | |
<div class="block"> | |
<p>Copyright © 2009 </p> | |
</div> | |
</div> | |
</div> | |
<div id="sidebar"> | |
<%= yield :sidebar %> | |
</div> | |
<div class="clear"></div> | |
</div> | |
</div> | |
</body> | |
</html> | |
CODE | |
file 'app/views/admin/homes/index.html.erb', <<-CODE | |
Admin Homepage | |
CODE | |
############## generate commands ################# | |
##generate("rspec") | |
generate("cucumber --testunit") | |
#authlogic migration | |
generate('model user username:string email:string crypted_password:string password_salt:string persistence_token:string') if yes?("create authlogic user (y,n) ?") | |
generate('theme admin --theme="drastic-dark" ') | |
run 'mkdir public/stylesheets/admin; mv public/stylesheets/web* public/stylesheets/admin; mv public/stylesheets/themes public/stylesheets/admin' | |
run 'rm app/views/layouts/admin.html.erb' | |
run "cp vendor/plugins/formtastic/generators/formtastic/templates/formtastic.css public/stylesheets/admin/" | |
#add staging environment | |
run "cp config/environments/production.rb config/environments/staging.rb" | |
file 'app/models/user.rb', <<-CODE | |
class User < ActiveRecord::Base | |
acts_as_authentic | |
end | |
CODE | |
generate('model news_item title:string published_at:datetime published:boolean image_file_name:string image_content_type:string image_file_size:integer image_updated_at:datetime') | |
gsub_file 'app/models/news_item.rb', /(class NewsItem.*)/, "\\1\n has_attached_file :image, :styles => { :medium => \"300x300>\", :thumb => \"100x100>\", :tiny => \"60x40>\"}" | |
generate('admin_section news_items') | |
########### run tasks ################ | |
rake("db:migrate") if yes?("Migrate database (y,n) ?") | |
rakefile("createuser.rake") do | |
<<-TASK | |
namespace :create do | |
task :default_admin_user => :environment do | |
u = User.new | |
u.username = 'admin' | |
u.email = 'admin@admin.it' | |
u.password = 'admin' | |
u.password_confirmation = 'admin' | |
u.save | |
end | |
end | |
TASK | |
end | |
rake("create:default_admin_user") if yes?("Create admin user (y,n) ?") | |
############## commands ################# | |
run "curl -L http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js > public/javascripts/jquery.js" | |
run "touch tmp/.gitignore log/.gitignore vendor/.gitignore" | |
run %{find . -type d -empty | grep -v "vendor" | grep -v ".git" | grep -v "tmp" | xargs -I xxx touch xxx/.gitignore} | |
file '.gitignore', <<-END | |
.DS_Store | |
log/*.log | |
tmp/**/* | |
config/database.yml | |
db/*.sqlite3 | |
END | |
run "rm README" | |
run "rm public/index.html" | |
run "rm public/favicon.ico" | |
run "rm public/robots.txt" | |
########### git stuff ############# | |
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