bullet_train-super_scaffolding 1.5.2 → 1.6.1
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/lib/bullet_train/super_scaffolding/scaffolders/crud_scaffolder.rb +5 -5
- data/lib/bullet_train/super_scaffolding/scaffolders/join_model_scaffolder.rb +10 -0
- data/lib/bullet_train/super_scaffolding/version.rb +1 -1
- data/lib/scaffolding/script.rb +131 -22
- data/lib/scaffolding/transformer.rb +2 -2
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b7efadfb9aedfb0c4f903bd3a3d3cfb4434049c028f36ceba9e431bb9b7fe49
|
4
|
+
data.tar.gz: 1ed8a32334f0f72d859abfdea2ab689a5e7222f452344254a5bc46ebda8069c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f68150179ed016be2eb00f51500eaaedae7b5f84dd851118422c4fe78024e4506f83ce47aa35d9526b7a6cb2f1a1e3d3692c694d124551436bd9498a1dd531c
|
7
|
+
data.tar.gz: 6934fcc20f30bf18d9a29c3d5b878a83612b01697af0226defa7c94bf7543c5423534f6397bd6bef472d2f63578d5558059df9ebb73ca8f7894aae0063bddc7b
|
@@ -51,6 +51,11 @@ module BulletTrain
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
+
# get all the attributes.
|
55
|
+
attributes = argv[2..]
|
56
|
+
|
57
|
+
check_required_options_for_attributes("crud", attributes, child, parent)
|
58
|
+
|
54
59
|
# `tr` here compensates for namespaced models (i.e. - `Projects::Deliverable` to `projects/deliverable`).
|
55
60
|
parent_reference = parent_without_namespace.tableize.singularize.tr("/", "_")
|
56
61
|
tableized_child = child.tableize.tr("/", "_")
|
@@ -82,11 +87,6 @@ module BulletTrain
|
|
82
87
|
"bin/super-scaffold crud Section Page,Site,Team title:text body:text\n"
|
83
88
|
end
|
84
89
|
|
85
|
-
# get all the attributes.
|
86
|
-
attributes = argv[2..]
|
87
|
-
|
88
|
-
check_required_options_for_attributes("crud", attributes, child, parent)
|
89
|
-
|
90
90
|
transformer = Scaffolding::Transformer.new(child, parents, @options)
|
91
91
|
transformer.scaffold_crud(attributes)
|
92
92
|
|
@@ -44,6 +44,16 @@ module BulletTrain
|
|
44
44
|
# There should only be two attributes.
|
45
45
|
attributes = [argv[1], argv[2]]
|
46
46
|
|
47
|
+
unless @options["skip-migration-generation"]
|
48
|
+
attributes_without_options = attributes.map { |attribute| attribute.gsub(/{.*}$/, "") }
|
49
|
+
attributes_without_id = attributes_without_options.map { |attribute| attribute.gsub(/_id$/, "") }
|
50
|
+
attributes_with_references = attributes_without_id.map { |attribute| attribute + ":references" }
|
51
|
+
|
52
|
+
generation_command = "bin/rails generate model #{child} #{attributes_with_references.join(" ")}"
|
53
|
+
puts "Generating model with '#{generation_command}'".green
|
54
|
+
`#{generation_command}`
|
55
|
+
end
|
56
|
+
|
47
57
|
# Pretend we're doing a `super_select` scaffolding because it will do the correct thing.
|
48
58
|
attributes = attributes.map { |attribute| attribute.gsub("{", ":super_select{") }
|
49
59
|
attributes = attributes.map { |attribute| attribute.gsub("}", ",required}") }
|
data/lib/scaffolding/script.rb
CHANGED
@@ -7,6 +7,28 @@ require "scaffolding/routes_file_manipulator"
|
|
7
7
|
|
8
8
|
require_relative "../bullet_train/terminal_commands"
|
9
9
|
|
10
|
+
FIELD_PARTIALS = {
|
11
|
+
address_field: nil,
|
12
|
+
boolean: "boolean",
|
13
|
+
buttons: "string",
|
14
|
+
cloudinary_image: "string",
|
15
|
+
color_picker: "string",
|
16
|
+
date_and_time_field: "datetime",
|
17
|
+
date_field: "date",
|
18
|
+
email_field: "string",
|
19
|
+
emoji_field: "string",
|
20
|
+
file_field: "attachment",
|
21
|
+
image: "attachment",
|
22
|
+
options: "string",
|
23
|
+
password_field: "string",
|
24
|
+
phone_field: "string",
|
25
|
+
super_select: "string",
|
26
|
+
text_area: "text",
|
27
|
+
text_field: "string",
|
28
|
+
number_field: "integer",
|
29
|
+
trix_editor: "text"
|
30
|
+
}
|
31
|
+
|
10
32
|
# filter out options.
|
11
33
|
argv = []
|
12
34
|
@options = {}
|
@@ -28,11 +50,63 @@ def standard_protip
|
|
28
50
|
puts "If you do that, you can reset to your last commit state by using `git checkout .` and `git clean -d -f` ."
|
29
51
|
end
|
30
52
|
|
53
|
+
def git_status
|
54
|
+
`git status`.split("\n")
|
55
|
+
end
|
56
|
+
|
57
|
+
def has_untracked_files?(status_lines)
|
58
|
+
status_lines.include?("Untracked files:")
|
59
|
+
end
|
60
|
+
|
61
|
+
# All untracked files begin with a tab (i.e. - "\tapp/models/model.rb").
|
62
|
+
def get_untracked_files(status_lines)
|
63
|
+
`git ls-files --other --exclude-standard`.split("\n")
|
64
|
+
end
|
65
|
+
|
31
66
|
def check_required_options_for_attributes(scaffolding_type, attributes, child, parent = nil)
|
67
|
+
tableized_parent = nil
|
68
|
+
|
69
|
+
# Ensure the parent attribute name has the proper namespacing for adding as a foreign key.
|
70
|
+
if parent.present?
|
71
|
+
if child.include?("::") && parent.include?("::")
|
72
|
+
child_parts = child.split("::")
|
73
|
+
parent_parts = parent.split("::")
|
74
|
+
child_parts_dup = child_parts.dup
|
75
|
+
parent_parts_dup = parent_parts.dup
|
76
|
+
|
77
|
+
# Pop off however many spaces match.
|
78
|
+
child_parts_dup.each.with_index do |child_part, idx|
|
79
|
+
if child_part == parent_parts_dup[idx]
|
80
|
+
child_parts.shift
|
81
|
+
parent_parts.shift
|
82
|
+
else
|
83
|
+
tableized_parent = parent_parts.map(&:downcase).join("_")
|
84
|
+
break
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
# In case we're not working with namespaces, just tableize the parent as is.
|
89
|
+
tableized_parent ||= parent.tableize.singularize.tr("/", "_") if parent.present?
|
90
|
+
end
|
91
|
+
|
92
|
+
generation_command = case scaffolding_type
|
93
|
+
when "crud"
|
94
|
+
"bin/rails generate model #{child} #{tableized_parent}:references"
|
95
|
+
when "crud-field"
|
96
|
+
"" # This is blank so we can create the proper migration name first after we get the attributes.
|
97
|
+
end
|
98
|
+
|
99
|
+
# Even if there are attributes passed to the scaffolder,
|
100
|
+
# They may already exist in previous migrations, so we
|
101
|
+
# only register ones that need to be generated.
|
102
|
+
# i.e. - *_ids attributes in the join-model scaffolder.
|
103
|
+
attributes_to_generate = []
|
104
|
+
|
32
105
|
attributes.each do |attribute|
|
33
106
|
parts = attribute.split(":")
|
34
107
|
name = parts.shift
|
35
108
|
type = parts.join(":")
|
109
|
+
type_without_option = type.gsub(/{.*}/, "")
|
36
110
|
|
37
111
|
unless Scaffolding.valid_attribute_type?(type)
|
38
112
|
raise "You have entered an invalid attribute type: #{type}. General data types are used when creating new models, but Bullet Train " \
|
@@ -53,6 +127,19 @@ def check_required_options_for_attributes(scaffolding_type, attributes, child, p
|
|
53
127
|
{}
|
54
128
|
end
|
55
129
|
|
130
|
+
data_type = if type == "image" && cloudinary_enabled?
|
131
|
+
"string"
|
132
|
+
elsif attribute_options[:multiple]
|
133
|
+
case type
|
134
|
+
when "file"
|
135
|
+
"attachments"
|
136
|
+
else
|
137
|
+
"jsonb"
|
138
|
+
end
|
139
|
+
else
|
140
|
+
FIELD_PARTIALS[type_without_option.to_sym]
|
141
|
+
end
|
142
|
+
|
56
143
|
if name.match?(/_id$/) || name.match?(/_ids$/)
|
57
144
|
attribute_options ||= {}
|
58
145
|
unless attribute_options[:vanilla]
|
@@ -85,6 +172,48 @@ def check_required_options_for_attributes(scaffolding_type, attributes, child, p
|
|
85
172
|
end
|
86
173
|
end
|
87
174
|
end
|
175
|
+
|
176
|
+
# TODO: Is there ever a case that we want this to be a string?
|
177
|
+
data_type = "references" if name.match?(/_id$/)
|
178
|
+
|
179
|
+
# For join models, we don't want to generate a migration when
|
180
|
+
# running the crud-field scaffolder in the last step, so we skip *_ids.
|
181
|
+
# Addresses belong_to :addressable, so they don't hae to be represented in a migration.
|
182
|
+
unless name.match?(/_ids$/) || data_type.nil?
|
183
|
+
generation_command += " #{name_without_id || name}:#{data_type}"
|
184
|
+
attributes_to_generate << name
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
# Generate the models/migrations with the attributes passed.
|
189
|
+
if attributes_to_generate.any?
|
190
|
+
case scaffolding_type
|
191
|
+
# "join-model" is not here because the `rails g` command is written inline in its own scaffolder.
|
192
|
+
when "crud"
|
193
|
+
puts "Generating #{child} model with '#{generation_command}'".green
|
194
|
+
when "crud-field"
|
195
|
+
generation_command = "bin/rails generate migration add_#{attributes_to_generate.join("_and_")}_to_#{child.tableize.tr("/", "_")}#{generation_command}"
|
196
|
+
puts "Adding new fields to #{child} with '#{generation_command}'".green
|
197
|
+
end
|
198
|
+
puts ""
|
199
|
+
|
200
|
+
unless @options["skip-migration-generation"]
|
201
|
+
untracked_files = has_untracked_files?(git_status) ? get_untracked_files(git_status) : []
|
202
|
+
generation_thread = Thread.new { `#{generation_command}` }
|
203
|
+
generation_thread.join # Wait for the process to finish.
|
204
|
+
|
205
|
+
newly_untracked_files = has_untracked_files?(git_status) ? get_untracked_files(git_status) : []
|
206
|
+
if (newly_untracked_files - untracked_files).size.zero?
|
207
|
+
error_message = <<~MESSAGE
|
208
|
+
Since you have already created the #{child} model, Super Scaffolding won't allow you to re-create it.
|
209
|
+
You can either delete the model and try Super Scaffolding again, or add the `--skip-migration-generation`
|
210
|
+
flag to Super Scaffold the classic Bullet Train way.
|
211
|
+
MESSAGE
|
212
|
+
puts ""
|
213
|
+
puts error_message.red
|
214
|
+
exit 1
|
215
|
+
end
|
216
|
+
end
|
88
217
|
end
|
89
218
|
end
|
90
219
|
|
@@ -120,36 +249,16 @@ elsif ARGV.first.present?
|
|
120
249
|
when "--field-partials"
|
121
250
|
puts "Bullet Train uses the following field partials for Super Scaffolding".blue
|
122
251
|
puts ""
|
123
|
-
field_partials = {
|
124
|
-
address_field: "string",
|
125
|
-
boolean: "boolean",
|
126
|
-
buttons: "string",
|
127
|
-
cloudinary_image: "string",
|
128
|
-
color_picker: "string",
|
129
|
-
date_and_time_field: "datetime",
|
130
|
-
date_field: "date_field",
|
131
|
-
email_field: "string",
|
132
|
-
emoji_field: "string",
|
133
|
-
file_field: "attachment",
|
134
|
-
options: "string",
|
135
|
-
password_field: "string",
|
136
|
-
phone_field: "string",
|
137
|
-
super_select: "string",
|
138
|
-
text_area: "text",
|
139
|
-
text_field: "string",
|
140
|
-
number_field: "integer",
|
141
|
-
trix_editor: "text"
|
142
|
-
}
|
143
252
|
|
144
253
|
max_name_length = 0
|
145
|
-
|
254
|
+
FIELD_PARTIALS.each do |key, value|
|
146
255
|
if key.to_s.length > max_name_length
|
147
256
|
max_name_length = key.to_s.length
|
148
257
|
end
|
149
258
|
end
|
150
259
|
|
151
260
|
printf "\t%#{max_name_length}s:Data Type\n".bold, "Field Partial Name"
|
152
|
-
|
261
|
+
FIELD_PARTIALS.each { |key, value| printf "\t%#{max_name_length}s:#{value}\n", key }
|
153
262
|
|
154
263
|
puts ""
|
155
264
|
puts "For more details, check out the documentation:"
|
@@ -102,7 +102,7 @@ class Scaffolding::Transformer
|
|
102
102
|
"absolutely_abstract/creative_concepts",
|
103
103
|
"completely_concrete/tangible_things",
|
104
104
|
"absolutely-abstract-creative-concepts",
|
105
|
-
"completely-concrete-tangible-things"
|
105
|
+
"completely-concrete-tangible-things"
|
106
106
|
]
|
107
107
|
|
108
108
|
class_name = [
|
@@ -115,7 +115,7 @@ class Scaffolding::Transformer
|
|
115
115
|
"Creative concepts",
|
116
116
|
"Tangible things",
|
117
117
|
"creative concepts",
|
118
|
-
"tangible things"
|
118
|
+
"tangible things"
|
119
119
|
]
|
120
120
|
|
121
121
|
(
|
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.6.1
|
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-10-
|
11
|
+
date: 2023-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: standard
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: masamune-ast
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.2.1
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.2.1
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: indefinite_article
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|