boring_generators 0.4.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +12 -0
  3. data/.github/workflows/ci.yml +8 -2
  4. data/CHANGELOG.md +27 -0
  5. data/Gemfile +5 -0
  6. data/Gemfile.lock +94 -21
  7. data/README.md +32 -6
  8. data/Rakefile +1 -0
  9. data/boring_generators.gemspec +1 -1
  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/ahoy/install/install_generator.rb +31 -0
  15. data/lib/generators/boring/ahoy/install/templates/README +10 -0
  16. data/lib/generators/boring/bootstrap/install/install_generator.rb +2 -2
  17. data/lib/generators/boring/ci/github_action/install/install_generator.rb +18 -4
  18. data/lib/generators/boring/ci/github_action/install/templates/ci.yml.tt +1 -11
  19. data/lib/generators/boring/devise/install/install_generator.rb +75 -0
  20. data/lib/generators/boring/favicon/build/build_generator.rb +120 -0
  21. data/lib/generators/boring/favicon/build/templates/favicon.html.erb.tt +19 -0
  22. data/lib/generators/boring/graphql/install/install_generator.rb +51 -0
  23. data/lib/generators/boring/graphql/install/templates/base_resolver.rb +2 -0
  24. data/lib/generators/boring/graphql/install/templates/hello_world_resolver.rb +11 -0
  25. data/lib/generators/boring/oauth/base_generator.rb +63 -0
  26. data/lib/generators/boring/oauth/facebook/install/install_generator.rb +42 -0
  27. data/lib/generators/boring/oauth/facebook/install/templates/README +23 -0
  28. data/lib/generators/boring/oauth/facebook/install/templates/omniauth.rb +3 -0
  29. data/lib/generators/boring/oauth/facebook/install/templates/omniauth_callbacks_controller.rb +21 -0
  30. data/lib/generators/boring/oauth/github/install/install_generator.rb +42 -0
  31. data/lib/generators/boring/oauth/github/install/templates/README +23 -0
  32. data/lib/generators/boring/oauth/github/install/templates/omniauth_callbacks_controller.rb +21 -0
  33. data/lib/generators/boring/oauth/google/install/install_generator.rb +36 -0
  34. data/lib/generators/boring/oauth/google/install/templates/README +23 -0
  35. data/lib/generators/boring/oauth/google/install/templates/omniauth_callbacks_controller.rb +21 -0
  36. data/lib/generators/boring/oauth/twitter/install/install_generator.rb +36 -0
  37. data/lib/generators/boring/oauth/twitter/install/templates/README +23 -0
  38. data/lib/generators/boring/oauth/twitter/install/templates/omniauth_callbacks_controller.rb +21 -0
  39. data/lib/generators/boring/payments/stripe/install/install_generator.rb +44 -0
  40. data/lib/generators/boring/payments/stripe/install/templates/README +14 -0
  41. data/lib/generators/boring/payments/stripe/install/templates/controllers/charges_controller.rb +38 -0
  42. data/lib/generators/boring/payments/stripe/install/templates/stripe.rb +6 -0
  43. data/lib/generators/boring/payments/stripe/install/templates/views/charges.html.erb +7 -0
  44. data/lib/generators/boring/payments/stripe/install/templates/views/create.html.erb +1 -0
  45. data/lib/generators/boring/payments/stripe/install/templates/views/new.html.erb +19 -0
  46. data/lib/generators/boring/pundit/install/install_generator.rb +85 -0
  47. data/lib/generators/boring/simple_form/install/install_generator.rb +44 -0
  48. data/lib/generators/boring/tailwind/install/install_generator.rb +12 -11
  49. data/lib/generators/boring/tailwind/install/templates/README +13 -0
  50. data/lib/generators/boring/twilio/install/install_generator.rb +30 -0
  51. data/lib/generators/boring/twilio/install/templates/README +11 -0
  52. data/lib/generators/boring/twilio/install/templates/twilio.rb +4 -0
  53. metadata +42 -665
  54. data/.travis.yml +0 -6
@@ -0,0 +1,23 @@
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
+ 3. Your omniauth callback URL will be: `<host>/users/auth/facebook/callback`. Please update
21
+ callback URL in Facebook after registering your omniauth application.
22
+
23
+ ===============================================================================
@@ -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,23 @@
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
+ 3. Your omniauth callback URL will be: `<host>/users/auth/github/callback`. Please update
21
+ callback URL in Github after registering your omniauth application.
22
+
23
+ ===============================================================================
@@ -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,23 @@
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
+ 3. Your omniauth callback URL will be: `<host>/users/auth/google_oauth2/callback`. Please update
21
+ callback URL in Google after registering your omniauth application.
22
+
23
+ ===============================================================================
@@ -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
@@ -0,0 +1,23 @@
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 twitter omniauth APP_ID and APP_SECRET in "config/initializers/devise.rb"
15
+ after registering the Rails application on: https://developer.twitter.com/en/apps
16
+ For example:
17
+
18
+ config.omniauth :twitter, "APP_ID", "APP_SECRET"
19
+
20
+ 3. Your omniauth callback URL will be: `<host>/users/auth/twitter/callback`. Please update
21
+ callback URL in Twitter after registering your omniauth application.
22
+
23
+ ===============================================================================
@@ -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: :twitter
4
+
5
+ def twitter
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: "Twitter") if is_navigational_format?
12
+ else
13
+ session["devise.twitter_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,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Boring
4
+ module Payments
5
+ module Stripe
6
+ class InstallGenerator < Rails::Generators::Base
7
+ desc "Adds stripe payment method to the application"
8
+ source_root File.expand_path("templates", __dir__)
9
+
10
+ def add_stripe_gem
11
+ say "Adding stripe gem", :green
12
+ Bundler.with_unbundled_env do
13
+ run "bundle add stripe"
14
+ end
15
+ end
16
+
17
+ def add_charges_controller
18
+ say "Adding stripe charge resources"
19
+ copy_file("controllers/charges_controller.rb", "app/controllers/charges_controller.rb")
20
+ end
21
+
22
+ def add_stripe_routes
23
+ route "resources :charges"
24
+ end
25
+
26
+ def add_stripe_initializer
27
+ say "Adding stripe initalizers"
28
+ copy_file("stripe.rb", "config/initializers/stripe.rb")
29
+ end
30
+
31
+ def add_stripe_views
32
+ say "Adding stripe views and layout"
33
+ copy_file("views/charges.html.erb", "app/views/layouts/charges.html.erb")
34
+ copy_file("views/new.html.erb", "app/views/charges/new.html.erb")
35
+ copy_file("views/create.html.erb", "app/views/charges/create.html.erb")
36
+ end
37
+
38
+ def show_readme
39
+ readme "README"
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,14 @@
1
+ ===============================================================================
2
+
3
+ Some setup you must do manually if you haven't yet:
4
+
5
+ Update the stripe PUBLISHABLE_KEY and SECRET_KEY in "config/initializers/stripe.rb"
6
+ after registering the Rails application on: https://dashboard.stripe.com/register
7
+ For example:
8
+
9
+ Rails.configuration.stripe = {
10
+ :publishable_key => ENV['PUBLISHABLE_KEY'],
11
+ :secret_key => ENV['SECRET_KEY']
12
+ }
13
+
14
+ ===============================================================================
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ChargesController < ApplicationController
4
+ def new
5
+ render
6
+ end
7
+
8
+ def create
9
+ if create_stripe_customer && create_stripe_charge
10
+ redirect_to root_path, flash: { success: "Boring stripe setup is successful" }
11
+ else
12
+ redirect_to new_charge_path, flash: { error: "Ugh. Something went wrong in setup." }
13
+ end
14
+ rescue Stripe::CardError => e
15
+ flash[:error] = e.message
16
+ redirect_to new_charge_path
17
+ end
18
+
19
+ private
20
+ def create_stripe_customer
21
+ @customer = Stripe::Customer.create({
22
+ email: params[:stripeEmail],
23
+ source: params[:stripeToken],
24
+ })
25
+ end
26
+
27
+ def create_stripe_charge
28
+ # Amount in cents
29
+ @amount = 500
30
+
31
+ Stripe::Charge.create({
32
+ customer: customer.id,
33
+ amount: @amount,
34
+ description: 'Rails Stripe customer',
35
+ currency: 'usd',
36
+ })
37
+ end
38
+ end
@@ -0,0 +1,6 @@
1
+ Rails.configuration.stripe = {
2
+ :publishable_key => ENV['PUBLISHABLE_KEY'],
3
+ :secret_key => ENV['SECRET_KEY']
4
+ }
5
+
6
+ Stripe.api_key = Rails.configuration.stripe[:secret_key]
@@ -0,0 +1,7 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head></head>
4
+ <body>
5
+ <%= yield %>
6
+ </body>
7
+ </html>
@@ -0,0 +1 @@
1
+ <h2>Thanks, you paid <strong>$5.00</strong>!</h2>
@@ -0,0 +1,19 @@
1
+ <%= form_tag charges_path do %>
2
+ <article>
3
+ <% if flash[:error].present? %>
4
+ <div id="error_explanation">
5
+ <p><%= flash[:error] %></p>
6
+ </div>
7
+ <% end %>
8
+
9
+ <label class="amount">
10
+ <span>Amount: $5.00</span>
11
+ </label>
12
+ </article>
13
+
14
+ <script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
15
+ data-key="<%= Rails.configuration.stripe[:publishable_key] %>"
16
+ data-description="A month's subscription"
17
+ data-amount="500"
18
+ data-locale="auto"></script>
19
+ <% end %>