/
base.rb
224 lines (188 loc) · 6.01 KB
/
base.rb
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# use this for local installs
SOURCE=ENV['LOCAL'] || 'http://github.com/pixels-and-bits/strappy/raw/master'
def file_append(file, data)
File.open(file, 'a') {|f| f.write(data) }
end
def file_inject(file_name, sentinel, string, before_after=:after)
gsub_file file_name, /(#{Regexp.escape(sentinel)})/mi do |match|
if :after == before_after
"#{match}\n#{string}"
else
"#{string}\n#{match}"
end
end
end
# Git
file '.gitignore', open("#{SOURCE}/gitignore").read
git :init
git :add => '.gitignore'
run 'rm -f public/images/rails.png'
run 'cp config/database.yml config/database.template.yml'
git :add => "."
git :commit => "-a -m 'Initial commit'"
# Haml, doing this before gemtools install since we are using 2.1
if `gem list haml | grep 2.1.0`.chomp == ''
unless File.exist?('tmp/haml')
inside('tmp') do
run 'rm -rf ./haml' if File.exist?('haml')
run 'git clone git://github.com/nex3/haml.git'
end
end
inside('tmp/haml') do
run 'rake install'
end
end
run 'echo N\n | haml --rails .'
run 'mkdir -p public/stylesheets/sass'
%w( main reset ).each do |file|
file "public/stylesheets/sass/#{file}.sass",
open("#{SOURCE}/common/public/stylesheets/sass/#{file}.sass").read
end
git :add => "."
git :commit => "-a -m 'Added Haml and Sass stylesheets'"
# GemTools
file 'config/gems.yml', open("#{SOURCE}/common/config/gems.yml").read
run 'sudo gem install gem_tools --no-rdoc --no-ri'
run 'sudo gemtools install'
initializer 'gem_tools.rb', "require 'gem_tools'\nGemTools.load_gems"
git :add => "."
git :commit => "-a -m 'Added GemTools config'"
# CoreExtensions
# plugin 'core_extensions',
# :git => 'git@github.com:UnderpantsGnome/core_extensions.git'
# git :add => "."
# git :commit => "-a -m 'Added Core Extensions'"
# install strappy rake tasks
rakefile 'strappy.rake', open("#{SOURCE}/common/lib/tasks/strappy.rake").read
# RSpec
generate 'rspec'
file 'spec/rcov.opts', open("#{SOURCE}/common/spec/rcov.opts").read
git :add => "."
git :commit => "-a -m 'Added RSpec'"
# SiteConfig
file 'config/site.yml', open("#{SOURCE}/common/config/site.yml").read
lib 'site_config.rb', open("#{SOURCE}/common/lib/site_config.rb").read
git :add => "."
git :commit => "-a -m 'Added SiteConfig'"
# CC.rb
rakefile('cruise.rake') { open("#{SOURCE}/common/lib/tasks/cruise.rake").read }
git :add => "."
git :commit => "-a -m 'Added cruise rake task'"
# Capistrano
capify!
file 'config/deploy.rb', open("#{SOURCE}/common/config/deploy.rb").read
%w( production staging ).each do |env|
file "config/deploy/#{env}.rb", "set :rails_env, \"#{env}\""
end
inside('config/environments') do
run 'cp development.rb staging.rb'
end
git :add => "."
git :commit => "-a -m 'Added Capistrano config'"
# jRails
plugin 'jrails', :svn => 'http://ennerchi.googlecode.com/svn/trunk/plugins/jrails'
# remove the installed files, we're using a newer version below
inside('public/javascripts') do
%w(
jquery-ui.js
jquery.js
).each do |file|
run "rm -f #{file}"
end
end
git :add => "."
git :commit => "-a -m 'Added jRails plugin'"
# jQuery
# clean up prototype files
inside('public/javascripts') do
%w(
application.js
controls.js
dragdrop.js
effects.js
prototype.js
).each do |file|
run "rm -f #{file}"
end
end
file 'public/javascripts/jquery.js',
open('http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js').read
file 'public/javascripts/jquery.full.js',
open('http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.js').read
file 'public/javascripts/jquery-ui.js',
open('http://ajax.googleapis.com/ajax/libs/jqueryui/1.5/jquery-ui.min.js').read
file 'public/javascripts/jquery-ui.full.js',
open('http://ajax.googleapis.com/ajax/libs/jqueryui/1.5/jquery-ui.js').read
file 'public/javascripts/jquery.form.js',
open('http://jqueryjs.googlecode.com/svn/trunk/plugins/form/jquery.form.js').read
file "public/javascripts/application.js", <<-JS
$(function() {
});
JS
git :add => "."
git :commit => "-a -m 'Added jQuery with UI and form plugin'"
# Blackbird
run 'mkdir -p public/blackbird'
file 'public/blackbird/blackbird.js',
open('http://blackbirdjs.googlecode.com/svn/trunk/blackbird.js').read
file 'public/blackbird/blackbird.css',
open('http://blackbirdjs.googlecode.com/svn/trunk/blackbird.css').read
file 'public/blackbird/blackbird.png',
open('http://blackbirdjs.googlecode.com/svn/trunk/blackbird.png').read
git :add => "."
git :commit => "-a -m 'Added Blackbird'"
# Add ApplicationController
file 'app/controllers/application_controller.rb',
open("#{SOURCE}/common/app/controllers/application_controller.rb").read
git :add => "."
git :commit => "-a -m 'Added ApplicationController'"
# Add ApplicationHelper
file 'app/helpers/application_helper.rb',
open("#{SOURCE}/common/app/helpers/application_helper.rb").read
git :add => "."
git :commit => "-a -m 'Added ApplicationHelper'"
# Add Layout
file 'app/views/layouts/application.html.haml',
open("#{SOURCE}/common/app/views/layouts/application.html.haml").read
git :add => "."
git :commit => "-a -m 'Added Layout'"
# Remove index.html and add HomeController
git :rm => 'public/index.html'
generate :rspec_controller, 'home'
route "map.root :controller => 'home'"
file 'app/views/home/index.html.haml', '%h1 Welcome'
file "spec/views/home/index.html.haml_spec.rb",
open("#{SOURCE}/common/spec/views/home/index.html.haml_spec.rb").read
file "spec/controllers/home_controller_spec.rb",
open("#{SOURCE}/common/spec/controllers/home_controller_spec.rb").read
git :add => "."
git :commit => "-a -m 'Removed index.html. Added HomeController'"
# Setup Authentication
templ = case ask(<<-EOQ
Choose an Authentication method:
1) Authlogic
2) Clearance
3) restful_authentication
4) None of the above
EOQ
).to_s
when '1'
"#{SOURCE}/authlogic/base.rb"
when '2'
"#{SOURCE}/clearance/base.rb"
when '3'
"#{SOURCE}/restful_authentication/base.rb"
else
nil
end
if templ.nil?
else
load_template(templ)
end
puts "\n#{'*' * 80}\n\n"
unless @auth_message.nil?
puts "#{@auth_message}"
puts ''
end
puts "All done. Enjoy."
puts "\n#{'*' * 80}\n\n"