bullet_train-super_scaffolding 1.2.26 → 1.3.0
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/app/views/account/scaffolding/absolutely_abstract/creative_concepts/_index.html.erb +3 -5
- data/app/views/account/scaffolding/absolutely_abstract/creative_concepts/show.html.erb +1 -1
- data/app/views/account/scaffolding/completely_concrete/tangible_things/_index.html.erb +3 -5
- data/app/views/account/scaffolding/completely_concrete/tangible_things/show.html.erb +1 -1
- data/config/locales/en/scaffolding/completely_concrete/tangible_things.en.yml +2 -0
- data/lib/bullet_train/super_scaffolding/scaffolders/crud_scaffolder.rb +2 -2
- data/lib/bullet_train/super_scaffolding/scaffolders/oauth_provider_scaffolder.rb +11 -8
- data/lib/bullet_train/super_scaffolding/version.rb +1 -1
- data/lib/scaffolding/block_manipulator.rb +1 -1
- data/lib/scaffolding/oauth_providers.rb +23 -93
- data/lib/scaffolding/script.rb +42 -8
- data/lib/scaffolding/transformer.rb +33 -63
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7a6281cfc5c70efe7e5bf88b2cafc61d86908e19440ef073b30b4d2ae516d61
|
4
|
+
data.tar.gz: 8503ac172be486e3910f337ef5a3aca84d7f6f0d2fc793b59017d53e22c5c3fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f57ebe01f983789000413350a1cda805f3109e15dd21cd0d0a54c45e660082f78c5b25b727c07fc6ba75b088013ceddd7ab5d27c430650c5de44aa33c59f82a6
|
7
|
+
data.tar.gz: 3084ca618a27a8550a8f94402fa6b44c15c5f456414e4145a2ec9d1b43375c4b66c25b5867f79f48d3ce0ee029ce7c64318b0af4fe632a9ef2264f97e1fce44d
|
@@ -6,7 +6,7 @@
|
|
6
6
|
<% pagy ||= nil %>
|
7
7
|
<% pagy, creative_concepts = pagy(creative_concepts, page_param: :creative_concepts_page) unless pagy %>
|
8
8
|
|
9
|
-
<%=
|
9
|
+
<%= cable_ready_updates_for context, :scaffolding_absolutely_abstract_creative_concepts do %>
|
10
10
|
<%= render 'account/shared/box' do |box| %>
|
11
11
|
<% box.title t(".contexts.#{context.class.name.underscore}.header") %>
|
12
12
|
<% box.description do %>
|
@@ -27,9 +27,7 @@
|
|
27
27
|
</tr>
|
28
28
|
</thead>
|
29
29
|
<tbody>
|
30
|
-
|
31
|
-
<%= render 'account/scaffolding/absolutely_abstract/creative_concepts/creative_concept', creative_concept: creative_concept %>
|
32
|
-
<% end %>
|
30
|
+
<%= render partial: 'account/scaffolding/absolutely_abstract/creative_concepts/creative_concept', collection: creative_concepts %>
|
33
31
|
</tbody>
|
34
32
|
</table>
|
35
33
|
<% end %>
|
@@ -43,7 +41,7 @@
|
|
43
41
|
|
44
42
|
<%# 🚅 super scaffolding will insert new targets one parent action model buttons above this line. %>
|
45
43
|
<%# 🚅 super scaffolding will insert new bulk action model buttons above this line. %>
|
46
|
-
<%= render "shared/bulk_action_select" %>
|
44
|
+
<%= render "shared/bulk_action_select" if creative_concepts.many? %>
|
47
45
|
|
48
46
|
<%= link_to t('global.buttons.back'), [:account, context], class: "#{first_button_primary(:absolutely_abstract_creative_concept)} back" unless hide_back %>
|
49
47
|
<% end %>
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<%= render 'account/shared/page' do |page| %>
|
2
2
|
<% page.title t('.section') %>
|
3
3
|
<% page.body do %>
|
4
|
-
<%=
|
4
|
+
<%= cable_ready_updates_for @creative_concept do %>
|
5
5
|
<%= render 'account/shared/box', divider: true do |box| %>
|
6
6
|
<% box.t :description, title: '.header' %>
|
7
7
|
<% box.body do %>
|
@@ -9,7 +9,7 @@
|
|
9
9
|
<% pagy, tangible_things = pagy(tangible_things, page_param: :tangible_things_page) unless pagy %>
|
10
10
|
|
11
11
|
<%= action_model_select_controller do %>
|
12
|
-
<%
|
12
|
+
<% cable_ready_updates_for context, collection do %>
|
13
13
|
<%= render 'account/shared/box', pagy: pagy do |box| %>
|
14
14
|
<% box.title t(".contexts.#{context.class.name.underscore}.header") %>
|
15
15
|
<% box.description do %>
|
@@ -35,9 +35,7 @@
|
|
35
35
|
</tr>
|
36
36
|
</thead>
|
37
37
|
<tbody>
|
38
|
-
|
39
|
-
<%= render 'account/scaffolding/completely_concrete/tangible_things/tangible_thing', tangible_thing: tangible_thing %>
|
40
|
-
<% end %>
|
38
|
+
<%= render partial: 'account/scaffolding/completely_concrete/tangible_things/tangible_thing', collection: tangible_things %>
|
41
39
|
</tbody>
|
42
40
|
</table>
|
43
41
|
<% end %>
|
@@ -53,7 +51,7 @@
|
|
53
51
|
|
54
52
|
<%# 🚅 super scaffolding will insert new targets one parent action model buttons above this line. %>
|
55
53
|
<%# 🚅 super scaffolding will insert new bulk action model buttons above this line. %>
|
56
|
-
<%= render "shared/bulk_action_select" %>
|
54
|
+
<%= render "shared/bulk_action_select" if tangible_things.many? %>
|
57
55
|
|
58
56
|
<% unless hide_back %>
|
59
57
|
<%= link_to t('global.buttons.back'), [:account, context], class: "#{first_button_primary(:completely_concrete_tangible_thing)} back" %>
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<%= render 'account/shared/page' do |page| %>
|
2
2
|
<% page.title t('.section') %>
|
3
3
|
<% page.body do %>
|
4
|
-
<%=
|
4
|
+
<%= cable_ready_updates_for @tangible_thing do %>
|
5
5
|
<%= render 'account/shared/box', divider: true do |box| %>
|
6
6
|
<% box.title t('.header') %>
|
7
7
|
<% box.description do %>
|
@@ -18,6 +18,8 @@ en:
|
|
18
18
|
confirmations:
|
19
19
|
# TODO customize for your use-case.
|
20
20
|
destroy: Are you sure you want to remove %{tangible_thing_name}? This will also remove any child resources and can't be undone.
|
21
|
+
tangible_thing:
|
22
|
+
buttons: *buttons
|
21
23
|
fields: &fields
|
22
24
|
id:
|
23
25
|
heading: Tangible Thing ID
|
@@ -12,8 +12,8 @@ module BulletTrain
|
|
12
12
|
puts " bin/super-scaffold crud Site Team name:text_field url:text_area"
|
13
13
|
puts ""
|
14
14
|
puts "E.g. a Section belongs to a Page, which belongs to a Site, which belongs to a Team:"
|
15
|
-
puts " rails g model Section page:references title:
|
16
|
-
puts " bin/super-scaffold crud Section Page,Site,Team title:
|
15
|
+
puts " rails g model Section page:references title:string body:text"
|
16
|
+
puts " bin/super-scaffold crud Section Page,Site,Team title:text_field body:text_area"
|
17
17
|
puts ""
|
18
18
|
puts "E.g. an Image belongs to either a Page or a Site:"
|
19
19
|
puts " Doable! See https://bit.ly/2NvO8El for a step by step guide."
|
@@ -5,13 +5,15 @@ module BulletTrain
|
|
5
5
|
def run
|
6
6
|
unless argv.count >= 5
|
7
7
|
puts ""
|
8
|
-
puts "🚅 usage: bin/super-scaffold oauth-provider <omniauth_gem> <gems_provider_name> <our_provider_name> <
|
8
|
+
puts "🚅 usage: bin/super-scaffold oauth-provider <omniauth_gem> <gems_provider_name> <our_provider_name> <PROVIDER_API_KEY_ENV_VAR_NAME> <PROVIDER_API_SECRET_ENV_VAR_NAME> [options]"
|
9
9
|
puts ""
|
10
10
|
puts "E.g. what we'd do to start Stripe off (if we didn't already do it):"
|
11
11
|
puts " bin/super-scaffold oauth-provider omniauth-stripe-connect stripe_connect Oauth::StripeAccount STRIPE_CLIENT_ID STRIPE_SECRET_KEY --icon=ti-money"
|
12
|
+
puts " (Please note here that the STRIPE_CLIENT_ID and STRIPE_SECRET_KEY strings are not the actual values, just the names we give to the environment variables.)"
|
12
13
|
puts ""
|
13
14
|
puts "E.g. what we actually did to start Shopify off:"
|
14
15
|
puts " bin/super-scaffold oauth-provider omniauth-shopify-oauth2 shopify Oauth::ShopifyAccount SHOPIFY_API_KEY SHOPIFY_API_SECRET_KEY --icon=ti-shopping-cart"
|
16
|
+
puts " (Please note here that the SHOPIFY_API_KEY and SHOPIFY_API_SECRET_KEY strings are not the actual values, just the names we give to the environment variables.)"
|
15
17
|
puts ""
|
16
18
|
puts "Options:"
|
17
19
|
puts ""
|
@@ -24,7 +26,7 @@ module BulletTrain
|
|
24
26
|
|
25
27
|
_, omniauth_gem, gems_provider_name, our_provider_name, api_key, api_secret = *ARGV
|
26
28
|
|
27
|
-
unless match = our_provider_name.match(/Oauth::(.*)Account/)
|
29
|
+
unless (match = our_provider_name.match(/Oauth::(.*)Account/))
|
28
30
|
puts "\n🚨 Your provider name must match the pattern of `Oauth::{Name}Account`, e.g. `Oauth::StripeAccount`\n".red
|
29
31
|
return
|
30
32
|
end
|
@@ -60,7 +62,6 @@ module BulletTrain
|
|
60
62
|
puts "but after you hit enter I'll open a page where you can view other icon options."
|
61
63
|
puts "When you find one you like, hover your mouse over it and then come back here and"
|
62
64
|
puts "and enter the name of the icon you want to use."
|
63
|
-
response = $stdin.gets.chomp
|
64
65
|
if TerminalCommands.can_open?
|
65
66
|
TerminalCommands.open_file_or_link("http://light.pinsupreme.com/icon_fonts_themefy.html")
|
66
67
|
else
|
@@ -80,6 +81,8 @@ module BulletTrain
|
|
80
81
|
|
81
82
|
options[:icon] = icon_name
|
82
83
|
|
84
|
+
empty_transformer = Scaffolding::Transformer.new("", "")
|
85
|
+
|
83
86
|
[
|
84
87
|
|
85
88
|
# User OAuth.
|
@@ -110,7 +113,7 @@ module BulletTrain
|
|
110
113
|
"./app/controllers/webhooks/incoming/oauth/stripe_account_webhooks_controller.rb"
|
111
114
|
|
112
115
|
].each do |name|
|
113
|
-
if File.directory?(
|
116
|
+
if File.directory?(empty_transformer.resolve_template_path(name))
|
114
117
|
oauth_scaffold_directory(name, options)
|
115
118
|
else
|
116
119
|
oauth_scaffold_file(name, options)
|
@@ -135,16 +138,16 @@ module BulletTrain
|
|
135
138
|
|
136
139
|
# find the database migration that defines this relationship.
|
137
140
|
migration_file_name = `grep "create_table #{oauth_transform_string(":oauth_stripe_accounts", options)}" db/migrate/*`.split(":").first
|
138
|
-
|
141
|
+
empty_transformer.replace_in_file(migration_file_name, "null: false", "null: true")
|
139
142
|
|
140
143
|
migration_file_name = `grep "create_table #{oauth_transform_string(":integrations_stripe_installations", options)}" db/migrate/*`.split(":").first
|
141
|
-
|
144
|
+
empty_transformer.replace_in_file(migration_file_name,
|
142
145
|
oauth_transform_string("t.references :oauth_stripe_account, null: false, foreign_key: true", options),
|
143
146
|
oauth_transform_string('t.references :oauth_stripe_account, null: false, foreign_key: true, index: {name: "index_stripe_installations_on_oauth_stripe_account_id"}', options))
|
144
147
|
|
145
148
|
migration_file_name = `grep "create_table #{oauth_transform_string(":webhooks_incoming_oauth_stripe_account_webhooks", options)}" db/migrate/*`.split(":").first
|
146
|
-
|
147
|
-
|
149
|
+
empty_transformer.replace_in_file(migration_file_name, "null: false", "null: true")
|
150
|
+
empty_transformer.replace_in_file(migration_file_name, "foreign_key: true", oauth_transform_string('foreign_key: true, index: {name: "index_stripe_webhooks_on_oauth_stripe_account_id"}'))
|
148
151
|
|
149
152
|
puts ""
|
150
153
|
puts "🎉"
|
@@ -6,7 +6,7 @@ module Scaffolding
|
|
6
6
|
#
|
7
7
|
# Wrap a block of ruby code with another block on the outside.
|
8
8
|
#
|
9
|
-
# @param [String] `starting` A string to search for at the start of the block. Eg "<%=
|
9
|
+
# @param [String] `starting` A string to search for at the start of the block. Eg "<%= cable_ready_updates_for context, collection do"
|
10
10
|
# @param [Array] `with` An array with two String elements. The text that should wrap the block. Eg ["<%= action_model_select_controller do %>", "<% end %>"]
|
11
11
|
#
|
12
12
|
def wrap_block(starting:, with:, lines:)
|
@@ -1,79 +1,6 @@
|
|
1
|
-
def legacy_resolve_template_path(file)
|
2
|
-
# Figure out the actual location of the file.
|
3
|
-
# Originally all the potential source files were in the repository alongside the application.
|
4
|
-
# Now the files could be provided by an included Ruby gem, so we allow those Ruby gems to register their base
|
5
|
-
# path and then we check them in order to see which template we should use.
|
6
|
-
BulletTrain::SuperScaffolding.template_paths.map do |base_path|
|
7
|
-
base_path = Pathname.new(base_path)
|
8
|
-
resolved_path = base_path.join(file).to_s
|
9
|
-
File.exist?(resolved_path) ? resolved_path : nil
|
10
|
-
end.compact.first || raise("Couldn't find the Super Scaffolding template for `#{file}` in any of the following locations:\n\n#{BulletTrain::SuperScaffolding.template_paths.join("\n")}")
|
11
|
-
end
|
12
|
-
|
13
|
-
def legacy_replace_in_file(file, before, after)
|
14
|
-
puts "Replacing in '#{file}'." unless silence_logs?
|
15
|
-
target_file_content = File.read(file)
|
16
|
-
target_file_content.gsub!(before, after)
|
17
|
-
File.write(file, target_file_content)
|
18
|
-
end
|
19
|
-
|
20
|
-
def legacy_add_line_to_file(file, content, hook, child, parent, options = {})
|
21
|
-
increase_indent = options[:increase_indent]
|
22
|
-
add_before = options[:add_before]
|
23
|
-
add_after = options[:add_after]
|
24
|
-
|
25
|
-
transformed_file_name = file
|
26
|
-
transformed_content = content
|
27
|
-
transform_hook = hook
|
28
|
-
|
29
|
-
target_file_content = File.read(transformed_file_name)
|
30
|
-
|
31
|
-
if target_file_content.include?(transformed_content)
|
32
|
-
puts "No need to update '#{transformed_file_name}'. It already has '#{transformed_content}'."
|
33
|
-
else
|
34
|
-
new_target_file_content = []
|
35
|
-
target_file_content.split("\n").each do |line|
|
36
|
-
if /#{Regexp.escape(transform_hook)}\s*$/.match?(line)
|
37
|
-
|
38
|
-
if add_before
|
39
|
-
new_target_file_content << "#{line} #{add_before}"
|
40
|
-
else
|
41
|
-
unless options[:prepend]
|
42
|
-
new_target_file_content << line
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
# get leading whitespace.
|
47
|
-
line =~ /^(\s*).*#{Regexp.escape(transform_hook)}.*/
|
48
|
-
leading_whitespace = $1
|
49
|
-
new_target_file_content << "#{leading_whitespace}#{" " if increase_indent}#{transformed_content}"
|
50
|
-
|
51
|
-
new_target_file_content << "#{leading_whitespace}#{add_after}" if add_after
|
52
|
-
|
53
|
-
if options[:prepend]
|
54
|
-
new_target_file_content << line
|
55
|
-
end
|
56
|
-
else
|
57
|
-
new_target_file_content << line
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
puts "Updating '#{transformed_file_name}'." unless silence_logs?
|
62
|
-
|
63
|
-
File.write(transformed_file_name, new_target_file_content.join("\n") + "\n")
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def encode_double_replacement_fix(string)
|
68
|
-
string.chars.join("~!@BT@!~")
|
69
|
-
end
|
70
|
-
|
71
|
-
def decode_double_replacement_fix(string)
|
72
|
-
string.gsub("~!@BT@!~", "")
|
73
|
-
end
|
74
|
-
|
75
1
|
def oauth_scaffold_directory(directory, options)
|
76
2
|
transformed_directory_name = oauth_transform_string(directory, options)
|
3
|
+
empty_transformer = Scaffolding::Transformer.new("", "")
|
77
4
|
begin
|
78
5
|
Dir.mkdir(transformed_directory_name)
|
79
6
|
rescue Errno::EEXIST => _
|
@@ -82,9 +9,9 @@ def oauth_scaffold_directory(directory, options)
|
|
82
9
|
puts "Proceeding to generate '#{transformed_directory_name}'."
|
83
10
|
end
|
84
11
|
|
85
|
-
Dir.foreach(
|
12
|
+
Dir.foreach(empty_transformer.resolve_template_path(directory)) do |file|
|
86
13
|
file = "#{directory}/#{file}"
|
87
|
-
unless File.directory?(
|
14
|
+
unless File.directory?(empty_transformer.resolve_template_path(file))
|
88
15
|
oauth_scaffold_file(file, options)
|
89
16
|
end
|
90
17
|
end
|
@@ -94,9 +21,10 @@ end
|
|
94
21
|
def oauth_scaffold_file(file, options)
|
95
22
|
transformed_file_name = oauth_transform_string(file, options)
|
96
23
|
transformed_file_content = []
|
24
|
+
empty_transformer = Scaffolding::Transformer.new("", "")
|
97
25
|
|
98
26
|
skipping = false
|
99
|
-
File.open(
|
27
|
+
File.open(empty_transformer.resolve_template_path(file)).each_line do |line|
|
100
28
|
if line.include?("# 🚅 skip when scaffolding.")
|
101
29
|
next
|
102
30
|
end
|
@@ -144,34 +72,36 @@ end
|
|
144
72
|
|
145
73
|
def oauth_transform_string(string, options)
|
146
74
|
name = options[:our_provider_name]
|
75
|
+
empty_transformer = Scaffolding::Transformer.new("", "")
|
147
76
|
|
148
77
|
# get these out of the way first.
|
149
|
-
string = string.gsub("stripe_connect: Stripe", encode_double_replacement_fix(options[:gems_provider_name] + ": " + name.titleize))
|
150
|
-
string = string.gsub("ti-money", encode_double_replacement_fix(options[:icon])) if options[:icon]
|
151
|
-
string = string.gsub("omniauth-stripe-connect", encode_double_replacement_fix(options[:omniauth_gem]))
|
152
|
-
string = string.gsub("stripe_connect", encode_double_replacement_fix(options[:gems_provider_name]))
|
153
|
-
string = string.gsub("STRIPE_CLIENT_ID", encode_double_replacement_fix(options[:api_key]))
|
154
|
-
string = string.gsub("STRIPE_SECRET_KEY", encode_double_replacement_fix(options[:api_secret]))
|
78
|
+
string = string.gsub("stripe_connect: Stripe", empty_transformer.encode_double_replacement_fix(options[:gems_provider_name] + ": " + name.titleize))
|
79
|
+
string = string.gsub("ti-money", empty_transformer.encode_double_replacement_fix(options[:icon])) if options[:icon]
|
80
|
+
string = string.gsub("omniauth-stripe-connect", empty_transformer.encode_double_replacement_fix(options[:omniauth_gem]))
|
81
|
+
string = string.gsub("stripe_connect", empty_transformer.encode_double_replacement_fix(options[:gems_provider_name]))
|
82
|
+
string = string.gsub("STRIPE_CLIENT_ID", empty_transformer.encode_double_replacement_fix(options[:api_key]))
|
83
|
+
string = string.gsub("STRIPE_SECRET_KEY", empty_transformer.encode_double_replacement_fix(options[:api_secret]))
|
155
84
|
|
156
85
|
# then try for some matches that give us a little more context on what they're looking for.
|
157
|
-
string = string.gsub("stripe-account", encode_double_replacement_fix(name.underscore.dasherize + "_account"))
|
158
|
-
string = string.gsub("stripe_account", encode_double_replacement_fix(name.underscore + "_account"))
|
159
|
-
string = string.gsub("StripeAccount", encode_double_replacement_fix(name + "Account"))
|
160
|
-
string = string.gsub("Stripe Account", encode_double_replacement_fix(name.titleize + " Account"))
|
161
|
-
string = string.gsub("Stripe account", encode_double_replacement_fix(name.titleize + " account"))
|
162
|
-
string = string.gsub("with Stripe", encode_double_replacement_fix("with " + name.titleize))
|
86
|
+
string = string.gsub("stripe-account", empty_transformer.encode_double_replacement_fix(name.underscore.dasherize + "_account"))
|
87
|
+
string = string.gsub("stripe_account", empty_transformer.encode_double_replacement_fix(name.underscore + "_account"))
|
88
|
+
string = string.gsub("StripeAccount", empty_transformer.encode_double_replacement_fix(name + "Account"))
|
89
|
+
string = string.gsub("Stripe Account", empty_transformer.encode_double_replacement_fix(name.titleize + " Account"))
|
90
|
+
string = string.gsub("Stripe account", empty_transformer.encode_double_replacement_fix(name.titleize + " account"))
|
91
|
+
string = string.gsub("with Stripe", empty_transformer.encode_double_replacement_fix("with " + name.titleize))
|
163
92
|
|
164
93
|
# finally, just do the simplest string replace. it's possible this can produce weird results.
|
165
94
|
# if they do, try adding more context aware replacements above, e.g. what i did with 'with'.
|
166
|
-
string = string.gsub("stripe", encode_double_replacement_fix(name.underscore))
|
167
|
-
string = string.gsub("Stripe", encode_double_replacement_fix(name))
|
95
|
+
string = string.gsub("stripe", empty_transformer.encode_double_replacement_fix(name.underscore))
|
96
|
+
string = string.gsub("Stripe", empty_transformer.encode_double_replacement_fix(name))
|
168
97
|
|
169
|
-
decode_double_replacement_fix(string)
|
98
|
+
empty_transformer.decode_double_replacement_fix(string)
|
170
99
|
end
|
171
100
|
|
172
101
|
def oauth_scaffold_add_line_to_file(file, content, after, options, additional_options = {})
|
102
|
+
empty_transformer = Scaffolding::Transformer.new("", "")
|
173
103
|
file = oauth_transform_string(file, options)
|
174
104
|
content = oauth_transform_string(content, options)
|
175
105
|
after = oauth_transform_string(after, options)
|
176
|
-
|
106
|
+
empty_transformer.add_line_to_file(file, content, after, additional_options)
|
177
107
|
end
|
data/lib/scaffolding/script.rb
CHANGED
@@ -1,6 +1,3 @@
|
|
1
|
-
# TODO these methods were removed from the global scope in super scaffolding and moved to `Scaffolding::Transformer`,
|
2
|
-
# but oauth provider scaffolding hasn't been updated yet.
|
3
|
-
|
4
1
|
require "scaffolding"
|
5
2
|
require "scaffolding/transformer"
|
6
3
|
require "scaffolding/block_manipulator"
|
@@ -87,7 +84,7 @@ end
|
|
87
84
|
|
88
85
|
def show_usage
|
89
86
|
puts ""
|
90
|
-
puts "🚅 usage: bin/super-scaffold [type] (... | --help)"
|
87
|
+
puts "🚅 usage: bin/super-scaffold [type] (... | --help | --field-partials)"
|
91
88
|
puts ""
|
92
89
|
puts "Supported types of scaffolding:"
|
93
90
|
puts ""
|
@@ -112,11 +109,48 @@ elsif argv.count > 1
|
|
112
109
|
puts "To use the original Super Scaffolding that you know and love, use the `crud` option.".yellow
|
113
110
|
|
114
111
|
show_usage
|
115
|
-
|
116
|
-
|
112
|
+
elsif ARGV.first.present?
|
113
|
+
case ARGV.first
|
114
|
+
when "--field-partials"
|
115
|
+
puts "Bullet Train uses the following field partials for Super Scaffolding".blue
|
117
116
|
puts ""
|
117
|
+
field_partials = {
|
118
|
+
boolean: "boolean",
|
119
|
+
buttons: "string",
|
120
|
+
cloudinary_image: "string",
|
121
|
+
color_picker: "string",
|
122
|
+
date_and_time_field: "datetime",
|
123
|
+
date_field: "date_field",
|
124
|
+
email_field: "string",
|
125
|
+
emoji_field: "string",
|
126
|
+
file_field: "attachment",
|
127
|
+
options: "string",
|
128
|
+
password_field: "string",
|
129
|
+
phone_field: "string",
|
130
|
+
super_select: "string",
|
131
|
+
text_area: "text",
|
132
|
+
text_field: "string",
|
133
|
+
number_field: "integer",
|
134
|
+
trix_editor: "text"
|
135
|
+
}
|
136
|
+
|
137
|
+
max_name_length = 0
|
138
|
+
field_partials.each do |key, value|
|
139
|
+
if key.to_s.length > max_name_length
|
140
|
+
max_name_length = key.to_s.length
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
printf "\t%#{max_name_length}s:Data Type\n".bold, "Field Partial Name"
|
145
|
+
field_partials.each { |key, value| printf "\t%#{max_name_length}s:#{value}\n", key }
|
146
|
+
|
147
|
+
puts ""
|
148
|
+
puts "For more details, check out the documentation:"
|
149
|
+
puts "https://bullettrain.co/docs/field-partials"
|
150
|
+
when "--help"
|
151
|
+
show_usage
|
152
|
+
else
|
118
153
|
puts "Invalid scaffolding type \"#{ARGV.first}\".".red
|
154
|
+
show_usage
|
119
155
|
end
|
120
|
-
|
121
|
-
show_usage
|
122
156
|
end
|
@@ -76,9 +76,7 @@ class Scaffolding::Transformer
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def transform_string(string)
|
79
|
-
[
|
80
|
-
|
81
|
-
# full class name plural.
|
79
|
+
full_class_name = [
|
82
80
|
"Scaffolding::AbsolutelyAbstract::CreativeConcepts",
|
83
81
|
"Scaffolding::CompletelyConcrete::TangibleThings",
|
84
82
|
"ScaffoldingAbsolutelyAbstractCreativeConcepts",
|
@@ -94,41 +92,19 @@ class Scaffolding::Transformer
|
|
94
92
|
"scaffolding_completely_concrete_tangible_things",
|
95
93
|
"scaffolding-absolutely-abstract-creative-concepts",
|
96
94
|
"scaffolding-completely-concrete-tangible-things",
|
95
|
+
"scaffolding.completely_concrete.tangible_things"
|
96
|
+
]
|
97
97
|
|
98
|
-
|
99
|
-
"Scaffolding::AbsolutelyAbstract::CreativeConcept",
|
100
|
-
"Scaffolding::CompletelyConcrete::TangibleThing",
|
101
|
-
"ScaffoldingAbsolutelyAbstractCreativeConcept",
|
102
|
-
"ScaffoldingCompletelyConcreteTangibleThing",
|
103
|
-
"Scaffolding Absolutely Abstract Creative Concept",
|
104
|
-
"Scaffolding Completely Concrete Tangible Thing",
|
105
|
-
"Scaffolding/Absolutely Abstract/Creative Concept",
|
106
|
-
"Scaffolding/Completely Concrete/Tangible Thing",
|
107
|
-
"scaffolding/absolutely_abstract/creative_concept",
|
108
|
-
"scaffolding/completely_concrete/tangible_thing",
|
109
|
-
"scaffolding_absolutely_abstract_creative_concept",
|
110
|
-
"scaffolding_completely_concrete_tangible_thing",
|
111
|
-
"scaffolding-absolutely-abstract-creative-concept",
|
112
|
-
"scaffolding-completely-concrete-tangible-thing",
|
113
|
-
"scaffolding.completely_concrete.tangible_things",
|
114
|
-
|
115
|
-
# class name in context plural.
|
98
|
+
class_name_with_context = [
|
116
99
|
"absolutely_abstract_creative_concepts",
|
117
100
|
"completely_concrete_tangible_things",
|
118
101
|
"absolutely_abstract/creative_concepts",
|
119
102
|
"completely_concrete/tangible_things",
|
120
103
|
"absolutely-abstract-creative-concepts",
|
121
104
|
"completely-concrete-tangible-things",
|
105
|
+
]
|
122
106
|
|
123
|
-
|
124
|
-
"absolutely_abstract_creative_concept",
|
125
|
-
"completely_concrete_tangible_thing",
|
126
|
-
"absolutely_abstract/creative_concept",
|
127
|
-
"completely_concrete/tangible_thing",
|
128
|
-
"absolutely-abstract-creative-concept",
|
129
|
-
"completely-concrete-tangible-thing",
|
130
|
-
|
131
|
-
# just class name singular.
|
107
|
+
class_name = [
|
132
108
|
"creative_concepts",
|
133
109
|
"tangible_things",
|
134
110
|
"creative-concepts",
|
@@ -139,24 +115,14 @@ class Scaffolding::Transformer
|
|
139
115
|
"Tangible things",
|
140
116
|
"creative concepts",
|
141
117
|
"tangible things",
|
118
|
+
]
|
142
119
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
"
|
148
|
-
|
149
|
-
"Tangible Thing",
|
150
|
-
"Creative concept",
|
151
|
-
"Tangible thing",
|
152
|
-
"creative concept",
|
153
|
-
"tangible thing",
|
154
|
-
|
155
|
-
# Account namespace vs. others.
|
156
|
-
":account",
|
157
|
-
"/account/"
|
158
|
-
|
159
|
-
].each do |needle|
|
120
|
+
(
|
121
|
+
full_class_name + full_class_name.map(&:singularize) +
|
122
|
+
class_name_with_context + class_name_with_context.map(&:singularize) +
|
123
|
+
class_name + class_name.map(&:singularize) +
|
124
|
+
[":account", "/account/"] # Account namespace vs. others.
|
125
|
+
).each do |needle|
|
160
126
|
string = string.gsub(needle, encode_double_replacement_fix(class_names_transformer.replacement_for(needle)))
|
161
127
|
end
|
162
128
|
|
@@ -175,9 +141,6 @@ class Scaffolding::Transformer
|
|
175
141
|
|
176
142
|
def resolve_template_path(file)
|
177
143
|
# Figure out the actual location of the file.
|
178
|
-
# Originally all the potential source files were in the repository alongside the application.
|
179
|
-
# Now the files could be provided by an included Ruby gem, so we allow those Ruby gems to register their base
|
180
|
-
# path and then we check them in order to see which template we should use.
|
181
144
|
BulletTrain::SuperScaffolding.template_paths.map do |base_path|
|
182
145
|
base_path = Pathname.new(base_path)
|
183
146
|
resolved_path = base_path.join(file).to_s
|
@@ -356,7 +319,12 @@ class Scaffolding::Transformer
|
|
356
319
|
return false
|
357
320
|
end
|
358
321
|
|
359
|
-
if
|
322
|
+
# When Super Scaffolding strong parameters, if an attribute named :project exists for a model `Project`,
|
323
|
+
# the `account_load_and_authorize_resource :project,` code prevents the attribute from being scaffolded
|
324
|
+
# since the transformed content is `:project,`. We bypass that here with this check.
|
325
|
+
content_matches_model_name = transformed_content.gsub(/[:|,]/, "").capitalize == child
|
326
|
+
|
327
|
+
if target_file_content.include?(transformed_content) && !content_matches_model_name
|
360
328
|
puts "No need to update '#{transformed_file_name}'. It already has '#{transformed_content}'." unless silence_logs?
|
361
329
|
|
362
330
|
else
|
@@ -878,8 +846,8 @@ class Scaffolding::Transformer
|
|
878
846
|
field_options[:color_picker_options] = "t('#{child.pluralize.underscore}.fields.#{name}.options')"
|
879
847
|
end
|
880
848
|
|
881
|
-
#
|
882
|
-
#
|
849
|
+
# When rendering a super_select element we need to use `html_options: {multiple: true}`,
|
850
|
+
# but all other fields simply use `multiple: true` to work.
|
883
851
|
if is_multiple
|
884
852
|
if type == "super_select"
|
885
853
|
field_options[:multiple] = "true"
|
@@ -1264,7 +1232,6 @@ class Scaffolding::Transformer
|
|
1264
1232
|
replace_in_file(migration_file_name, "foreign_key: true", "foreign_key: {to_table: \"#{attribute_options[:class_name].tableize.tr("/", "_")}\"}", /t\.references :#{name_without_id}/)
|
1265
1233
|
replace_in_file(migration_file_name, "foreign_key: true", "foreign_key: {to_table: \"#{attribute_options[:class_name].tableize.tr("/", "_")}\"}", /add_reference :#{child.underscore.pluralize.tr("/", "_")}, :#{name_without_id}/)
|
1266
1234
|
|
1267
|
-
# TODO also solve the 60 character long index limitation.
|
1268
1235
|
modified_migration = true
|
1269
1236
|
else
|
1270
1237
|
add_additional_step :yellow, "We would have expected there to be a migration that defined `#{expected_reference}`, but we didn't find one. Where was the reference added to this model? It's _probably_ the original creation of the table. Either way, you need to rollback, change \"foreign_key: true\" to \"foreign_key: {to_table: '#{attribute_options[:class_name].tableize.tr("/", "_")}'}\" for this column, and re-run the migration."
|
@@ -1300,14 +1267,17 @@ class Scaffolding::Transformer
|
|
1300
1267
|
|
1301
1268
|
# Add `default: false` to boolean migrations.
|
1302
1269
|
if boolean_buttons
|
1303
|
-
|
1304
|
-
|
1270
|
+
# Give priority to crud-field migrations if they exist.
|
1271
|
+
add_column_reference = "add_column :#{class_names_transformer.table_name}, :#{name}"
|
1272
|
+
create_table_reference = "create_table :#{class_names_transformer.table_name}"
|
1273
|
+
confirmation_migration_file_name = `grep "#{add_column_reference}" db/migrate/*`.split(":").first
|
1274
|
+
confirmation_migration_file_name ||= `grep "#{create_table_reference}" db/migrate/*`.split(":").first
|
1305
1275
|
|
1306
1276
|
old_line, new_line = nil
|
1307
1277
|
File.open(confirmation_migration_file_name) do |migration_file|
|
1308
1278
|
old_lines = migration_file.readlines
|
1309
1279
|
old_lines.each do |line|
|
1310
|
-
target_attribute = line.match?(/\s*t\.boolean :#{name}/)
|
1280
|
+
target_attribute = line.match?(/:#{class_names_transformer.table_name}, :#{name}, :boolean/) || line.match?(/\s*t\.boolean :#{name}/)
|
1311
1281
|
if target_attribute
|
1312
1282
|
old_line = line
|
1313
1283
|
new_line = "#{old_line.chomp}, default: false\n"
|
@@ -1532,6 +1502,8 @@ class Scaffolding::Transformer
|
|
1532
1502
|
|
1533
1503
|
# add sortability.
|
1534
1504
|
if cli_options["sortable"]
|
1505
|
+
scaffold_replace_line_in_file("./app/views/account/scaffolding/completely_concrete/tangible_things/_index.html.erb", transform_string("<tbody data-controller=\"sortable\" data-sortable-reorder-path-value=\"<%= url_for [:reorder, :account, context, collection] %>\">"), "<tbody>")
|
1506
|
+
|
1535
1507
|
unless cli_options["skip-model"]
|
1536
1508
|
scaffold_add_line_to_file("./app/models/scaffolding/completely_concrete/tangible_thing.rb", "def collection\n absolutely_abstract_creative_concept.completely_concrete_tangible_things\nend\n\n", METHODS_HOOK, prepend: true)
|
1537
1509
|
scaffold_add_line_to_file("./app/models/scaffolding/completely_concrete/tangible_thing.rb", "include Sortable\n", CONCERNS_HOOK, prepend: true)
|
@@ -1543,10 +1515,6 @@ class Scaffolding::Transformer
|
|
1543
1515
|
Scaffolding::FileManipulator.write(migration, new_lines)
|
1544
1516
|
end
|
1545
1517
|
|
1546
|
-
unless cli_options["skip-table"]
|
1547
|
-
scaffold_replace_line_in_file("./app/views/account/scaffolding/completely_concrete/tangible_things/_index.html.erb", transform_string("<tbody data-controller=\"sortable\" data-sortable-reorder-path-value=\"<%= url_for [:reorder, :account, context, collection] %>\">"), "<tbody>")
|
1548
|
-
end
|
1549
|
-
|
1550
1518
|
unless cli_options["skip-controller"]
|
1551
1519
|
scaffold_add_line_to_file("./app/controllers/account/scaffolding/completely_concrete/tangible_things_controller.rb", "include SortableActions\n", "Account::ApplicationController", increase_indent: true)
|
1552
1520
|
end
|
@@ -1642,7 +1610,9 @@ class Scaffolding::Transformer
|
|
1642
1610
|
icon_name = cli_options["sidebar"]
|
1643
1611
|
else
|
1644
1612
|
puts ""
|
1645
|
-
|
1613
|
+
# TODO: Update this help text letting developers know they can Super Scaffold
|
1614
|
+
# models without a parent after the `--skip-parent` logic is implemented.
|
1615
|
+
puts "Hey, models that are scoped directly off of a Team are eligible to be added to the navbar."
|
1646
1616
|
puts "Do you want to add this resource to the sidebar menu? (y/N)"
|
1647
1617
|
response = $stdin.gets.chomp
|
1648
1618
|
if response.downcase[0] == "y"
|
@@ -1693,7 +1663,7 @@ class Scaffolding::Transformer
|
|
1693
1663
|
end
|
1694
1664
|
end
|
1695
1665
|
|
1696
|
-
add_additional_step :yellow, transform_string("If you would like the table view you've just generated to reactively update when a Tangible Thing is updated on the server, please edit `app/models/scaffolding/absolutely_abstract/creative_concept.rb`, locate the `has_many :completely_concrete_tangible_things`, and add `
|
1666
|
+
add_additional_step :yellow, transform_string("If you would like the table view you've just generated to reactively update when a Tangible Thing is updated on the server, please edit `app/models/scaffolding/absolutely_abstract/creative_concept.rb`, locate the `has_many :completely_concrete_tangible_things`, and add `enable_cable_ready_updates: true` to it.")
|
1697
1667
|
|
1698
1668
|
restart_server unless ENV["CI"].present?
|
1699
1669
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bullet_train-super_scaffolding
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Culver
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: standard
|
@@ -170,12 +170,12 @@ files:
|
|
170
170
|
- lib/scaffolding/script.rb
|
171
171
|
- lib/scaffolding/transformer.rb
|
172
172
|
- lib/tasks/bullet_train/super_scaffolding_tasks.rake
|
173
|
-
homepage: https://github.com/bullet-train-co/bullet_train-super_scaffolding
|
173
|
+
homepage: https://github.com/bullet-train-co/bullet_train-core/tree/main/bullet_train-super_scaffolding
|
174
174
|
licenses:
|
175
175
|
- MIT
|
176
176
|
metadata:
|
177
|
-
homepage_uri: https://github.com/bullet-train-co/bullet_train-super_scaffolding
|
178
|
-
source_code_uri: https://github.com/bullet-train-co/bullet_train-super_scaffolding
|
177
|
+
homepage_uri: https://github.com/bullet-train-co/bullet_train-core/tree/main/bullet_train-super_scaffolding
|
178
|
+
source_code_uri: https://github.com/bullet-train-co/bullet_train-core/tree/main/bullet_train-super_scaffolding
|
179
179
|
post_install_message:
|
180
180
|
rdoc_options: []
|
181
181
|
require_paths:
|