rails_app_generator 0.2.42 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +23 -0
- data/after_templates/addons/scenic/_.rb +64 -0
- data/after_templates/addons/scenic/app/controllers/home_controller.rb +24 -0
- data/after_templates/addons/scenic/app/services/seed_service.rb +104 -0
- data/after_templates/addons/scenic/app/views/home/index.html.erb +3 -0
- data/after_templates/addons/scenic/app/views/home/individual_visitors_by_monument.html.erb +24 -0
- data/after_templates/addons/scenic/app/views/home/reseed.html.erb +3 -0
- data/after_templates/addons/scenic/app/views/home/visitors_by_monument.html.erb +22 -0
- data/after_templates/addons/scenic/app/views/layouts/_footer.html.erb +0 -0
- data/after_templates/addons/scenic/app/views/layouts/_navbar.html.erb +10 -0
- data/after_templates/addons/scenic/app/views/layouts/application.html.erb +29 -0
- data/after_templates/addons/scenic/db/seeds.rb +1 -0
- data/after_templates/addons/scenic/db/views/individual_visitors_by_monuments_v01.sql +9 -0
- data/after_templates/addons/scenic/db/views/visitors_by_monuments_v01.sql +8 -0
- data/after_templates/application/klueless/_.rb +6 -1
- data/after_templates/application/klueless/app/avo/cards/amount_raised.rb +14 -0
- data/after_templates/application/klueless/app/avo/cards/example_custom_partial.rb +7 -0
- data/after_templates/application/klueless/app/avo/cards/example_metric.rb +38 -0
- data/after_templates/application/klueless/app/avo/cards/percent_done.rb +10 -0
- data/after_templates/application/klueless/app/avo/cards/rubocop_card.rb +10 -0
- data/after_templates/application/klueless/app/avo/resources/rubocop_resource.rb +8 -0
- data/after_templates/application/klueless/app/controllers/home_controller.rb +9 -1
- data/after_templates/application/klueless/app/services/seed_service.rb +49 -3
- data/after_templates/application/klueless/app/views/layouts/_navbar.html.erb +9 -3
- data/after_templates/application/klueless/db/seeds.rb +1 -18
- data/after_templates/application/klueless/db/views/rubocop_logs_v01.sql +23 -0
- data/docs/last_run/app_generator_data.json +1 -0
- data/docs/last_run/rails_options_data.json +1 -0
- data/lib/rails_app_generator/cli/profile.rb +1 -3
- data/lib/rails_app_generator/starter.rb +46 -8
- data/lib/rails_app_generator/version.rb +1 -1
- data/package-lock.json +2 -2
- data/package.json +1 -1
- data/profiles/addons/scenic.json +14 -0
- data/profiles/application/klueless.json +4 -2
- data/tasks/profile.thor +1 -0
- data/templates/thor_task/profile/after_template.rb +19 -30
- data/templates/thor_task/profile/app/controllers/home_controller.rb +4 -0
- data/templates/thor_task/profile/app/services/seed_service.rb +27 -0
- data/templates/thor_task/profile/db/seeds.rb +1 -0
- metadata +23 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c6189ce2463be4e23bbda3e3b1d17c03142b60a7a754feeb7d7dcc75c26fc5f
|
4
|
+
data.tar.gz: 2d216396594ae4ee2d86626c9b3202419ae6a69536f564e7ba3a044771f7bd0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56a17d613f635bb7242ca6c04a93f0ec0f8a03ca987a30813ad15ce3f9d015eb174d8ec7d14d24a12cab3e0011756d702e67704ddfb2841e39ca1e18b1921683
|
7
|
+
data.tar.gz: 35bb905e32d9d650f828754ac4696ddd13c55ed9503f9bd270f30addae97c3a8b6e53ef8cd450c70a65b5630ac5437e1db8e0fc1a4a55a25c5a416c71e92c82f
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,26 @@
|
|
1
|
+
# [0.3.0](https://github.com/klueless-io/rails_app_generator/compare/v0.2.43...v0.3.0) (2022-09-02)
|
2
|
+
|
3
|
+
|
4
|
+
### Features
|
5
|
+
|
6
|
+
* add target_folder_exists handling ([cf0b7c6](https://github.com/klueless-io/rails_app_generator/commit/cf0b7c6d9b09fddc6cef940b17d3ce431b9c4eff))
|
7
|
+
|
8
|
+
## [0.2.43](https://github.com/klueless-io/rails_app_generator/compare/v0.2.42...v0.2.43) (2022-08-31)
|
9
|
+
|
10
|
+
|
11
|
+
### Bug Fixes
|
12
|
+
|
13
|
+
* add scenic profile ([dc309e6](https://github.com/klueless-io/rails_app_generator/commit/dc309e6f399cec7085de3133aa32989bc7ff7ed4))
|
14
|
+
* add scenic profile ([44614f7](https://github.com/klueless-io/rails_app_generator/commit/44614f70d73fe41cee5fd9cb9af5d20f0aa4f915))
|
15
|
+
|
16
|
+
## [0.2.42](https://github.com/klueless-io/rails_app_generator/compare/v0.2.41...v0.2.42) (2022-08-30)
|
17
|
+
|
18
|
+
|
19
|
+
### Bug Fixes
|
20
|
+
|
21
|
+
* add scenic addon ([93a9561](https://github.com/klueless-io/rails_app_generator/commit/93a9561131658399b91075e15c6d9680f1b73ece))
|
22
|
+
* cops ([fe3e6b7](https://github.com/klueless-io/rails_app_generator/commit/fe3e6b7031a57b0f212fd91491ebc7f32928b9c1))
|
23
|
+
|
1
24
|
## [0.2.41](https://github.com/klueless-io/rails_app_generator/compare/v0.2.40...v0.2.41) (2022-08-30)
|
2
25
|
|
3
26
|
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Ads methods to ActiveRecord:Migration to create and manage database views in Rails
|
4
|
+
#
|
5
|
+
# exe/rag addons/scenic
|
6
|
+
|
7
|
+
self.local_template_path = File.dirname(__FILE__)
|
8
|
+
|
9
|
+
gac 'base rails 7 image created'
|
10
|
+
|
11
|
+
prepare_environment
|
12
|
+
|
13
|
+
after_bundle do
|
14
|
+
force_copy
|
15
|
+
|
16
|
+
create_db
|
17
|
+
scaffolds
|
18
|
+
setup_customizations
|
19
|
+
migrate_db
|
20
|
+
end
|
21
|
+
|
22
|
+
def scaffolds
|
23
|
+
add_scaffold('country', 'code', 'name')
|
24
|
+
add_scaffold('monument', 'name', 'description', 'country:references')
|
25
|
+
add_scaffold('visitor', 'name', 'monument:references')
|
26
|
+
|
27
|
+
generate('scenic:model visitors_by_monument')
|
28
|
+
generate('scenic:model individual_visitors_by_monument --materialized')
|
29
|
+
|
30
|
+
directory "db/views"
|
31
|
+
end
|
32
|
+
|
33
|
+
def setup_customizations
|
34
|
+
route("root 'home#index'")
|
35
|
+
|
36
|
+
add_controller('home', 'index', 'visitors_by_monument', 'individual_visitors_by_monument', 'reseed', 'refresh_material_view')
|
37
|
+
|
38
|
+
directory "app/controllers"
|
39
|
+
directory "app/models"
|
40
|
+
directory "app/views"
|
41
|
+
template 'app/views/layouts/application.html.erb' , 'app/views/layouts/application.html.erb'
|
42
|
+
directory "app/services"
|
43
|
+
end
|
44
|
+
|
45
|
+
def create_db
|
46
|
+
gsub_file('config/database.yml', ' encoding: unicode', db_development_settings)
|
47
|
+
rails_command('db:environment:set RAILS_ENV=development')
|
48
|
+
db(drop: true, create: true)
|
49
|
+
end
|
50
|
+
|
51
|
+
def migrate_db
|
52
|
+
template 'db/seeds.rb' , 'db/seeds.rb'
|
53
|
+
|
54
|
+
db(migrate: true, seed: true)
|
55
|
+
end
|
56
|
+
|
57
|
+
def db_development_settings
|
58
|
+
<<-'RUBY'
|
59
|
+
encoding: unicode
|
60
|
+
host: <%= ENV['DATABASE_HOST'] %>
|
61
|
+
username: <%= ENV['DATABASE_USERNAME'] %>
|
62
|
+
password: <%= ENV['DATABASE_PASSWORD'] %>
|
63
|
+
RUBY
|
64
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class HomeController < ApplicationController
|
2
|
+
def index
|
3
|
+
end
|
4
|
+
|
5
|
+
def visitors_by_monument
|
6
|
+
@visitors = VisitorsByMonument.all.order(:visits)
|
7
|
+
end
|
8
|
+
|
9
|
+
def individual_visitors_by_monument
|
10
|
+
@visitors = IndividualVisitorsByMonument.all.order(:visits)
|
11
|
+
end
|
12
|
+
|
13
|
+
def reseed
|
14
|
+
SeedService.seed(variant: :refresh)
|
15
|
+
|
16
|
+
redirect_back_or_to root_path
|
17
|
+
end
|
18
|
+
|
19
|
+
def refresh_material_view
|
20
|
+
IndividualVisitorsByMonument.refresh
|
21
|
+
|
22
|
+
redirect_back_or_to root_path
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class SeedService
|
4
|
+
class << self
|
5
|
+
def seed(variant: :reset)
|
6
|
+
service = SeedService.new
|
7
|
+
service.call(variant: variant)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
NAMES = %w[
|
12
|
+
Adyson Aimee Aisha Akira Alani Albert Aleah Aleena Alena Alexus Alfred Ali Alia
|
13
|
+
Amelie Amina Amirah Amiya Anabella Anabelle Andrew Angeline Angelique Ann Annabel Aliana
|
14
|
+
Armani Arthur Aryana Ashanti Ashleigh Ashly Aspen Averie Avery Ayana Barbara
|
15
|
+
Brynlee Cailyn Cal Camilla Campbell Carina Carissa Carlee Carley Carlie Carolyn Cassie
|
16
|
+
Charlie Charlize Chaya Cherish Cierra Clair Clare Clarence Cloe Corinne Cristal
|
17
|
+
Destiney Dominique Dorsey Early Edith Edward Eileen Elaine Elisa Ellen Elmer Elsa Elsie
|
18
|
+
Fay Felicity Finley Frances Frank Fred Frederick Frida Gemma George Gia Giada Giana Gillian
|
19
|
+
Hana Harris Harry Haven Henderson Henry Herbert Hezekiah Hillary Iliana India
|
20
|
+
James Jamya Janae Janet Janiah Jaslyn Jaycee Jaylah Jaylee Jaylen Jaylene Jaylyn
|
21
|
+
John Johnie Joseph Joslyn Joyce Judith Julianne June Kaia Kaila Kailee Kaiya Kaley
|
22
|
+
Karma Kasey Katrina Kaya Kaylen Kayley Kaylyn Keely Kelsie Kendal Kenna Keyla Kierra
|
23
|
+
Leanna Lewis Leyla Libby Lilianna Lillianna Lilyana Lina Litzy Lizeth Lonzo Lorelai
|
24
|
+
Maeve Magdalena Maia Makena Maleah Maliyah Mara Mareli Mariam Marianna Mariela Marisa
|
25
|
+
Miah Micah Milagros Mina Mira Mollie Monique Monserrat Mont Moriah Mylie Natalya
|
26
|
+
Paloma Pamela Patience Paula Peter Phoenix Precious Raelynn Raina Raven Rayna Rayne Regan
|
27
|
+
Rollin Roselyn Rosemary Roy Ryann Saige Salma Sam Samuel Sanaa Sanai Sarahi Sariah Savanah
|
28
|
+
Shyann Shyanne Shyla Siena Sonia Stacy Stephany Susan Taliyah Tamara Taniya Taniyah
|
29
|
+
Tianna Tom Valery Walter Will William Willie Wilmer Xiomara Yadira Yamilet Yaritza Yasmine Yazmin
|
30
|
+
Yoselin Yuliana Zaniyah Zara Zaria Zion
|
31
|
+
%
|
32
|
+
].freeze
|
33
|
+
|
34
|
+
attr_reader :au, :us, :gb, :monuments
|
35
|
+
|
36
|
+
def call(variant: :reset)
|
37
|
+
reset if variant == :reset
|
38
|
+
refresh if variant == :refresh
|
39
|
+
create
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def reset
|
45
|
+
Visitor.delete_all
|
46
|
+
Monument.delete_all
|
47
|
+
Country.delete_all
|
48
|
+
end
|
49
|
+
|
50
|
+
def refresh
|
51
|
+
Visitor.delete_all
|
52
|
+
end
|
53
|
+
|
54
|
+
def create
|
55
|
+
upsert_countries
|
56
|
+
upsert_monuments
|
57
|
+
create_visitors
|
58
|
+
end
|
59
|
+
|
60
|
+
def upsert_countries
|
61
|
+
@au = Country.create_with(name: 'Australia').find_or_create_by(code: 'AU')
|
62
|
+
@us = Country.create_with(name: 'United States').find_or_create_by(code: 'US')
|
63
|
+
@gb = Country.create_with(name: 'United Kingdom').find_or_create_by(code: 'GB')
|
64
|
+
end
|
65
|
+
|
66
|
+
def upsert_monuments
|
67
|
+
@monuments = [
|
68
|
+
Monument.create_with(country: au,
|
69
|
+
description: 'The Sydney Opera House is a multi-venue performing arts centre in Sydney, New South Wales, Australia. It is the largest performing arts centre in Australia and the second largest in the world.')
|
70
|
+
.find_or_create_by(name: 'Sydney Opera House'),
|
71
|
+
Monument.create_with(country: au,
|
72
|
+
description: 'The Sydney Harbour Bridge is a viaduct bridge in Sydney, New South Wales, Australia. It is the longest viaduct bridge in Australia and the second longest in the world.')
|
73
|
+
.find_or_create_by(name: 'Sydney Harbour Bridge'),
|
74
|
+
Monument.create_with(country: au,
|
75
|
+
description: 'The Big Banana is a large, round, fruit-bearing tree in the Australian bushland of the Great Barrier Reef. It is the largest tree in the world.')
|
76
|
+
.find_or_create_by(name: 'The Big Banana'),
|
77
|
+
Monument.create_with(country: us,
|
78
|
+
description: 'The Statue of Liberty is a colossal neoclassical sculpture on Liberty Island in New York Harbor, New York, in the United States. The statue was a gift from the people of France to the people of the United States in 1886.')
|
79
|
+
.find_or_create_by(name: 'Statue of Liberty'),
|
80
|
+
Monument.create_with(country: us,
|
81
|
+
description: 'The Golden Gate Bridge is a suspension bridge spanning the Golden Gate, the one-mile-wide strait connecting San Francisco Bay and the Pacific Ocean. The bridge was completed in 1937.')
|
82
|
+
.find_or_create_by(name: 'Golden Gate Bridge'),
|
83
|
+
Monument.create_with(country: us,
|
84
|
+
description: 'The Empire State Building is a 102-story skyscraper in Midtown Manhattan, New York City. It is the world\'s tallest building, a structure that is the 4th-tallest building in the world.')
|
85
|
+
.find_or_create_by(name: 'Empire State Building'),
|
86
|
+
Monument.create_with(country: gb,
|
87
|
+
description: 'The Tower of London is a historic London tower on the north bank of the River Thames in central London. It is the most-visited paid monument in the world.')
|
88
|
+
.find_or_create_by(name: 'Tower of London'),
|
89
|
+
Monument.create_with(country: gb, description: 'The Big Ben is a clock tower in the north of London. It is the world\'s tallest clock tower.')
|
90
|
+
.find_or_create_by(name: 'Big Ben'),
|
91
|
+
Monument.create_with(country: gb,
|
92
|
+
description: 'The London Eye is a giant Ferris wheel situated on the South Bank of the River Thames in London, England. It is the world\'s largest Ferris wheel.')
|
93
|
+
.find_or_create_by(name: 'London Eye')
|
94
|
+
]
|
95
|
+
end
|
96
|
+
|
97
|
+
def create_visitors
|
98
|
+
NAMES.each do |name|
|
99
|
+
rand(1..10).times do # number monuments to visited (duplicates are fine)
|
100
|
+
Visitor.create(name: name, monument: monuments.sample)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<h1>Individual Visitors by Monument</h1>
|
2
|
+
|
3
|
+
<pre><code><%= File.read('db/views/individual_visitors_by_monuments_v01.sql') %></code></pre>
|
4
|
+
|
5
|
+
<table>
|
6
|
+
<thead>
|
7
|
+
<tr>
|
8
|
+
<th>Person</th>
|
9
|
+
<th>Monument</th>
|
10
|
+
<th>Country</th>
|
11
|
+
<th>Visits</th>
|
12
|
+
</tr>
|
13
|
+
</thead>
|
14
|
+
<tbody>
|
15
|
+
<% @visitors.each do |visitor| %>
|
16
|
+
<tr>
|
17
|
+
<td><%= visitor.person %></td>
|
18
|
+
<td><%= visitor.monument %></td>
|
19
|
+
<td><%= visitor.country %></td>
|
20
|
+
<td><%= visitor.visits %></td>
|
21
|
+
</tr>
|
22
|
+
<% end %>
|
23
|
+
</tbody>
|
24
|
+
</table>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<h1>Visitors by Monument</h1>
|
2
|
+
|
3
|
+
<pre><code><%= File.read('db/views/visitors_by_monuments_v01.sql') %></code></pre>
|
4
|
+
|
5
|
+
<table>
|
6
|
+
<thead>
|
7
|
+
<tr>
|
8
|
+
<th>Monument</th>
|
9
|
+
<th>Country</th>
|
10
|
+
<th>Visits</th>
|
11
|
+
</tr>
|
12
|
+
</thead>
|
13
|
+
<tbody>
|
14
|
+
<% @visitors.each do |visitor| %>
|
15
|
+
<tr>
|
16
|
+
<td><%= visitor.monument %></td>
|
17
|
+
<td><%= visitor.country %></td>
|
18
|
+
<td><%= visitor.visits %></td>
|
19
|
+
</tr>
|
20
|
+
<% end %>
|
21
|
+
</tbody>
|
22
|
+
</table>
|
File without changes
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<%= link_to 'Home', root_path %>
|
2
|
+
| <%= link_to 'Countries', countries_path %>
|
3
|
+
| <%= link_to 'Monuments', monuments_path %>
|
4
|
+
| <%= link_to 'Visitors', visitors_path %>
|
5
|
+
<br>
|
6
|
+
<%= link_to 'Visits (View)', home_visitors_by_monument_path %>
|
7
|
+
| <%= link_to 'Visits (Materialized)', home_individual_visitors_by_monument_path %>
|
8
|
+
| <%= link_to 'Re-Seed', home_reseed_path, style: 'color: blue; font-weight: 600;' %>
|
9
|
+
| <%= link_to 'Refresh Material View', home_refresh_material_view_path, style: 'color: blue; font-weight: 600;' %>
|
10
|
+
<hr />
|
@@ -0,0 +1,29 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title><%= camelized %></title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<%%= csrf_meta_tags %>
|
7
|
+
<%%= csp_meta_tag %>
|
8
|
+
|
9
|
+
<%- if options[:skip_hotwire] || options[:skip_javascript] -%>
|
10
|
+
<%%= stylesheet_link_tag "application" %>
|
11
|
+
<%- else -%>
|
12
|
+
<%%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
|
13
|
+
<%- end -%>
|
14
|
+
</head>
|
15
|
+
|
16
|
+
<body>
|
17
|
+
<header>
|
18
|
+
<%%= render 'layouts/navbar' %>
|
19
|
+
<hr />
|
20
|
+
</header>
|
21
|
+
<main>
|
22
|
+
<%%= yield %>
|
23
|
+
</main>
|
24
|
+
<footer>
|
25
|
+
<%%= render 'layouts/footer' %>
|
26
|
+
</footer>
|
27
|
+
</body>
|
28
|
+
</html>
|
29
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
SeedService.seed
|
@@ -0,0 +1,9 @@
|
|
1
|
+
select
|
2
|
+
visitors.name as person,
|
3
|
+
monuments.name as monument,
|
4
|
+
countries.name as country,
|
5
|
+
count(*) as visits
|
6
|
+
from visitors
|
7
|
+
join monuments on visitors.monument_id = monuments.id
|
8
|
+
join countries on monuments.country_id = countries.id
|
9
|
+
group by person, monument, country
|
@@ -44,6 +44,10 @@ def scaffolds
|
|
44
44
|
# add_scaffold('db_schema_foreign_key', 'left', 'right', 'name', 'on_update', 'on_delete', 'column', 'db_schema_table:references')
|
45
45
|
# add_scaffold('db_schema_index', 'name', 'fields', 'using', 'order:jsonb', 'where', 'unique', 'db_schema_table:references')
|
46
46
|
# add_scaffold('db_schema_view', 'name', 'materialized:boolean', 'sql_definition', 'db_schema_table:references')
|
47
|
+
|
48
|
+
generate('scenic:model rubocop_log --materialized')
|
49
|
+
|
50
|
+
directory "db/views"
|
47
51
|
end
|
48
52
|
|
49
53
|
def setup_customizations
|
@@ -51,13 +55,14 @@ def setup_customizations
|
|
51
55
|
|
52
56
|
force_copy
|
53
57
|
|
54
|
-
add_controller('home', 'index', 'quick_signin', 'reseed')
|
58
|
+
add_controller('home', 'index', 'quick_signin', 'reseed', 'refresh_material_view')
|
55
59
|
|
56
60
|
directory "app/controllers"
|
57
61
|
directory "app/models"
|
58
62
|
directory "app/views"
|
59
63
|
template 'app/views/layouts/application.html.erb', 'app/views/layouts/application.html.erb'
|
60
64
|
directory "app/queries"
|
65
|
+
directory "app/services"
|
61
66
|
end
|
62
67
|
|
63
68
|
def setup_avo
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class AmountRaised < Avo::Dashboards::MetricCard
|
2
|
+
self.id = "amount_raised"
|
3
|
+
self.label = "Amount raised"
|
4
|
+
# self.description = "Some description"
|
5
|
+
# self.cols = 1
|
6
|
+
# self.initial_range = 30
|
7
|
+
# self.ranges = [7, 30, 60, 365, "TODAY", "MTD", "QTD", "YTD", "ALL"]
|
8
|
+
self.prefix = "$"
|
9
|
+
# self.suffix = ""
|
10
|
+
|
11
|
+
query do
|
12
|
+
result 9001
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class ExampleMetric < Avo::Dashboards::MetricCard
|
2
|
+
self.id = "users_metric"
|
3
|
+
self.label = "Users count"
|
4
|
+
self.description = "Users description"
|
5
|
+
self.cols = 1
|
6
|
+
self.initial_range = 30
|
7
|
+
self.ranges = [7, 30, 60, 365, "TODAY", "MTD", "QTD", "YTD", "ALL"]
|
8
|
+
# self.prefix = "$"
|
9
|
+
# self.suffix = "%"
|
10
|
+
self.refresh_every = 10.minutes
|
11
|
+
|
12
|
+
# You have access to context, params, range, current dashboard, and current card
|
13
|
+
query do
|
14
|
+
from = Date.today.midnight - 1.week
|
15
|
+
to = DateTime.current
|
16
|
+
|
17
|
+
if range.present?
|
18
|
+
if range.to_s == range.to_i.to_s
|
19
|
+
from = DateTime.current - range.to_i.days
|
20
|
+
else
|
21
|
+
case range
|
22
|
+
when "TODAY"
|
23
|
+
from = DateTime.current.beginning_of_day
|
24
|
+
when "MTD"
|
25
|
+
from = DateTime.current.beginning_of_month
|
26
|
+
when "QTD"
|
27
|
+
from = DateTime.current.beginning_of_quarter
|
28
|
+
when "YTD"
|
29
|
+
from = DateTime.current.beginning_of_year
|
30
|
+
when "ALL"
|
31
|
+
from = Time.at(0)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
result User.where(created_at: from..to).count
|
37
|
+
end
|
38
|
+
end
|
@@ -7,6 +7,14 @@ class HomeController < ApplicationController
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def reseed
|
10
|
-
SeedService.seed
|
10
|
+
SeedService.seed(variant: :refresh)
|
11
|
+
|
12
|
+
redirect_back_or_to root_path
|
13
|
+
end
|
14
|
+
|
15
|
+
def refresh_material_view
|
16
|
+
RubocopLog.refresh
|
17
|
+
|
18
|
+
redirect_back_or_to root_path
|
11
19
|
end
|
12
20
|
end
|
@@ -1,7 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class SeedService
|
4
|
+
PRINTSPEAK_DATA_PATH = "/Users/davidcruwys/dev/printspeak/printspeak-generator/.builders/.data/"
|
5
|
+
|
2
6
|
class << self
|
3
|
-
def seed
|
4
|
-
|
7
|
+
def seed(variant: :reset)
|
8
|
+
service = SeedService.new
|
9
|
+
service.call(variant: variant)
|
5
10
|
end
|
6
11
|
end
|
7
|
-
|
12
|
+
|
13
|
+
def call(variant: :reset)
|
14
|
+
reset if variant == :reset
|
15
|
+
refresh if variant == :refresh
|
16
|
+
create
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def get_data(filename)
|
22
|
+
json = File.read(File.join(PRINTSPEAK_DATA_PATH, filename))
|
23
|
+
JSON.parse(json)
|
24
|
+
end
|
25
|
+
|
26
|
+
def reset
|
27
|
+
User.delete_all
|
28
|
+
RailsApp.delete_all
|
29
|
+
Rubocop.delete_all
|
30
|
+
TableCount.delete_all
|
31
|
+
end
|
32
|
+
|
33
|
+
def refresh
|
34
|
+
end
|
35
|
+
|
36
|
+
def create
|
37
|
+
refresh_printspeak
|
38
|
+
|
39
|
+
RubocopLog.refresh
|
40
|
+
end
|
41
|
+
|
42
|
+
def refresh_printspeak
|
43
|
+
david = User.create_with(name: 'david', password: 'password').find_or_create_by(email: 'david@site.com')
|
44
|
+
|
45
|
+
rails_app = RailsApp.create_with(user: david).find_or_create_by(name: 'Printspeak')
|
46
|
+
|
47
|
+
puts 'Create Rubocop Data'
|
48
|
+
Rubocop.create(rails_app: rails_app, data: get_data('rubocop.json'))
|
49
|
+
|
50
|
+
puts 'Create Table Count Data'
|
51
|
+
TableCount.create(rails_app: rails_app, data: get_data('sql_count.json'))
|
52
|
+
end
|
53
|
+
end
|
@@ -1,4 +1,10 @@
|
|
1
|
-
<%= link_to 'Home', root_path %>
|
2
|
-
<%= link_to '
|
3
|
-
<%= link_to '
|
1
|
+
<%= link_to 'Home', root_path %>
|
2
|
+
| <%= link_to 'Re-Seed', home_reseed_path, style: 'color: blue; font-weight: 600;' %>
|
3
|
+
| <%= link_to 'Refresh Material View', home_refresh_material_view_path, style: 'color: blue; font-weight: 600;' %>
|
4
|
+
| <%= link_to 'Quick Sign In', home_quick_signin_path %>
|
5
|
+
| <%= link_to 'Admin', avo_path %>
|
6
|
+
<hr />
|
7
|
+
|
8
|
+
<%= link_to 'Visits (View)', home_visitors_by_monument_path %>
|
9
|
+
| <%= link_to 'Visits (Materialized)', home_individual_visitors_by_monument_path %>
|
4
10
|
<hr />
|
@@ -1,18 +1 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
david = User.create_with(name: 'david', password: 'password').find_or_create_by(email: 'david@site.com')
|
4
|
-
|
5
|
-
def get_data(filename)
|
6
|
-
json = File.read(File.join(@data_path, filename))
|
7
|
-
JSON.parse(json)
|
8
|
-
end
|
9
|
-
|
10
|
-
rails_app = RailsApp.create(name: 'Printspeak', user: david)
|
11
|
-
|
12
|
-
puts 'Create Rubocop Data'
|
13
|
-
Rubocop.create(rails_app: rails_app, data: get_data('rubocop.json'))
|
14
|
-
|
15
|
-
puts 'Create Table Count Data'
|
16
|
-
TableCount.create(rails_app: rails_app, data: get_data('sql_count.json'))
|
17
|
-
|
18
|
-
|
1
|
+
SeedService.seed
|
@@ -0,0 +1,23 @@
|
|
1
|
+
WITH
|
2
|
+
|
3
|
+
files AS (
|
4
|
+
SELECT jsonb_array_elements(data->'files') FROM rubocops
|
5
|
+
),
|
6
|
+
lines AS (
|
7
|
+
SELECT
|
8
|
+
jsonb_array_elements(files)->>'file' as file,
|
9
|
+
jsonb_array_elements(files)->'lines' as lines
|
10
|
+
FROM files
|
11
|
+
),
|
12
|
+
rubocop_log AS (
|
13
|
+
SELECT
|
14
|
+
jsonb_array_elements(lines)->>'position' as position,
|
15
|
+
jsonb_array_elements(lines)->>'status' as status,
|
16
|
+
jsonb_array_elements(lines)->>'status_message' as status_message,
|
17
|
+
jsonb_array_elements(lines)->>'cop' as cop,
|
18
|
+
jsonb_array_elements(lines)->>'message' as message,
|
19
|
+
jsonb_array_elements(lines)->>'full_line' as full_line,
|
20
|
+
jsonb_array_elements(lines)->>'file_name' as file_name
|
21
|
+
FROM lines
|
22
|
+
)
|
23
|
+
select * from rubocop_log
|
@@ -29,9 +29,7 @@ module RailsAppGenerator
|
|
29
29
|
RailsAppGenerator::Util.write_last_run('rails_options_data.json', opts.to_h)
|
30
30
|
|
31
31
|
starter = RailsAppGenerator::Starter.new(**args)
|
32
|
-
|
33
|
-
starter.delete_target_folder
|
34
|
-
starter.start(opts)
|
32
|
+
starter.start(opts) if starter.handle_target_folder_found?
|
35
33
|
end
|
36
34
|
# rubocop:enable Metrics/AbcSize
|
37
35
|
end
|
@@ -28,17 +28,22 @@ module RailsAppGenerator
|
|
28
28
|
# points to templates related to rails addons
|
29
29
|
attr_reader :addon_template_path
|
30
30
|
|
31
|
+
attr_reader :when_folder_exist # [abort destroy keep_git overwrite]
|
32
|
+
|
31
33
|
attr_reader :capture_output
|
32
34
|
attr_reader :console_output
|
33
35
|
|
36
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
34
37
|
def initialize(**args)
|
35
|
-
@app_path
|
36
|
-
@destination_root
|
37
|
-
@rails_template_path
|
38
|
-
@override_template_path
|
39
|
-
@addon_template_path
|
40
|
-
@
|
38
|
+
@app_path = args[:app_path] || '.'
|
39
|
+
@destination_root = args[:destination_root] || Dir.pwd
|
40
|
+
@rails_template_path = args[:rails_template_path] || AppGenerator.rails_template_path
|
41
|
+
@override_template_path = args[:override_template_path] || AppGenerator.override_template_path
|
42
|
+
@addon_template_path = args[:addon_template_path] || AppGenerator.addon_template_path
|
43
|
+
@when_folder_exist = args[:when_folder_exist] || 'abort'
|
44
|
+
@capture_output = args[:capture_output].nil? ? false : args[:capture_output]
|
41
45
|
end
|
46
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
42
47
|
|
43
48
|
def target_path
|
44
49
|
File.expand_path(File.join(destination_root, app_path))
|
@@ -58,12 +63,45 @@ module RailsAppGenerator
|
|
58
63
|
end
|
59
64
|
end
|
60
65
|
|
61
|
-
def
|
62
|
-
|
66
|
+
def handle_target_folder_found?
|
67
|
+
return true unless File.directory?(target_path)
|
68
|
+
|
69
|
+
case when_folder_exist
|
70
|
+
when 'abort'
|
71
|
+
puts "Target folder [#{target_path}] already exists. Aborting"
|
72
|
+
false
|
73
|
+
when 'destroy'
|
74
|
+
puts "Target folder [#{target_path}] already exists. Destroying it"
|
75
|
+
FileUtils.rm_rf(target_path)
|
76
|
+
true
|
77
|
+
when 'keep_git'
|
78
|
+
puts "Target folder [#{target_path}] already exists. Wiping it but keeping git history"
|
79
|
+
clean_target_folder
|
80
|
+
true
|
81
|
+
when 'overwrite'
|
82
|
+
puts "Target folder [#{target_path}] already exists. Overwriting it"
|
83
|
+
true
|
84
|
+
else
|
85
|
+
raise "Invalid when_folder_exist: #{when_folder_exist}"
|
86
|
+
end
|
63
87
|
end
|
64
88
|
|
65
89
|
private
|
66
90
|
|
91
|
+
def clean_target_folder
|
92
|
+
Dir.entries(target_path).each do |entry|
|
93
|
+
entry_path = File.join(target_path, entry)
|
94
|
+
|
95
|
+
next if ['.', '..', '.git'].include?(entry)
|
96
|
+
|
97
|
+
if File.file?(entry_path)
|
98
|
+
File.delete(entry_path)
|
99
|
+
elsif File.directory?(entry_path)
|
100
|
+
FileUtils.rm_rf(entry_path)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
67
105
|
# Rails options returns a flat array of options
|
68
106
|
#
|
69
107
|
# It can work accept a flat array of options or a
|
data/package-lock.json
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "rails_app_generator",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.3.1",
|
4
4
|
"lockfileVersion": 2,
|
5
5
|
"requires": true,
|
6
6
|
"packages": {
|
7
7
|
"": {
|
8
8
|
"name": "rails_app_generator",
|
9
|
-
"version": "0.
|
9
|
+
"version": "0.3.1",
|
10
10
|
"dependencies": {
|
11
11
|
"daisyui": "^2.20.0"
|
12
12
|
},
|
data/package.json
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
{
|
2
|
+
"args": {
|
3
|
+
"app_path": "r7_scenic",
|
4
|
+
"destination_root": "/Users/davidcruwys/dev/kgems/rails_app_generator/a/addons"
|
5
|
+
},
|
6
|
+
"opts": {
|
7
|
+
"skip_git": true,
|
8
|
+
"skip_test": true,
|
9
|
+
"database": "postgresql",
|
10
|
+
"add_minimal_css": true,
|
11
|
+
"template": "/Users/davidcruwys/dev/kgems/rails_app_generator/after_templates/addons/scenic/_.rb",
|
12
|
+
"add_scenic": true
|
13
|
+
}
|
14
|
+
}
|
@@ -2,7 +2,8 @@
|
|
2
2
|
"args": {
|
3
3
|
"app_path": "klueless",
|
4
4
|
"destination_root": "/Users/davidcruwys/dev/kweb",
|
5
|
-
"note": "add sidekiq to handle the data import tasks, add impersonate"
|
5
|
+
"note": "add sidekiq to handle the data import tasks, add impersonate",
|
6
|
+
"when_folder_exist": "keep_git"
|
6
7
|
},
|
7
8
|
"opts": {
|
8
9
|
"skip_test": true,
|
@@ -18,6 +19,7 @@
|
|
18
19
|
"add_factory_bot_rails": true,
|
19
20
|
"add_faker": true,
|
20
21
|
"add_ransack": false,
|
21
|
-
"add_rubocop": true
|
22
|
+
"add_rubocop": true,
|
23
|
+
"add_scenic": true
|
22
24
|
}
|
23
25
|
}
|
data/tasks/profile.thor
CHANGED
@@ -42,6 +42,7 @@ class Profile < Thor
|
|
42
42
|
template('profile/after_template.rb' , after_template_path('_.rb') , force: options[:force])
|
43
43
|
template('profile/app/controllers/home_controller.rb' , after_template_path('app/controllers/home_controller.rb') , force: options[:force])
|
44
44
|
template('profile/app/views/home/index.html.erb' , after_template_path('app/views/home/index.html.erb') , force: options[:force])
|
45
|
+
template('profile/app/services/seed_service.rb' , after_template_path('app/services/seed_service.rb') , force: options[:force])
|
45
46
|
|
46
47
|
copy_file('profile/app/views/layouts/_navbar.html.erb' , after_template_path('app/views/layouts/_navbar.html.erb') , force: options[:force])
|
47
48
|
copy_file('profile/app/views/layouts/_footer.html.erb' , after_template_path('app/views/layouts/_footer.html.erb') , force: options[:force])
|
@@ -11,9 +11,10 @@ gac 'base rails 7 image created'
|
|
11
11
|
prepare_environment
|
12
12
|
|
13
13
|
after_bundle do
|
14
|
+
create_db
|
14
15
|
scaffolds
|
15
16
|
setup_customizations
|
16
|
-
|
17
|
+
migrate_db
|
17
18
|
end
|
18
19
|
|
19
20
|
def scaffolds
|
@@ -33,38 +34,26 @@ def setup_customizations
|
|
33
34
|
directory "app/models"
|
34
35
|
directory "app/views"
|
35
36
|
template 'app/views/layouts/application.html.erb' , 'app/views/layouts/application.html.erb'
|
37
|
+
directory "app/services"
|
36
38
|
end
|
37
39
|
|
38
|
-
def
|
40
|
+
def create_db
|
41
|
+
# uncomment this if you need custom configuration in database.yml
|
42
|
+
# gsub_file('config/database.yml', ' encoding: unicode', db_development_settings)
|
43
|
+
db(drop: true, create: true)
|
44
|
+
end
|
45
|
+
|
46
|
+
def migrate_db
|
39
47
|
template 'db/seeds.rb' , 'db/seeds.rb'
|
40
48
|
|
41
|
-
|
42
|
-
db_seed
|
49
|
+
db(migrate: true, seed: true)
|
43
50
|
end
|
44
51
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
# run('bin/importmap pin sortablejs')
|
54
|
-
# run('npm install daisyui')
|
55
|
-
# rubocop
|
56
|
-
#
|
57
|
-
# directory 'app/assets/images'
|
58
|
-
# create_file 'app/assets/stylesheets/custom-bootstrap-import.scss' , read_template('custom-bootstrap-import.scss')
|
59
|
-
# append_to_file 'app/assets/config/manifest.js' , read_template('manifest.js')
|
60
|
-
# insert_into_file 'app/views/layouts/application.html.erb', read_template('application.html.erb'),
|
61
|
-
# before: %( <%%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %>)
|
62
|
-
# gsub_file 'app/views/layouts/application.html.erb', %(container mx-auto mt-28 px-5 flex), 'container mx-auto px-5'
|
63
|
-
# template 'home.css', 'app/assets/stylesheets/home.css'
|
64
|
-
#
|
65
|
-
# add_controller('page', 'benefits', 'faq', 'terms', 'privacy', '--skip-routes')
|
66
|
-
# route(<<-'RUBY')
|
67
|
-
# PageController.action_methods.each do |action|
|
68
|
-
# get "/#{action}", to: "page##{action}", as: "page_#{action}"
|
69
|
-
# end
|
70
|
-
# RUBY
|
52
|
+
def db_development_settings
|
53
|
+
<<-'RUBY'
|
54
|
+
encoding: unicode
|
55
|
+
host: <%= ENV['DATABASE_HOST'] %>
|
56
|
+
username: <%= ENV['DATABASE_USERNAME'] %>
|
57
|
+
password: <%= ENV['DATABASE_PASSWORD'] %>
|
58
|
+
RUBY
|
59
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class SeedService
|
2
|
+
class << self
|
3
|
+
def seed
|
4
|
+
service = SeedService.new
|
5
|
+
service.call
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def call
|
10
|
+
reset
|
11
|
+
create
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def reset
|
17
|
+
# Person.delete_all
|
18
|
+
# Post.delete_all
|
19
|
+
# Project.delete_all
|
20
|
+
end
|
21
|
+
|
22
|
+
def create
|
23
|
+
# FactoryBot.create_list(:post, rand(10..20))
|
24
|
+
# FactoryBot.create_list(:person, rand(10..20))
|
25
|
+
# FactoryBot.create_list(:project, rand(10..20))
|
26
|
+
end
|
27
|
+
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# SeedService.seed
|
1
2
|
# david = User.create(email: 'david@site.com', name: 'david', password: 'password')
|
2
3
|
# james = User.create(email: 'james@site.com', name: 'james', password: 'password')
|
3
4
|
# sally = User.create(email: 'sally@site.com', name: 'sally', password: 'password')
|
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.
|
4
|
+
version: 0.3.1
|
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-
|
11
|
+
date: 2022-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bootsnap
|
@@ -440,11 +440,29 @@ files:
|
|
440
440
|
- after_templates/addons/rubocop/app/controllers/home_controller.rb
|
441
441
|
- after_templates/addons/rubocop/app/views/home/index.html.erb
|
442
442
|
- after_templates/addons/rubocop/app/views/layouts/application.html.erb
|
443
|
+
- after_templates/addons/scenic/_.rb
|
444
|
+
- after_templates/addons/scenic/app/controllers/home_controller.rb
|
445
|
+
- after_templates/addons/scenic/app/services/seed_service.rb
|
446
|
+
- after_templates/addons/scenic/app/views/home/index.html.erb
|
447
|
+
- after_templates/addons/scenic/app/views/home/individual_visitors_by_monument.html.erb
|
448
|
+
- after_templates/addons/scenic/app/views/home/reseed.html.erb
|
449
|
+
- after_templates/addons/scenic/app/views/home/visitors_by_monument.html.erb
|
450
|
+
- after_templates/addons/scenic/app/views/layouts/_footer.html.erb
|
451
|
+
- after_templates/addons/scenic/app/views/layouts/_navbar.html.erb
|
452
|
+
- after_templates/addons/scenic/app/views/layouts/application.html.erb
|
453
|
+
- after_templates/addons/scenic/db/seeds.rb
|
454
|
+
- after_templates/addons/scenic/db/views/individual_visitors_by_monuments_v01.sql
|
455
|
+
- after_templates/addons/scenic/db/views/visitors_by_monuments_v01.sql
|
443
456
|
- after_templates/addons/twilio_ruby/_.rb
|
444
457
|
- after_templates/addons/twilio_ruby/app/controllers/home_controller.rb
|
445
458
|
- after_templates/addons/twilio_ruby/app/views/home/index.html.erb
|
446
459
|
- after_templates/addons/twilio_ruby/config/initializers/twilio.rb
|
447
460
|
- after_templates/application/klueless/_.rb
|
461
|
+
- after_templates/application/klueless/app/avo/cards/amount_raised.rb
|
462
|
+
- after_templates/application/klueless/app/avo/cards/example_custom_partial.rb
|
463
|
+
- after_templates/application/klueless/app/avo/cards/example_metric.rb
|
464
|
+
- after_templates/application/klueless/app/avo/cards/percent_done.rb
|
465
|
+
- after_templates/application/klueless/app/avo/cards/rubocop_card.rb
|
448
466
|
- after_templates/application/klueless/app/avo/dashboards/dashboard.rb
|
449
467
|
- after_templates/application/klueless/app/avo/resources/db_schema_resource.rb
|
450
468
|
- after_templates/application/klueless/app/avo/resources/rails_app_resource.rb
|
@@ -468,6 +486,7 @@ files:
|
|
468
486
|
- after_templates/application/klueless/config/initializers/avo.rb
|
469
487
|
- after_templates/application/klueless/config/locales/en.yml
|
470
488
|
- after_templates/application/klueless/db/seeds.rb
|
489
|
+
- after_templates/application/klueless/db/views/rubocop_logs_v01.sql
|
471
490
|
- after_templates/application/printspeak/_.rb
|
472
491
|
- after_templates/application/printspeak/app/assets/images/.keep
|
473
492
|
- after_templates/application/printspeak/app/assets/images/about/1.jpg
|
@@ -800,6 +819,7 @@ files:
|
|
800
819
|
- profiles/addons/redcarpet.json
|
801
820
|
- profiles/addons/rolify.json
|
802
821
|
- profiles/addons/rubocop.json
|
822
|
+
- profiles/addons/scenic.json
|
803
823
|
- profiles/addons/twilio_ruby.json
|
804
824
|
- profiles/application/klueless.json
|
805
825
|
- profiles/application/printspeak.json
|
@@ -861,6 +881,7 @@ files:
|
|
861
881
|
- templates/thor_task/addon/addon.tt
|
862
882
|
- templates/thor_task/profile/after_template.rb
|
863
883
|
- templates/thor_task/profile/app/controllers/home_controller.rb
|
884
|
+
- templates/thor_task/profile/app/services/seed_service.rb
|
864
885
|
- templates/thor_task/profile/app/views/home/index.html.erb.tt
|
865
886
|
- templates/thor_task/profile/app/views/layouts/_footer.html.erb.tt
|
866
887
|
- templates/thor_task/profile/app/views/layouts/_navbar.html.erb
|