/
fingertips.rb
181 lines (130 loc) · 5.07 KB
/
fingertips.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
# * Use plugins or gems?
# * Add an option which prepares the app for svn usage.
require 'fileutils'
TEMPLATE_HOME = ENV['TEMPLATE_HOME'] ||
'http://github.com/Fingertips/rails-template/raw/master/templates/'
class Rails::TemplateRunner
def name
File.basename(root)
end
def template_file(template)
contents = open(File.join(TEMPLATE_HOME, template)).read
contents.gsub!('{{app_name}}', name)
contents.gsub!('{{AppName}}', name.camelize)
file template, contents
end
end
def test_cache(dir)
if ENV['TEST_TEMPLATE'] && File.exist?(File.join('../vendor_cache', dir))
puts "[!] Using #{dir} cache..."
FileUtils.cp_r "../vendor_cache/#{dir}", "vendor"
else
yield
if ENV['TEST_TEMPLATE']
puts "[!] Creating #{dir} cache..."
FileUtils.mkdir_p "../vendor_cache"
FileUtils.cp_r "vendor/#{dir}", "../vendor_cache"
end
end
end
####
#
# Skeleton template
#
# Setup
template_file 'config/database.yml'
# Gems
environment "gem 'test-spec', :version => '~> 0.10.0', :lib => 'test/spec'", :env => :test
rake 'gems:install', :env => :test, :sudo => true
# Rails
test_cache 'rails' do
# On 2.3.4 the git command is broken as it only executes in_root
inside 'vendor' do
Git.run 'clone git://github.com/Fingertips/rails.git'
run 'cd rails && git remote add rails git://github.com/rails/rails.git'
end
end
# Plugins
test_cache 'plugins' do
plugin 'authentication-needed-san', :git => 'git://github.com/Fingertips/authentication-needed-san.git'
plugin 'authorization-san', :git => 'git://github.com/Fingertips/authorization-san.git'
plugin 'generator-san', :git => 'git://github.com/Fingertips/generator-san.git'
plugin 'on-test-spec', :git => 'git://github.com/Fingertips/on-test-spec.git'
plugin 'peiji-san', :git => 'git://github.com/Fingertips/peiji-san.git'
plugin 'risosu-san', :git => 'git://github.com/Fingertips/risosu-san.git'
plugin 'validates_email-san', :git => 'git://github.com/Fingertips/validates_email-san.git'
end
# Misc
template_file '.kick'
template_file 'Rakefile'
# Test
template_file 'test/test_helper.rb'
template_file 'test/ext/authentication.rb'
template_file 'test/ext/file_fixtures.rb'
template_file 'test/ext/time.rb'
# Lib
initializer 'core_ext.rb',
%{require 'active_record_ext'
ActiveRecord::Base.send(:extend, ActiveRecord::Ext)
ActiveRecord::Base.send(:include, ActiveRecord::BasicScopes)}
template_file 'lib/active_record_ext.rb'
template_file 'test/lib/active_record_ext_test.rb'
template_file 'lib/token.rb'
template_file 'test/lib/token_test.rb'
####
#
# Application template
#
initializer 'application.rb', %{SYSTEM_EMAIL_ADDRESS = '#{name.camelize} Support <support@example.com>'}
# Routes
# For some reason these routes are generated in the reversed order...
route 'map.root :controller => "members", :action => "new"'
route 'map.resource :session, :collection => { :clear => :get }'
route 'map.resources :passwords'
route 'map.resources :members'
# Models
generate :model_san, 'member role:string email:string hashed_password:string reset_password_token:string'
template_file 'app/models/member.rb'
template_file 'test/unit/member_test.rb'
template_file 'test/fixtures/members.yml'
template_file 'app/models/member/authentication.rb'
template_file 'test/unit/member/authentication_test.rb'
template_file 'app/models/mailer.rb'
template_file 'test/unit/mailer_test.rb'
# Controllers
initializer 'mime_types.rb', %{Mime::Type.register 'image/jpeg', :jpg}
template_file 'app/controllers/application_controller.rb'
template_file 'test/functional/application_controller_test.rb'
template_file 'app/controllers/members_controller.rb'
template_file 'test/functional/members_controller_test.rb'
template_file 'app/controllers/passwords_controller.rb'
template_file 'test/functional/passwords_controller_test.rb'
template_file 'app/controllers/sessions_controller.rb'
template_file 'test/functional/sessions_controller_test.rb'
# Helpers
template_file 'app/helpers/application_helper.rb'
template_file 'test/unit/helpers/application_helper_test.rb'
# Views
run 'rm public/index.html'
template_file 'public/403.html'
template_file 'public/stylesheets/default.css'
template_file 'public/stylesheets/reset.css'
template_file 'public/javascripts/ready.js'
template_file 'app/views/layouts/application.html.erb'
template_file 'app/views/layouts/_application_javascript_includes.html.erb'
template_file 'app/views/layouts/_head.html.erb'
template_file 'app/views/members/new.html.erb'
template_file 'app/views/members/show.html.erb'
template_file 'app/views/members/edit.html.erb'
template_file 'app/views/passwords/new.html.erb'
template_file 'app/views/passwords/sent.html.erb'
template_file 'app/views/passwords/edit.html.erb'
template_file 'app/views/passwords/reset.html.erb'
template_file 'app/views/sessions/new.html.erb'
template_file 'app/views/sessions/_form.html.erb'
template_file 'app/views/sessions/_status.html.erb'
template_file 'app/views/mailer/reset_password_message.erb'
# Finalize
rake 'db:create:all'
rake 'db:migrate'
exec 'rake test'