boring_generators 0.3.0 → 0.8.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.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +12 -0
  3. data/.github/workflows/ci.yml +23 -0
  4. data/CHANGELOG.md +31 -0
  5. data/Gemfile +6 -0
  6. data/Gemfile.lock +150 -0
  7. data/README.md +47 -7
  8. data/Rakefile +1 -0
  9. data/boring_generators.gemspec +2 -0
  10. data/exe/boring +5 -0
  11. data/lib/boring_generators.rb +1 -0
  12. data/lib/boring_generators/cli.rb +26 -0
  13. data/lib/boring_generators/version.rb +1 -1
  14. data/lib/generators/boring/bootstrap/install/install_generator.rb +2 -2
  15. data/lib/generators/boring/ci/circleci/install/install_generator.rb +31 -0
  16. data/lib/generators/boring/ci/circleci/install/templates/config.psql.yml.tt +48 -0
  17. data/lib/generators/boring/ci/circleci/install/templates/config.sql.yml.tt +48 -0
  18. data/lib/generators/boring/ci/circleci/install/templates/database.yml.ci.tt +14 -0
  19. data/lib/generators/boring/ci/github_action/install/install_generator.rb +45 -0
  20. data/lib/generators/boring/ci/github_action/install/templates/ci.yml.tt +49 -0
  21. data/lib/generators/boring/ci/travisci/install/install_generator.rb +23 -0
  22. data/lib/generators/boring/ci/travisci/install/templates/.travis.yml.tt +35 -0
  23. data/lib/generators/boring/devise/install/install_generator.rb +75 -0
  24. data/lib/generators/boring/favicon/build/build_generator.rb +120 -0
  25. data/lib/generators/boring/favicon/build/templates/favicon.html.erb.tt +19 -0
  26. data/lib/generators/boring/graphql/install/install_generator.rb +51 -0
  27. data/lib/generators/boring/graphql/install/templates/base_resolver.rb +2 -0
  28. data/lib/generators/boring/graphql/install/templates/hello_world_resolver.rb +11 -0
  29. data/lib/generators/boring/oauth/base_generator.rb +63 -0
  30. data/lib/generators/boring/oauth/facebook/install/install_generator.rb +42 -0
  31. data/lib/generators/boring/oauth/facebook/install/templates/README +20 -0
  32. data/lib/generators/boring/oauth/facebook/install/templates/omniauth.rb +3 -0
  33. data/lib/generators/boring/oauth/facebook/install/templates/omniauth_callbacks_controller.rb +21 -0
  34. data/lib/generators/boring/oauth/github/install/install_generator.rb +42 -0
  35. data/lib/generators/boring/oauth/github/install/templates/README +20 -0
  36. data/lib/generators/boring/oauth/github/install/templates/omniauth_callbacks_controller.rb +21 -0
  37. data/lib/generators/boring/oauth/google/install/install_generator.rb +36 -0
  38. data/lib/generators/boring/oauth/google/install/templates/README +20 -0
  39. data/lib/generators/boring/oauth/google/install/templates/omniauth_callbacks_controller.rb +21 -0
  40. data/lib/generators/boring/oauth/twitter/install/install_generator.rb +36 -0
  41. data/lib/generators/boring/oauth/twitter/install/templates/README +20 -0
  42. data/lib/generators/boring/oauth/twitter/install/templates/omniauth_callbacks_controller.rb +21 -0
  43. data/lib/generators/boring/pundit/install/install_generator.rb +85 -0
  44. data/lib/generators/boring/rubocop/install/install_generator.rb +37 -0
  45. data/lib/generators/boring/rubocop/install/templates/.rubocop.yml.tt +262 -0
  46. data/lib/generators/boring/simple_form/install/install_generator.rb +44 -0
  47. data/lib/generators/boring/tailwind/install/install_generator.rb +13 -12
  48. data/lib/generators/boring/tailwind/install/templates/README +13 -0
  49. data/lib/generators/boring/twilio/install/install_generator.rb +30 -0
  50. data/lib/generators/boring/twilio/install/templates/README +11 -0
  51. data/lib/generators/boring/twilio/install/templates/twilio.rb +4 -0
  52. metadata +2525 -5
  53. data/.travis.yml +0 -6
@@ -0,0 +1,19 @@
1
+ <%%= favicon_link_tag "favicons/favicon-16x16.ico", rel: 'shortcut icon', type: 'image/x-icon' %>
2
+ <%%= favicon_link_tag "favicons/favicon-32x32.ico", rel: 'shortcut icon', type: 'image/x-icon' %>
3
+ <%%= favicon_link_tag "favicons/apple-touch-icon-57x57.png", rel: 'apple-touch-icon', type: 'image/png', sizes: "57x57" %>
4
+ <%%= favicon_link_tag "favicons/apple-touch-icon-60x60.png", rel: 'apple-touch-icon', type: 'image/png', sizes: "60x60" %>
5
+ <%%= favicon_link_tag "favicons/apple-touch-icon-72x72.png", rel: 'apple-touch-icon', type: 'image/png', sizes: "72x72" %>
6
+ <%%= favicon_link_tag "favicons/apple-touch-icon-76x76.png", rel: 'apple-touch-icon', type: 'image/png', sizes: "76x76" %>
7
+ <%%= favicon_link_tag "favicons/apple-touch-icon-114x114.png", rel: 'apple-touch-icon', type: 'image/png', sizes: "114x114" %>
8
+ <%%= favicon_link_tag "favicons/apple-touch-icon-120x120.png", rel: 'apple-touch-icon', type: 'image/png', sizes: "120x120" %>
9
+ <%%= favicon_link_tag "favicons/apple-touch-icon-129x129.png", rel: 'apple-touch-icon', type: 'image/png', sizes: "129x129" %>
10
+ <%%= favicon_link_tag "favicons/apple-touch-icon-144x144.png", rel: 'apple-touch-icon', type: 'image/png', sizes: "144x144" %>
11
+ <%%= favicon_link_tag "favicons/apple-touch-icon-152x152.png", rel: 'apple-touch-icon', type: 'image/png', sizes: "152x152" %>
12
+ <%%= favicon_link_tag "favicons/apple-touch-icon.png", rel: 'apple-touch-icon', type: 'image/png' %>
13
+ <%%= favicon_link_tag "favicons/apple-touch-icon-120x120-precomposed.png", rel: 'apple-touch-icon-precomposed', type: 'image/png', sizes: "120x120" %>
14
+ <%%= favicon_link_tag "favicons/apple-touch-icon-129x129-precomposed.png", rel: 'apple-touch-icon-precomposed', type: 'image/png', sizes: "129x129" %>
15
+ <%%= favicon_link_tag "favicons/apple-touch-icon-152x152-precomposed.png", rel: 'apple-touch-icon-precomposed', type: 'image/png', sizes: "152x152" %>
16
+ <%%= favicon_link_tag "favicons/apple-touch-icon-precomposed.png", rel: 'apple-touch-icon-precomposed', type: 'image/png' %>
17
+ <meta name="msapplication-TileImage" content="<%%= image_path("favicons/mstile-144x144.png") %>" />
18
+ <meta name="msapplication-TileColor" content="<%= @primary_color %>" />
19
+ <meta name="application-name" content="<%= @application_name %>">
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Boring
4
+ module Graphql
5
+ class InstallGenerator < Rails::Generators::Base
6
+ desc "Adds GraphQL to the application"
7
+ source_root File.expand_path("templates", __dir__)
8
+
9
+ OPTIONS = %w(relay batch playground no-graphiql schema)
10
+
11
+ class_option :skip_resolver_setup, type: :boolean, aliases: "-s",
12
+ desc: "Skips adding GraphQL resolver setup to the application"
13
+
14
+ def add_graphql_gem
15
+ say "Adding graphql gem", :green
16
+ graphql_gem = <<~RUBY
17
+ \n
18
+ # for building APIs
19
+ gem 'graphql', '~> 1.11'
20
+ RUBY
21
+ append_to_file "Gemfile", graphql_gem
22
+ run "bundle install"
23
+ end
24
+
25
+ def run_graphql_generator
26
+ say "Running GraphQL default generator", :green
27
+ run "bundle exec rails generate graphql:install"
28
+ run "bundle install"
29
+
30
+ graphiql_precompile_assets = <<~RUBY
31
+ \n
32
+ if Rails.env.development?
33
+ Rails.application.config.assets.precompile += %w[graphiql/rails/application.js graphiql/rails/application.css]
34
+ end
35
+ RUBY
36
+ append_to_file "config/initializers/assets.rb", graphiql_precompile_assets
37
+ end
38
+
39
+ def adds_graphql_resolver
40
+ return if options[:skip_resolver_setup]
41
+ template("base_resolver.rb", "app/graphql/resolvers/base_resolver.rb")
42
+ template("hello_world_resolver.rb", "app/graphql/resolvers/hello_world_resolver.rb")
43
+
44
+ insert_into_file "app/graphql/types/query_type.rb", <<~RUBY, after: /class QueryType < Types::BaseObject\n/
45
+ \t\t# TODO: remove me
46
+ \t\tfield :hello, resolver: Resolvers::HelloWorldResolver
47
+ RUBY
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,2 @@
1
+ class Resolvers::BaseResolver < GraphQL::Schema::Resolver
2
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Resolvers::HelloWorldResolver < Resolvers::BaseResolver
4
+ description "Returns hello world"
5
+
6
+ type String, null: false
7
+
8
+ def resolve
9
+ "Hello World"
10
+ end
11
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler'
4
+
5
+ module Boring
6
+ module Oauth
7
+ module BaseGenerator
8
+ def add_provider_and_uuid_user_details
9
+ say "Adding migration to add provider and uuid columns to users", :green
10
+ Bundler.with_unbundled_env do
11
+ run "DISABLE_SPRING=1 bundle exec rails generate migration AddOmniauthToUsers provider:string uid:string"
12
+ end
13
+ end
14
+
15
+ def configure_devise_omniauth
16
+ say "Adding omniauth devise configuration", :green
17
+ if File.exist?("config/initializers/devise.rb")
18
+ insert_into_file "config/initializers/devise.rb", <<~RUBY, after: /Devise.setup do \|config\|/
19
+ \n
20
+ \tconfig.omniauth :#{@oauth_name}, "APP_ID", "APP_SECRET"
21
+ RUBY
22
+ else
23
+ raise MissingDeviseConfigurationError, <<~ERROR
24
+ Looks like the devise installation is incomplete. Could not find devise.rb in config/initializers.
25
+ ERROR
26
+ end
27
+ end
28
+
29
+ def add_omniauth_callback_routes
30
+ devise_route = '# devise_for :users, controllers: { omniauth_callbacks: "users/omniauth_callbacks" }'.dup
31
+ route devise_route
32
+ end
33
+
34
+ def add_omniauth_callback_controller
35
+ say "Copying omniauth_callbacks_controller.rb", :green
36
+ template("omniauth_callbacks_controller.rb", "app/controllers/users/omniauth_callbacks_controller.rb")
37
+ end
38
+
39
+ def configure_and_add_devise_setting_in_user_model
40
+ say "Configuring #{@oauth_name.to_s} omniauth for user model", :green
41
+ insert_into_file "app/models/user.rb", <<~RUBY, after: /class User < ApplicationRecord/
42
+ \n\tdevise :omniauthable, omniauth_providers: %i[#{@oauth_name}]
43
+
44
+ \tdef self.from_omniauth(auth)
45
+ \twhere(provider: auth.provider, uid: auth.uid).first_or_create do |user|
46
+ \tuser.email = auth.info.email
47
+ \tuser.password = Devise.friendly_token[0, 20]
48
+ \tuser.name = auth.info.name # assuming the user model has a name
49
+ \t# user.image = auth.info.image # assuming the user model has an image
50
+ \t# If you are using confirmable and the provider(s) you use validate emails,
51
+ \t# uncomment the line below to skip the confirmation emails.
52
+ \t# user.skip_confirmation!
53
+ \tend
54
+ \tend
55
+ RUBY
56
+ end
57
+
58
+ def show_readme
59
+ readme "README"
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler'
4
+ require 'generators/boring/oauth/base_generator'
5
+
6
+ module Boring
7
+ module Oauth
8
+ module Facebook
9
+ class InstallGenerator < Rails::Generators::Base
10
+ include Boring::Oauth::BaseGenerator
11
+
12
+ class MissingDeviseConfigurationError < StandardError; end
13
+
14
+ desc "Adds facebook OmniAuth to the application"
15
+ source_root File.expand_path("templates", __dir__)
16
+
17
+ def add_facebook_omniauth_gem
18
+ say "Adding Facebook OmniAuth gem", :green
19
+ facebook_omniauth_gem = <<~RUBY
20
+ \n
21
+ # for omniauth facebook
22
+ gem 'omniauth-facebook', '~> 8.0'
23
+ RUBY
24
+ append_to_file "Gemfile", facebook_omniauth_gem
25
+ Bundler.with_unbundled_env do
26
+ run "bundle install"
27
+ end
28
+ end
29
+
30
+ def invoke_common_generator_methods
31
+ @oauth_name = :facebook
32
+ add_provider_and_uuid_user_details
33
+ configure_devise_omniauth
34
+ add_omniauth_callback_routes
35
+ add_omniauth_callback_controller
36
+ configure_and_add_devise_setting_in_user_model
37
+ show_readme
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,20 @@
1
+ ===============================================================================
2
+
3
+ Some setup you must do manually if you haven't yet:
4
+
5
+ 1. Ensure you have overridden or uncommented the routes for generated omniauth callback controllers in your routes.rb.
6
+ For example:
7
+
8
+ Rails.application.routes.draw do
9
+ devise_for :users, controllers: {
10
+ omniauth_callbacks: "users/omniauth_callbacks"
11
+ }
12
+ end
13
+
14
+ 2. Update the devise facebook omniauth APP_ID and APP_SECRET in "config/initializers/devise.rb"
15
+ after registering the Rails application on: https://developers.facebook.com/apps/
16
+ For example:
17
+
18
+ config.omniauth :facebook, "APP_ID", "APP_SECRET"
19
+
20
+ ===============================================================================
@@ -0,0 +1,3 @@
1
+ Devise.setup do |config|
2
+ config.omniauth :twitter, ENV['TWITTER_KEY'], ENV['TWITTER_SECRET']
3
+ end
@@ -0,0 +1,21 @@
1
+ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
2
+ # See https://github.com/omniauth/omniauth/wiki/FAQ#rails-session-is-clobbered-after-callback-on-developer-strategy
3
+ skip_before_action :verify_authenticity_token, only: :facebook
4
+
5
+ def facebook
6
+ # You need to implement the method below in your model (e.g. app/models/user.rb)
7
+ @user = User.from_omniauth(request.env["omniauth.auth"])
8
+
9
+ if @user.persisted?
10
+ sign_in_and_redirect @user, event: :authentication #this will throw if @user is not activated
11
+ set_flash_message(:notice, :success, kind: "Facebook") if is_navigational_format?
12
+ else
13
+ session["devise.facebook_data"] = request.env["omniauth.auth"].except(:extra) # Removing extra as it can overflow some session stores
14
+ redirect_to new_user_registration_url
15
+ end
16
+ end
17
+
18
+ def failure
19
+ redirect_to root_path
20
+ end
21
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler'
4
+ require 'generators/boring/oauth/base_generator'
5
+
6
+ module Boring
7
+ module Oauth
8
+ module Github
9
+ class InstallGenerator < Rails::Generators::Base
10
+ include Boring::Oauth::BaseGenerator
11
+
12
+ class MissingDeviseConfigurationError < StandardError; end
13
+
14
+ desc "Adds GitHub OmniAuth to the application"
15
+ source_root File.expand_path("templates", __dir__)
16
+
17
+ def add_github_omniauth_gem
18
+ say "Adding GitHub OmniAuth gem", :green
19
+ github_omniauth_gem = <<~RUBY
20
+ \n
21
+ # for omniauth github
22
+ gem 'omniauth-github', '~> 1.4.0'
23
+ RUBY
24
+ append_to_file "Gemfile", github_omniauth_gem
25
+ Bundler.with_unbundled_env do
26
+ run "bundle install"
27
+ end
28
+ end
29
+
30
+ def invoke_common_generator_methods
31
+ @oauth_name = :github
32
+ add_provider_and_uuid_user_details
33
+ configure_devise_omniauth
34
+ add_omniauth_callback_routes
35
+ add_omniauth_callback_controller
36
+ configure_and_add_devise_setting_in_user_model
37
+ show_readme
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,20 @@
1
+ ===============================================================================
2
+
3
+ Some setup you must do manually if you haven't yet:
4
+
5
+ 1. Ensure you have overridden or uncommented the routes for generated omniauth callback controllers in your routes.rb.
6
+ For example:
7
+
8
+ Rails.application.routes.draw do
9
+ devise_for :users, controllers: {
10
+ omniauth_callbacks: "users/omniauth_callbacks"
11
+ }
12
+ end
13
+
14
+ 2. Update the devise github omniauth APP_ID and APP_SECRET in "config/initializers/devise.rb"
15
+ after registering the Rails application on: https://github.com/settings/applications/new
16
+ For example:
17
+
18
+ config.omniauth :github, "APP_ID", "APP_SECRET"
19
+
20
+ ===============================================================================
@@ -0,0 +1,21 @@
1
+ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
2
+ # See https://github.com/omniauth/omniauth/wiki/FAQ#rails-session-is-clobbered-after-callback-on-developer-strategy
3
+ skip_before_action :verify_authenticity_token, only: :github
4
+
5
+ def github
6
+ # You need to implement the method below in your model (e.g. app/models/user.rb)
7
+ @user = User.from_omniauth(request.env["omniauth.auth"])
8
+
9
+ if @user.persisted?
10
+ sign_in_and_redirect @user, event: :authentication #this will throw if @user is not activated
11
+ set_flash_message(:notice, :success, kind: "GitHub") if is_navigational_format?
12
+ else
13
+ session["devise.github_data"] = request.env["omniauth.auth"].except(:extra) # Removing extra as it can overflow some session stores
14
+ redirect_to new_user_registration_url
15
+ end
16
+ end
17
+
18
+ def failure
19
+ redirect_to root_path
20
+ end
21
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler'
4
+ require 'generators/boring/oauth/base_generator'
5
+
6
+ module Boring
7
+ module Oauth
8
+ module Google
9
+ class InstallGenerator < Rails::Generators::Base
10
+ include Boring::Oauth::BaseGenerator
11
+
12
+ class MissingDeviseConfigurationError < StandardError; end
13
+
14
+ desc "Adds Google OmniAuth to the application"
15
+ source_root File.expand_path("templates", __dir__)
16
+
17
+ def add_github_omniauth_gem
18
+ say "Adding GitHub OmniAuth gem", :green
19
+ Bundler.with_unbundled_env do
20
+ run "bundle add omniauth-google-oauth2"
21
+ end
22
+ end
23
+
24
+ def invoke_common_generator_methods
25
+ @oauth_name = :google_oauth2
26
+ add_provider_and_uuid_user_details
27
+ configure_devise_omniauth
28
+ add_omniauth_callback_routes
29
+ add_omniauth_callback_controller
30
+ configure_and_add_devise_setting_in_user_model
31
+ show_readme
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,20 @@
1
+ ===============================================================================
2
+
3
+ Some setup you must do manually if you haven't yet:
4
+
5
+ 1. Ensure you have overridden or uncommented the routes for generated omniauth callback controllers in your routes.rb.
6
+ For example:
7
+
8
+ Rails.application.routes.draw do
9
+ devise_for :users, controllers: {
10
+ omniauth_callbacks: "users/omniauth_callbacks"
11
+ }
12
+ end
13
+
14
+ 2. Update the devise google omniauth APP_ID and APP_SECRET in "config/initializers/devise.rb"
15
+ after registering the Rails application on: https://code.google.com/apis/console/
16
+ For example:
17
+
18
+ config.omniauth :google_auth, "APP_ID", "APP_SECRET"
19
+
20
+ ===============================================================================
@@ -0,0 +1,21 @@
1
+ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
2
+ # See https://github.com/omniauth/omniauth/wiki/FAQ#rails-session-is-clobbered-after-callback-on-developer-strategy
3
+ skip_before_action :verify_authenticity_token, only: :google_auth
4
+
5
+ def google_auth
6
+ # You need to implement the method below in your model (e.g. app/models/user.rb)
7
+ @user = User.from_omniauth(request.env["omniauth.auth"])
8
+
9
+ if @user.persisted?
10
+ sign_in_and_redirect @user, event: :authentication #this will throw if @user is not activated
11
+ set_flash_message(:notice, :success, kind: "Google") if is_navigational_format?
12
+ else
13
+ session["devise.google_data"] = request.env["omniauth.auth"].except(:extra) # Removing extra as it can overflow some session stores
14
+ redirect_to new_user_registration_url
15
+ end
16
+ end
17
+
18
+ def failure
19
+ redirect_to root_path
20
+ end
21
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler'
4
+ require 'generators/boring/oauth/base_generator'
5
+
6
+ module Boring
7
+ module Oauth
8
+ module Twitter
9
+ class InstallGenerator < Rails::Generators::Base
10
+ include Boring::Oauth::BaseGenerator
11
+
12
+ class MissingDeviseConfigurationError < StandardError; end
13
+
14
+ desc "Adds Twitter OmniAuth to the application"
15
+ source_root File.expand_path("templates", __dir__)
16
+
17
+ def add_twitter_omniauth_gem
18
+ say "Adding Twitter OmniAuth gem", :green
19
+ Bundler.with_unbundled_env do
20
+ run "bundle add omniauth-twitter"
21
+ end
22
+ end
23
+
24
+ def invoke_common_generator_methods
25
+ @oauth_name = :twitter
26
+ add_provider_and_uuid_user_details
27
+ configure_devise_omniauth
28
+ add_omniauth_callback_routes
29
+ add_omniauth_callback_controller
30
+ configure_and_add_devise_setting_in_user_model
31
+ show_readme
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end