rails_app_generator 0.1.12 → 0.1.13
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/after_templates/addons/honeybadger/_.rb +46 -0
- data/after_templates/addons/honeybadger/app/controllers/application_controller.rb +9 -0
- data/after_templates/addons/honeybadger/app/controllers/errors_controller.rb +17 -0
- data/after_templates/addons/honeybadger/app/controllers/products_controller.rb +72 -0
- data/after_templates/addons/honeybadger/app/views/home/index.html.erb +49 -0
- data/after_templates/addons/honeybadger/public/404.html +69 -0
- data/after_templates/addons/honeybadger/public/500.html +68 -0
- data/lib/rails_app_generator/add_on.rb +36 -0
- data/lib/rails_app_generator/addons/honeybadger.rb +19 -0
- data/lib/rails_app_generator/app_generator.rb +57 -32
- data/lib/rails_app_generator/options/rails_options.rb +1 -0
- data/lib/rails_app_generator/version.rb +1 -1
- data/package-lock.json +2 -2
- data/package.json +1 -1
- data/profiles/addons/{rails_html_sanitizer.json → honeybadger.json} +3 -3
- data/tasks/addon.thor +43 -5
- data/tasks/profile.thor +22 -18
- data/templates/addons/honeybadger/en.yml +10 -0
- data/templates/addons/honeybadger/honeybadger.sample.yml +37 -0
- data/templates/thor_task/addon/addon.tt +13 -6
- data/templates/thor_task/profile/after_template.rb.tt +30 -1
- data/templates/thor_task/profile/home/index.html.erb.tt +4 -0
- metadata +13 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1505eaa23b41f69afe5f4060221b479ae01209f1a76df69577ef715b17c9455f
|
4
|
+
data.tar.gz: f33d5a7001365a84503d2640053604e3e6fe52632f54f0c03c17fe36ff83c869
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00b2d94306f636e25800d4d6ed09d8536535f47c630662ee6beda2939dbf871e01721d2978e19dc6bb5c0e281f47913d73535bfb2ef8ecaee427726e9308be7f
|
7
|
+
data.tar.gz: 3dde1c772e2d56ad34d9b190742c25725e744145e4754630425613ced8525e026d935a671f8335b3fb60a56122547b0bc589845bb9f1de61689c94a74b5e0070
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## [0.1.12](https://github.com/klueless-io/rails_app_generator/compare/v0.1.11...v0.1.12) (2022-08-02)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* update rails-html-sanitizer example ([7f3a2d8](https://github.com/klueless-io/rails_app_generator/commit/7f3a2d810a968748baf4f8a4a147b086a26781c0))
|
7
|
+
|
1
8
|
## [0.1.11](https://github.com/klueless-io/rails_app_generator/compare/v0.1.10...v0.1.11) (2022-08-02)
|
2
9
|
|
3
10
|
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# require 'pry'
|
4
|
+
|
5
|
+
# Make managing application errors a more pleasant experience.
|
6
|
+
#
|
7
|
+
# exe/rag addons/honeybadger
|
8
|
+
# see: https://honeybadger.wistia.com/medias/l3cmyucx8f
|
9
|
+
|
10
|
+
self.local_template_path = File.dirname(__FILE__)
|
11
|
+
|
12
|
+
gac 'base rails 7 image created'
|
13
|
+
|
14
|
+
add_controller('home', 'index')
|
15
|
+
route("root 'home#index'")
|
16
|
+
|
17
|
+
force_copy
|
18
|
+
|
19
|
+
copy_file 'app/views/home/index.html.erb', 'app/views/home/index.html.erb'
|
20
|
+
copy_file 'app/controllers/application_controller.rb', 'app/controllers/application_controller.rb'
|
21
|
+
copy_file 'app/controllers/errors_controller.rb', 'app/controllers/errors_controller.rb'
|
22
|
+
|
23
|
+
# Test if this is really needed
|
24
|
+
insert_into_file 'config/application.rb', after: 'class Application < Rails::Application' do
|
25
|
+
<<-RUBY
|
26
|
+
config.generators.system_tests = nil
|
27
|
+
RUBY
|
28
|
+
end
|
29
|
+
|
30
|
+
copy_file 'public/404.html', 'public/404.html'
|
31
|
+
copy_file 'public/500.html', 'public/500.html'
|
32
|
+
|
33
|
+
copy_file 'config/locales/en.yml', 'config/locales/en.yml'
|
34
|
+
|
35
|
+
move_file('config/honeybadger.sample.yml', 'config/honeybadger.yml')
|
36
|
+
|
37
|
+
after_bundle do
|
38
|
+
setup_db
|
39
|
+
end
|
40
|
+
|
41
|
+
def setup_db
|
42
|
+
add_scaffold('product', 'name', 'price:integer')
|
43
|
+
copy_file 'app/controllers/products_controller.rb', 'app/controllers/products_controller.rb'
|
44
|
+
|
45
|
+
db_migrate
|
46
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class ErrorsController < ApplicationController
|
2
|
+
def not_found
|
3
|
+
render status: 404
|
4
|
+
end
|
5
|
+
|
6
|
+
def internal_server
|
7
|
+
render status: 500
|
8
|
+
end
|
9
|
+
|
10
|
+
def unprocessable
|
11
|
+
render status: 422
|
12
|
+
end
|
13
|
+
|
14
|
+
def unacceptable
|
15
|
+
render status: 406
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
class ProductsController < ApplicationController
|
2
|
+
before_action :set_product, only: %i[ show edit update destroy ]
|
3
|
+
|
4
|
+
# GET /products or /products.json
|
5
|
+
def index
|
6
|
+
@products = Product.all
|
7
|
+
end
|
8
|
+
|
9
|
+
# GET /products/1 or /products/1.json
|
10
|
+
def show
|
11
|
+
end
|
12
|
+
|
13
|
+
# GET /products/new
|
14
|
+
def new
|
15
|
+
# remove this comment to see error in Honeybadger
|
16
|
+
raise 'Oh No!'
|
17
|
+
@product = Product.new
|
18
|
+
end
|
19
|
+
|
20
|
+
# GET /products/1/edit
|
21
|
+
def edit
|
22
|
+
end
|
23
|
+
|
24
|
+
# POST /products or /products.json
|
25
|
+
def create
|
26
|
+
@product = Product.new(product_params)
|
27
|
+
|
28
|
+
respond_to do |format|
|
29
|
+
if @product.save
|
30
|
+
format.html { redirect_to product_url(@product), notice: "Product was successfully created." }
|
31
|
+
format.json { render :show, status: :created, location: @product }
|
32
|
+
else
|
33
|
+
format.html { render :new, status: :unprocessable_entity }
|
34
|
+
format.json { render json: @product.errors, status: :unprocessable_entity }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# PATCH/PUT /products/1 or /products/1.json
|
40
|
+
def update
|
41
|
+
respond_to do |format|
|
42
|
+
if @product.update(product_params)
|
43
|
+
format.html { redirect_to product_url(@product), notice: "Product was successfully updated." }
|
44
|
+
format.json { render :show, status: :ok, location: @product }
|
45
|
+
else
|
46
|
+
format.html { render :edit, status: :unprocessable_entity }
|
47
|
+
format.json { render json: @product.errors, status: :unprocessable_entity }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# DELETE /products/1 or /products/1.json
|
53
|
+
def destroy
|
54
|
+
@product.destroy
|
55
|
+
|
56
|
+
respond_to do |format|
|
57
|
+
format.html { redirect_to products_url, notice: "Product was successfully destroyed." }
|
58
|
+
format.json { head :no_content }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
# Use callbacks to share common setup or constraints between actions.
|
64
|
+
def set_product
|
65
|
+
@product = Product.find(params[:id])
|
66
|
+
end
|
67
|
+
|
68
|
+
# Only allow a list of trusted parameters through.
|
69
|
+
def product_params
|
70
|
+
params.require(:product).permit(:name, :price)
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
<h1>Honeybadger</h1>
|
2
|
+
|
3
|
+
<h2>Make managing application errors a more pleasant experience.</h2>
|
4
|
+
|
5
|
+
<p>Follow the instructions below and then click on products -> new</p>
|
6
|
+
|
7
|
+
<%= link_to 'Products', products_path %>
|
8
|
+
|
9
|
+
<h2>Instructions</h2>
|
10
|
+
|
11
|
+
<p>If you want to see 404/500 HTML inplace of the debug routing error when in development then alter the following file</p>
|
12
|
+
|
13
|
+
<b>config/environments/development.rb</b>
|
14
|
+
<pre>
|
15
|
+
|
16
|
+
# config.consider_all_requests_local = true
|
17
|
+
config.consider_all_requests_local = false
|
18
|
+
|
19
|
+
</pre>
|
20
|
+
|
21
|
+
<p>If you want to see the exception message in Honeybadger then make sure then remove the comment<p>
|
22
|
+
|
23
|
+
<b>config/honeybadger.yml</b>
|
24
|
+
|
25
|
+
<pre>
|
26
|
+
# report_data: true
|
27
|
+
report_data: true
|
28
|
+
</pre>
|
29
|
+
|
30
|
+
<p>If you want to send the exception message to Honeybadger then make sure your remove development from the list<p>
|
31
|
+
|
32
|
+
<pre>
|
33
|
+
# development_environments:
|
34
|
+
- test
|
35
|
+
- development
|
36
|
+
- cucumber
|
37
|
+
</pre>
|
38
|
+
|
39
|
+
<p>Test frrom the command line using</p>
|
40
|
+
|
41
|
+
<pre>
|
42
|
+
bundle exec honeybadger test
|
43
|
+
</pre>
|
44
|
+
|
45
|
+
<p>More information can be found at
|
46
|
+
<a href="http://honeybadger.io/">http://honeybadger.io/</a> and
|
47
|
+
<a hreg="https://honeybadger.wistia.com/medias/l3cmyucx8f">https://honeybadger.wistia.com/medias/l3cmyucx8f</a>
|
48
|
+
|
49
|
+
</p>
|
@@ -0,0 +1,69 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
.rails-default-error-page {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
.rails-default-error-page div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
.rails-default-error-page div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
.rails-default-error-page h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
.rails-default-error-page div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body class="rails-default-error-page">
|
58
|
+
<!-- This file lives in public/404.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
62
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
63
|
+
</div>
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
65
|
+
</div>
|
66
|
+
<!-- HONEYBADGER FEEDBACK -->
|
67
|
+
<!-- HONEYBADGER ERROR -->
|
68
|
+
</body>
|
69
|
+
</html>
|
@@ -0,0 +1,68 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
.rails-default-error-page {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
.rails-default-error-page div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
.rails-default-error-page div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
.rails-default-error-page h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
.rails-default-error-page div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body class="rails-default-error-page">
|
58
|
+
<!-- This file lives in public/500.html -->
|
59
|
+
<!-- HONEYBADGER FEEDBACK -->
|
60
|
+
<!-- HONEYBADGER ERROR -->
|
61
|
+
<div class="dialog">
|
62
|
+
<div>
|
63
|
+
<h1>We're sorry, but something went wrong.</h1>
|
64
|
+
</div>
|
65
|
+
<p>If you are the application owner check the logs for more information.</p>
|
66
|
+
</div>
|
67
|
+
</body>
|
68
|
+
</html>
|
@@ -21,6 +21,7 @@ module RailsAppGenerator
|
|
21
21
|
def apply; end
|
22
22
|
|
23
23
|
# list any methods that you want access to, but not to be exposed as a thor command
|
24
|
+
# rubocop:disable Metrics/BlockLength
|
24
25
|
no_commands do
|
25
26
|
def source_paths
|
26
27
|
[
|
@@ -43,7 +44,42 @@ module RailsAppGenerator
|
|
43
44
|
klass = addon_name.nil? ? self.class : self.class.get(addon_name)
|
44
45
|
Dependencies.new(klass, context).satisfied?
|
45
46
|
end
|
47
|
+
|
48
|
+
def read_template(template_file)
|
49
|
+
path = find_in_source_paths(template_file)
|
50
|
+
|
51
|
+
File.read(path)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Moves a file at given location, to another location. Both files are relative to the destination_root
|
55
|
+
#
|
56
|
+
# ==== Parameters
|
57
|
+
# path<String>:: source_path of the file to be moved (relative to destination_root)
|
58
|
+
# path<String>:: target_path of the file moving to (relative to destination_root)
|
59
|
+
# config<Hash>:: give :verbose => false to not log the status.
|
60
|
+
#
|
61
|
+
# ==== Example
|
62
|
+
#
|
63
|
+
# move_file 'README', 'readme.md'
|
64
|
+
# move_file 'config/xmen.sample.yml', 'config/xmen.yml
|
65
|
+
#
|
66
|
+
# rubocop:disable Metrics/AbcSize
|
67
|
+
def move_file(source_path, target_path, config = {})
|
68
|
+
source = File.expand_path(source_path, destination_root)
|
69
|
+
target = File.expand_path(target_path, destination_root)
|
70
|
+
config.merge!({ verbose: true })
|
71
|
+
|
72
|
+
say_status :move_file_source, relative_to_original_destination_root(source), config.fetch(:verbose, true)
|
73
|
+
say_status :move_file_source, relative_to_original_destination_root(target), config.fetch(:verbose, true)
|
74
|
+
|
75
|
+
return unless !options[:pretend] && File.exist?(source)
|
76
|
+
|
77
|
+
require 'fileutils'
|
78
|
+
::FileUtils.mv(source, target)
|
79
|
+
end
|
80
|
+
# rubocop:enable Metrics/AbcSize
|
46
81
|
end
|
82
|
+
# rubocop:enable Metrics/BlockLength
|
47
83
|
|
48
84
|
class << self
|
49
85
|
def apply(context = Context.new({}))
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RailsAppGenerator
|
4
|
+
# Custom add-ons for RailsAppGenerator
|
5
|
+
module AddOns
|
6
|
+
# Add Honeybadger to rails application
|
7
|
+
class Honeybadger < AddOn
|
8
|
+
required_gem gem.version('honeybadger', '4.12.1', 'Make managing application errors a more pleasant experience.')
|
9
|
+
|
10
|
+
def apply
|
11
|
+
run('bundle exec honeybadger install 1111')
|
12
|
+
say 'Update the honeybadger.yml file with your API key.'
|
13
|
+
|
14
|
+
copy_file('honeybadger.sample.yml', 'config/honeybadger.sample.yml')
|
15
|
+
append_to_file('config/locales/en.yml', read_template('en.yml'))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -149,6 +149,7 @@ module RailsAppGenerator
|
|
149
149
|
# gem "net-sftp", "3.0.0"
|
150
150
|
# gem "prawn", "2.4.0"
|
151
151
|
# gem "prawn-table", "0.2.2"
|
152
|
+
# gem "appraisal"
|
152
153
|
|
153
154
|
class_option :add_irbrc , type: :boolean, default: false
|
154
155
|
class_option :add_foreman , type: :boolean, default: false
|
@@ -173,6 +174,7 @@ module RailsAppGenerator
|
|
173
174
|
|
174
175
|
# NEW GEM ADDONS
|
175
176
|
class_option :add_rails_html_sanitizer , type: :boolean, default: false
|
177
|
+
class_option :add_honeybadger , type: :boolean, default: false
|
176
178
|
|
177
179
|
class << self
|
178
180
|
# points to the original rails templates
|
@@ -300,6 +302,7 @@ module RailsAppGenerator
|
|
300
302
|
# # add(:rspec) if options[:testing_framework] == 'rspec'
|
301
303
|
# end
|
302
304
|
|
305
|
+
# rubocop:disable Metrics/AbcSize
|
303
306
|
def finish_template
|
304
307
|
puts 'finish template'
|
305
308
|
|
@@ -315,33 +318,16 @@ module RailsAppGenerator
|
|
315
318
|
add(:views, :errors, :scaffold) if options[:add_views]
|
316
319
|
add_if(:factory_bot)
|
317
320
|
add_if(:shoulda)
|
321
|
+
add_if(:rails_app_generator)
|
322
|
+
add_if(:honeybadger)
|
318
323
|
|
319
324
|
# invoke :rails_customization
|
320
325
|
super
|
321
326
|
end
|
327
|
+
# rubocop:enable Metrics/AbcSize
|
322
328
|
|
323
329
|
no_commands do
|
324
|
-
#
|
325
|
-
# gac 'base rails 7 image created'
|
326
|
-
# force_copy
|
327
|
-
# add_controller('home', 'index')
|
328
|
-
# add_scaffold('people', 'first_name', 'last_name', 'age:integer', 'address:text')
|
329
|
-
# route("root 'home#index'")
|
330
|
-
# css_install('tailwind')
|
331
|
-
# rails_command('db:migrate')
|
332
|
-
# db_migrate
|
333
|
-
# bundle_add('hotwire-rails')
|
334
|
-
# rails_command('hotwire:install')
|
335
|
-
# run('bin/importmap pin sortablejs')
|
336
|
-
# run('npm install daisyui')
|
337
|
-
# create_file 'app/assets/stylesheets/custom-bootstrap-import.scss' , read_template('custom-bootstrap-import.scss')
|
338
|
-
# append_to_file 'app/assets/config/manifest.js' , read_template('manifest.js')
|
339
|
-
# insert_into_file 'app/views/layouts/application.html.erb', read_template('application.html.erb')
|
340
|
-
# insert_into_file 'app/views/layouts/application.html.erb', read_template('application.html.erb'),
|
341
|
-
# before: %( <%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %>)
|
342
|
-
|
343
|
-
# gsub_file 'app/views/layouts/application.html.erb', %(container mx-auto mt-28 px-5 flex), 'container mx-auto px-5'
|
344
|
-
# template 'home.css', 'app/assets/stylesheets/home.css'
|
330
|
+
# https://codingpackets.com/blog/rails-generators-cheat-sheet/
|
345
331
|
|
346
332
|
# OLD style will be removed soon
|
347
333
|
def local_template_base(xxx)
|
@@ -396,6 +382,10 @@ module RailsAppGenerator
|
|
396
382
|
run("bundle add #{name}")
|
397
383
|
end
|
398
384
|
|
385
|
+
def bundle_exec(name, *args)
|
386
|
+
run("bundle exec #{name} #{args.join(' ')}")
|
387
|
+
end
|
388
|
+
|
399
389
|
# If you need to manually install tailwind (instead of using the --template option)
|
400
390
|
# you can use css_install('tailwind')
|
401
391
|
def css_install(name)
|
@@ -435,6 +425,34 @@ module RailsAppGenerator
|
|
435
425
|
template_files.map { |template_file| read_template(template_file) }.join(join)
|
436
426
|
end
|
437
427
|
|
428
|
+
# Moves a file at given location, to another location. Both files are relative to the destination_root
|
429
|
+
#
|
430
|
+
# ==== Parameters
|
431
|
+
# path<String>:: source_path of the file to be moved (relative to destination_root)
|
432
|
+
# path<String>:: target_path of the file moving to (relative to destination_root)
|
433
|
+
# config<Hash>:: give :verbose => false to not log the status.
|
434
|
+
#
|
435
|
+
# ==== Example
|
436
|
+
#
|
437
|
+
# move_file 'README', 'readme.md'
|
438
|
+
# move_file 'config/xmen.sample.yml', 'config/xmen.yml
|
439
|
+
#
|
440
|
+
# rubocop:disable Metrics/AbcSize
|
441
|
+
def move_file(source_path, target_path, config = {})
|
442
|
+
source = File.expand_path(source_path, destination_root)
|
443
|
+
target = File.expand_path(target_path, destination_root)
|
444
|
+
config.merge!({ verbose: true })
|
445
|
+
|
446
|
+
say_status :move_file_source, relative_to_original_destination_root(source), config.fetch(:verbose, true)
|
447
|
+
say_status :move_file_source, relative_to_original_destination_root(target), config.fetch(:verbose, true)
|
448
|
+
|
449
|
+
return unless !options[:pretend] && File.exist?(source)
|
450
|
+
|
451
|
+
require 'fileutils'
|
452
|
+
::FileUtils.mv(source, target)
|
453
|
+
end
|
454
|
+
# rubocop:enable Metrics/AbcSize
|
455
|
+
|
438
456
|
# Local template path is handy when you want template files used when working with the --template flag
|
439
457
|
attr_accessor :local_template_path
|
440
458
|
|
@@ -466,17 +484,16 @@ module RailsAppGenerator
|
|
466
484
|
end
|
467
485
|
|
468
486
|
def add_if(addon)
|
469
|
-
|
470
|
-
add(addon) if options[option_name]
|
487
|
+
add(addon) if active?(addon)
|
471
488
|
end
|
472
489
|
|
473
|
-
def skip_flag?(option_name)
|
474
|
-
|
490
|
+
# def skip_flag?(option_name)
|
491
|
+
# value = options["skip_#{option_name}".to_sym]
|
475
492
|
|
476
|
-
|
493
|
+
# return true if value.nil?
|
477
494
|
|
478
|
-
|
479
|
-
end
|
495
|
+
# value == true
|
496
|
+
# end
|
480
497
|
|
481
498
|
def add_flag?(option_name)
|
482
499
|
value = options["add_#{option_name}".to_sym]
|
@@ -487,7 +504,7 @@ module RailsAppGenerator
|
|
487
504
|
end
|
488
505
|
|
489
506
|
def active?(option_name)
|
490
|
-
add_flag?(option_name) || !skip_flag?(option_name)
|
507
|
+
add_flag?(option_name) # || !skip_flag?(option_name)
|
491
508
|
end
|
492
509
|
|
493
510
|
def uses?(addon)
|
@@ -505,10 +522,18 @@ module RailsAppGenerator
|
|
505
522
|
end
|
506
523
|
end
|
507
524
|
|
508
|
-
def
|
525
|
+
def addon_classes
|
509
526
|
AddOns.constants
|
510
|
-
.
|
511
|
-
.
|
527
|
+
.map { |addon_klass_name| AddOns.const_get(addon_klass_name) }
|
528
|
+
.select { |klass| klass.is_a?(Class) && klass.respond_to?(:addon_name) }
|
529
|
+
end
|
530
|
+
|
531
|
+
def active_addon_classes
|
532
|
+
addon_classes.select { |klass| active?(klass.addon_name) }
|
533
|
+
end
|
534
|
+
|
535
|
+
def addon_gemfile_entries
|
536
|
+
active_addon_classes.flat_map(&:gem_entries)
|
512
537
|
end
|
513
538
|
end
|
514
539
|
|
data/package-lock.json
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "rails_app_generator",
|
3
|
-
"version": "0.1.
|
3
|
+
"version": "0.1.13",
|
4
4
|
"lockfileVersion": 2,
|
5
5
|
"requires": true,
|
6
6
|
"packages": {
|
7
7
|
"": {
|
8
8
|
"name": "rails_app_generator",
|
9
|
-
"version": "0.1.
|
9
|
+
"version": "0.1.13",
|
10
10
|
"dependencies": {
|
11
11
|
"daisyui": "^2.20.0"
|
12
12
|
},
|
data/package.json
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"args": {
|
3
|
-
"app_path": "
|
3
|
+
"app_path": "honeybadger",
|
4
4
|
"destination_root": "/Users/davidcruwys/dev/kgems/rails_app_generator/a/addons"
|
5
5
|
},
|
6
6
|
"opts": {
|
7
7
|
"skip_git": true,
|
8
8
|
"skip_test": true,
|
9
|
-
"template": "/Users/davidcruwys/dev/kgems/rails_app_generator/after_templates/addons/
|
10
|
-
"
|
9
|
+
"template": "/Users/davidcruwys/dev/kgems/rails_app_generator/after_templates/addons/honeybadger/_.rb",
|
10
|
+
"add_honeybadger": true
|
11
11
|
}
|
12
12
|
}
|
data/tasks/addon.thor
CHANGED
@@ -12,10 +12,19 @@ class AddOn < Thor
|
|
12
12
|
|
13
13
|
source_root(File.expand_path('../templates/thor_task', File.dirname(__FILE__)))
|
14
14
|
|
15
|
+
Data = Struct.new(
|
16
|
+
:name,
|
17
|
+
:name_dash,
|
18
|
+
:name_snake,
|
19
|
+
:name_human,
|
20
|
+
:name_camel,
|
21
|
+
:addon_config_code,
|
22
|
+
keyword_init: true
|
23
|
+
)
|
15
24
|
GemInfo = Struct.new(:name, :version, :description, keyword_init: true)
|
16
25
|
|
17
26
|
attr_accessor :name
|
18
|
-
attr_accessor :
|
27
|
+
attr_accessor :data
|
19
28
|
|
20
29
|
# method_option :from, :required => true
|
21
30
|
desc 'new', 'Create a new Addon for Rails App Generator'
|
@@ -24,14 +33,12 @@ class AddOn < Thor
|
|
24
33
|
method_option :depends_on, type: :string, desc: 'This AddOn depends on another AddOn/Gem. active_record is a common dependency'
|
25
34
|
def new(name)
|
26
35
|
self.name = name
|
27
|
-
|
28
|
-
code = [build_depends_on_code, build_required_gem_code].compact
|
29
|
-
code << '' if code.any?
|
30
|
-
self.addon_config_code = code.join("\n")
|
36
|
+
self.data = build_data(name)
|
31
37
|
|
32
38
|
template('addon/addon', "lib/rails_app_generator/addons/#{name}.rb", force: options[:force])
|
33
39
|
end
|
34
40
|
|
41
|
+
# rubocop:disable Metrics/BlockLength
|
35
42
|
no_commands do
|
36
43
|
def build_depends_on_code
|
37
44
|
return nil unless options[:depends_on]
|
@@ -53,5 +60,36 @@ class AddOn < Thor
|
|
53
60
|
|
54
61
|
::GemInfo.get(gem_name)
|
55
62
|
end
|
63
|
+
|
64
|
+
def build_data(name)
|
65
|
+
code = [build_depends_on_code, build_required_gem_code].compact
|
66
|
+
code << '' if code.any?
|
67
|
+
|
68
|
+
Data.new(
|
69
|
+
name: name,
|
70
|
+
name_dash: dash(name),
|
71
|
+
name_snake: snake(name),
|
72
|
+
name_human: human(name),
|
73
|
+
name_camel: camel(name),
|
74
|
+
addon_config_code: code.join("\n")
|
75
|
+
)
|
76
|
+
end
|
77
|
+
|
78
|
+
def human(value)
|
79
|
+
Cmdlet::Case::Human.new.call(value)
|
80
|
+
end
|
81
|
+
|
82
|
+
def dash(value)
|
83
|
+
Cmdlet::Case::Dash.new.call(value)
|
84
|
+
end
|
85
|
+
|
86
|
+
def snake(value)
|
87
|
+
Cmdlet::Case::Snake.new.call(value)
|
88
|
+
end
|
89
|
+
|
90
|
+
def camel(value)
|
91
|
+
Cmdlet::Case::Camel.new.call(value)
|
92
|
+
end
|
56
93
|
end
|
94
|
+
# rubocop:enable Metrics/BlockLength
|
57
95
|
end
|
data/tasks/profile.thor
CHANGED
@@ -17,6 +17,7 @@ class Profile < Thor
|
|
17
17
|
:name_dash,
|
18
18
|
:name_snake,
|
19
19
|
:name_human,
|
20
|
+
:name_camel,
|
20
21
|
:description,
|
21
22
|
:destination_root,
|
22
23
|
:template_file,
|
@@ -44,18 +45,6 @@ class Profile < Thor
|
|
44
45
|
|
45
46
|
# rubocop:disable Metrics/BlockLength
|
46
47
|
no_commands do
|
47
|
-
def human(value)
|
48
|
-
Cmdlet::Case::Human.new.call(value)
|
49
|
-
end
|
50
|
-
|
51
|
-
def dash(value)
|
52
|
-
Cmdlet::Case::Dash.new.call(value)
|
53
|
-
end
|
54
|
-
|
55
|
-
def snake(value)
|
56
|
-
Cmdlet::Case::Snake.new.call(value)
|
57
|
-
end
|
58
|
-
|
59
48
|
def profile_path(file)
|
60
49
|
path = 'profiles'
|
61
50
|
path = File.join(path, options[:variant]) if options[:variant]
|
@@ -72,18 +61,17 @@ class Profile < Thor
|
|
72
61
|
def build_data(name)
|
73
62
|
gi = gem_info(name)
|
74
63
|
|
75
|
-
name_dash = dash(name)
|
76
|
-
name_snake = snake(name)
|
77
64
|
description = gi ? gi.description : 'Description goes here'
|
78
65
|
|
79
66
|
Data.new(
|
80
67
|
name: name,
|
81
|
-
name_dash:
|
82
|
-
name_snake:
|
83
|
-
name_human: human(
|
68
|
+
name_dash: dash(name),
|
69
|
+
name_snake: snake(name),
|
70
|
+
name_human: human(name),
|
71
|
+
name_camel: camel(name),
|
84
72
|
description: description,
|
85
73
|
destination_root: build_destination_root,
|
86
|
-
template_file: build_template_file(
|
74
|
+
template_file: build_template_file(snake(name))
|
87
75
|
)
|
88
76
|
end
|
89
77
|
|
@@ -109,6 +97,22 @@ class Profile < Thor
|
|
109
97
|
|
110
98
|
GemInfo.get(gem_name)
|
111
99
|
end
|
100
|
+
|
101
|
+
def human(value)
|
102
|
+
Cmdlet::Case::Human.new.call(value)
|
103
|
+
end
|
104
|
+
|
105
|
+
def dash(value)
|
106
|
+
Cmdlet::Case::Dash.new.call(value)
|
107
|
+
end
|
108
|
+
|
109
|
+
def snake(value)
|
110
|
+
Cmdlet::Case::Snake.new.call(value)
|
111
|
+
end
|
112
|
+
|
113
|
+
def camel(value)
|
114
|
+
Cmdlet::Case::Camel.new.call(value)
|
115
|
+
end
|
112
116
|
end
|
113
117
|
# rubocop:enable Metrics/BlockLength
|
114
118
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
honeybadger:
|
2
|
+
feedback:
|
3
|
+
heading: "Care to help us fix this?"
|
4
|
+
explanation: "Any information you can provide will help us fix the problem."
|
5
|
+
submit: "Send"
|
6
|
+
thanks: "Thanks for the feedback!"
|
7
|
+
labels:
|
8
|
+
name: "Your name"
|
9
|
+
email: "Your email address"
|
10
|
+
comment: "Comment (required)"
|
@@ -0,0 +1,37 @@
|
|
1
|
+
---
|
2
|
+
# For more options, see https://docs.honeybadger.io/lib/ruby/gem-reference/configuration
|
3
|
+
|
4
|
+
api_key: 'hbp_f56DVeEaIvMMjqbMJAT7haJpQ7qfLP1ezvc0'
|
5
|
+
|
6
|
+
# The environment your app is running in.
|
7
|
+
env: "<%= Rails.env %>"
|
8
|
+
|
9
|
+
# The absolute path to your project folder.
|
10
|
+
root: "<%= Rails.root.to_s %>"
|
11
|
+
|
12
|
+
# Honeybadger won't report errors in these environments.
|
13
|
+
development_environments:
|
14
|
+
- test
|
15
|
+
- development
|
16
|
+
- cucumber
|
17
|
+
|
18
|
+
# By default, Honeybadger won't report errors in the development_environments.
|
19
|
+
# You can override this by explicitly setting report_data to true or false.
|
20
|
+
# report_data: true
|
21
|
+
|
22
|
+
# The current Git revision of your project. Defaults to the last commit hash.
|
23
|
+
# revision: null
|
24
|
+
|
25
|
+
# Enable verbose debug logging (useful for troubleshooting).
|
26
|
+
debug: false
|
27
|
+
|
28
|
+
# Displaying the Error ID
|
29
|
+
# Add to your html: <!-- HONEYBADGER ERROR -->
|
30
|
+
user_informer:
|
31
|
+
enabled: true
|
32
|
+
info: "Error ID: {{error_id}}"
|
33
|
+
|
34
|
+
# Displaying a Feedback Form
|
35
|
+
# Add to your html: <!-- HONEYBADGER FEEDBACK -->
|
36
|
+
feedback:
|
37
|
+
enabled: true
|
@@ -1,16 +1,23 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# NEW GEM ADDONS
|
4
|
+
# lib/rails_app_generator/app_generator.rb
|
5
|
+
# class_option :add_<%= data.name_snake %>, type: :boolean, default: false
|
6
|
+
# add_if(:<%= data.name_snake %>)
|
7
|
+
# lib/rails_app_generator/options/rails_options.rb
|
8
|
+
# register_option :add_<%= data.name_snake %>, type: :boolean, default: false
|
9
|
+
|
3
10
|
module RailsAppGenerator
|
4
11
|
# Custom add-ons for RailsAppGenerator
|
5
12
|
module AddOns
|
6
|
-
# Add <%=
|
7
|
-
class <%=
|
8
|
-
<%= addon_config_code %>
|
13
|
+
# Add <%= data.name_camel %> to rails application
|
14
|
+
class <%= data.name_camel %> < AddOn
|
15
|
+
<%= data.addon_config_code %>
|
9
16
|
def apply
|
10
|
-
# say 'Setting up <%=
|
11
|
-
# template('<%=
|
17
|
+
# say 'Setting up <%= data.name_camel %>'
|
18
|
+
# template('<%= data.name_snake%>_template.rb', 'target/<%= data.name_snake%>.rb', force: true)
|
12
19
|
# template('app/javascript/stylesheets/components.scss')
|
13
|
-
# create_file('target/<%=
|
20
|
+
# create_file('target/<%= data.name_snake%>.rb', 'put your content here')
|
14
21
|
# directory 'app/template', 'app/target', force: true
|
15
22
|
# empty_directory 'app/target'
|
16
23
|
# inject_into_file('app/application.js', "some content")
|
@@ -1,7 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# require 'pry'
|
4
|
+
|
3
5
|
# <%= data.description %>
|
4
|
-
|
6
|
+
#
|
7
|
+
# exe/rag addons/<%= data.name_snake %>
|
5
8
|
|
6
9
|
self.local_template_path = File.dirname(__FILE__)
|
7
10
|
|
@@ -13,3 +16,29 @@ route("root 'home#index'")
|
|
13
16
|
force_copy
|
14
17
|
|
15
18
|
copy_file 'home/index.html.erb', 'app/views/home/index.html.erb'
|
19
|
+
|
20
|
+
after_bundle do
|
21
|
+
setup_db
|
22
|
+
end
|
23
|
+
|
24
|
+
def setup_db
|
25
|
+
# add_scaffold('post', 'title', 'body:text')
|
26
|
+
# add_scaffold('people', 'first_name', 'last_name', 'age:integer', 'address:text')
|
27
|
+
# add_scaffold('product', 'name', 'price:integer')
|
28
|
+
|
29
|
+
# db_migrate
|
30
|
+
end
|
31
|
+
|
32
|
+
# Other template command examples
|
33
|
+
# css_install('tailwind')
|
34
|
+
# rails_command('db:migrate')
|
35
|
+
# bundle_add('hotwire-rails')
|
36
|
+
# rails_command('hotwire:install')
|
37
|
+
# run('bin/importmap pin sortablejs')
|
38
|
+
# run('npm install daisyui')
|
39
|
+
# create_file 'app/assets/stylesheets/custom-bootstrap-import.scss' , read_template('custom-bootstrap-import.scss')
|
40
|
+
# append_to_file 'app/assets/config/manifest.js' , read_template('manifest.js')
|
41
|
+
# insert_into_file 'app/views/layouts/application.html.erb', read_template('application.html.erb'),
|
42
|
+
# before: %( <%%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %>)
|
43
|
+
# gsub_file 'app/views/layouts/application.html.erb', %(container mx-auto mt-28 px-5 flex), 'container mx-auto px-5'
|
44
|
+
# template 'home.css', 'app/assets/stylesheets/home.css'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_app_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Cruwys
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-08-
|
11
|
+
date: 2022-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bootsnap
|
@@ -160,6 +160,13 @@ files:
|
|
160
160
|
- README.md
|
161
161
|
- Rakefile
|
162
162
|
- after_templates/README.md
|
163
|
+
- after_templates/addons/honeybadger/_.rb
|
164
|
+
- after_templates/addons/honeybadger/app/controllers/application_controller.rb
|
165
|
+
- after_templates/addons/honeybadger/app/controllers/errors_controller.rb
|
166
|
+
- after_templates/addons/honeybadger/app/controllers/products_controller.rb
|
167
|
+
- after_templates/addons/honeybadger/app/views/home/index.html.erb
|
168
|
+
- after_templates/addons/honeybadger/public/404.html
|
169
|
+
- after_templates/addons/honeybadger/public/500.html
|
163
170
|
- after_templates/addons/rails_html_sanitizer/_.rb
|
164
171
|
- after_templates/addons/rails_html_sanitizer/home/index.html.erb
|
165
172
|
- after_templates/addons/rails_html_sanitizer_xxx/home/index.html.erb
|
@@ -304,6 +311,7 @@ files:
|
|
304
311
|
- lib/rails_app_generator/addons/foreman.rb
|
305
312
|
- lib/rails_app_generator/addons/generators.rb
|
306
313
|
- lib/rails_app_generator/addons/high_voltage.rb
|
314
|
+
- lib/rails_app_generator/addons/honeybadger.rb
|
307
315
|
- lib/rails_app_generator/addons/inline_svg.rb
|
308
316
|
- lib/rails_app_generator/addons/irbrc.rb
|
309
317
|
- lib/rails_app_generator/addons/lograge.rb
|
@@ -353,8 +361,8 @@ files:
|
|
353
361
|
- lib/rails_app_generator/version.rb
|
354
362
|
- package-lock.json
|
355
363
|
- package.json
|
364
|
+
- profiles/addons/honeybadger.json
|
356
365
|
- profiles/addons/rails-html-sanitizer.json
|
357
|
-
- profiles/addons/rails_html_sanitizer.json
|
358
366
|
- profiles/rag-add-some-pages.json
|
359
367
|
- profiles/rag-bootstrap.json
|
360
368
|
- profiles/rag-devise.json
|
@@ -401,6 +409,8 @@ files:
|
|
401
409
|
- templates/addons/generators/lib/generators/rails/navigation/navigation_generator.rb
|
402
410
|
- templates/addons/generators/lib/generators/rails/scaffold_controller_generator.rb
|
403
411
|
- templates/addons/high_voltage/config/initializers/high_voltage.rb
|
412
|
+
- templates/addons/honeybadger/en.yml
|
413
|
+
- templates/addons/honeybadger/honeybadger.sample.yml
|
404
414
|
- templates/addons/irbrc/.irbrc.erb
|
405
415
|
- templates/addons/lograge/config/initializers/lograge.rb
|
406
416
|
- templates/addons/pundit/app/controllers/authorized_controller.rb.erb
|