supercharts-bullet_train 1.1.0 β 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -17
- data/app/views/account/scaffolding/completely_concrete/tangible_things/tangible_things_chart/show.html.erb +12 -30
- data/app/views/shared/supercharts/_chart_skeleton.html.erb +1 -2
- data/app/views/shared/supercharts/_filter_button.html.erb +8 -1
- data/lib/bullet_train/supercharts/engine.rb +2 -2
- data/lib/bullet_train/supercharts/scaffolders/chart_scaffolder.rb +2 -2
- data/lib/bullet_train/supercharts/version.rb +1 -1
- data/lib/scaffolding/app/controllers/account/scaffolding/completely_concrete/tangible_things/tangible_things_chart_controller.rb +11 -24
- data/lib/scaffolding/supercharts_chart_transformer.rb +72 -20
- data/lib/scaffolding/supercharts_routes_file_manipulator.rb +21 -23
- data/lib/scaffolding/supercharts_transformer.rb +11 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e811c023b43cfac138f37ad0cab28985d10a22732cb31222d64ada7566f7e2f
|
4
|
+
data.tar.gz: 129ebeb5e7114f83260850f5575292ca36fa93c4b8ae12af58c088a4245fdf47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0e757aa845f016496c787282abfee6ae47792de9d6bbca3b3c4b1b4b6495228423215614e5596652589c752b1a7a8b976efa22f6257eb02ae175b81ff4ede2b
|
7
|
+
data.tar.gz: 3de0a84b61460b609434a1cca51016fc303943d4cefd0f49140e6b9fb225c473b45214d2f886823a33b1748a3195d2d58c8cc90a624d9faf99b2911be1c64b53
|
data/README.md
CHANGED
@@ -90,30 +90,35 @@ This will generated some new files and modify some files like inserting a `turbo
|
|
90
90
|
|
91
91
|
### Generate some test data
|
92
92
|
|
93
|
-
We'll use a
|
93
|
+
We'll use a new seed file create `click_throughs` with random-looking `created_at` properties (in this case creating a log normal spike and long-tail curve typical of a launch).
|
94
94
|
|
95
95
|
```ruby
|
96
|
-
#
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
96
|
+
# db/seeds/click_throughs.rb
|
97
|
+
team = Team.first
|
98
|
+
|
99
|
+
if team.present?
|
100
|
+
ClickThrough.delete_all # start fresh
|
101
|
+
|
102
|
+
# Rubystats::LognormalDistribution.new(1, 4.0)
|
103
|
+
sample_logn_days_since_launch = [0.374752478249304,2.573715367349214,8.205364533794372,0.018758139772852223,0.007503724554433451,9.795277947976652,8.920746829981699,0.10551189188869997,1.764721845714895,0.16013475895174034,0.09656162234229956,1.051545673721908,3.4605465909422444,0.5284662248320162,12.552059342378902,0.802742590175781,0.02109366834525422,0.02664778128443366,4.390318514353362,0.09774971155444112,1.2046433918447472,6.842861969154294,0.011979372791258703,0.064030764714403,0.254580889613002,0.8375254371675241,6.645595256049555,0.004578324225909655,7.645897327323974,3.8198662350854358,2.5433159804484093,12.23258356052949,8.590508575839966,0.36652090412334615,0.11151312341555021,0.17233489061676868,0.2146532779238352,0.14245752689762017,0.19342953572076568,0.1529907988439447,0.00750514011797885,0.4518938917044475,2.824609604776437,0.9950891711469877,1.0656326056125578,0.1261305417548888,0.009966388079746133,11.001041702449946,0.0013675811570916427,0.02367451456093704,0.01894224395588477,4.440315660471336,0.09493622122995193,0.07657312652331208,1.4874835063144172,0.13842079252030612,2.1017802510726815,4.196227775076141,0.054093691138304485,0.0051252791552137186,3.0245345093639773,0.00032997376067659843,0.006931535931463956,1.78040031800141,1.2156342429038396,1.7978965235819222,0.818322573101528,0.08369936871534746,0.16412718021762976,9.844260419603875,5.14537997872604,10.644277259959916,2.516432067417657,0.02670462498452867,0.009043612354757327,2.481241138462057,1.9882680498827123,0.11922535105626798,0.20284489863820995,0.1274031773301022,0.35779282006366203,1.0571276594384351,1.0249771657735456,0.6552185634235514,0.7524783523736271,0.2539575382334551,0.5439132099545871]
|
104
|
+
|
105
|
+
sample_logn_days_since_launch.each do |days_offset|
|
106
|
+
created_at = 2.weeks.ago + days_offset.days
|
107
|
+
|
108
|
+
team.click_throughs.create!(created_at: created_at)
|
104
109
|
end
|
105
110
|
end
|
106
111
|
```
|
107
112
|
|
108
|
-
Then
|
113
|
+
Then run:
|
109
114
|
|
110
|
-
```
|
111
|
-
|
115
|
+
```sh
|
116
|
+
bin/rails r db/seeds/click_throughs.rb
|
112
117
|
```
|
113
118
|
|
114
119
|
Visit your app in `localhost:3000` and you should see your new chart.
|
115
120
|
|
116
|
-
![Example chart inside a Bullet Train app showing Click Throughs in the last 30 days](https://user-images.githubusercontent.com/104179/
|
121
|
+
![Example chart inside a Bullet Train app showing Click Throughs in the last 30 days](https://user-images.githubusercontent.com/104179/222187945-1ff4a8c5-96d1-40e8-b421-d48c6cc4425d.gif)
|
117
122
|
|
118
123
|
## Modifying the chart
|
119
124
|
|
@@ -147,12 +152,12 @@ For the following types of changes, you'll need to create your own Stimulus cont
|
|
147
152
|
If you just want to make aesthetic changes, you can change the following css variables found at the top of your scaffolded `show.html.erb`. In this case, these are all TailwindCSS classes that set the appropriate custom CSS properties scoped to just that chart.
|
148
153
|
|
149
154
|
```html
|
150
|
-
[--axis-color:theme('colors.gray.300')] dark:[--axis-color:theme('colors.
|
151
|
-
[--grid-color:theme('colors.gray.100')] dark:[--grid-color:theme('colors.
|
155
|
+
[--axis-color:theme('colors.gray.300')] dark:[--axis-color:theme('colors.slate.500')]
|
156
|
+
[--grid-color:theme('colors.gray.100')] dark:[--grid-color:theme('colors.slate.800')]
|
152
157
|
[--line-color:#a86fe7]
|
153
158
|
[--point-color:theme('colors.gray.800')] dark:[--point-color:theme('colors.white')]
|
154
|
-
[--point-stroke-color:theme('colors.white')] dark:[--point-stroke-color:theme('colors.
|
155
|
-
[--point-stroke-color-hover:theme('colors.gray.100')] dark:[--point-stroke-color-hover:theme('colors.
|
159
|
+
[--point-stroke-color:theme('colors.white')] dark:[--point-stroke-color:theme('colors.slate.700')]
|
160
|
+
[--point-stroke-color-hover:theme('colors.gray.100')] dark:[--point-stroke-color-hover:theme('colors.slate.800')]
|
156
161
|
[--bar-fill-color:var(--line-color)]
|
157
162
|
[--bar-hover-fill-color:var(--point-color)]
|
158
163
|
[--point-radius:4] md:[--point-radius:6]
|
@@ -1,12 +1,12 @@
|
|
1
1
|
<%= turbo_frame_tag :charts_tangible_things do %>
|
2
2
|
<div class="p-8 rounded-md shadow
|
3
|
-
bg-white dark:bg-
|
4
|
-
[--axis-color:theme('colors.gray.300')] dark:[--axis-color:theme('colors.
|
5
|
-
[--grid-color:theme('colors.gray.100')] dark:[--grid-color:theme('colors.
|
6
|
-
[--line-color
|
3
|
+
bg-white dark:bg-slate-900
|
4
|
+
[--axis-color:theme('colors.gray.300')] dark:[--axis-color:theme('colors.slate.500')]
|
5
|
+
[--grid-color:theme('colors.gray.100')] dark:[--grid-color:theme('colors.slate.800')]
|
6
|
+
[--line-color:theme('colors.primary.400')] dark:[--line-color:theme('colors.primary.600')]
|
7
7
|
[--point-color:theme('colors.gray.800')] dark:[--point-color:theme('colors.white')]
|
8
|
-
[--point-stroke-color:theme('colors.white')] dark:[--point-stroke-color:theme('colors.
|
9
|
-
[--point-stroke-color-hover:theme('colors.gray.100')] dark:[--point-stroke-color-hover:theme('colors.
|
8
|
+
[--point-stroke-color:theme('colors.white')] dark:[--point-stroke-color:theme('colors.slate.900')]
|
9
|
+
[--point-stroke-color-hover:theme('colors.gray.100')] dark:[--point-stroke-color-hover:theme('colors.slate.800')]
|
10
10
|
[--bar-fill-color:var(--line-color)]
|
11
11
|
[--bar-hover-fill-color:var(--point-color)]
|
12
12
|
[--point-radius:4] md:[--point-radius:6]
|
@@ -24,13 +24,7 @@
|
|
24
24
|
<div class="relative">
|
25
25
|
<div data-supercharts--describable-target="overallDescription">
|
26
26
|
<h2 class="text-xs uppercase dark:text-white/50">
|
27
|
-
|
28
|
-
Tangible Things last 7 days
|
29
|
-
<% elsif @timespan == "1m" %>
|
30
|
-
Tangible Things last month
|
31
|
-
<% elsif @timespan == "ytd" %>
|
32
|
-
Tangible Things since start of year
|
33
|
-
<% end %>
|
27
|
+
<%= t(['tangible_things.chart.description', @timespan].join('.')) %>
|
34
28
|
</h2>
|
35
29
|
<p class="font-semibold dark:text-white mt-2" style="font-size: 1.8rem;">
|
36
30
|
<%= @total %>
|
@@ -40,13 +34,7 @@
|
|
40
34
|
<template data-supercharts--describable-target="contextualDescriptionTemplate">
|
41
35
|
<p class="font-semibold dark:text-white mb-1" style="font-size: 1.6rem;">%value%</p>
|
42
36
|
<p class="text-xs uppercase dark:text-white/50">
|
43
|
-
|
44
|
-
Tangible Things on <span class="whitespace-nowrap">%label%</span>
|
45
|
-
<% elsif @period == :week %>
|
46
|
-
Tangible Things in <span class="whitespace-nowrap">%label%</span>
|
47
|
-
<% elsif @period == :month %>
|
48
|
-
Tangible Things in <span class="whitespace-nowrap">%label%</span>
|
49
|
-
<% end %>
|
37
|
+
<%= t(['tangible_things.chart.contextual_description', @timespan].join('.')).html_safe %>
|
50
38
|
</p>
|
51
39
|
</template>
|
52
40
|
</div>
|
@@ -56,9 +44,9 @@
|
|
56
44
|
>
|
57
45
|
<div class="flex items-center justify-center">
|
58
46
|
<div class="inline-flex space-x-1" role="group">
|
59
|
-
<%= render "shared/supercharts/filter_button", path: polymorphic_path([:account, @absolutely_abstract_creative_concept, :tangible_things, :chart], timespan: "1w"),
|
60
|
-
<%= render "shared/supercharts/filter_button", path: polymorphic_path([:account, @absolutely_abstract_creative_concept, :tangible_things, :chart], timespan: "1m")
|
61
|
-
<%= render "shared/supercharts/filter_button", path: polymorphic_path([:account, @absolutely_abstract_creative_concept, :tangible_things, :chart], timespan: "ytd"),
|
47
|
+
<%= render "shared/supercharts/filter_button", label: t("tangible_things.chart.filters.1w.abbr"), alt: t("tangible_things.chart.filters.1w.label"), path: polymorphic_path([:account, @absolutely_abstract_creative_concept, :tangible_things, :chart], timespan: "1w"), first: true %>
|
48
|
+
<%= render "shared/supercharts/filter_button", label: t("tangible_things.chart.filters.1m.abbr"), alt: t("tangible_things.chart.filters.1m.label"), path: polymorphic_path([:account, @absolutely_abstract_creative_concept, :tangible_things, :chart], timespan: "1m") %>
|
49
|
+
<%= render "shared/supercharts/filter_button", label: t("tangible_things.chart.filters.ytd.abbr"), alt: t("tangible_things.chart.filters.ytd.label"), path: polymorphic_path([:account, @absolutely_abstract_creative_concept, :tangible_things, :chart], timespan: "ytd"), last: true %>
|
62
50
|
</div>
|
63
51
|
</div>
|
64
52
|
<template data-supercharts--filters-target="data">
|
@@ -77,13 +65,7 @@
|
|
77
65
|
data-action="update-chart->superchart#updateChart"
|
78
66
|
>
|
79
67
|
<canvas data-superchart-target="chartjsCanvas" style="height: var(--chart-height)">
|
80
|
-
|
81
|
-
Chart of Tangible Things last 7 days
|
82
|
-
<% elsif @timespan == "1m" %>
|
83
|
-
Chart of Tangible Things last month
|
84
|
-
<% elsif @timespan == "ytd" %>
|
85
|
-
Chart of Tangible Things since start of year
|
86
|
-
<% end %>
|
68
|
+
<%= t(['tangible_things.chart.alt_description', @timespan].join('.')) %>
|
87
69
|
</canvas>
|
88
70
|
<template data-superchart-target="csvData" data-supercharts--filterable-target="chartSourceData"></template>
|
89
71
|
<template data-superchart-target="chartjsOptions"></template>
|
@@ -2,8 +2,15 @@
|
|
2
2
|
first ||= false
|
3
3
|
last ||= false
|
4
4
|
label ||= "link"
|
5
|
+
alt ||= nil
|
5
6
|
path ||= ""
|
6
7
|
button_classes = "px-5 py-1.5 dark:text-white font-small text-xs leading-tight uppercase hover:bg-blue-800/50 hover:text-white focus:bg-blue-700 focus:outline-none focus:ring-0 active:bg-blue-800 transition duration-150 ease-in-out rounded-lg"
|
8
|
+
options = {
|
9
|
+
class: [button_classes, "bg-gray-400 dark:bg-blue-800 text-white hover:bg-blue-400 dark:hover:bg-blue-800/100": current_page?(path)]
|
10
|
+
}
|
11
|
+
unless alt.nil?
|
12
|
+
options[:title] = alt.upcase_first
|
13
|
+
end
|
7
14
|
%>
|
8
15
|
|
9
|
-
<%= link_to label, path,
|
16
|
+
<%= link_to label, path, options %>
|
@@ -3,9 +3,9 @@ module BulletTrain
|
|
3
3
|
class Engine < ::Rails::Engine
|
4
4
|
initializer "bullet_train.super_scaffolding.templates.register_template_path" do |app|
|
5
5
|
# Register the base path of this package with the Super Scaffolding engine.
|
6
|
-
BulletTrain::SuperScaffolding.template_paths << File.expand_path(
|
6
|
+
BulletTrain::SuperScaffolding.template_paths << File.expand_path("../../../..", __FILE__)
|
7
7
|
BulletTrain::SuperScaffolding.scaffolders.merge!({
|
8
|
-
"supercharts:chart" => "BulletTrain::Supercharts::Scaffolders::ChartScaffolder"
|
8
|
+
"supercharts:chart" => "BulletTrain::Supercharts::Scaffolders::ChartScaffolder"
|
9
9
|
})
|
10
10
|
end
|
11
11
|
end
|
@@ -19,14 +19,14 @@ module BulletTrain
|
|
19
19
|
puts ""
|
20
20
|
exit
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
target_model, parent_models = argv
|
24
24
|
parent_models = parent_models.split(",")
|
25
25
|
parent_models += ["Team"]
|
26
26
|
parent_models = parent_models.map(&:classify).uniq
|
27
27
|
|
28
28
|
transformer = Scaffolding::SuperchartsChartTransformer.new(target_model, parent_models)
|
29
|
-
|
29
|
+
|
30
30
|
transformer.scaffold_supercharts
|
31
31
|
end
|
32
32
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "csv"
|
2
2
|
|
3
3
|
class Account::Scaffolding::CompletelyConcrete::TangibleThings::TangibleThingsChartController < Account::ApplicationController
|
4
4
|
include ActionView::Helpers::NumberHelper
|
@@ -7,18 +7,18 @@ class Account::Scaffolding::CompletelyConcrete::TangibleThings::TangibleThingsCh
|
|
7
7
|
# GET /account/scaffolding/absolutely_abstract/creative_concepts/:absolutely_abstract_creative_concept_id/completely_concrete/tangible_things/chart
|
8
8
|
def show
|
9
9
|
@tangible_things = @absolutely_abstract_creative_concept.completely_concrete_tangible_things
|
10
|
-
|
10
|
+
|
11
11
|
@timespan = params[:timespan]
|
12
12
|
case @timespan
|
13
13
|
when "ytd"
|
14
14
|
range = Time.now.beginning_of_year..Time.now
|
15
15
|
range_days = (range.max - range.min).seconds.in_days
|
16
|
-
if range_days > 4.months.in_days
|
17
|
-
|
16
|
+
@period = if range_days > 4.months.in_days
|
17
|
+
:month
|
18
18
|
elsif range_days > 1.month.in_days
|
19
|
-
|
19
|
+
:week
|
20
20
|
else
|
21
|
-
|
21
|
+
:day
|
22
22
|
end
|
23
23
|
series = @tangible_things.group_by_period(@period, :created_at, range: range, expand_range: true)
|
24
24
|
when "1w"
|
@@ -30,26 +30,13 @@ class Account::Scaffolding::CompletelyConcrete::TangibleThings::TangibleThingsCh
|
|
30
30
|
@period = :day
|
31
31
|
series = @tangible_things.group_by_period(@period, :created_at, range: range)
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
counts = series.count
|
35
35
|
@total = counts.values.reduce(:+)
|
36
|
-
|
37
|
-
date_format_abbr =
|
38
|
-
|
39
|
-
|
40
|
-
"Week of %b %e"
|
41
|
-
elsif @period == :month
|
42
|
-
"%b"
|
43
|
-
end
|
44
|
-
|
45
|
-
date_format_full = if @period == :day
|
46
|
-
"%B %e"
|
47
|
-
elsif @period == :week
|
48
|
-
"week of %B %e"
|
49
|
-
elsif @period == :month
|
50
|
-
"%B, %Y"
|
51
|
-
end
|
52
|
-
|
36
|
+
|
37
|
+
date_format_abbr = t(["tangible_things.chart.date_abbr", @period].join("."))
|
38
|
+
date_format_full = t(["tangible_things.chart.date_full", @period].join("."))
|
39
|
+
|
53
40
|
@csv = CSV.generate(" ", headers: %w[date_abbr date_full count count_formatted], write_headers: true, encoding: "UTF-8") do |csv|
|
54
41
|
counts.each do |date, count|
|
55
42
|
csv.add_row [date.strftime(date_format_abbr), date.strftime(date_format_full), count, number_with_delimiter(count)]
|
@@ -1,16 +1,18 @@
|
|
1
1
|
require "scaffolding/supercharts_transformer"
|
2
2
|
|
3
3
|
class Scaffolding::SuperchartsChartTransformer < Scaffolding::SuperchartsTransformer
|
4
|
+
RUBY_NEW_CHARTS_HOOK = "# π super scaffolding will insert new charts above this line."
|
5
|
+
|
4
6
|
def scaffold_supercharts
|
5
7
|
super
|
6
|
-
|
8
|
+
|
7
9
|
# copy files over and do the appropriate string replace.
|
8
10
|
files = [
|
9
11
|
"./lib/scaffolding/app/controllers/account/scaffolding/completely_concrete/tangible_things/tangible_things_chart_controller.rb",
|
10
12
|
"./app/views/account/scaffolding/completely_concrete/tangible_things/tangible_things_chart",
|
11
|
-
"./app/views/shared/supercharts"
|
13
|
+
"./app/views/shared/supercharts"
|
12
14
|
].compact
|
13
|
-
|
15
|
+
|
14
16
|
files.each do |name|
|
15
17
|
if File.directory?(resolve_template_path(name))
|
16
18
|
scaffold_directory(name)
|
@@ -18,14 +20,64 @@ class Scaffolding::SuperchartsChartTransformer < Scaffolding::SuperchartsTransfo
|
|
18
20
|
scaffold_file(name)
|
19
21
|
end
|
20
22
|
end
|
21
|
-
|
23
|
+
|
24
|
+
# locale
|
25
|
+
locale_file = "./config/locales/en/scaffolding/completely_concrete/tangible_things.en.yml"
|
26
|
+
|
27
|
+
# add locale file if missing
|
28
|
+
unless File.file?(transform_string(locale_file))
|
29
|
+
scaffold_file(locale_file)
|
30
|
+
add_locale_helper_export_fix
|
31
|
+
end
|
32
|
+
|
33
|
+
# add locale strings for chart
|
34
|
+
scaffold_add_line_to_file(locale_file, RUBY_NEW_CHARTS_HOOK, " account:", prepend: true, increase_indent: true, exact_match: true)
|
35
|
+
# ensure the right indentation
|
36
|
+
scaffold_replace_line_in_file(locale_file, " #{RUBY_NEW_CHARTS_HOOK}", " #{RUBY_NEW_CHARTS_HOOK}")
|
37
|
+
|
38
|
+
locale_yaml = <<~YAML
|
39
|
+
chart:
|
40
|
+
filters:
|
41
|
+
1w:
|
42
|
+
abbr: 1w
|
43
|
+
label: "last week"
|
44
|
+
1m:
|
45
|
+
abbr: 1m
|
46
|
+
label: "last month"
|
47
|
+
ytd:
|
48
|
+
abbr: ytd
|
49
|
+
label: "year to date"
|
50
|
+
description:
|
51
|
+
1w: Tangible Things last 7 days
|
52
|
+
1m: Tangible Things last month
|
53
|
+
ytd: Tangible Things since start of year
|
54
|
+
contextual_description:
|
55
|
+
1w: Tangible Things on <span class="whitespace-nowrap">%label%</span>
|
56
|
+
1m: Tangible Things in <span class="whitespace-nowrap">%label%</span>
|
57
|
+
ytd: Tangible Things in <span class="whitespace-nowrap">%label%</span>
|
58
|
+
alt_description:
|
59
|
+
1w: Chart of Tangible Things last 7 days
|
60
|
+
1m: Chart of Tangible Things last month
|
61
|
+
ytd: Chart of Tangible Things since start of year
|
62
|
+
date_abbr:
|
63
|
+
day: "%e"
|
64
|
+
week: "Week of %b %e"
|
65
|
+
month: "%b"
|
66
|
+
date_full:
|
67
|
+
day: "%B %e"
|
68
|
+
week: "week of %B %e"
|
69
|
+
month: "%B, %Y"
|
70
|
+
YAML
|
71
|
+
|
72
|
+
scaffold_add_line_to_file("./config/locales/en/scaffolding/completely_concrete/tangible_things.en.yml", locale_yaml, RUBY_NEW_CHARTS_HOOK, prepend: true)
|
73
|
+
|
22
74
|
# add children to the show page of their parent.
|
23
75
|
unless cli_options["skip-parent"] || parent == "None"
|
24
76
|
lines_to_add = <<~RUBY
|
25
77
|
<div class="mt-4 [--chart-height:150px] md:[--chart-height:200px]">
|
26
78
|
<%= turbo_frame_tag :charts_tangible_things, src: polymorphic_path([:account, @creative_concept, :tangible_things, :chart], timespan: "1m") do %>
|
27
79
|
<%= render "shared/supercharts/chart_skeleton" do %>
|
28
|
-
|
80
|
+
<%= t('tangible_things.label') %>…
|
29
81
|
<% end %>
|
30
82
|
<% end %>
|
31
83
|
</div>
|
@@ -37,53 +89,53 @@ class Scaffolding::SuperchartsChartTransformer < Scaffolding::SuperchartsTransfo
|
|
37
89
|
prepend: true
|
38
90
|
)
|
39
91
|
end
|
40
|
-
|
92
|
+
|
41
93
|
# add user permissions.
|
42
94
|
add_ability_line_to_roles_yml
|
43
|
-
|
95
|
+
|
44
96
|
# apply routes.
|
45
97
|
# TODO this is a hack and should be in its own RouteFileManipulator class
|
46
98
|
lines = File.read("config/routes.rb").lines.map(&:chomp)
|
47
99
|
account_namespace_found = false
|
48
|
-
|
100
|
+
|
49
101
|
lines.each_with_index do |line, index|
|
50
102
|
if line.match?("namespace :account do")
|
51
103
|
account_namespace_found = true
|
52
104
|
elsif account_namespace_found && line.match?(transform_string("resources :tangible_things"))
|
53
105
|
chart_resource_lines = transform_string("collection do\nresource :chart, only: :show, module: :tangible_things, as: :tangible_things_chart, controller: :tangible_things_chart\nend")
|
54
|
-
if line.match?
|
55
|
-
|
106
|
+
lines[index] = if line.match?(/do$/)
|
107
|
+
"#{line}\n#{chart_resource_lines}\n"
|
56
108
|
else
|
57
|
-
|
109
|
+
"#{line} do\n#{chart_resource_lines}\nend"
|
58
110
|
end
|
59
111
|
end
|
60
112
|
end
|
61
|
-
|
113
|
+
|
62
114
|
File.write("config/routes.rb", lines.join("\n"))
|
63
|
-
|
115
|
+
|
64
116
|
puts `standardrb --fix ./config/routes.rb`
|
65
|
-
|
117
|
+
|
66
118
|
restart_server unless ENV["CI"].present?
|
67
119
|
end
|
68
|
-
|
120
|
+
|
69
121
|
def parent_show_file
|
70
122
|
@target_show_file ||= "./app/views/account/scaffolding/absolutely_abstract/creative_concepts/show.html.erb"
|
71
123
|
end
|
72
|
-
|
124
|
+
|
73
125
|
def transform_string(string)
|
74
126
|
[
|
75
127
|
"Scaffolding::CompletelyConcrete::TangibleThings::TangibleThingsChart",
|
76
|
-
"lib/scaffolding/app"
|
128
|
+
"lib/scaffolding/app"
|
77
129
|
].each do |needle|
|
78
130
|
# TODO There might be more to do here?
|
79
131
|
# What method is this calling?
|
80
132
|
string = string.gsub(needle, encode_double_replacement_fix(replacement_for(needle)))
|
81
133
|
end
|
82
|
-
|
134
|
+
|
83
135
|
string = super(string)
|
84
136
|
decode_double_replacement_fix(string)
|
85
137
|
end
|
86
|
-
|
138
|
+
|
87
139
|
def replacement_for(string)
|
88
140
|
case string
|
89
141
|
when "Scaffolding::CompletelyConcrete::TangibleThings::TangibleThingsChart"
|
@@ -94,4 +146,4 @@ class Scaffolding::SuperchartsChartTransformer < Scaffolding::SuperchartsTransfo
|
|
94
146
|
"π"
|
95
147
|
end
|
96
148
|
end
|
97
|
-
end
|
149
|
+
end
|
@@ -1,85 +1,83 @@
|
|
1
1
|
class Scaffolding::SuperchartsRoutesFileManipulator < Scaffolding::RoutesFileManipulator
|
2
|
-
|
3
2
|
def apply(base_namespaces, prepend_namespace_to_child: nil)
|
4
3
|
child_namespaces, child_resource, parent_namespaces, parent_resource = divergent_parts
|
5
|
-
|
4
|
+
|
6
5
|
within = find_or_create_namespaces(base_namespaces)
|
7
|
-
|
6
|
+
|
8
7
|
# e.g. Project and Projects::Deliverable
|
9
8
|
if parent_namespaces.empty? && child_namespaces.one? && parent_resource == child_namespaces.first
|
10
|
-
|
9
|
+
|
11
10
|
# resources :projects do
|
12
11
|
# scope module: 'projects' do
|
13
12
|
# resources :deliverables, only: collection_actions
|
14
13
|
# end
|
15
14
|
# end
|
16
|
-
|
15
|
+
|
17
16
|
parent_within = find_or_convert_resource_block(parent_resource, within: within)
|
18
|
-
|
17
|
+
|
19
18
|
# add the new resource within that namespace.
|
20
19
|
line = "scope module: '#{parent_resource}' do"
|
21
20
|
# TODO you haven't tested this yet.
|
22
21
|
unless (scope_within = find(/#{line}/, parent_within))
|
23
22
|
scope_within = insert([line, "end"], parent_within)
|
24
23
|
end
|
25
|
-
|
24
|
+
|
26
25
|
find_or_create_resource([child_resource], options: "only: collection_actions", within: scope_within)
|
27
|
-
|
26
|
+
|
28
27
|
# namespace :projects do
|
29
28
|
# resources :deliverables, except: collection_actions
|
30
29
|
# end
|
31
|
-
|
30
|
+
|
32
31
|
# We want to see if there are any namespaces one level above the parent itself,
|
33
32
|
# because namespaces with the same name as the resource can exist on the same level.
|
34
33
|
parent_block_start = find_block_parent(parent_within)
|
35
34
|
namespace_line_within = find_or_create_namespaces(child_namespaces, parent_block_start)
|
36
|
-
|
35
|
+
|
37
36
|
if prepend_namespace_to_child.present?
|
38
37
|
namespace_line_within = find_or_create_namespaces([prepend_namespace_to_child], namespace_line_within)
|
39
38
|
end
|
40
|
-
|
39
|
+
|
41
40
|
find_or_create_resource([child_resource], options: "except: collection_actions", within: namespace_line_within)
|
42
41
|
unless find_namespaces(child_namespaces, within)[child_namespaces.last]
|
43
42
|
raise "tried to insert `namespace :#{child_namespaces.last}` but it seems we failed"
|
44
43
|
end
|
45
|
-
|
44
|
+
|
46
45
|
# e.g. Projects::Deliverable and Objective Under It, Abstract::Concept and Concrete::Thing
|
47
46
|
elsif parent_namespaces.any?
|
48
|
-
|
47
|
+
|
49
48
|
# namespace :projects do
|
50
49
|
# resources :deliverables
|
51
50
|
# end
|
52
51
|
top_parent_namespace = find_namespaces(parent_namespaces, within)[parent_namespaces.first]
|
53
|
-
|
52
|
+
|
54
53
|
find_or_create_resource(child_namespaces + [child_resource], within: top_parent_namespace)
|
55
|
-
|
54
|
+
|
56
55
|
# resources :projects_deliverables, path: 'projects/deliverables' do
|
57
56
|
# resources :objectives
|
58
57
|
# end
|
59
58
|
block_parent_within = find_block_parent(top_parent_namespace)
|
60
59
|
parent_namespaces_and_resource = (parent_namespaces + [parent_resource]).join("_")
|
61
60
|
parent_within = find_or_create_resource_block([parent_namespaces_and_resource], options: "path: '#{parent_namespaces_and_resource.tr("_", "/")}'", within: block_parent_within)
|
62
|
-
|
61
|
+
|
63
62
|
if prepend_namespace_to_child.present?
|
64
63
|
parent_within = find_or_create_namespaces([prepend_namespace_to_child], parent_within)
|
65
64
|
end
|
66
|
-
|
65
|
+
|
67
66
|
find_or_create_resource(child_namespaces + [child_resource], within: parent_within)
|
68
67
|
else
|
69
|
-
|
68
|
+
|
70
69
|
begin
|
71
70
|
within = find_or_convert_resource_block(parent_resource, within: within)
|
72
71
|
rescue
|
73
72
|
within = find_or_convert_resource_block(parent_resource, options: "except: collection_actions", within: within)
|
74
73
|
end
|
75
|
-
|
74
|
+
|
76
75
|
if prepend_namespace_to_child.present?
|
77
76
|
within = find_or_create_namespaces([prepend_namespace_to_child], within)
|
78
77
|
end
|
79
|
-
|
78
|
+
|
80
79
|
find_or_create_resource(child_namespaces + [child_resource], options: define_concerns, within: within)
|
81
|
-
|
80
|
+
|
82
81
|
end
|
83
82
|
end
|
84
|
-
|
85
|
-
end
|
83
|
+
end
|
@@ -2,18 +2,16 @@ class Scaffolding::SuperchartsTransformer < Scaffolding::Transformer
|
|
2
2
|
def initialize(child, parents, cli_options = {})
|
3
3
|
super(child, parents, cli_options)
|
4
4
|
end
|
5
|
-
|
5
|
+
|
6
6
|
def scaffold_supercharts
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
add_additional_step :red, "We were not able to generate the routes for your Action Model automatically because: \"#{exception.message}\" You'll need to add them manually, which admittedly can be complicated. See https://blog.bullettrain.co/nested-namespaced-rails-routing-examples/ for guidance. ππ»ββοΈ"
|
17
|
-
end
|
7
|
+
# Update the routes to add the namespace and base resource
|
8
|
+
routes_manipulator = Scaffolding::RoutesFileManipulator.new("config/routes.rb", transform_string("Scaffolding::CompletelyConcrete::TangibleThings"), transform_string("Scaffolding::AbsolutelyAbstract::CreativeConcept"))
|
9
|
+
routes_manipulator.apply(["account"])
|
10
|
+
Scaffolding::FileManipulator.write("config/routes.rb", routes_manipulator.lines)
|
11
|
+
rescue BulletTrain::SuperScaffolding::CannotFindParentResourceException => exception
|
12
|
+
# TODO It would be great if we could automatically generate whatever the structure of the route needs to be and
|
13
|
+
# tell them where to try and inject it. Obviously we can't calculate the line number, otherwise the robots would
|
14
|
+
# have already inserted the routes, but at least we can try to do some of the complicated work for them.
|
15
|
+
add_additional_step :red, "We were not able to generate the routes for your Action Model automatically because: \"#{exception.message}\" You'll need to add them manually, which admittedly can be complicated. See https://blog.bullettrain.co/nested-namespaced-rails-routing-examples/ for guidance. ππ»ββοΈ"
|
18
16
|
end
|
19
|
-
end
|
17
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: supercharts-bullet_train
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pascal LalibertΓ©
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|