boring_generators 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +1 -1
- data/CHANGELOG.md +6 -0
- data/README.md +5 -0
- data/lib/boring_generators/version.rb +1 -1
- data/lib/generators/boring/bootstrap/install/install_generator.rb +2 -2
- data/lib/generators/boring/ci/github_action/install/install_generator.rb +2 -2
- data/lib/generators/boring/devise/install/install_generator.rb +67 -0
- data/lib/generators/boring/favicon/build/build_generator.rb +120 -0
- data/lib/generators/boring/favicon/build/templates/favicon.html.erb.tt +19 -0
- data/lib/generators/boring/graphql/install/install_generator.rb +51 -0
- data/lib/generators/boring/graphql/install/templates/base_resolver.rb +2 -0
- data/lib/generators/boring/graphql/install/templates/hello_world_resolver.rb +11 -0
- data/lib/generators/boring/pundit/install/install_generator.rb +85 -0
- data/lib/generators/boring/simple_form/install/install_generator.rb +44 -0
- metadata +10 -3
- data/.travis.yml +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75b70f624969fe4703d011e6eb9885aec618fa1292ed919610a151257126bbf0
|
4
|
+
data.tar.gz: e34d25d853079666eeb09c4a5c27b306f4a8a835a8d5e3f300ad7a126eb81b23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 042b85804c5a7fc75f79596d55ab2ca4ec688268781717dbb2d02755bc5b9d40ffe17b60951f46fb2c2365c8560c466b4161a029f2d3da1e8987f6306d1bd6ee
|
7
|
+
data.tar.gz: a643190096fbd0c4b78e798547219f56d1877e4f91110ff8919448c56a77a7c9a8d4170eadfc70353615e73b886fb6101bfabea290f6b52ad4b815c068096609
|
data/.github/workflows/ci.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
3
|
## master (unreleased)
|
4
|
+
* Adds favicon build generator. ([@abhaynikam][])
|
5
|
+
* Adds Pundit install generator. ([@CiTroNaK][])
|
6
|
+
* Adds GraphQL generator. ([@abhaynikam][])
|
7
|
+
* Adds SimpleForm generator. ([@abhaynikam][])
|
8
|
+
* Adds Devise generator. ([@abhaynikam][])
|
4
9
|
|
5
10
|
## 0.4.0 (October 23rd, 2020)
|
6
11
|
* Adds CircleCI install generator. ([@abhaynikam][])
|
@@ -28,3 +33,4 @@
|
|
28
33
|
* Initial release. ([@abhaynikam][])
|
29
34
|
|
30
35
|
[@abhaynikam]: https://github.com/abhaynikam
|
36
|
+
[@CiTroNaK]: https://github.com/CiTroNaK
|
data/README.md
CHANGED
@@ -50,6 +50,11 @@ The boring generator introduces following generators:
|
|
50
50
|
- Install GitHub Actions: `rails generate boring:ci:github_action:install --repository_name=<name> --ruby_version=<version>`
|
51
51
|
- Install Travis CI: `rails generate boring:ci:travisci:install --ruby_version=<version>`
|
52
52
|
- Install Rubocop: `rails generate boring:rubocop:install --ruby_version=<version>`
|
53
|
+
- Build Favicon: `rails generate boring:favicon:build --application_name=<application_name> --favico_letter=<favico_letter> --primary_color=<color>`
|
54
|
+
- Install Pundit: `rails generate boring:pundit:install`
|
55
|
+
- Install GraphQL: `rails generate boring:graphql:install`
|
56
|
+
- Install SimpleForm: `rails generate boring:simple_form:install --css_framework=<css_framework>`
|
57
|
+
- Install Devise: `rails generate boring:devise:install`
|
53
58
|
|
54
59
|
## Development
|
55
60
|
|
@@ -12,7 +12,7 @@ module Boring
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def add_jquery_plugin_provider_to_webpack_environment
|
15
|
-
say "
|
15
|
+
say "Adding jQuery and popper JS plugin in the webpack", :green
|
16
16
|
if File.exist?("config/webpack/environment.js")
|
17
17
|
insert_into_file "config/webpack/environment.js", <<~RUBY, after: /@rails\/webpacker.*\n/
|
18
18
|
const webpack = require("webpack")
|
@@ -37,7 +37,7 @@ module Boring
|
|
37
37
|
'@import "~bootstrap/scss/bootstrap";'
|
38
38
|
end
|
39
39
|
else
|
40
|
-
say "Copying application.scss with
|
40
|
+
say "Copying application.scss with bootstrap imports", :green
|
41
41
|
template("application.scss", "app/javascript/stylesheets/application.scss")
|
42
42
|
end
|
43
43
|
end
|
@@ -14,9 +14,9 @@ module Boring
|
|
14
14
|
class_option :ruby_version, type: :string, aliases: "-v",
|
15
15
|
desc: "Tell us the ruby version which you use for the application. Default to Ruby #{DEFAULT_RUBY_VERSION}"
|
16
16
|
class_option :node_version, type: :string, aliases: "-v",
|
17
|
-
desc: "Tell us the node version which you use for the application. Default to
|
17
|
+
desc: "Tell us the node version which you use for the application. Default to Node #{DEFAULT_NODE_VERSION}"
|
18
18
|
class_option :repository_name, type: :string, aliases: "-rn",
|
19
|
-
desc: "Tell us the repository name to be used as database name on
|
19
|
+
desc: "Tell us the repository name to be used as database name on GitHub Actions. Defaults to #{DEFAULT_REPOSITORY_NAME}"
|
20
20
|
|
21
21
|
def add_github_actions_configuration
|
22
22
|
@ruby_version = options[:ruby_version] ? options[:ruby_version] : DEFAULT_RUBY_VERSION
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Boring
|
4
|
+
module Devise
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
desc "Adds devise to the application"
|
7
|
+
|
8
|
+
DEFAULT_DEVISE_MODEL_NAME = "User"
|
9
|
+
|
10
|
+
class_option :model_name, type: :string, aliases: "-m",
|
11
|
+
desc: "Tell us the user model name which will be used for authentication. Defaults to #{DEFAULT_DEVISE_MODEL_NAME}"
|
12
|
+
class_option :skip_devise_view, type: :boolean, aliases: "-sv",
|
13
|
+
desc: "Skip generating devise views"
|
14
|
+
class_option :skip_devise_model, type: :boolean, aliases: "-sm",
|
15
|
+
desc: "Skip generating devise model"
|
16
|
+
|
17
|
+
def add_devise_gem
|
18
|
+
say "Adding devise gem", :green
|
19
|
+
devise_gem = <<~RUBY
|
20
|
+
\n
|
21
|
+
# for authentication
|
22
|
+
gem 'devise', '~> 4.7'
|
23
|
+
RUBY
|
24
|
+
append_to_file "Gemfile", devise_gem
|
25
|
+
run "bundle install"
|
26
|
+
end
|
27
|
+
|
28
|
+
def generating_devise_defaults
|
29
|
+
say "Generating devise defaults", :green
|
30
|
+
run "DISABLE_SPRING=1 rails generate devise:install"
|
31
|
+
end
|
32
|
+
|
33
|
+
def add_devise_action_mailer_development_config
|
34
|
+
say "Adding devise Action Mailer development configuration", :green
|
35
|
+
insert_into_file "config/environments/development.rb", <<~RUBY, after: /Rails.application.configure do/
|
36
|
+
\n
|
37
|
+
\tconfig.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
|
38
|
+
RUBY
|
39
|
+
end
|
40
|
+
|
41
|
+
def add_devise_user_model
|
42
|
+
return if options[:skip_devise_model]
|
43
|
+
|
44
|
+
say "Adding devise user model", :green
|
45
|
+
model_name = options[:model_name] || DEFAULT_DEVISE_MODEL_NAME
|
46
|
+
|
47
|
+
run "DISABLE_SPRING=1 rails generate devise #{model_name}"
|
48
|
+
end
|
49
|
+
|
50
|
+
def add_devise_authentication_filter_to_application_controller
|
51
|
+
insert_into_file "app/controllers/application_controller.rb", <<~RUBY, after: /class ApplicationController < ActionController::Base/
|
52
|
+
\n
|
53
|
+
\tbefore_action :authenticate_user!
|
54
|
+
RUBY
|
55
|
+
end
|
56
|
+
|
57
|
+
def add_devise_views
|
58
|
+
return if options[:skip_devise_view]
|
59
|
+
|
60
|
+
say "Adding devise views", :green
|
61
|
+
model_name = options[:model_name] || DEFAULT_DEVISE_MODEL_NAME
|
62
|
+
|
63
|
+
run "rails generate devise:views #{model_name.pluralize}"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Boring
|
4
|
+
module Favicon
|
5
|
+
class BuildGenerator < Rails::Generators::Base
|
6
|
+
desc "Build favicons for all platforms"
|
7
|
+
source_root File.expand_path("templates", __dir__)
|
8
|
+
|
9
|
+
ICO_SIZES = %w(16 32)
|
10
|
+
APPLE_SIZES = %w(57 60 72 76 114 120 129 144 152)
|
11
|
+
APPLE_PRECOMPOSED_SIZES = %w(120 129 152)
|
12
|
+
SMALL_BREAK = 50
|
13
|
+
LARGE_BREAK = 150
|
14
|
+
MS_TILE_SIZES = %w(144)
|
15
|
+
FAVICON_DIR = "favicons"
|
16
|
+
FILE_FAVICO_DIR = "app/assets/images/#{FAVICON_DIR}"
|
17
|
+
DEFAULT_PRIMARY_COLOR = "#082472"
|
18
|
+
DEFAULT_FAVICON_LETTER = "B" # B for boring_generators :)
|
19
|
+
DEFAULT_IMAGE_PATH = "#{FILE_FAVICO_DIR}/template.png"
|
20
|
+
|
21
|
+
class_option :primary_color, type: :string, aliases: "-color",
|
22
|
+
desc: "Tell us the primary color to build favicon. Default to primary: #{DEFAULT_PRIMARY_COLOR}"
|
23
|
+
class_option :favico_letter, type: :string, aliases: "-letter",
|
24
|
+
desc: "Tell us the favicon letter to build favicon. Default to primary: #{DEFAULT_FAVICON_LETTER}"
|
25
|
+
class_option :font_file_path, type: :string, aliases: "-fp",
|
26
|
+
desc: "Tell us the font to be used generate favicon."
|
27
|
+
class_option :application_name, type: :string, aliases: "-app_name",
|
28
|
+
desc: "Tell us the application name to be used in favicon partial."
|
29
|
+
|
30
|
+
def build_favicon
|
31
|
+
@application_name = options[:application_name]
|
32
|
+
@primary_color = options[:primary_color]
|
33
|
+
|
34
|
+
unless /Version/m =~ (`convert -version`)
|
35
|
+
say <<~WARNING, :red
|
36
|
+
ERROR: You do not have ImageMagick installed.
|
37
|
+
WARNING
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def create_favicon_directory
|
42
|
+
unless File.exists?(FILE_FAVICO_DIR)
|
43
|
+
Dir.mkdir FILE_FAVICO_DIR
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def build_favicon_for_existing_template_image
|
48
|
+
return unless File.exist?(DEFAULT_IMAGE_PATH)
|
49
|
+
|
50
|
+
say "Converting template image to favicons..."
|
51
|
+
template_name = "#{FILE_FAVICO_DIR}/template.png"
|
52
|
+
template_small_name = "#{FILE_FAVICO_DIR}/template-small.png"
|
53
|
+
template_large_name = "#{FILE_FAVICO_DIR}/template-large.png"
|
54
|
+
template_small_name = template_name unless File.file?(template_small_name)
|
55
|
+
template_large_name = template_name unless File.file?(template_large_name)
|
56
|
+
ICO_SIZES.each do |size|
|
57
|
+
ico_template = template_name
|
58
|
+
ico_template = template_small_name if size.to_i <= SMALL_BREAK
|
59
|
+
ico_template = template_small_name if size.to_i >= LARGE_BREAK
|
60
|
+
(`convert #{ico_template} -resize #{size}x#{size} #{FILE_FAVICO_DIR}/favicon-#{size}x#{size}.ico`)
|
61
|
+
end
|
62
|
+
APPLE_SIZES.each do |size|
|
63
|
+
ico_template = template_name
|
64
|
+
ico_template = template_small_name if size.to_i <= SMALL_BREAK
|
65
|
+
ico_template = template_small_name if size.to_i >= LARGE_BREAK
|
66
|
+
(`convert #{ico_template} -resize #{size}x#{size} #{FILE_FAVICO_DIR}/apple-touch-icon-#{size}x#{size}.png`)
|
67
|
+
end
|
68
|
+
APPLE_PRECOMPOSED_SIZES.each do |size|
|
69
|
+
ico_template = template_name
|
70
|
+
ico_template = template_small_name if size.to_i <= SMALL_BREAK
|
71
|
+
ico_template = template_small_name if size.to_i >= LARGE_BREAK
|
72
|
+
(`convert #{ico_template} -resize #{size}x#{size} #{FILE_FAVICO_DIR}/apple-touch-icon-#{size}x#{size}-precomposed.png`)
|
73
|
+
end
|
74
|
+
MS_TILE_SIZES.each do |size|
|
75
|
+
ico_template = template_name
|
76
|
+
ico_template = template_small_name if size.to_i <= SMALL_BREAK
|
77
|
+
ico_template = template_small_name if size.to_i >= LARGE_BREAK
|
78
|
+
(`convert #{ico_template} -resize #{size}x#{size} #{FILE_FAVICO_DIR}/mstile-#{size}x#{size}.png`)
|
79
|
+
end
|
80
|
+
ico_template = template_name
|
81
|
+
ico_template = template_small_name if 152 <= SMALL_BREAK
|
82
|
+
ico_template = template_small_name if 152 >= LARGE_BREAK
|
83
|
+
(`convert #{ico_template} -resize 152x152 #{FILE_FAVICO_DIR}/apple-touch-icon.png`)
|
84
|
+
(`convert #{ico_template} -resize 152x152 #{FILE_FAVICO_DIR}/apple-touch-icon-precomposed.png`)
|
85
|
+
end
|
86
|
+
|
87
|
+
def generate_new_favicon_using_favico_letter
|
88
|
+
return if File.exist?(DEFAULT_IMAGE_PATH)
|
89
|
+
say "Creating favicons from application...", :green
|
90
|
+
|
91
|
+
favico_letter = options[:favico_letter] || @application_name.try(:first) || DEFAULT_FAVICON_LETTER
|
92
|
+
font_file_path = options[:font_file_path]
|
93
|
+
favicon_color = options[:primary_color] || DEFAULT_PRIMARY_COLOR
|
94
|
+
|
95
|
+
ICO_SIZES.each do |size|
|
96
|
+
(`convert -background "#{favicon_color}" -fill white -size #{size}x#{size} -gravity center #{font_file_path ? "-font #{font_file_path}" : ""} label:#{favico_letter} #{FILE_FAVICO_DIR}/favicon-#{size}x#{size}.ico`)
|
97
|
+
end
|
98
|
+
APPLE_SIZES.each do |size|
|
99
|
+
(`convert -background "#{favicon_color}" -fill white -size #{size}x#{size} -gravity center #{font_file_path ? "-font #{font_file_path}" : ""} label:#{favico_letter} #{FILE_FAVICO_DIR}/apple-touch-icon-#{size}x#{size}.png`)
|
100
|
+
end
|
101
|
+
APPLE_PRECOMPOSED_SIZES.each do |size|
|
102
|
+
(`convert -background "#{favicon_color}" -fill white -size #{size}x#{size} -gravity center #{font_file_path ? "-font #{font_file_path}" : ""} label:#{favico_letter} #{FILE_FAVICO_DIR}/apple-touch-icon-#{size}x#{size}-precomposed.png`)
|
103
|
+
end
|
104
|
+
MS_TILE_SIZES.each do |size|
|
105
|
+
(`convert -background "#{favicon_color}" -fill white -size #{size}x#{size} -gravity center #{font_file_path ? "-font #{font_file_path}" : ""} label:#{favico_letter} #{FILE_FAVICO_DIR}/mstile-#{size}x#{size}.png`)
|
106
|
+
end
|
107
|
+
(`convert -background "#{favicon_color}" -fill white -size 152x152 -gravity center #{font_file_path ? "-font #{font_file_path}" : ""} label:#{favico_letter} #{FILE_FAVICO_DIR}/apple-touch-icon.png`)
|
108
|
+
(`convert -background "#{favicon_color}" -fill white -size 152x152 -gravity center #{font_file_path ? "-font #{font_file_path}" : ""} label:#{favico_letter} #{FILE_FAVICO_DIR}/apple-touch-icon-precomposed.png`)
|
109
|
+
end
|
110
|
+
|
111
|
+
def add_favicon_partial
|
112
|
+
say "Copying favicon layout partial", :green
|
113
|
+
template("favicon.html.erb", "app/views/layouts/shared/_favicon.html.erb")
|
114
|
+
insert_into_file "app/views/layouts/application.html.erb", <<~RUBY, after: /head.*\n/
|
115
|
+
\t\t<%= render 'layouts/shared/favicon' %>
|
116
|
+
RUBY
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -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,85 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler'
|
4
|
+
|
5
|
+
module Boring
|
6
|
+
module Pundit
|
7
|
+
class InstallGenerator < Rails::Generators::Base
|
8
|
+
desc "Adds pundit to the application"
|
9
|
+
|
10
|
+
class_option :skip_ensuring_policies, type: :boolean, aliases: "-s",
|
11
|
+
desc: "Skip before_action to ensure user is authorized"
|
12
|
+
class_option :skip_rescue, type: :boolean, aliases: "-sr",
|
13
|
+
desc: "Skip adding rescue for Pundit::NotAuthorizedError"
|
14
|
+
class_option :skip_generator, type: :boolean, aliases: "-sg",
|
15
|
+
desc: "Skip running Pundit install generator"
|
16
|
+
|
17
|
+
def add_pundit_gem
|
18
|
+
say "Adding Pundit gem", :green
|
19
|
+
pundit_gem = <<~RUBY
|
20
|
+
\n
|
21
|
+
# for authorization
|
22
|
+
gem 'pundit', '~> 2.1'
|
23
|
+
RUBY
|
24
|
+
append_to_file "Gemfile", pundit_gem
|
25
|
+
run "bundle install"
|
26
|
+
end
|
27
|
+
|
28
|
+
def run_pundit_generator
|
29
|
+
return if options[:skip_generator]
|
30
|
+
|
31
|
+
say "Running Pundit Generator", :green
|
32
|
+
run "DISABLE_SPRING=1 rails generate pundit:install"
|
33
|
+
end
|
34
|
+
|
35
|
+
def inject_pundit_to_controller
|
36
|
+
say "Adding Pundit module into ApplicationController", :green
|
37
|
+
inject_into_file 'app/controllers/application_controller.rb', after: "class ApplicationController < ActionController::Base\n" do
|
38
|
+
" include Pundit\n"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def ensure_policies
|
43
|
+
return if options[:skip_ensuring_policies]
|
44
|
+
|
45
|
+
say "Force ensuring policies", :green
|
46
|
+
inject_into_file 'app/controllers/application_controller.rb', after: "include Pundit\n" do
|
47
|
+
" after_action :verify_authorized\n"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def rescue_from_not_authorized
|
52
|
+
return if options[:skip_rescue]
|
53
|
+
|
54
|
+
say "Adding rescue from Pundit::NotAuthorizedError", :green
|
55
|
+
|
56
|
+
after = if File.read('app/controllers/application_controller.rb') =~ (/:verify_authorized/)
|
57
|
+
"after_action :verify_authorized\n"
|
58
|
+
else
|
59
|
+
"include Pundit\n"
|
60
|
+
end
|
61
|
+
|
62
|
+
inject_into_file 'app/controllers/application_controller.rb', after: after do
|
63
|
+
<<~RUBY
|
64
|
+
\trescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
|
65
|
+
|
66
|
+
\tprivate
|
67
|
+
|
68
|
+
\tdef user_not_authorized
|
69
|
+
\t flash[:alert] = "You are not authorized to perform this action."
|
70
|
+
\t redirect_to(request.referrer || root_path)
|
71
|
+
\tend
|
72
|
+
RUBY
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def after_run
|
77
|
+
unless options[:skip_rescue]
|
78
|
+
say "\nPlease check the `application_controller.rb` file and fix any potential issues"
|
79
|
+
end
|
80
|
+
|
81
|
+
say "\nDon't forget, that you can generate policies with \nrails g pundit:policy Model\n"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Boring
|
4
|
+
module SimpleForm
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
desc "Adds SimpleForm to the application"
|
7
|
+
source_root File.expand_path("templates", __dir__)
|
8
|
+
|
9
|
+
class_option :css_framework, type: :string, aliases: "-css",
|
10
|
+
desc: "Skip before_action to ensure user is authorized"
|
11
|
+
class_option :skip_generator, type: :boolean, aliases: "-sg",
|
12
|
+
desc: "Skip running Pundit install generator"
|
13
|
+
|
14
|
+
ALLOWED_CSS_FRAMEWORK = %w(bootstrap foundation)
|
15
|
+
|
16
|
+
def add_bullet_gem
|
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"
|
25
|
+
end
|
26
|
+
|
27
|
+
def run_simple_form_generator
|
28
|
+
return if options[:skip_generator]
|
29
|
+
|
30
|
+
say "Running SimpleForm Generator", :green
|
31
|
+
if options[:css_framework].present? && ALLOWED_CSS_FRAMEWORK.include?(options[:css_framework])
|
32
|
+
run "rails generate simple_form:install --#{options[:css_framework]}"
|
33
|
+
elsif options[:css_framework].present?
|
34
|
+
say <<~WARNING, :red
|
35
|
+
ERROR: Invalid option css_framework: #{options[:css_framework]}. Generator allows css_framework: #{ALLOWED_CSS_FRAMEWORK.join(", ")}
|
36
|
+
WARNING
|
37
|
+
else
|
38
|
+
run "rails generate simple_form:install"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
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.
|
4
|
+
version: 0.5.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: 2020-
|
11
|
+
date: 2020-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -36,7 +36,6 @@ files:
|
|
36
36
|
- ".github/PULL_REQUEST_TEMPLATE.md"
|
37
37
|
- ".github/workflows/ci.yml"
|
38
38
|
- ".gitignore"
|
39
|
-
- ".travis.yml"
|
40
39
|
- CHANGELOG.md
|
41
40
|
- CODE_OF_CONDUCT.md
|
42
41
|
- CONTRIBUTING.md
|
@@ -66,14 +65,22 @@ files:
|
|
66
65
|
- lib/generators/boring/ci/github_action/install/templates/ci.yml.tt
|
67
66
|
- lib/generators/boring/ci/travisci/install/install_generator.rb
|
68
67
|
- lib/generators/boring/ci/travisci/install/templates/.travis.yml.tt
|
68
|
+
- lib/generators/boring/devise/install/install_generator.rb
|
69
|
+
- lib/generators/boring/favicon/build/build_generator.rb
|
70
|
+
- lib/generators/boring/favicon/build/templates/favicon.html.erb.tt
|
69
71
|
- lib/generators/boring/font_awesome/ruby_gem/install/install_generator.rb
|
70
72
|
- lib/generators/boring/font_awesome/yarn/install/install_generator.rb
|
71
73
|
- lib/generators/boring/font_awesome/yarn/install/templates/application.scss
|
74
|
+
- lib/generators/boring/graphql/install/install_generator.rb
|
75
|
+
- lib/generators/boring/graphql/install/templates/base_resolver.rb
|
76
|
+
- lib/generators/boring/graphql/install/templates/hello_world_resolver.rb
|
72
77
|
- lib/generators/boring/jquery/install/install_generator.rb
|
73
78
|
- lib/generators/boring/pry/install/install_generator.rb
|
74
79
|
- lib/generators/boring/pry/install/templates/pryrc
|
80
|
+
- lib/generators/boring/pundit/install/install_generator.rb
|
75
81
|
- lib/generators/boring/rubocop/install/install_generator.rb
|
76
82
|
- lib/generators/boring/rubocop/install/templates/.rubocop.yml.tt
|
83
|
+
- lib/generators/boring/simple_form/install/install_generator.rb
|
77
84
|
- lib/generators/boring/tailwind/install/install_generator.rb
|
78
85
|
- lib/generators/boring/tailwind/install/templates/application.scss
|
79
86
|
- tmp/templates/app_template/.ruby-version
|