myrails 5.0.0 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,13 @@
1
+ module Install
2
+ module ApplicationHelper
3
+ def self.included(thor)
4
+ thor.class_eval do
5
+
6
+ def install_application_helper
7
+ copy_file 'rails/app/helpers/application_helper.rb', 'app/helpers/application_helper.rb'
8
+ end
9
+
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ module Install
2
+ module Assets
3
+ def self.included(thor)
4
+ thor.class_eval do
5
+
6
+ def install_assets
7
+ run "rm app/assets/stylesheets/application.css"
8
+ copy_file 'rails/app/assets/stylesheets/application.css.sass', 'app/assets/stylesheets/application.css.sass'
9
+ copy_file 'rails/app/assets/javascripts/application.js', 'app/assets/javascripts/application.js'
10
+ copy_file 'rails/app/assets/stylesheets/animate.scss', 'app/assets/stylesheets/animate.scss'
11
+ copy_file 'rails/app/assets/stylesheets/will_paginate.scss', 'app/assets/stylesheets/will_paginate.scss'
12
+ end
13
+
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,80 @@
1
+ module Layout
2
+ module Bootstrap
3
+ def self.included(thor)
4
+ thor.class_eval do
5
+ def choose_bootstrap_theme
6
+ themes = Dir[File.join(@templates, 'rails', 'app','assets', 'stylesheets', 'bootstrap', 'bootstrap_themes', '*')]
7
+
8
+ themes.each_with_index do |theme, index|
9
+ say "[#{index}] #{File.basename(theme,'.*')}"
10
+ end
11
+
12
+ idx = ask("Choose a color theme (by number) for the application. Default: 'spacelab'")
13
+ idx = idx.empty? ? themes.index{|theme| theme if theme.include?('spacelab')} : idx.to_i
14
+
15
+ copy_file(themes[idx], "app/assets/stylesheets/#{File.basename(themes[idx])}")
16
+
17
+ inject_into_file 'app/assets/stylesheets/application.css.sass', before: "@import will_paginate" do <<-CODE
18
+ @import #{File.basename(themes[idx], '.*')}
19
+ CODE
20
+ end
21
+ end
22
+
23
+ def choose_bootstrap_footer
24
+ footers = Dir[File.join(@templates, 'rails', 'app', 'views','layout', 'bootstrap', 'footers', '*.haml')]
25
+ footers_css = Dir[File.join(@templates, 'rails', 'app', 'views', 'layout', 'bootstrap', 'footers', 'css', '*')]
26
+
27
+ footers.each_with_index do |footer, index|
28
+ say "[#{index}] #{File.basename(footer,'.html.*')}"
29
+ end
30
+
31
+ idx = ask("Chose a footer theme (by number) for the application. Deault: 'footer-distributed (Basic)'")
32
+ idx = idx.empty? ? footers.index{|footer| footer if footer.include?('footer-distributed.html.haml')} : idx.to_i
33
+ copy_file footers[idx], "app/views/layouts/_footer.html.haml"
34
+ copy_file footers_css[idx], "app/assets/stylesheets/#{File.basename(footers_css[idx])}"
35
+
36
+ inject_into_file 'app/assets/stylesheets/application.css.sass', after: "@import animate\n" do <<-CODE
37
+ @import #{File.basename(footers_css[idx], '.*')}
38
+ CODE
39
+ end
40
+ end
41
+
42
+ def copy_bootstrap_files
43
+ template 'rails/app/views/layout/bootstrap/application.html.haml', 'app/views/layouts/application.html.haml'
44
+ template 'rails/app/views/layout/bootstrap/_nav.html.haml', 'app/views/layouts/_nav.html.haml'
45
+ copy_file 'rails/app/views/layout/bootstrap/_info_messages.html.haml', 'app/views/layouts/_info_messages.html.haml'
46
+ copy_file 'rails/app/views/layout/bootstrap/_success_message.html.haml', 'app/views/layouts/_success_message.html.haml'
47
+ copy_file 'rails/app/views/layout/bootstrap/_error_messages.html.haml', 'app/views/layouts/_error_messages.html.haml'
48
+ # copy_file 'rails/app/views/layout/bootstrap/_footer.html.haml', 'app/views/layouts/_footer.html.haml'
49
+ end
50
+
51
+ desc 'install_bootstrap', 'Generate Bootrap css theme'
52
+ def install_bootstrap
53
+ @templates = "#{__dir__}/../templates"
54
+
55
+ insert_into_file 'Gemfile', after: "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n" do <<-CODE
56
+ gem 'bootstrap-sass', '~> 3.3.1'
57
+ gem 'autoprefixer-rails'
58
+ CODE
59
+ end
60
+
61
+ insert_into_file 'app/assets/stylesheets/application.css.sass', before: '@import trix' do <<-CODE
62
+ @import bootstrap-sprockets
63
+ @import bootstrap
64
+ CODE
65
+ end
66
+
67
+ insert_into_file 'app/assets/javascripts/application.js', before: '//= require trix' do <<-CODE
68
+ //= require bootstrap-sprockets
69
+ CODE
70
+ end
71
+ run 'bundle install'
72
+ choose_bootstrap_theme
73
+ choose_bootstrap_footer
74
+ copy_bootstrap_files
75
+
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,110 @@
1
+ module Install
2
+ module Capistrano
3
+ def self.included(thor)
4
+ thor.class_eval do
5
+
6
+ def add_capistrano_gems
7
+ insert_into_file 'Gemfile', after: "group :development do\n" do <<-CODE
8
+ gem 'capistrano', '~> 3.6', group: :development
9
+ gem 'capistrano-rails', '~> 1.3', group: :development
10
+ gem 'capistrano-rvm', group: :development
11
+ CODE
12
+ end
13
+
14
+ run 'bundle install'
15
+ end
16
+
17
+ def configure_capfile
18
+ gsub_file 'Capfile', '# require "capistrano/rvm"', 'require "capistrano/rvm"'
19
+
20
+ insert_into_file 'Capfile', after: "require \"capistrano/rvm\"\n" do <<-CODE
21
+ require "capistrano/rails"
22
+ CODE
23
+ end
24
+ end
25
+
26
+ def configure_deploy
27
+ gsub_file 'config/deploy.rb', '# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp', 'ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp'
28
+ gsub_file 'config/deploy.rb', '# set :deploy_to, "/var/www/my_app_name"', 'set :deploy_to, "/var/www/#{fetch(:application)}"'
29
+ gsub_file 'config/deploy.rb', '# append :linked_dirs, "log", "tmp/pids", "tmp/cache", "tmp/sockets", "public/system"', 'append :linked_dirs, "log", "tmp/pids", "tmp/cache", "tmp/sockets", "public/system"'
30
+
31
+ insert_into_file 'config/deploy.rb', before: '# Default branch is :master' do <<-CODE
32
+ set :deploy_via, :remote_cache
33
+ set :ssh_options, {forward_agent: true}
34
+ CODE
35
+ end
36
+ end
37
+
38
+ def copy_templates
39
+ puts __dir__
40
+ Dir["#{__dir__}/../templates/capistrano/**/*"].each do |file|
41
+ puts file
42
+ copy_file file, "#{file.gsub(__dir__+'/../templates/capistrano/', '')}" unless File.directory? file
43
+ end
44
+ end
45
+
46
+ def configure_env_files
47
+ insert_into_file 'config/deploy/production.rb', before: "# role-based syntax" do <<-CODE
48
+ set :fqdn,'domain.com'
49
+ CODE
50
+ end
51
+
52
+ insert_into_file 'config/deploy/staging.rb', before: "# role-based syntax" do <<-CODE
53
+ set :fqdn,'domain.com'
54
+ CODE
55
+ end
56
+ end
57
+
58
+ def add_tasks
59
+ insert_into_file 'config/deploy.rb', after: "# set :ssh_options, verify_host_key: :secure\n" do <<-CODE
60
+ namespace :deploy do
61
+ # after :restart, :clear_cache do
62
+ # on roles(:app), in: :groups, limit: 3, wait: 10 do
63
+ # # Here we can do anything such as:
64
+ # # within release_path do
65
+ # # execute :rake, 'cache:clear'
66
+ # # end
67
+ # end
68
+ # end
69
+ before :finishing, :restart do
70
+ on roles(:app) do
71
+ invoke 'unicorn:restart'
72
+ invoke 'nginx:restart'
73
+ end
74
+ end
75
+
76
+ task :upload_app_yml do
77
+ on roles(:app) do
78
+ info 'Uploading application.yml'
79
+ upload!("\#{Dir.pwd}/config/application.yml", "\#{fetch(:release_path)}/config")
80
+ end
81
+ end
82
+
83
+ before :starting, 'maintenance:on'
84
+ before :starting, 'monit:stop'
85
+ before :compile_assets, :upload_app_yml
86
+ before :published, 'nginx:create_nginx_config'
87
+ before :published, 'unicorn:create_unicorn_config'
88
+ before :published,'unicorn:create_unicorn_init'
89
+ after :restart, 'monit:create_monit_conf'
90
+ after :finished, 'monit:start'
91
+ after :finished, 'maintenance:off'
92
+ end
93
+ CODE
94
+ end
95
+ end
96
+
97
+ def install_capistrano
98
+ add_capistrano_gems
99
+ run 'bundle exec cap install'
100
+ configure_capfile
101
+ run 'mkdir -p config/deploy/templates/maintenance'
102
+ copy_templates
103
+ add_tasks
104
+ configure_env_files
105
+ end
106
+
107
+ end
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,15 @@
1
+ module Rails
2
+ module Database
3
+ def self.included(thor)
4
+ thor.class_eval do
5
+
6
+ def mysql_switch
7
+ gsub_file 'Gemfile', "gem 'sqlite3'", "gem 'mysql2', '>= 0.3.13', '< 0.5'"
8
+ run 'bundle install'
9
+ copy_file 'db/mysql_database.yml', 'config/database.yml'
10
+ end
11
+
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,73 @@
1
+ module Install
2
+ module Devise
3
+ def self.included(thor)
4
+ thor.class_eval do
5
+
6
+ def add_gem
7
+ insert_into_file 'Gemfile', after: "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n" do <<-CODE
8
+ gem 'devise'
9
+ CODE
10
+ end
11
+ run 'bundle update'
12
+ end
13
+
14
+ def add_rspec_config
15
+ copy_file 'spec/support/configs/devise.rb', 'spec/support/configs/devise.rb'
16
+ end
17
+
18
+ def configure_devise
19
+ @devise_model = ask("What would you like to call the devise model? Default: user")
20
+ @devise_model = @devise_model.empty? ? 'user' : @devise_model
21
+ run 'rails generate devise:install'
22
+ run 'rake db:migrate'
23
+ run "rails generate devise #{@devise_model}"
24
+ run 'rails generate devise:views'
25
+
26
+ gsub_file 'app/controllers/application_controller.rb', "protect_from_forgery with: :exception", "protect_from_forgery"
27
+ inject_into_file 'app/controllers/application_controller.rb', after: "protect_from_forgery\n" do <<-CODE
28
+ # Devise authentication method
29
+ before_action :authenticate_#{@devise_model}!
30
+ CODE
31
+ end
32
+ add_additional_fields
33
+ end
34
+
35
+ def configure_ui_controller
36
+ if File.exist?('app/controllers/ui_controller.rb')
37
+ inject_into_file 'app/controllers/ui_controller.rb', after: "class UiController < ApplicationController\n" do <<-CODE
38
+ skip_before_action :authenticate_#{@devise_model}!
39
+ CODE
40
+ end
41
+ end
42
+ end
43
+
44
+ def add_additional_fields
45
+ if yes?('Will you be needing registration params override? Answer "yes" if you will be adding attributes to the user model')
46
+ inject_into_file 'app/controllers/application_controller.rb', after: "before_action :authenticate_#{@devise_model}!\n" do <<-CODE
47
+ # Before action include additional registration params
48
+ # (see #configure_permitted_parameters)
49
+ before_action :configure_permitted_parameters, if: :devise_controller?
50
+ CODE
51
+ end
52
+
53
+ inject_into_file 'app/controllers/application_controller.rb', after: "private\n" do <<-CODE
54
+ # Register additional registration params
55
+ def configure_permitted_parameters
56
+ devise_parameter_sanitizer.permit(:sign_up, keys: [:attribute, :attribute])
57
+ end
58
+ CODE
59
+ end
60
+ end
61
+ end
62
+
63
+ def install_devise
64
+ add_gem
65
+ add_rspec_config
66
+ configure_devise
67
+ configure_ui_controller
68
+ end
69
+
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,28 @@
1
+ module Install
2
+ module DotEnv
3
+ def self.included(thor)
4
+ thor.class_eval do
5
+
6
+ desc 'install_dotenv', 'Install dotenv gem'
7
+ def install_dotenv
8
+ insert_into_file 'Gemfile', after: "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n" do <<-CODE
9
+ gem 'dotenv-rails', groups: [:development, :test]
10
+ CODE
11
+ end
12
+
13
+ run 'bundle install'
14
+
15
+ inject_into_file 'config.ru', after: "require_relative 'config/environment'\n" do <<-CODE
16
+ require 'dotenv'
17
+ Dotenv.load
18
+ CODE
19
+ end
20
+ copy_file 'rails/env.config', '.env.development'
21
+ copy_file 'rails/env.config', '.env.test'
22
+ run 'touch .env.production'
23
+ end
24
+
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,107 @@
1
+ module Rails
2
+ module Engines
3
+ def self.included(thor)
4
+ thor.class_eval do
5
+
6
+ desc 'engine(full | mountable)', 'Generate a full or mountable engine. default: mountable'
7
+ option :name, required: true
8
+ def engine(etype='mountable')
9
+ run "rails plugin new #{options[:name]} --dummy-path=spec/dummy --skip-test-unit --#{etype}"
10
+ end
11
+
12
+ def add_gemspec_info
13
+ gsub_file "#{options[:name]}.gemspec", 's.homepage = "TODO"', 's.homepage = "http://TBD.com"'
14
+ gsub_file "#{options[:name]}.gemspec", "s.summary = \"TODO: Summary of #{options[:name].camelize}.\"", "s.summary = \"Summary of #{options[:name].camelize}.\""
15
+ gsub_file "#{options[:name]}.gemspec", "s.description = \"TODO: Description of #{options[:name].camelize}.\"", "s.description = \"Description of #{options[:name].camelize}.\""
16
+
17
+ inject_into_file "#{options[:name]}.gemspec", after: "s.license = \"MIT\"\n" do <<-CODE
18
+ s.test_files = Dir["spec/**/*"]
19
+ CODE
20
+ end
21
+ end
22
+
23
+ def add_engine_gems
24
+ inject_into_file "#{options[:name]}.gemspec", after: "s.add_development_dependency \"sqlite3\"\n" do <<-CODE
25
+ s.add_development_dependency 'rspec-rails'
26
+ s.add_development_dependency 'capybara'
27
+ s.add_development_dependency 'factory_bot_rails'
28
+ s.add_development_dependency "faker"
29
+ s.add_development_dependency "byebug"
30
+ s.add_development_dependency 'rails-controller-testing'
31
+ s.add_development_dependency 'pundit-matchers'
32
+ s.add_development_dependency "simplecov"
33
+ s.add_development_dependency "shoulda-matchers"
34
+ s.add_development_dependency "database_cleaner"
35
+ s.add_dependency 'pundit'
36
+ s.add_dependency 'bootstrap-sass', '~> 3.3.6'
37
+ s.add_dependency 'autoprefixer-rails'
38
+ s.add_dependency "haml-rails"
39
+ s.add_dependency "font-awesome-rails"
40
+ s.add_dependency 'record_tag_helper'
41
+ CODE
42
+ end
43
+
44
+ run 'bundle'
45
+ end
46
+
47
+ def copy_rspec_files
48
+ Dir["#{__dir__}/myrails/templates/spec/**/*"].each do |file|
49
+ if file.include? '/support/'
50
+ copy_file file, "#{file.gsub(__dir__+'/myrails/templates/', '')}" unless File.directory? file
51
+ end
52
+ end
53
+ end
54
+
55
+ def configure_rake_file
56
+ copy_file 'engines/rakefile', 'Rakefile'
57
+ end
58
+
59
+ def configure_rspec
60
+ run 'rails g rspec:install'
61
+
62
+ gsub_file 'spec/rails_helper.rb', "# Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }", "Dir[File.join(__dir__, 'support', '**', '*.rb')].each { |f| require f }"
63
+
64
+ gsub_file 'spec/rails_helper.rb', "require File.expand_path('../../config/environment', __FILE__)", "require_relative 'dummy/config/environment'"
65
+
66
+ inject_into_file 'spec/rails_helper.rb', after: "require 'rspec/rails'\n" do <<-CODE
67
+ require 'shoulda/matchers'
68
+ require 'factory_bot'
69
+ require 'database_cleaner'
70
+ CODE
71
+ end
72
+
73
+ inject_into_file 'spec/rails_helper.rb', after: "RSpec.configure do |config|\n" do <<-CODE
74
+ config.mock_with :rspec
75
+ config.infer_base_class_for_anonymous_controllers = false
76
+ config.order = "random"
77
+ CODE
78
+ end
79
+ end
80
+
81
+ def configure_engine
82
+ inject_into_file "lib/#{options[:name]}/engine.rb", after: "class Engine < ::Rails::Engine\n" do <<-CODE
83
+ config.generators do |g|
84
+ g.test_framework :rspec, :fixture => false
85
+ g.fixture_replacement :factory_bot, :dir => 'spec/factories'
86
+ g.assets false
87
+ g.helper false
88
+ end
89
+ CODE
90
+ end
91
+ end
92
+
93
+ desc 'engine_setup', 'Configure rails engine for development with RSpec, Capybara and FactoryBot'
94
+ option :name, required: true
95
+ def engine_setup
96
+ add_gemspec_info
97
+ add_engine_gems
98
+ configure_rake_file
99
+ configure_rspec
100
+ copy_rspec_files
101
+ configure_engine
102
+ end
103
+
104
+ end
105
+ end
106
+ end
107
+ end