6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/scaffolding/supercharts_chart_transformer.rb', line 6
def scaffold_supercharts
super
files = [
"./lib/scaffolding/app/controllers/account/scaffolding/completely_concrete/tangible_things/tangible_things_chart_controller.rb",
"./app/views/account/scaffolding/completely_concrete/tangible_things/tangible_things_chart",
"./app/views/shared/supercharts"
].compact
files.each do |name|
if File.directory?(resolve_template_path(name))
scaffold_directory(name)
else
scaffold_file(name)
end
end
locale_file = "./config/locales/en/scaffolding/completely_concrete/tangible_things.en.yml"
unless File.file?(transform_string(locale_file))
scaffold_file(locale_file)
add_locale_helper_export_fix
end
scaffold_add_line_to_file(locale_file, RUBY_NEW_CHARTS_HOOK, " account:", prepend: true, increase_indent: true, exact_match: true)
scaffold_replace_line_in_file(locale_file, " #{RUBY_NEW_CHARTS_HOOK}", " #{RUBY_NEW_CHARTS_HOOK}")
locale_yaml = <<~YAML
chart:
filters:
1w:
abbr: 1w
label: "last week"
1m:
abbr: 1m
label: "last month"
ytd:
abbr: ytd
label: "year to date"
description:
1w: Tangible Things last 7 days
1m: Tangible Things last month
ytd: Tangible Things since start of year
contextual_description:
1w: Tangible Things on <span class="whitespace-nowrap">%label%</span>
1m: Tangible Things in <span class="whitespace-nowrap">%label%</span>
ytd: Tangible Things in <span class="whitespace-nowrap">%label%</span>
alt_description:
1w: Chart of Tangible Things last 7 days
1m: Chart of Tangible Things last month
ytd: Chart of Tangible Things since start of year
date_abbr:
day: "%e"
week: "Week of %b %e"
month: "%b"
date_full:
day: "%B %e"
week: "week of %B %e"
month: "%B, %Y"
YAML
scaffold_add_line_to_file("./config/locales/en/scaffolding/completely_concrete/tangible_things.en.yml", locale_yaml, RUBY_NEW_CHARTS_HOOK, prepend: true)
unless cli_options["skip-parent"] || parent == "None"
lines_to_add = <<~RUBY
<div class="mt-4 [--chart-height:150px] md:[--chart-height:200px]">
<%= turbo_frame_tag :charts_tangible_things, src: polymorphic_path([:account, @creative_concept, :tangible_things, :chart], timespan: "1m") do %>
<%= render "shared/supercharts/chart_skeleton" do %>
<%= t('tangible_things.label') %>…
<% end %>
<% end %>
</div>
RUBY
scaffold_add_line_to_file(
parent_show_file,
lines_to_add,
"<%# 🚅 super scaffolding will insert new children above this line. %>",
prepend: true
)
end
add_ability_line_to_roles_yml
lines = File.read("config/routes.rb").lines.map(&:chomp)
account_namespace_found = false
lines.each_with_index do |line, index|
if line.match?("namespace :account do")
account_namespace_found = true
elsif account_namespace_found && line.match?(transform_string("resources :tangible_things"))
chart_resource_lines = transform_string("collection do\nresource :chart, only: :show, module: :tangible_things, as: :tangible_things_chart, controller: :tangible_things_chart\nend")
lines[index] = if line.match?(/do$/)
"#{line}\n#{chart_resource_lines}\n"
else
"#{line} do\n#{chart_resource_lines}\nend"
end
end
end
File.write("config/routes.rb", lines.join("\n"))
puts `standardrb --fix ./config/routes.rb`
restart_server unless ENV["CI"].present?
end
|