-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.rb
216 lines (177 loc) · 6.53 KB
/
template.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
def get_file(file)
get "#{template_url}/#{file}", file
end
def template_url
'https://github.com/stulzer/rails-template/raw/master'
end
run 'rm Gemfile app/views/layouts/application.html.erb app/helpers/application_helper.rb app/assets/stylesheets/application.css config/locales/en.yml config/database.yml'
initializer 'generators.rb', <<-CODE
module #{app_name.gsub(/-/, '_').camelize}
class Application < Rails::Application
config.generators do |g|
g.test_framework :rspec, fixture: false, views: false
g.fixture_replacement :factory_girl, dir: 'spec/factories'
end
end
end
CODE
initializer 'action_mailer.rb', <<-CODE
module #{app_name.gsub(/-/, '_').camelize}
class Application < Rails::Application
config.action_mailer.default_url_options = { host: 'localhost:3000' }
end
end
CODE
initializer 'internationalization.rb', <<-CODE
module #{app_name.gsub(/-/, '_').camelize}
class Application < Rails::Application
config.time_zone = 'Brasilia'
config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**/*.{rb,yml}').to_s]
config.i18n.enforce_available_locales = false
config.i18n.available_locales = [:en, :'pt-BR']
config.i18n.default_locale = :'pt-BR'
end
end
CODE
initializer 'asset_pipeline.rb', <<-CODE
module #{app_name.gsub(/-/, '_').camelize}
class Application < Rails::Application
config.assets.precompile += [ 'admin/module.js', 'admin/module.css', '.svg', '.eot', '.woff', '.ttf' ]
end
end
CODE
get_file 'Gemfile'
get_file 'config/database.yml'
# locales
get_file 'config/locales/en/rails.yml'
get_file 'config/locales/en/admin.yml'
get_file 'config/locales/en/app.yml'
get_file 'config/locales/en/devise.views.yml'
get_file 'config/locales/en/devise.yml'
get_file 'config/locales/pt-BR/rails.yml'
get_file 'config/locales/pt-BR/admin.yml'
get_file 'config/locales/pt-BR/app.yml'
get_file 'config/locales/pt-BR/devise.views.yml'
get_file 'config/locales/pt-BR/devise.yml'
# application layout and helper
get_file 'app/views/layouts/application.html.erb'
get_file 'app/helpers/application_helper.rb'
# error_messages_for
run 'mkdir -p app/views/shared'
get_file 'app/views/shared/_error_messages.html.erb'
# basic sass files
get_file 'app/assets/stylesheets/application/misc/_normalize.scss'
get_file 'app/assets/stylesheets/application/misc/_functions.scss'
get_file 'app/assets/stylesheets/application/misc/_mixins.scss'
get_file 'app/assets/stylesheets/application.css'
get_file 'app/assets/stylesheets/application/imports.scss'
# basic admin assets
get_file 'app/assets/stylesheets/admin/module.css.scss'
get_file 'app/assets/stylesheets/admin/misc/_vars.scss'
get_file 'app/assets/stylesheets/admin/misc/_normalize.scss'
get_file 'app/assets/stylesheets/admin/ui/_buttons.scss'
get_file 'app/assets/stylesheets/admin/ui/_confirmable.scss'
get_file 'app/assets/stylesheets/admin/ui/_forms.scss'
get_file 'app/assets/stylesheets/admin/ui/_header.scss'
get_file 'app/assets/stylesheets/admin/ui/_index.scss'
get_file 'app/assets/stylesheets/admin/ui/_markdown.scss'
get_file 'app/assets/stylesheets/admin/ui/_nav.scss'
get_file 'app/assets/stylesheets/admin/vendor/_avgrund.scss'
get_file 'app/assets/stylesheets/admin/vendor/_meny.scss'
get_file 'app/assets/javascripts/admin/avgrund.js'
get_file 'app/assets/javascripts/admin/bootstrap-markdown.js'
# basic admin views
run 'mkdir -p app/views/admin app/views/admin/passwords app/views/admin/sessions app/views/admin/admins app/views/admin/shared app/views/devise/mailer'
get_file 'app/views/admin/passwords/edit.html.erb'
get_file 'app/views/admin/passwords/new.html.erb'
get_file 'app/views/admin/sessions/new.html.erb'
get_file 'app/views/admin/shared/_links.erb'
get_file 'app/views/admin/shared/_modal_box.html.erb'
get_file 'app/views/devise/mailer/reset_password_instructions.html.erb'
get_file 'app/assets/javascripts/admin/module.js'
get_file 'app/assets/javascripts/admin/meny.js'
get_file 'app/views/layouts/admin.html.erb'
# basic admin controllers
run 'mkdir -p app/controllers/admin'
get_file 'app/controllers/admin/base_controller.rb'
get_file 'app/controllers/admin/passwords_controller.rb'
get_file 'app/controllers/admin/sessions_controller.rb'
get_file 'app/controllers/admin/unlocks_controller.rb'
# basic admin views
get_file 'app/controllers/admin/admins_controller.rb'
get_file 'app/views/admin/admins/index.html.erb'
get_file 'app/views/admin/admins/show.html.erb'
get_file 'app/views/admin/admins/new.html.erb'
get_file 'app/views/admin/admins/edit.html.erb'
get_file 'app/views/admin/admins/_form.html.erb'
get_file 'app/views/admin/admins/destroy.js.erb'
get_file 'app/views/admin/admins/confirm_destroy.js.erb'
# admin helper
get_file 'app/helpers/admin_helper.rb'
# basic js files
run 'rm app/assets/javascripts/application.js'
get_file 'app/assets/javascripts/application.js'
get_file 'app/assets/javascripts/dispatcher.js'
get_file 'app/assets/javascripts/jquery.validate.js'
run 'mkdir -p app/assets/javascripts/validate/localization'
get_file 'app/assets/javascripts/validate/localization/messages_pt_BR.js'
# bundling
run 'bundle install'
inject_into_file 'config/database.yml', after: 'port: 5432' do <<-CODE
development:
<<: *defaults
database: #{app_name.gsub(/-/, '_')}_development
test: &test
<<: *defaults
database: #{app_name.gsub(/-/, '_')}_test
CODE
end
# rspec
generate 'rspec:install'
# devise
generate 'devise:install'
# devise
generate 'devise admin'
# admin routes
inject_into_file 'config/routes.rb', after: 'devise_for :admins' do <<-'RUBY'
, controllers: {
sessions: 'admin/sessions',
passwords: 'admin/passwords',
unlocks: 'admin/unlocks'
}
namespace :admin do
resources :admins do
member do
get 'confirm_destroy'
end
end
root to: 'admins#index'
end
RUBY
end
# adding html responder
inject_into_file 'app/controllers/application_controller.rb', "
respond_to :html",
after: 'protect_from_forgery with: :exception'
# Improve README
get_file 'README.md_example'
run 'mv README.md_example README.md'
run 'rm README.rdoc'
# init guard
run 'bundle exec guard init livereload'
run 'mv spec/spec_helper.rb spec/.spec_helper_backup'
get_file 'spec/spec_helper.rb'
run 'mv spec/rails_helper.rb spec/.rails_helper_backup'
get_file 'spec/rails_helper.rb'
generate 'migration add_name_to_admins name'
run 'bundle binstubs rspec-core'
run 'bundle binstubs guard'
rake 'db:create'
rake 'db:migrate'
rake 'db:test:prepare'
# git
git :init
git add: '.'
git commit: %Q{ -m 'First commit' }
puts '=================================='
puts 'CHECK SPECS HELPERS spec/rails_helper.rb spec/rails_helper.rb'