Sutto / rails-template forked from imajes/rails-template

based on the awesome rg by mrn

This URL has Read+Write access

rails-template / rails_template.rb
100644 185 lines (150 sloc) 6.316 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# Darcy's Rails Template, based off Peter Cooper's Template
# and James Cox's fork. Using some code from:
# * http://github.com/lackac/app_lego/tree
 
require 'open-uri'
 
GITHUB_USER = "Sutto"
 
def download(from, to = from.split("/").last)
  file to, open(from).read
rescue Exception => e
  puts "Frak me - No internets (#{e.message})"
  exit!
end
 
def from_repo(from, to = from.split("/").last)
  download("http://github.com/#{GITHUB_USER}/rails-template/raw/master/#{from}", to)
end
 
def commit_state(comment)
  git :add => "."
  git :commit => "-am '#{comment}'"
end
 
####################
# Base Application #
####################
 
# Delete unnecessary files
run "rm README"
run "rm public/index.html"
run "rm public/favicon.ico"
run "rm public/robots.txt"
run "rm public/images/rails.png"
run "rm -f public/javascripts/*"
 
# Move the database config
run "cp config/database.yml config/database.yml.example"
 
# Git ignore Setup
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}
from_repo "raw_gitignore", ".gitignore"
 
git :init
commit_state "Added base / rough application"
 
######################
# View Related Stuff #
######################
 
# Download JQuery
run "mkdir -p public/javascripts/jquery"
download "http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js", "public/javascripts/jquery/jquery.min.js"
 
commit_state "jQuery Base"
 
##################################
# Adding the initial set of gems #
#################################
 
# Layout / View related stuff
gem 'mislav-will_paginate', :version => '>= 2.2.3', :lib => 'will_paginate', :source => 'http://gems.github.com'
gem 'chriseppstein-compass', :lib => 'compass', :source => 'http://gems.github.com'
# Testing stuff
gem "thoughtbot-shoulda", :lib => "shoulda", :source => 'http://gems.github.com'
gem "rr"
# General
gem "searchlogic"
gem "justinfrench-formtastic", :lib => 'formtastic', :source => 'http://gems.github.com'
 
commit_state "Added gems to the app"
 
###########################
# Initialize HAML / Rails #
###########################
 
run "haml --rails ."
run "echo -e 'y\nn\n' | compass --rails ."
run "mkdir -p public/stylesheets/960"
%w(text reset 960).each do |file|
  from_repo "#{file}.css", "public/stylesheets/960/#{file}.css"
end
file "app/stylesheets/screen.sass", "@import compass/utilities.sass\n@import util.sass\n"
from_repo "_util.sass", "app/stylesheets/_util.sass"
 
commit_state "Initialize Haml and Compass"
 
######################################
# Install all of the default plugins #
######################################
 
plugin "paperclip", :git => "git://github.com/thoughtbot/paperclip.git" # Can has br0kedness.
plugin "machinist", :git => "git://github.com/notahat/machinist.git"
plugin "forgery", :git => "git://github.com/sevenwire/forgery.git"
plugin "state_machine", :git => "git://github.com/pluginaweek/state_machine.git"
if yes?("do you anticipate needing background tasks?")
  plugin :git => "git://github.com/tobi/delayed_job.git"
end
plugin "nh-toolkit", :git => "git://github.com/Sutto/ninjahideout-toolkit.git"
 
commit_state "Added plugins"
 
##################################
# Initialize the Settings Plugin #
##################################
 
file "config/site.yml",<<-END
default:
site_name: Some Site
END
 
commit_state "Set up default site settings"
 
###############################
# Setup the default templates #
###############################
 
run "mkdir -p app/views/shared"
 
from_repo "application.html.haml", "app/views/layouts/application.html.haml"
from_repo "header.html.haml", "app/views/shared/_header.html.haml"
from_repo "footer.html.haml", "app/views/shared/_footer.html.haml"
from_repo "app_controller.rb", "app/controllers/application_controller.rb"
run "mkdir -p test/blueprints"
from_repo "test_helper.rb", "test/test_helper.rb"
from_repo "user_blueprint.rb", "test/blueprints/user_blueprint.rb"
commit_state "added default layout"
 
########################################
# Generates a user, controller + views #
########################################
 
if yes?("Would you like authentication?")
  gem "authlogic"
  generate :controller, "Users"
  generate :controller, "UserSessions"
  # Controllers
  from_repo "auth/users_controller.rb", "app/controllers/users_controller.rb"
  from_repo "auth/user_sessions_controller.rb", "app/controllers/user_sessions_controller.rb"
  # Views
  %w(_form edit new).each do |name|
    from_repo "auth/users.#{name}.html.haml", "app/views/users/#{name}.html.haml"
  end
  from_repo "auth/login.html.haml", "app/views/user_sessions/new.html.haml"
  # Routes
  route "map.resources :users"
  route "map.resource :user_session"
  # Models
  generate :session, "UserSession"
  fields = [
    "login:string", "crypted_password:string", "password_salt:string",
    "persistence_token:string", "single_access_token:string", "perishable_token:string",
    "login_count:integer", "last_request_at:datetime", "current_login_at:datetime",
    "last_login_at:datetime", "current_login_ip:string", "last_login_ip:string",
    "display_name:string", "created_at:datetime", "updated_at:datetime", "type:string", "slug:string"
  ]
  generate :model, "User", fields.join(" ")
  from_repo "auth/user.rb", "app/models/user.rb"
  from_repo "auth/user_session.rb", "app/models/user_session.rb"
  commit_state "Added basic authorization stuff"
end
 
##################################################
# If the user says to, add a default index site. #
##################################################
 
if yes?("Would you like to generate a default index?")
  controller = "class SiteController < ApplicationController\n\n def index\n page_is 'Welcome'\n end\n\nend\n"
  # Actually do the work
  generate :controller, "Site"
  route "map.root :controller => 'site'"
  file "app/views/site/index.html.haml", "%h2== Welcome to \#{Settings.site_name}\n"
  file "app/controllers/site_controller.rb", controller
  commit_state "Added a default site controller"
end
 
################################
# Finally, Run rake db migrate #
################################
 
rake "db:migrate"
rake "gems:unpack"
 
commit_state "Unpacked and migrated"