myrails 5.0.0 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ module Install
2
+ module Figaro
3
+ def self.included(thor)
4
+ thor.class_eval do
5
+
6
+ def install_figaro
7
+ insert_into_file 'Gemfile', after: "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n" do <<-CODE
8
+ gem "figaro"
9
+ CODE
10
+ end
11
+
12
+ run 'bundle install'
13
+ run 'bundle exec figaro install'
14
+ copy_file 'rails/config/application.example.yml', 'config/application.example.yml'
15
+ end
16
+
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ module Install
2
+ module Footnotes
3
+ def self.included(thor)
4
+ thor.class_eval do
5
+
6
+ desc 'install_footnotes', 'Install rails-footnotes and run its generator'
7
+ def install_footnotes
8
+ insert_into_file 'Gemfile', after: "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n" do <<-CODE
9
+ gem 'rails-footnotes'
10
+ CODE
11
+ end
12
+ run 'bundle install'
13
+ run 'rails generate rails_footnotes:install'
14
+ end
15
+
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,10 @@
1
+ GEM
2
+ specs:
3
+
4
+ PLATFORMS
5
+ ruby
6
+
7
+ DEPENDENCIES
8
+
9
+ BUNDLED WITH
10
+ 1.16.1
@@ -0,0 +1,62 @@
1
+ module Install
2
+ module Gems
3
+ def self.included(thor)
4
+ thor.class_eval do
5
+
6
+ def add_test_group
7
+ insert_into_file 'Gemfile', before: "group :development, :test do" do <<-CODE
8
+ group :test do
9
+ gem 'simplecov'
10
+ gem 'shoulda-matchers'
11
+ gem 'factory_bot_rails'
12
+ gem 'database_cleaner'
13
+ gem 'chromedriver-helper'
14
+ gem 'launchy'
15
+ gem 'rails-controller-testing'
16
+ end
17
+ CODE
18
+ end
19
+ end
20
+
21
+ def add_development_test_gems
22
+ insert_into_file 'Gemfile', after: "group :development, :test do\n" do <<-CODE
23
+ gem 'faker'
24
+ gem 'yard'
25
+ gem 'letter_opener'
26
+ gem "rails-erd"
27
+ CODE
28
+ end
29
+ end
30
+
31
+ def add_rails_gems
32
+ insert_into_file 'Gemfile', after: "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n" do <<-CODE
33
+ gem 'haml-rails'
34
+ gem "ransack"
35
+ gem 'will_paginate'
36
+ gem "font-awesome-rails"
37
+ gem 'trix'
38
+ gem 'record_tag_helper'
39
+ gem 'jquery-rails'
40
+ CODE
41
+ end
42
+ end
43
+
44
+ def add_private_section
45
+ insert_into_file 'app/controllers/application_controller.rb', before: 'end' do <<-CODE
46
+ private
47
+ CODE
48
+ end
49
+ end
50
+
51
+ def install_gems
52
+ add_test_group
53
+ add_development_test_gems
54
+ add_rails_gems
55
+ run 'bundle install'
56
+ add_private_section
57
+ end
58
+
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,24 @@
1
+ module Install
2
+ module Heroku
3
+ def self.included(thor)
4
+ thor.class_eval do
5
+
6
+ desc 'install_heroku', 'setup application for use with heroku using sqlite3 for development'
7
+ def install_heroku
8
+ insert_into_file 'Gemfile', before: "group :development, :test do\n" do <<-CODE
9
+ group :production do
10
+ gem 'pg'
11
+ gem 'rails_12factor'
12
+ end
13
+
14
+ CODE
15
+ end
16
+ copy_file 'db/sqlite3_database.yml', 'config/database.yml'
17
+ copy_file 'heroku/Procfile', 'Procfile'
18
+ copy_file 'heroku/puma.rb', 'config/puma.rb'
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,43 @@
1
+ module Layout
2
+ module Material
3
+ def self.included(thor)
4
+ thor.class_eval do
5
+ def copy_material_files
6
+ Dir["#{__dir__}/myrails/templates/rails/app/views/layout/material/**/*"].each do |file|
7
+ copy_file file, "app/views/layouts/#{File.basename(file)}"
8
+ end
9
+ end
10
+
11
+ desc 'install_material', 'Generate Material css theme'
12
+ def install_material
13
+ @templates = "#{__dir__}/../templates"
14
+
15
+ insert_into_file 'Gemfile', after: "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n" do <<-CODE
16
+ gem 'materialize-sass'
17
+ gem 'material_icons'
18
+ CODE
19
+ end
20
+
21
+ run 'bundle install'
22
+
23
+ copy_material_files
24
+
25
+ insert_into_file 'app/assets/stylesheets/application.css.sass', before: '@import trix' do <<-CODE
26
+ @import "materialize/components/color"
27
+ $primary-color: color("grey", "darken-3") !default
28
+ $secondary-color: color("grey", "base") !default
29
+ @import materialize
30
+ @import material_icons
31
+ CODE
32
+ end
33
+
34
+ insert_into_file 'app/assets/javascripts/application.js', before: "//= require trix" do <<-CODE
35
+ //= require materialize
36
+ CODE
37
+ end
38
+ end
39
+
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,51 @@
1
+ module Install
2
+ module Pundit
3
+ def self.included(thor)
4
+ thor.class_eval do
5
+
6
+ def add_pundit_gems
7
+ insert_into_file 'Gemfile', after: "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n" do <<-CODE
8
+ gem 'pundit'
9
+ CODE
10
+ end
11
+
12
+ insert_into_file 'Gemfile', after: "group :test do\n" do <<-CODE
13
+ gem 'pundit-matchers'
14
+ CODE
15
+ end
16
+ run 'bundle update'
17
+ end
18
+
19
+ def enable_pundit
20
+ inject_into_file 'app/controllers/application_controller.rb', after: "class ApplicationController < ActionController::Base\n" do <<-CODE
21
+ # Add pundit authorization
22
+ include Pundit
23
+ # Rescue from pundit error
24
+ # (see #user_not_authorized)
25
+ rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
26
+ CODE
27
+ end
28
+
29
+ inject_into_file 'app/controllers/application_controller.rb', after: "private\n" do <<-CODE
30
+ # Method to gracefully let a user know they are are not authorized
31
+ #
32
+ # @return flash [Hash] the action notice
33
+ def user_not_authorized
34
+ flash[:alert] = "You are not authorized to perform this action."
35
+ redirect_to root_path
36
+ end
37
+ CODE
38
+ end
39
+ end
40
+
41
+ desc 'install_pundit', 'Install pundit gem and generate pundit files and application controller code'
42
+ def install_pundit
43
+ add_pundit_gems
44
+ run 'rails g pundit:install'
45
+ enable_pundit
46
+ end
47
+
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,102 @@
1
+ module Rails
2
+ module Generators
3
+ def self.included(thor)
4
+ thor.class_eval do
5
+
6
+ desc 'model', "Generates a rails model with the given name along with its related spec file and namespace prefix for table creation. Use '/' to create a namespaced model"
7
+ option :name, required: true
8
+ def model
9
+ template 'rails/app/models/model.rb', "app/models/#{options[:name].downcase}.rb"
10
+ template 'rails/app/models/namespace_model.rb', "app/models/#{options[:name].split("/").first.singularize.downcase}.rb" if options[:name].include?("/")
11
+ template 'spec/model.rb', "spec/models/#{options[:name].downcase}_spec.rb"
12
+ end
13
+
14
+ desc 'controller', "Generates a rails controller with the given name along with related spec file. Use '/' to create a namespaced controller"
15
+ option :name, required: true
16
+ def controller
17
+ template 'rails/app/controllers/controller.rb', "app/controllers/#{options[:name].downcase.pluralize}_controller.rb"
18
+ if options[:name].include?("/")
19
+ parent, child = options[:name].split("/")
20
+ template 'rails/app/controllers/namespace_controller.rb', "app/controllers/#{parent}/#{parent.downcase}_controller.rb"
21
+ end
22
+ template 'spec/controller.rb', "spec/controllers/#{options[:name].downcase.pluralize}_controller_spec.rb"
23
+ run "mkdir -p app/views/#{options[:name].downcase.pluralize}"
24
+ end
25
+
26
+ desc 'policy', "Generates a pundit policy with the given name and a related spec file. Use '/' to create a namespaced policy"
27
+ option :name, required: true
28
+ def policy
29
+ template 'rails/app/policies/pundit.rb', "app/policies/#{options[:name].downcase}_policy.rb"
30
+ template 'spec/pundit.rb', "spec/policies/#{options[:name].downcase}_policy_spec.rb"
31
+ end
32
+
33
+ desc 'presenter', "Generates a presenter class with the given name and a related spec file. Use '/' to create a namespaced presenter"
34
+ option :name, required: true
35
+ def presenters
36
+ copy_file 'rails/app/presenters/base.rb', 'app/presenters/base_presenter.rb'
37
+ template 'rails/app/presenters/presenter.rb', "app/presenters/#{options[:name].downcase}_presenter.rb"
38
+ copy_file 'rails/app/presenters/presenter_config.rb', 'spec/support/configs/presenter.rb'
39
+ template 'rails/app/presenters/presenter_spec.rb', "spec/presenters/#{options[:name].downcase}_presenter_spec.rb"
40
+ end
41
+
42
+ desc 'factory', "Generates a factory_bot factory in the spec/factories directory. Use '/' to create a namespaced factory"
43
+ option :name, required: true
44
+ def factory
45
+ template 'spec/factory.rb', "spec/factories/#{options[:name].downcase}.rb"
46
+ end
47
+
48
+ desc 'sendgrid', 'Generate sendgrid initializer and mail interceptor'
49
+ option :email, required: true
50
+ def sendgrid
51
+ copy_file 'rails/app/mailers/sendgrid.rb', 'config/initializers/sendgrid.rb'
52
+ template 'rails/app/mailers/dev_mail_interceptor.rb', 'app/mailers/dev_mail_interceptor.rb'
53
+ ENVIRONMENTS.each do |environment|
54
+ unless environment == 'production'
55
+ inject_into_file "config/environments/#{environment}.rb", after: "Rails.application.configure do\n" do <<-CODE
56
+ ActionMailer::Base.register_interceptor(DevMailInterceptor)
57
+ CODE
58
+ end
59
+ end
60
+ end
61
+ end
62
+
63
+ desc 'config_env', 'Add code to environment files. Host refers to url options. Name option referes to controller and mailer default_url_options'
64
+ option :name, required: true
65
+ def config_env
66
+ ENVIRONMENTS.each do |environment|
67
+ case environment
68
+ when 'development'
69
+ inject_into_file 'config/environments/development.rb', after: "config.action_mailer.raise_delivery_errors = false\n" do <<-CODE
70
+ config.action_mailer.delivery_method = :letter_opener
71
+ config.action_mailer.perform_deliveries = false
72
+ config.action_mailer.default_url_options = { host: ENV['DEFAULT_HOST'] }
73
+ config.action_controller.default_url_options = { host: ENV['DEFAULT_HOST'] }
74
+ CODE
75
+ end
76
+ when 'test'
77
+ inject_into_file 'config/environments/test.rb', after: "config.action_mailer.delivery_method = :test\n" do <<-CODE
78
+ config.action_mailer.default_url_options = { host: ENV['DEFAULT_HOST'] }
79
+ config.action_controller.default_url_options = { host: ENV['DEFAULT_HOST'] }
80
+ CODE
81
+ end
82
+ when 'production'
83
+ inject_into_file 'config/environments/production.rb', after: "config.active_record.dump_schema_after_migration = false\n" do <<-CODE
84
+ config.action_mailer.default_url_options = { host: ENV['DEFAULT_HOST'] }
85
+ config.action_controller.default_url_options = { host: ENV['DEFAULT_HOST'] }
86
+ config.assets.compile = true
87
+ CODE
88
+ end
89
+ end
90
+ end
91
+ end
92
+
93
+ desc 'new_ui NAME', 'Create a new ui view'
94
+ def new_ui(name)
95
+ run "touch app/views/ui/#{name}.html.haml"
96
+ say "DON'T FORGET: Restart Powify App"
97
+ end
98
+
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,65 @@
1
+ module Install
2
+ module RSpec
3
+ def self.included(thor)
4
+ thor.class_eval do
5
+
6
+ desc 'install_rspec', 'Generate rspec structure & rspec configuration that I commonly use'
7
+ def install_rspec
8
+ insert_into_file 'Gemfile', after: "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n" do <<-CODE
9
+ gem 'rspec-rails', group: :test
10
+ gem 'email-spec', group: :test
11
+ CODE
12
+ end
13
+
14
+ run 'bundle install'
15
+ run 'rails g rspec:install'
16
+
17
+ install_rails_helper
18
+
19
+ Dir["#{__dir__}/../templates/spec/**/*"].each do |file|
20
+ if file.include?('/support/') && !['devise'].include?(File.basename(file, '.rb'))
21
+ copy_file file, "#{file.gsub(__dir__+'/../templates/', '')}" unless File.directory? file
22
+ end
23
+ end
24
+ end
25
+
26
+ desc 'install_rails_helper', 'Add code to rspec/rails_helper so rspec runs the way I like'
27
+ def install_rails_helper
28
+ inject_into_file "spec/rails_helper.rb", after: "require 'rspec/rails'\n" do <<-CODE
29
+ require 'simplecov'
30
+ SimpleCov.start
31
+
32
+ Capybara.app_host = "http://localhost:3000"
33
+ Capybara.server_host = "localhost"
34
+ Capybara.server_port = "3000"
35
+
36
+ #use Chromedriver
37
+ unless ENV['NOCHROME']
38
+ Capybara.register_driver :selenium do |app|
39
+ Capybara::Selenium::Driver.new(app, :browser => :chrome)
40
+ end
41
+ end
42
+ CODE
43
+ end
44
+
45
+ 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 }"
46
+
47
+ gsub_file "spec/rails_helper.rb", "config.use_transactional_fixtures = true", "config.use_transactional_fixtures = false"
48
+
49
+ inject_into_file 'spec/rails_helper.rb', after: "RSpec.configure do |config|\n" do <<-CODE
50
+ # Can use methods like dom_id in features
51
+ config.include ActionView::RecordIdentifier, type: :feature
52
+ # Can use methods likke strip_tags in features
53
+ config.include ActionView::Helpers::SanitizeHelper, type: :feature
54
+ # Can use methods like truncate
55
+ config.include ActionView::Helpers::TextHelper, type: :feature
56
+ config.include(JavascriptHelper, type: :feature)
57
+ config.include MailerHelper
58
+ CODE
59
+ end
60
+ end
61
+
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,46 @@
1
+ module RSpec
2
+ module Generators
3
+ def self.included(thor)
4
+ thor.class_eval do
5
+
6
+ desc 'shared_example', 'Generates an RSpec shared example template in the support directory'
7
+ option :text, required: true
8
+ def shared_example
9
+ template 'spec/shared_example.rb', 'spec/support/shared_examples/shared_examples.rb'
10
+ end
11
+
12
+ desc 'request', 'Generates an RSpec request spec'
13
+ option :name, required: true
14
+ def request
15
+ template 'spec/request.rb', "spec/requests/#{options[:name]}_spec.rb"
16
+ copy_file 'spec/request_shared_example.rb', 'spec/support/shared_examples/request_shared_examples.rb'
17
+ end
18
+
19
+ desc 'feature', 'Generates an RSpec feature spec'
20
+ option :name, required: true
21
+ def feature
22
+ copy_file 'spec/feature.rb', "spec/features/#{options[:name]}_spec.rb"
23
+ end
24
+
25
+ desc 'helper', 'Generates an RSpec helper in support/helpers for extracting reusable code'
26
+ long_desc <<-LONGDESC
27
+ `myrails helper` will generate an RSpec helper module to use with rspec.
28
+
29
+ You can optionally specify a type parameter which will only include the module for the given type of spec.
30
+
31
+ > $ myrails helper --name article --type :feature
32
+ LONGDESC
33
+ option :name, required: true
34
+ option :type
35
+ def helper
36
+ template 'spec/helper.rb', "spec/support/helpers/#{options[:name].downcase.gsub("\s", '_')}.rb"
37
+ insert_into_file 'spec/rails_helper.rb', after: "RSpec.configure do |config|\n" do <<-CODE
38
+ config.include #{options[:name].camelize.gsub("\s", '')}Helper#{", type: #{options[:type]}" if options[:type]}
39
+ CODE
40
+ end
41
+ end
42
+
43
+ end
44
+ end
45
+ end
46
+ end