boring_generators 0.6.0 → 0.11.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 (50) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +7 -1
  3. data/CHANGELOG.md +23 -0
  4. data/Gemfile.lock +65 -65
  5. data/README.md +20 -7
  6. data/Rakefile +1 -0
  7. data/lib/boring_generators/version.rb +1 -1
  8. data/lib/generators/boring/active_storage/aws/install/install_generator.rb +10 -8
  9. data/lib/generators/boring/active_storage/azure/install/install_generator.rb +9 -7
  10. data/lib/generators/boring/active_storage/google/install/install_generator.rb +9 -7
  11. data/lib/generators/boring/ahoy/install/install_generator.rb +31 -0
  12. data/lib/generators/boring/ahoy/install/templates/README +10 -0
  13. data/lib/generators/boring/audit/install/install_generator.rb +12 -9
  14. data/lib/generators/boring/bullet/install/install_generator.rb +4 -8
  15. data/lib/generators/boring/ci/github_action/install/install_generator.rb +1 -1
  16. data/lib/generators/boring/ci/github_action/install/templates/ci.yml.tt +15 -2
  17. data/lib/generators/boring/devise/install/install_generator.rb +1 -7
  18. data/lib/generators/boring/font_awesome/ruby_gem/install/install_generator.rb +3 -8
  19. data/lib/generators/boring/graphql/install/install_generator.rb +3 -7
  20. data/lib/generators/boring/oauth/base_generator.rb +63 -0
  21. data/lib/generators/boring/oauth/facebook/install/install_generator.rb +12 -67
  22. data/lib/generators/boring/oauth/facebook/install/templates/README +2 -3
  23. data/lib/generators/boring/oauth/github/install/install_generator.rb +36 -0
  24. data/lib/generators/boring/oauth/github/install/templates/README +23 -0
  25. data/lib/generators/boring/oauth/github/install/templates/omniauth_callbacks_controller.rb +21 -0
  26. data/lib/generators/boring/oauth/google/install/install_generator.rb +36 -0
  27. data/lib/generators/boring/oauth/google/install/templates/README +23 -0
  28. data/lib/generators/boring/oauth/google/install/templates/omniauth_callbacks_controller.rb +21 -0
  29. data/lib/generators/boring/oauth/twitter/install/install_generator.rb +36 -0
  30. data/lib/generators/boring/oauth/twitter/install/templates/README +23 -0
  31. data/lib/generators/boring/oauth/twitter/install/templates/omniauth_callbacks_controller.rb +21 -0
  32. data/lib/generators/boring/paper_trail/install/install_generator.rb +40 -0
  33. data/lib/generators/boring/payments/stripe/install/install_generator.rb +43 -0
  34. data/lib/generators/boring/payments/stripe/install/templates/README +21 -0
  35. data/lib/generators/boring/payments/stripe/install/templates/controllers/stripe/checkouts_controller.rb +63 -0
  36. data/lib/generators/boring/payments/stripe/install/templates/stripe.rb +1 -0
  37. data/lib/generators/boring/payments/stripe/install/templates/views/stripe/checkouts/create.js.erb +13 -0
  38. data/lib/generators/boring/payments/stripe/install/templates/views/stripe/checkouts/show.html.erb +8 -0
  39. data/lib/generators/boring/pry/install/install_generator.rb +4 -9
  40. data/lib/generators/boring/pundit/install/install_generator.rb +1 -7
  41. data/lib/generators/boring/rails_admin/install/install_generator.rb +36 -0
  42. data/lib/generators/boring/rubocop/install/install_generator.rb +3 -1
  43. data/lib/generators/boring/simple_form/install/install_generator.rb +4 -8
  44. data/lib/generators/boring/stimulus/install/install_generator.rb +24 -0
  45. data/lib/generators/boring/tailwind/install/install_generator.rb +11 -10
  46. data/lib/generators/boring/tailwind/install/templates/README +13 -0
  47. data/lib/generators/boring/twilio/install/install_generator.rb +26 -0
  48. data/lib/generators/boring/twilio/install/templates/README +11 -0
  49. data/lib/generators/boring/twilio/install/templates/twilio.rb +4 -0
  50. metadata +27 -2
@@ -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,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Boring
4
+ module PaperTrail
5
+ class InstallGenerator < Rails::Generators::Base
6
+ desc "Adds paper trail to the application"
7
+ source_root File.expand_path("templates", __dir__)
8
+
9
+ class_option :skip_generator, type: :boolean, aliases: "-sg",
10
+ desc: "Skip running paper_trail install generator"
11
+ class_option :skip_user_track_config, type: :boolean, aliases: "-sutc",
12
+ desc: "Skip adding config for tracking devise user in paper_trail"
13
+
14
+ def add_bullet_gem
15
+ say "Adding paper trail gems", :green
16
+ Bundler.with_unbundled_env do
17
+ run "bundle add paper_trail"
18
+ end
19
+ end
20
+
21
+ def run_paper_trail_generator
22
+ return if options[:skip_generator]
23
+
24
+ say "Running rails_admin generator", :green
25
+ Bundler.with_unbundled_env do
26
+ run "DISABLE_SPRING=1 bundle exec rails generate paper_trail:install --with-changes"
27
+ end
28
+ end
29
+
30
+ def set_configuration_to_track_whodunnit
31
+ return if options[:skip_user_track_config]
32
+
33
+ say "Setting configuration to track devise current_user", :green
34
+ insert_into_file "app/controllers/application_controller.rb", <<~RUBY, after: /class ApplicationController < ActionController::Base/
35
+ \tbefore_action :set_paper_trail_whodunnit
36
+ RUBY
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,43 @@
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_checkouts_resources
18
+ say "Adding stripe checkout resources"
19
+ copy_file("controllers/stripe/checkouts_controller.rb", "app/controllers/stripe/checkouts_controller.rb")
20
+ copy_file("views/stripe/checkouts/create.js.erb", "app/views/stripe/checkouts/create.js.erb")
21
+ copy_file("views/stripe/checkouts/show.html.erb", "app/views/stripe/checkouts/show.html.erb")
22
+ end
23
+
24
+ def add_stripe_routes
25
+ route <<~ROUTE
26
+ namespace :stripe do
27
+ resource :checkout, only: [:create, :show]
28
+ end
29
+ ROUTE
30
+ end
31
+
32
+ def add_stripe_initializer
33
+ say "Adding stripe initalizers"
34
+ copy_file("stripe.rb", "config/initializers/stripe.rb")
35
+ end
36
+
37
+ def show_readme
38
+ readme "README"
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,21 @@
1
+ ===============================================================================
2
+
3
+ Some setup you must do manually if you haven't yet:
4
+
5
+ 1. Register your Rails application on: https://dashboard.stripe.com/register
6
+ 2. Update the stripe PUBLISHABLE_KEY in "config/initializers/stripe.rb"
7
+ For example:
8
+
9
+ Stripe.api_key = ENV['STRIPE_SECRET_KEY']
10
+
11
+ 3. Update stripe PUBLISHABLE_KEY in the "views/stripe/checkouts/create.js.erb"
12
+ For example:
13
+
14
+ var stripe = Stripe(ENV["STRIPE_PUBLISHABLE_KEY"]);
15
+
16
+ 4. Update "controllers/stripe/checkouts_controller.rb" with stripe checkout
17
+ line_items, success and failure callback URLs.
18
+
19
+ 5. Go to: http://localhost:3000/stripe/checkout and try the checkout flow.
20
+
21
+ ===============================================================================
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Stripe::CheckoutsController < ApplicationController
4
+ def create
5
+ begin
6
+ @stripe_session = Stripe::Checkout::Session.create(checkout_payload)
7
+
8
+ respond_to :js
9
+ rescue Stripe::CardError => e
10
+ puts "Status is: #{e.http_status}"
11
+ puts "Type is: #{e.error.type}"
12
+ puts "Charge ID is: #{e.error.charge}"
13
+ # The following fields are optional
14
+ puts "Code is: #{e.error.code}" if e.error.code
15
+ puts "Decline code is: #{e.error.decline_code}" if e.error.decline_code
16
+ puts "Param is: #{e.error.param}" if e.error.param
17
+ puts "Message is: #{e.error.message}" if e.error.message
18
+ rescue Stripe::RateLimitError => e
19
+ # Too many requests made to the API too quickly
20
+ rescue Stripe::InvalidRequestError => e
21
+ # Invalid parameters were supplied to Stripe's API
22
+ rescue Stripe::AuthenticationError => e
23
+ # Authentication with Stripe's API failed
24
+ # (maybe you changed API keys recently)
25
+ rescue Stripe::APIConnectionError => e
26
+ # Network communication with Stripe failed
27
+ rescue Stripe::StripeError => e
28
+ # Display a very generic error to the user, and maybe send
29
+ # yourself an email
30
+ rescue => e
31
+ # Something else happened, completely unrelated to Stripe
32
+ end
33
+ end
34
+
35
+ def show
36
+ render
37
+ end
38
+
39
+ private
40
+ # In the payload, the line items consists of list of items the customer is purchasing.
41
+ # Refer the guides to learn more about parameters accepted by the <line_items>
42
+ # https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items
43
+ #
44
+ # Sample: <line_items> looks like as follows:
45
+ # line_items: [{
46
+ # price_data: {
47
+ # currency: 'usd', # Three-letter ISO currency code, in lowercase
48
+ # product: <product_id> # Product ID created on stripe.
49
+ # product_data: { name: 'T-shirt' }, # Product Data (Either product_data or product is requried).
50
+ # unit_amount: 2000, # A non-negative integer in cents representing how much to charge
51
+ # },
52
+ # quantity: 1,
53
+ # }]
54
+ def checkout_payload
55
+ {
56
+ payment_method_types: ['card'], # https://stripe.com/docs/api/payment_methods/object#payment_method_object-type
57
+ line_items: @line_items || [],
58
+ mode: 'payment',
59
+ success_url: root_url, # <custom_success_path>
60
+ cancel_url: root_url, # <custom_cancellation_path>
61
+ }
62
+ end
63
+ end
@@ -0,0 +1 @@
1
+ Stripe.api_key = ENV['STRIPE_SECRET_KEY']
@@ -0,0 +1,13 @@
1
+ // TODO: Please update the stripe publishable key here.
2
+ var stripe = Stripe(ENV["STRIPE_PUBLISHABLE_KEY"]);
3
+
4
+ stripe.redirectToCheckout({
5
+ sessionId: "<%= @stripe_session.id %>"
6
+ }).then(function(result) {
7
+ // If `redirectToCheckout` fails due to a browser or network
8
+ // error, you should display the localized error message to your
9
+ // customer using `error.message`.
10
+ if (result.error) {
11
+ alert(result.error.message);
12
+ }
13
+ });
@@ -0,0 +1,8 @@
1
+ <div style="text-align:center;">
2
+ <h1>Checkout View</h1>
3
+ <h5>(from <a href="https://github.com/abhaynikam/boring_generators">Boring Generator Gem</a>)</h5>
4
+
5
+ <%= button_to "Try Checkout", stripe_checkout_path, remote: true, class: "btn btn-primary" %>
6
+ <script src="https://js.stripe.com/v3/"></script>
7
+ </div>
8
+
@@ -7,15 +7,10 @@ module Boring
7
7
  source_root File.expand_path("templates", __dir__)
8
8
 
9
9
  def add_bullet_gem
10
- say "Adding Bullet gem", :green
11
- pry_gem_content = <<~RUBY
12
- \n
13
- # for using pry as Rails console
14
- gem "pry"
15
- gem "pry-rails"
16
- RUBY
17
- append_to_file "Gemfile", pry_gem_content
18
- run "bundle install"
10
+ say "Adding pry gems", :green
11
+ Bundler.with_unbundled_env do
12
+ run "bundle add pry pry-rails"
13
+ end
19
14
  end
20
15
 
21
16
  def add_pryrc_configuration
@@ -14,14 +14,8 @@ module Boring
14
14
 
15
15
  def add_pundit_gem
16
16
  say "Adding Pundit gem", :green
17
- pundit_gem = <<~RUBY
18
- \n
19
- # for authorization
20
- gem 'pundit', '~> 2.1'
21
- RUBY
22
- append_to_file "Gemfile", pundit_gem
23
17
  Bundler.with_unbundled_env do
24
- run "bundle install"
18
+ run "bundle add pundit"
25
19
  end
26
20
  end
27
21
 
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Boring
4
+ module RailsAdmin
5
+ class InstallGenerator < Rails::Generators::Base
6
+ desc "Adds rails_admin to the application"
7
+ source_root File.expand_path("templates", __dir__)
8
+
9
+ class_option :skip_generator, type: :boolean, aliases: "-sg",
10
+ desc: "Skip running rails_admin install generator"
11
+ class_option :route_name, type: :string, aliases: "-r",
12
+ desc: "Mount the rails_admin engine on route"
13
+
14
+ def add_rails_admin_ruby_gem
15
+ say "Adding rails_admin gem", :green
16
+ Bundler.with_unbundled_env do
17
+ run "bundle add rails_admin"
18
+ end
19
+ end
20
+
21
+ def run_rails_admin_generator
22
+ return if options[:skip_generator]
23
+ if options[:route_name].present?
24
+ say "Running rails_admin generator", :green
25
+ Bundler.with_unbundled_env do
26
+ run "DISABLE_SPRING=1 bundle exec rails generate rails_admin:install #{options[:route_name]}"
27
+ end
28
+ else
29
+ say <<~WARNING, :red
30
+ ERROR: Please specify the --route_name=<name> where you want to mount the rails_admin engine
31
+ WARNING
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -23,7 +23,9 @@ module Boring
23
23
  \tgem "rubocop-performance", require: false
24
24
  RUBY
25
25
  insert_into_file "Gemfile", bullet_gem_content, after: /group :development do/
26
- run "bundle install"
26
+ Bundler.with_unbundled_env do
27
+ run "bundle install"
28
+ end
27
29
  end
28
30
 
29
31
  def add_rails_prefered_rubocop_rules
@@ -15,13 +15,9 @@ module Boring
15
15
 
16
16
  def add_bullet_gem
17
17
  say "Adding SimpleForm gem", :green
18
- simple_form_content = <<~RUBY
19
- \n
20
- # for simple forms
21
- gem 'simple_form', '~> 5.0'
22
- RUBY
23
- append_to_file "Gemfile", simple_form_content
24
- run "bundle install"
18
+ Bundler.with_unbundled_env do
19
+ run "bundle add simple_form"
20
+ end
25
21
  end
26
22
 
27
23
  def run_simple_form_generator
@@ -29,7 +25,7 @@ module Boring
29
25
 
30
26
  say "Running SimpleForm Generator", :green
31
27
  if options[:css_framework].present? && ALLOWED_CSS_FRAMEWORK.include?(options[:css_framework])
32
- run "rails generate simple_form:install --#{options[:css_framework]}"
28
+ run "DISABLE_SPRING=1 bundle exec rails generate simple_form:install --#{options[:css_framework]}"
33
29
  elsif options[:css_framework].present?
34
30
  say <<~WARNING, :red
35
31
  ERROR: Invalid option css_framework: #{options[:css_framework]}. Generator allows css_framework: #{ALLOWED_CSS_FRAMEWORK.join(", ")}
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Boring
4
+ module Stimulus
5
+ class InstallGenerator < Rails::Generators::Base
6
+ desc "Adds Stimulus to the application"
7
+ source_root File.expand_path("templates", __dir__)
8
+
9
+ def add_stimulus_ruby_gem
10
+ say "Adding Stimulus gem", :green
11
+ Bundler.with_unbundled_env do
12
+ run "bundle add stimulus-rails"
13
+ end
14
+ end
15
+
16
+ def generating_devise_defaults
17
+ say "Generating stimulus defaults", :green
18
+ Bundler.with_unbundled_env do
19
+ run "DISABLE_SPRING=1 bundle exec rails stimulus:install"
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end