myrails 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +74 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/myrails +3 -0
- data/bin/setup +8 -0
- data/lib/myrails/templates/assets/animate.scss +3340 -0
- data/lib/myrails/templates/assets/application.css.sass +6 -0
- data/lib/myrails/templates/assets/application.js +10 -0
- data/lib/myrails/templates/assets/bootstrap_themes/cerulean.scss +11 -0
- data/lib/myrails/templates/assets/bootstrap_themes/cosmo.scss +11 -0
- data/lib/myrails/templates/assets/bootstrap_themes/cyborg.scss +11 -0
- data/lib/myrails/templates/assets/bootstrap_themes/darkly.scss +11 -0
- data/lib/myrails/templates/assets/bootstrap_themes/flatly.scss +11 -0
- data/lib/myrails/templates/assets/bootstrap_themes/journal.scss +11 -0
- data/lib/myrails/templates/assets/bootstrap_themes/lumen.scss +11 -0
- data/lib/myrails/templates/assets/bootstrap_themes/paper.scss +11 -0
- data/lib/myrails/templates/assets/bootstrap_themes/readable.scss +11 -0
- data/lib/myrails/templates/assets/bootstrap_themes/sandstone.scss +11 -0
- data/lib/myrails/templates/assets/bootstrap_themes/simplex.scss +11 -0
- data/lib/myrails/templates/assets/bootstrap_themes/slate.scss +11 -0
- data/lib/myrails/templates/assets/bootstrap_themes/spacelab.scss +11 -0
- data/lib/myrails/templates/assets/bootstrap_themes/superhero.scss +11 -0
- data/lib/myrails/templates/assets/bootstrap_themes/united.scss +11 -0
- data/lib/myrails/templates/assets/bootstrap_themes/yeti.scss +11 -0
- data/lib/myrails/templates/assets/will_paginate.scss +104 -0
- data/lib/myrails/templates/db/mysql_database.yml +55 -0
- data/lib/myrails/templates/db/sqlite3_database.yml +28 -0
- data/lib/myrails/templates/heroku/Procfile +1 -0
- data/lib/myrails/templates/heroku/puma.rb +15 -0
- data/lib/myrails/templates/layout/_error_messages.html.haml +6 -0
- data/lib/myrails/templates/layout/_info_messages.html.haml +9 -0
- data/lib/myrails/templates/layout/_nav.html.haml +24 -0
- data/lib/myrails/templates/layout/_success_message.html.haml +3 -0
- data/lib/myrails/templates/layout/application.html.haml +14 -0
- data/lib/myrails/templates/layout/footers/css/footer-distributed-with-address-and-phones.scss +168 -0
- data/lib/myrails/templates/layout/footers/css/footer-distributed-with-contact-form.scss +200 -0
- data/lib/myrails/templates/layout/footers/css/footer-distributed-with-search.scss +140 -0
- data/lib/myrails/templates/layout/footers/css/footer-distributed.scss +74 -0
- data/lib/myrails/templates/layout/footers/footer-distributed-with-address-and-phones.html.haml +45 -0
- data/lib/myrails/templates/layout/footers/footer-distributed-with-contact-form.html.haml +33 -0
- data/lib/myrails/templates/layout/footers/footer-distributed-with-search.html.haml +19 -0
- data/lib/myrails/templates/layout/footers/footer-distributed.html.haml +24 -0
- data/lib/myrails/templates/mailer/dev_mail_interceptor.rb +27 -0
- data/lib/myrails/templates/mailer/sendgrid.rb +8 -0
- data/lib/myrails/templates/presenters/base.rb +33 -0
- data/lib/myrails/templates/presenters/presenter.rb +19 -0
- data/lib/myrails/templates/presenters/presenter_config.rb +4 -0
- data/lib/myrails/templates/presenters/presenter_spec.rb +17 -0
- data/lib/myrails/templates/rails/application_helper.rb +49 -0
- data/lib/myrails/templates/rails/controller.rb +12 -0
- data/lib/myrails/templates/rails/model.rb +2 -0
- data/lib/myrails/templates/rails/pundit.rb +26 -0
- data/lib/myrails/templates/rspec/controller.rb +98 -0
- data/lib/myrails/templates/rspec/database_cleaner.rb +18 -0
- data/lib/myrails/templates/rspec/devise.rb +38 -0
- data/lib/myrails/templates/rspec/factory.rb +5 -0
- data/lib/myrails/templates/rspec/factory_girl.rb +3 -0
- data/lib/myrails/templates/rspec/files.rb +3 -0
- data/lib/myrails/templates/rspec/javascript.rb +8 -0
- data/lib/myrails/templates/rspec/mailer.rb +7 -0
- data/lib/myrails/templates/rspec/model.rb +5 -0
- data/lib/myrails/templates/rspec/pundit.rb +28 -0
- data/lib/myrails/templates/rspec/pundit_matchers.rb +47 -0
- data/lib/myrails/templates/rspec/router.rb +7 -0
- data/lib/myrails/templates/rspec/shoulda_matchers.rb +16 -0
- data/lib/myrails/templates/rspec/silence_backtrace.rb +8 -0
- data/lib/myrails/templates/ui/index.html.haml +6 -0
- data/lib/myrails/templates/ui/ui_controller.rb +8 -0
- data/lib/myrails/version.rb +3 -0
- data/lib/myrails.rb +399 -0
- data/myrails.gemspec +37 -0
- data/spec/controllers/sam_controller_spec.rb +98 -0
- data/spec/myrails_spec.rb +11 -0
- data/spec/spec_helper.rb +2 -0
- metadata +197 -0
data/lib/myrails.rb
ADDED
@@ -0,0 +1,399 @@
|
|
1
|
+
require_relative "../lib/myrails/version"
|
2
|
+
require 'thor'
|
3
|
+
require 'active_support/all'
|
4
|
+
|
5
|
+
module Myrails
|
6
|
+
class Myrails < Thor
|
7
|
+
include Thor::Actions
|
8
|
+
source_root "#{__dir__}/myrails/templates"
|
9
|
+
TEMPLATES = source_root
|
10
|
+
ENVIRONMENTS = %w(development test production)
|
11
|
+
|
12
|
+
class_option :name
|
13
|
+
class_option :email
|
14
|
+
|
15
|
+
desc 'model --name=model-name', 'Generates and empty rails model with the given name and its related spec file'
|
16
|
+
option :name, required: true
|
17
|
+
def model
|
18
|
+
template 'rspec/model.rb', "spec/models/#{options[:name]}_spec.rb"
|
19
|
+
template 'rails/model.rb', "app/models/#{options[:name]}.rb"
|
20
|
+
end
|
21
|
+
|
22
|
+
desc 'controller --name=controller-name', 'Generate a rails controller with the given name along with boiler plate code and related spec filet'
|
23
|
+
option :name, required: true
|
24
|
+
def controller
|
25
|
+
template 'rails/controller.rb', "app/controllers/#{options[:name]}_controller.rb"
|
26
|
+
template 'rspec/controller.rb', "spec/controllers/#{options[:name]}_controller_spec.rb"
|
27
|
+
run "mkdir app/views/#{options[:name]}"
|
28
|
+
end
|
29
|
+
|
30
|
+
desc 'policy --name=policy-name', 'Generate a pundit policy with the given name and a related spec file'
|
31
|
+
option :name, required: true
|
32
|
+
def policy
|
33
|
+
template 'rails/pundit.rb', "app/policies/#{options[:name]}_policy.rb"
|
34
|
+
template 'rspec/pundit.rb', "spec/policies/#{options[:name]}_policy_spec.rb"
|
35
|
+
end
|
36
|
+
|
37
|
+
desc 'presenter --name=presenter-name', 'Generate a presenter class with the given name and a related spec file'
|
38
|
+
option :name, required: true
|
39
|
+
def presenters
|
40
|
+
copy_file 'presenters/base.rb', 'app/presenters/base_presenter.rb'
|
41
|
+
template 'presenters/presenter.rb', "app/presenters/#{options[:name]}_presenter.rb"
|
42
|
+
copy_file 'presenters/presenter_config.rb', 'spec/support/configs/presenter.rb'
|
43
|
+
template 'presenters/presenter_spec.rb', "spec/presenters/#{options[:name]}_presenter_spec.rb"
|
44
|
+
end
|
45
|
+
|
46
|
+
desc 'factory --name=factory-name', 'Generate a factory girl factory for use with rspec'
|
47
|
+
option :name, required: true
|
48
|
+
def factory
|
49
|
+
template 'rspec/factory.rb', "spec/factories/#{options[:name]}.rb"
|
50
|
+
end
|
51
|
+
|
52
|
+
desc 'application_helper_install', 'Replace current application helper with one that has commonly used code'
|
53
|
+
def application_helper_install
|
54
|
+
copy_file 'rails/application_helper.rb', 'app/helpers/application_helper.rb'
|
55
|
+
end
|
56
|
+
|
57
|
+
desc 'ui_install', 'Generate UI files and code for prototyping views in app/views/ui'
|
58
|
+
def ui_install
|
59
|
+
copy_file 'ui/ui_controller.rb', 'app/controllers/ui_controller.rb'
|
60
|
+
copy_file 'ui/index.html.haml', 'app/views/ui/index.html.haml'
|
61
|
+
inject_into_file 'config/routes.rb', after: "Rails.application.routes.draw do\n" do <<-CODE
|
62
|
+
# Requires an application restart everytime a new page is added.
|
63
|
+
Dir.glob('app/views/ui/*.html.haml').sort.each do |file|
|
64
|
+
action = File.basename(file,'.html.haml')
|
65
|
+
get "ui/#{action}", controller: 'ui', action: action
|
66
|
+
end
|
67
|
+
CODE
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
desc 'rspec_install', 'Generate rspec structure & rspec configuration that I commonly use'
|
72
|
+
def rspec_install
|
73
|
+
run 'rails g rspec:install'
|
74
|
+
copy_file 'rspec/database_cleaner.rb', "spec/support/configs/database_cleaner.rb"
|
75
|
+
copy_file 'rspec/factory_girl.rb', 'spec/support/configs/factory_girl.rb'
|
76
|
+
copy_file 'rspec/shoulda_matchers.rb', 'spec/support/configs/shoulda_matchers.rb'
|
77
|
+
copy_file 'rspec/silence_backtrace.rb', 'spec/support/configs/silence_rspec_backtrace.rb'
|
78
|
+
copy_file 'rspec/javascript.rb', 'spec/support/configs/javascript.rb'
|
79
|
+
copy_file 'rspec/mailer.rb', 'spec/support/configs/mailer.rb'
|
80
|
+
copy_file 'rspec/router.rb', 'spec/support/configs/router.rb'
|
81
|
+
copy_file 'rspec/files.rb', 'spec/support/configs/files.rb'
|
82
|
+
end
|
83
|
+
|
84
|
+
desc 'mailer_install --email=email@example.com', 'Generate sendgrid initializer and mail interceptor'
|
85
|
+
option :email, required: true
|
86
|
+
def mailer_install
|
87
|
+
copy_file 'mailer/sendgrid.rb', 'config/initializers/sendgrid.rb'
|
88
|
+
template 'mailer/dev_mail_interceptor.rb', 'app/mailers/dev_mail_interceptor.rb'
|
89
|
+
ENVIRONMENTS.each do |environment|
|
90
|
+
unless environment == 'production'
|
91
|
+
inject_into_file "config/environments/#{environment}.rb", after: "# config.action_view.raise_on_missing_translations = true\n" do <<-CODE
|
92
|
+
ActionMailer::Base.register_interceptor(DevMailInterceptor)
|
93
|
+
CODE
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
desc 'config_env --name=host-localhost:3000', 'Add code to environment files. Host refers to url options'
|
100
|
+
option :name, required: true
|
101
|
+
def config_env
|
102
|
+
ENVIRONMENTS.each do |environment|
|
103
|
+
if options[:name].nil?
|
104
|
+
say "Missing parameter: --name"
|
105
|
+
else
|
106
|
+
case environment
|
107
|
+
when 'development'
|
108
|
+
inject_into_file 'config/environments/development.rb', after: "config.action_mailer.raise_delivery_errors = false\n" do <<-CODE
|
109
|
+
config.action_mailer.delivery_method = :letter_opener
|
110
|
+
config.action_mailer.perform_deliveries = false
|
111
|
+
config.action_mailer.default_url_options = { host: 'http://#{options[:name]}.dev' }
|
112
|
+
config.action_controller.default_url_options = { host: 'http://#{options[:name]}.dev' }
|
113
|
+
CODE
|
114
|
+
end
|
115
|
+
when 'test'
|
116
|
+
inject_into_file 'config/environments/test.rb', after: "config.action_mailer.delivery_method = :test\n" do <<-CODE
|
117
|
+
config.action_mailer.default_url_options = { host: 'http://localhost:3000' }
|
118
|
+
config.action_controller.default_url_options = { host: 'http://localhost:3000' }
|
119
|
+
CODE
|
120
|
+
end
|
121
|
+
when 'production'
|
122
|
+
inject_into_file 'config/environments/production.rb', after: "config.active_record.dump_schema_after_migration = false\n" do <<-CODE
|
123
|
+
config.action_mailer.default_url_options = { host: '' }
|
124
|
+
config.action_controller.default_url_options = { host: '' }
|
125
|
+
config.assets.compile = true
|
126
|
+
CODE
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
desc 'rails_helper_install', 'Add code to rspec/rails_helper so rspec runs the way I like'
|
134
|
+
def rails_helper_install
|
135
|
+
inject_into_file "spec/rails_helper.rb", after: "require 'rspec/rails'\n" do <<-CODE
|
136
|
+
require 'simplecov'
|
137
|
+
SimpleCov.start
|
138
|
+
#use Chromedriver
|
139
|
+
unless ENV['NOCHROME']
|
140
|
+
Capybara.register_driver :selenium do |app|
|
141
|
+
Capybara::Selenium::Driver.new(app, :browser => :chrome)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
CODE
|
145
|
+
end
|
146
|
+
|
147
|
+
gsub_file 'spec/rails_helper.rb', "# Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }", "Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }"
|
148
|
+
|
149
|
+
gsub_file "spec/rails_helper.rb", "config.use_transactional_fixtures = true", "config.use_transactional_fixtures = false"
|
150
|
+
|
151
|
+
inject_into_file 'spec/rails_helper.rb', after: "RSpec.configure do |config|\n" do <<-CODE
|
152
|
+
config.include(JavascriptHelper, type: :feature)
|
153
|
+
CODE
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
desc 'devise_install', 'Generate devise files'
|
158
|
+
def devise_install
|
159
|
+
insert_into_file 'Gemfile', after: "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n" do <<-CODE
|
160
|
+
gem 'devise', '~> 4.2.0'
|
161
|
+
CODE
|
162
|
+
end
|
163
|
+
run 'bundle update'
|
164
|
+
copy_file 'rspec/devise.rb', 'spec/support/configs/devise.rb'
|
165
|
+
|
166
|
+
devise_model = ask("What would you like to call the devise model? Default: user")
|
167
|
+
devise_model = devise_model.empty? ? 'user' : devise_model
|
168
|
+
run 'rails generate devise:install'
|
169
|
+
run 'rake db:migrate'
|
170
|
+
run "rails generate devise #{devise_model}"
|
171
|
+
run 'rails generate devise:views'
|
172
|
+
|
173
|
+
inject_into_file 'app/controllers/application_controller.rb', before: 'protect_from_forgery with: :exception' do <<-CODE
|
174
|
+
# Devise authentication method
|
175
|
+
before_action :authenticate_#{devise_model}!
|
176
|
+
CODE
|
177
|
+
end
|
178
|
+
|
179
|
+
if File.exist?('app/controllers/ui_controller.rb')
|
180
|
+
inject_into_file 'app/controllers/ui_controller.rb', after: "class UiController < ApplicationController\n" do <<-CODE
|
181
|
+
skip_before_action :authenticate_#{devise_model}!
|
182
|
+
CODE
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
if yes?('Will you be needing registration params override? Answer "yes" if you will be adding attributes to the user model')
|
187
|
+
inject_into_file 'app/controllers/application_controller.rb', after: "skip_before_action :authenticate_#{devise_model}!\n" do <<-CODE
|
188
|
+
# Before action include additional registration params
|
189
|
+
# (see #configure_permitted_parameters)
|
190
|
+
before_action :configure_permitted_parameters, if: :devise_controller?
|
191
|
+
CODE
|
192
|
+
end
|
193
|
+
|
194
|
+
inject_into_file 'app/controllers/application_controller.rb', after: "private\n" do <<-CODE
|
195
|
+
# Register additional registration params
|
196
|
+
def configure_permitted_parameters
|
197
|
+
devise_parameter_sanitizer.permit(:sign_up, keys: [:attribute, :attribute])
|
198
|
+
end
|
199
|
+
CODE
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
desc 'pundit_install', 'Install pundit gem and generate pundit files and application controller code'
|
205
|
+
def pundit_install
|
206
|
+
insert_into_file 'Gemfile', after: "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n" do <<-CODE
|
207
|
+
gem 'pundit'
|
208
|
+
CODE
|
209
|
+
end
|
210
|
+
|
211
|
+
insert_into_file 'Gemfile', before: "group :development, :test do" do <<-CODE
|
212
|
+
gem 'pundit-matchers', '~> 1.1.0'
|
213
|
+
CODE
|
214
|
+
end
|
215
|
+
|
216
|
+
run 'bundle update'
|
217
|
+
run 'rails g pundit:install'
|
218
|
+
|
219
|
+
inject_into_file 'app/controllers/application_controller.rb', before: '# Prevent CSRF attacks by raising an exception.' do <<-CODE
|
220
|
+
# Add pundit authorization
|
221
|
+
include Pundit
|
222
|
+
CODE
|
223
|
+
end
|
224
|
+
|
225
|
+
inject_into_file 'app/controllers/application_controller.rb', after: "protect_from_forgery with: :exception\n" do <<-CODE
|
226
|
+
# Rescue from pundit error
|
227
|
+
# (see #user_not_authorized)
|
228
|
+
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
|
229
|
+
CODE
|
230
|
+
end
|
231
|
+
|
232
|
+
inject_into_file 'app/controllers/application_controller.rb', after: "private\n" do <<-CODE
|
233
|
+
# Method to gracefully let a user know they are are not authorized
|
234
|
+
#
|
235
|
+
# @return flash [Hash] the action notice
|
236
|
+
def user_not_authorized
|
237
|
+
flash[:alert] = "You are not authorized to perform this action."
|
238
|
+
redirect_to home_path
|
239
|
+
end
|
240
|
+
CODE
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
desc 'footnotes_install', 'Install rails-footnotes and run its generator'
|
245
|
+
def footnotes_install
|
246
|
+
insert_into_file 'Gemfile', after: "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n" do <<-CODE
|
247
|
+
gem 'rails-footnotes'
|
248
|
+
CODE
|
249
|
+
end
|
250
|
+
run 'bundle install'
|
251
|
+
run 'rails generate rails_footnotes:install'
|
252
|
+
end
|
253
|
+
|
254
|
+
desc 'gems_install', 'Add & Install gems that I commonly use'
|
255
|
+
def gems_install
|
256
|
+
insert_into_file 'Gemfile', before: "group :development, :test do" do <<-CODE
|
257
|
+
group :test do
|
258
|
+
gem 'rspec-rails'
|
259
|
+
gem 'simplecov'
|
260
|
+
gem 'shoulda-matchers'
|
261
|
+
gem 'factory_girl_rails'
|
262
|
+
gem 'database_cleaner'
|
263
|
+
gem 'capybara'
|
264
|
+
gem 'selenium-webdriver'
|
265
|
+
gem 'chromedriver-helper'
|
266
|
+
gem 'launchy'
|
267
|
+
gem 'rails-controller-testing'
|
268
|
+
end
|
269
|
+
|
270
|
+
CODE
|
271
|
+
end
|
272
|
+
|
273
|
+
insert_into_file 'Gemfile', after: "group :development, :test do\n" do <<-CODE
|
274
|
+
gem 'faker'
|
275
|
+
gem 'yard'
|
276
|
+
gem 'letter_opener'
|
277
|
+
gem "rails-erd"
|
278
|
+
CODE
|
279
|
+
end
|
280
|
+
|
281
|
+
insert_into_file 'Gemfile', after: "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n" do <<-CODE
|
282
|
+
gem 'node'
|
283
|
+
gem 'bootstrap-sass', '~> 3.3.1'
|
284
|
+
gem 'autoprefixer-rails'
|
285
|
+
gem 'haml-rails'
|
286
|
+
gem "ransack"
|
287
|
+
gem 'will_paginate'
|
288
|
+
gem "font-awesome-rails"
|
289
|
+
gem 'trix'
|
290
|
+
gem 'record_tag_helper'
|
291
|
+
CODE
|
292
|
+
end
|
293
|
+
run 'bundle install'
|
294
|
+
|
295
|
+
insert_into_file 'app/controllers/application_controller.rb', before: 'end' do <<-CODE
|
296
|
+
private
|
297
|
+
CODE
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
desc 'assets_install', 'Generate common asset pipeline files'
|
302
|
+
def assets_install
|
303
|
+
run "rm app/assets/stylesheets/application.css"
|
304
|
+
copy_file 'assets/application.css.sass', 'app/assets/stylesheets/application.css.sass'
|
305
|
+
copy_file 'assets/application.js', 'app/assets/javascripts/application.js'
|
306
|
+
copy_file 'assets/animate.scss', 'app/assets/stylesheets/animate.scss'
|
307
|
+
copy_file 'assets/will_paginate.scss', 'app/assets/stylesheets/will_paginate.scss'
|
308
|
+
end
|
309
|
+
|
310
|
+
|
311
|
+
desc 'css_install', 'Generate & include application css theme'
|
312
|
+
def css_install
|
313
|
+
themes = Dir[File.join(TEMPLATES, 'assets', 'bootstrap_themes', '*')]
|
314
|
+
|
315
|
+
themes.each_with_index do |theme, index|
|
316
|
+
say "[#{index}] #{File.basename(theme,'.*')}"
|
317
|
+
end
|
318
|
+
|
319
|
+
idx = ask("Choose a color theme (by number) for the application. Default: 'spacelab'")
|
320
|
+
idx = idx.empty? ? themes.index{|theme| theme if theme.include?('spacelab')} : idx.to_i
|
321
|
+
copy_file(themes[idx], "app/assets/stylesheets/#{File.basename(themes[idx])}")
|
322
|
+
|
323
|
+
inject_into_file 'app/assets/stylesheets/application.css.sass', before: "@import will_paginate" do <<-CODE
|
324
|
+
@import #{File.basename(themes[idx], '.*')}
|
325
|
+
CODE
|
326
|
+
end
|
327
|
+
end
|
328
|
+
|
329
|
+
desc 'footer_install', 'Generate & include application footer'
|
330
|
+
def footer_install
|
331
|
+
footers = Dir[File.join(TEMPLATES, 'layout', 'footers', '*.haml')]
|
332
|
+
footers_css = Dir[File.join(TEMPLATES, 'layout', 'footers', 'css', '*')]
|
333
|
+
|
334
|
+
footers.each_with_index do |footer, index|
|
335
|
+
say "[#{index}] #{File.basename(footer,'.html.*')}"
|
336
|
+
end
|
337
|
+
|
338
|
+
idx = ask("Chose a footer theme (by number) for the application. Deault: 'footer-distributed (Basic)'")
|
339
|
+
idx = idx.empty? ? footers.index{|footer| footer if footer.include?('footer-distributed.html.haml')} : idx.to_i
|
340
|
+
copy_file footers[idx], "app/views/layouts/_footer.html.haml"
|
341
|
+
copy_file footers_css[idx], "app/assets/stylesheets/#{File.basename(footers_css[idx])}"
|
342
|
+
|
343
|
+
inject_into_file 'app/assets/stylesheets/application.css.sass', after: "@import animate\n" do <<-CODE
|
344
|
+
@import #{File.basename(footers_css[idx], '.*')}
|
345
|
+
CODE
|
346
|
+
end
|
347
|
+
end
|
348
|
+
|
349
|
+
desc 'layout_install', 'Generate common layout files'
|
350
|
+
def layout_install
|
351
|
+
run 'rm app/views/layouts/application.html.erb'
|
352
|
+
template 'layout/application.html.haml', 'app/views/layouts/application.html.haml'
|
353
|
+
template 'layout/_nav.html.haml', 'app/views/layouts/_nav.html.haml'
|
354
|
+
copy_file 'layout/_info_messages.html.haml', 'app/views/layouts/_info_messages.html.haml'
|
355
|
+
copy_file 'layout/_success_message.html.haml', 'app/views/layouts/_success_message.html.haml'
|
356
|
+
copy_file 'layout/_error_messages.html.haml', 'app/views/layouts/_error_messages.html.haml'
|
357
|
+
end
|
358
|
+
|
359
|
+
desc 'heroku_install', 'setup application for use with heroku using sqlite3 for development'
|
360
|
+
def heroku_install
|
361
|
+
insert_into_file 'Gemfile', before: "group :development, :test do\n" do <<-CODE
|
362
|
+
group :production do
|
363
|
+
gem 'pg'
|
364
|
+
gem 'rails_12factor'
|
365
|
+
end
|
366
|
+
|
367
|
+
CODE
|
368
|
+
end
|
369
|
+
copy_file 'db/sqlite3_database.yml', 'config/database.yml'
|
370
|
+
copy_file 'heroku/Procfile', 'Procfile'
|
371
|
+
copy_file 'heroku/puma.rb', 'config/puma.rb'
|
372
|
+
end
|
373
|
+
|
374
|
+
desc 'git_init', "Initialize git with some files autormoatically ignored"
|
375
|
+
def git_init
|
376
|
+
run 'git init'
|
377
|
+
run 'echo /coverage >> .gitignore'
|
378
|
+
run 'echo /config/application.yml >> .gitignore'
|
379
|
+
run 'git add --all'
|
380
|
+
run "git commit -m 'initial commit'"
|
381
|
+
end
|
382
|
+
|
383
|
+
desc 'mysql_switch', 'Switch to mysql database'
|
384
|
+
def mysql_switch
|
385
|
+
gsub_file 'Gemfile', "gem 'sqlite3'", "gem 'mysql2', '>= 0.3.13', '< 0.5'"
|
386
|
+
run 'bundle install'
|
387
|
+
copy_file 'db/mysql_database.yml', 'config/database.yml'
|
388
|
+
end
|
389
|
+
|
390
|
+
desc 'new_ui NAME', 'Create a new ui view'
|
391
|
+
option :name, required: true
|
392
|
+
def new_ui(name)
|
393
|
+
run "touch app/views/ui/#{name}.html.haml"
|
394
|
+
say "DON'T FORGET: Restart Powify App"
|
395
|
+
end
|
396
|
+
end
|
397
|
+
end
|
398
|
+
|
399
|
+
Myrails::Myrails.start(ARGV)
|
data/myrails.gemspec
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'myrails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "myrails"
|
8
|
+
spec.version = Myrails::VERSION
|
9
|
+
spec.authors = ["Vell"]
|
10
|
+
spec.email = ["lovell.mcilwain@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A thor backed generator for generating rails related files based on my style of coding}
|
13
|
+
spec.description = %q{Generates files with with boiler plate code. Supports pundit, presenters, installing of themes from bootswatch and others.}
|
14
|
+
spec.homepage = "https://github.com/vmcilwain/myrails"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = Dir["{bin,lib}/**/*", "LICENSE.txt", "README.md", 'Rakefile', 'Gemfile', 'myrails.gemspec']
|
27
|
+
spec.test_files = Dir["spec/**/*"]
|
28
|
+
spec.bindir = "bin"
|
29
|
+
spec.executables = ['myrails']
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
33
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
34
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
35
|
+
spec.add_dependency 'activesupport', '~> 5.0.0.1'
|
36
|
+
spec.add_dependency 'thor', '~> 0.19.1'
|
37
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
# Does this controller require authentication?
|
4
|
+
describe SamController do
|
5
|
+
# let(:user) {create :user}
|
6
|
+
let(:sams) {[]}
|
7
|
+
let(:sam) {create :sam}
|
8
|
+
|
9
|
+
# before {sign_in user}
|
10
|
+
|
11
|
+
describe 'GET index' do
|
12
|
+
before do
|
13
|
+
3.times {sams << create(:sam)}
|
14
|
+
get :index
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'sets @sams' do
|
18
|
+
expect(assigns[:sams]).to eq sams
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'GET show' do
|
23
|
+
before {get :show, params: {id: sam.id}}
|
24
|
+
|
25
|
+
it 'sets @sam' do
|
26
|
+
expect(assigns[:sam]).to eq sam
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'GET new' do
|
31
|
+
before {get :new}
|
32
|
+
|
33
|
+
it 'sets @sam' do
|
34
|
+
expect(assigns[:sam]).to be_a_new Sam
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'POST create' do
|
39
|
+
context 'successful create' do
|
40
|
+
before {post :create, params: {sam: attributes_for(:sam)}}
|
41
|
+
|
42
|
+
subject(:s){assigns[:sam]}
|
43
|
+
|
44
|
+
it 'redirects to :show'
|
45
|
+
it 'sets @sam'
|
46
|
+
it 'sets flash[:success]'
|
47
|
+
it 'tags the current_user as creator'
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'unsuccessful create' do
|
51
|
+
before {post :create, params: {sam: attributes_for(:sam, attr: nil)}}
|
52
|
+
|
53
|
+
it 'renders :new template'
|
54
|
+
it 'sets @sam'
|
55
|
+
it 'sets flash[:error]'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe 'GET edit' do
|
60
|
+
before {get :edit, params: {id: sam.id}}
|
61
|
+
|
62
|
+
it 'sets @sam' do
|
63
|
+
expect(assigns[:sam]).to eq sam
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe 'PUT/PATCH update' do
|
68
|
+
context 'successful update' do
|
69
|
+
before {put :update, params: {id: sam.id, sam: attributes_for(:sam)}}
|
70
|
+
|
71
|
+
subject(:s) {assigns[:sam]}
|
72
|
+
|
73
|
+
it 'redirects to :show'
|
74
|
+
it 'sets @sam'
|
75
|
+
it 'sets flash[:success]'
|
76
|
+
it 'tags current_user as updater'
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'unsuccessful update' do
|
80
|
+
before {put :update, params: {id: sam.id, sam: attributes_for(:sam, attr: nil)}}
|
81
|
+
|
82
|
+
it 'renders :edit template'
|
83
|
+
it 'sets @sam'
|
84
|
+
it 'sets flash[:error]'
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe 'DELETE destroy' do
|
89
|
+
before {delete :destroy, params: {id: sam.id}}
|
90
|
+
|
91
|
+
it 'redirects to :index' do
|
92
|
+
expect(response).to redirect_to sams_path
|
93
|
+
end
|
94
|
+
it 'sets @sam'
|
95
|
+
it 'deletes @sam'
|
96
|
+
it 'sets flash[success]'
|
97
|
+
end
|
98
|
+
end
|
data/spec/spec_helper.rb
ADDED