boring_generators 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 66c4c0c7499756d66e0d992e4ec79ad105f310b40384a49d99b1a3f96ebfaeab
4
- data.tar.gz: '074778686e124d14e6010e6a886b209484abf2774e0836e48631c900738f3ae8'
3
+ metadata.gz: 1c38ce00aea24f2d84874abeaf67e8fc1e917934b8dc24e7a722c695cd55b75f
4
+ data.tar.gz: 3373b320ace30d8a04e14af9780b65b819f266712cfd37e676f89872ce157cb5
5
5
  SHA512:
6
- metadata.gz: 44e5a7cfde50201a16ce39cd6c1e28618efe002229e81f15613278bdfdb5f448a4d02532d974b7fe232742cd5d6b5c55ac9aa851b84cad8bc90c1cb7c9efdb77
7
- data.tar.gz: 7ec572ba9730632511e08d4aa6a943a8c97db89ae93c0b5d2db4813b9ece7ac53b586b1690d2f636d1bd7fcff6c46572501ec69752af1008b43c949e1789e456
6
+ metadata.gz: f9e074f948419ff51132578335b1b9003ba99f73779b535b0a306753a3057dd924833d31eeb12091af4ebbb0db59b0ea5faa207da0ae9e413a6c3c7d61f24f32
7
+ data.tar.gz: 5c06d9e92fa9b7f5599cdf77d5c391c59adffea7ccdad470e723daa1190bc94ded77b57e4417564b5ebcc53507c3b421b1093b827ea81aaa4ea2786813531df6
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## master (unreleased)
4
4
 
5
+ ## 0.7.0 (January 30th, 2021)
6
+ * Upgrade the Tailwind CSS generator to support Tailwind V2.0. ([@abhaynikam][])
7
+ * Adds Devise GitHub Omniauth generator. ([@abhaynikam][])
8
+
5
9
  ## 0.6.0 (January 10th, 2021)
6
10
  * Updates default ruby version of GitHub Actions install generator. ([@jamesglover][])
7
11
  * Simplify generated GitHub Actions install ([@jamesglover][])
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- boring_generators (0.5.0)
4
+ boring_generators (0.7.0)
5
5
  railties
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -61,6 +61,7 @@ The boring generator introduces following generators:
61
61
  - Install SimpleForm: `rails generate boring:simple_form:install --css_framework=<css_framework>`
62
62
  - Install Devise: `rails generate boring:devise:install`
63
63
  - Install Devise Facebook Omniauth: `rails generate boring:oauth:facebook:install`
64
+ - Install Devise GitHub Omniauth: `rails generate boring:oauth:github:install`
64
65
 
65
66
  ## Development
66
67
 
@@ -1,3 +1,3 @@
1
1
  module BoringGenerators
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.0"
3
3
  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
@@ -1,11 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'bundler'
4
+ require 'generators/boring/oauth/base_generator'
4
5
 
5
6
  module Boring
6
7
  module Oauth
7
8
  module Facebook
8
9
  class InstallGenerator < Rails::Generators::Base
10
+ include Boring::Oauth::BaseGenerator
11
+
9
12
  class MissingDeviseConfigurationError < StandardError; end
10
13
 
11
14
  desc "Adds facebook OmniAuth to the application"
@@ -24,66 +27,14 @@ module Boring
24
27
  end
25
28
  end
26
29
 
27
- def add_provider_and_uuid_user_details
28
- say "Adding migration to add provider and uuid columns to users", :green
29
- Bundler.with_unbundled_env do
30
- run "DISABLE_SPRING=1 bundle exec rails generate migration AddOmniauthToUsers provider:string uid:string"
31
- end
32
- end
33
-
34
- def configure_devise_omniauth_facebook
35
- say "Adding omniauth devise configuration", :green
36
- if File.exist?("config/initializers/devise.rb")
37
- insert_into_file "config/initializers/devise.rb", <<~RUBY, after: /Devise.setup do \|config\|/
38
- \n
39
- \tconfig.omniauth :facebook, "APP_ID", "APP_SECRET"
40
- RUBY
41
- else
42
- raise MissingDeviseConfigurationError, <<~ERROR
43
- Looks like the devise installation is incomplete. Could not find devise.rb in config/initializers.
44
- ERROR
45
- end
46
- end
47
-
48
- def add_omniauth_callback_routes
49
- devise_route = '# devise_for :users, controllers: { omniauth_callbacks: "users/omniauth_callbacks" }'.dup
50
- route devise_route
51
- end
52
-
53
- def add_omniauth_callback_controller
54
- say "Copying omniauth_callbacks_controller.rb", :green
55
- template("omniauth_callbacks_controller.rb", "app/controllers/users/omniauth_callbacks_controller.rb")
56
- end
57
-
58
- def configure_and_add_devise_setting_in_user_model
59
- say "Configuring facebook omniauth for user model", :green
60
- insert_into_file "app/models/user.rb", <<~RUBY, after: /class User < ApplicationRecord/
61
-
62
- \tdevise :omniauthable, omniauth_providers: %i[facebook]
63
-
64
- \tdef self.from_omniauth(auth)
65
- \twhere(provider: auth.provider, uid: auth.uid).first_or_create do |user|
66
- \tuser.email = auth.info.email
67
- \tuser.password = Devise.friendly_token[0, 20]
68
- \tuser.name = auth.info.name # assuming the user model has a name
69
- \t# user.image = auth.info.image # assuming the user model has an image
70
- \t# If you are using confirmable and the provider(s) you use validate emails,
71
- \t# uncomment the line below to skip the confirmation emails.
72
- \t# user.skip_confirmation!
73
- \tend
74
- \tend
75
- RUBY
76
- end
77
-
78
- def add_the_facebook_devise_omniauth_view
79
- insert_into_file "app/views/users/sessions/new.html.erb", <<~RUBY, after: /<%= render "users\/shared\/links" %>/
80
-
81
- <%= link_to "Sign in with Facebook", user_facebook_omniauth_authorize_path %>
82
- RUBY
83
- end
84
-
85
- def show_readme
86
- readme "README"
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
87
38
  end
88
39
  end
89
40
  end
@@ -16,9 +16,5 @@ Some setup you must do manually if you haven't yet:
16
16
  For example:
17
17
 
18
18
  config.omniauth :facebook, "APP_ID", "APP_SECRET"
19
- 3. Ensure you have added the facebook omniauth route in the devise session view:
20
- For example:
21
-
22
- <%= link_to "Sign in with Facebook", user_facebook_omniauth_authorize_path %>
23
19
 
24
20
  ===============================================================================
@@ -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
@@ -6,18 +6,12 @@ module Boring
6
6
  desc "Adds Tailwind CSS to the application"
7
7
  source_root File.expand_path("templates", __dir__)
8
8
 
9
- class_option :skip_tailwind_css_ui, type: :boolean, aliases: "-sui",
10
- desc: "Skip adding @tailwindcss/ui package"
11
9
  class_option :skip_tailwind_init_full, type: :boolean, aliases: "-sif",
12
10
  desc: "Skip running tailwindcss init with --full option"
13
11
 
14
12
  def add_tailwind_package
15
13
  say "Adding tailwind package", :green
16
- if options[:skip_tailwind_css_ui]
17
- run "yarn add tailwindcss"
18
- else
19
- run "yarn add tailwindcss @tailwindcss/ui"
20
- end
14
+ run "yarn add tailwindcss@latest postcss@latest autoprefixer@latest"
21
15
  end
22
16
 
23
17
  def create_tailwind_config
@@ -54,9 +48,12 @@ module Boring
54
48
 
55
49
  def insert_stylesheet_in_the_application
56
50
  if File.exist?("app/javascript/packs/application.js")
57
- append_to_file "app/javascript/packs/application.js" do
58
- 'import "stylesheets/application"'
59
- end
51
+ stylesheet_tailwind_imports = <<~RUBY
52
+ \n
53
+ import "stylesheets/application"
54
+ RUBY
55
+
56
+ append_to_file "app/javascript/packs/application.js", stylesheet_tailwind_imports
60
57
  else
61
58
  say <<~WARNING, :red
62
59
  ERROR: Looks like the webpacker installation is incomplete. Could not find application.js in app/javascript/packs.
@@ -69,6 +66,10 @@ module Boring
69
66
  \t\t<%= stylesheet_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
70
67
  RUBY
71
68
  end
69
+
70
+ def show_readme
71
+ readme "README"
72
+ end
72
73
  end
73
74
  end
74
75
  end
@@ -0,0 +1,13 @@
1
+ ===============================================================================
2
+
3
+ Some setup you must do manually if you haven't yet:
4
+
5
+ Current webpacker version relies on the older version of PostCSS.
6
+ Tailwind 2.0 doesn't support the older version of PostCSS. Please
7
+ update package.json to update webpacker version.
8
+
9
+ ```
10
+ "@rails/webpacker": "rails/webpacker#b6c2180",
11
+ ```
12
+
13
+ ===============================================================================
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: boring_generators
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abhay Nikam
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-10 00:00:00.000000000 Z
11
+ date: 2021-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -79,10 +79,14 @@ files:
79
79
  - lib/generators/boring/graphql/install/templates/base_resolver.rb
80
80
  - lib/generators/boring/graphql/install/templates/hello_world_resolver.rb
81
81
  - lib/generators/boring/jquery/install/install_generator.rb
82
+ - lib/generators/boring/oauth/base_generator.rb
82
83
  - lib/generators/boring/oauth/facebook/install/install_generator.rb
83
84
  - lib/generators/boring/oauth/facebook/install/templates/README
84
85
  - lib/generators/boring/oauth/facebook/install/templates/omniauth.rb
85
86
  - lib/generators/boring/oauth/facebook/install/templates/omniauth_callbacks_controller.rb
87
+ - lib/generators/boring/oauth/github/install/install_generator.rb
88
+ - lib/generators/boring/oauth/github/install/templates/README
89
+ - lib/generators/boring/oauth/github/install/templates/omniauth_callbacks_controller.rb
86
90
  - lib/generators/boring/pry/install/install_generator.rb
87
91
  - lib/generators/boring/pry/install/templates/pryrc
88
92
  - lib/generators/boring/pundit/install/install_generator.rb
@@ -90,6 +94,7 @@ files:
90
94
  - lib/generators/boring/rubocop/install/templates/.rubocop.yml.tt
91
95
  - lib/generators/boring/simple_form/install/install_generator.rb
92
96
  - lib/generators/boring/tailwind/install/install_generator.rb
97
+ - lib/generators/boring/tailwind/install/templates/README
93
98
  - lib/generators/boring/tailwind/install/templates/application.scss
94
99
  - tmp/templates/app_template/.ruby-version
95
100
  - tmp/templates/app_template/Gemfile