bullet_train 1.5.2 → 1.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/docs/action-models.md +0 -2
- data/docs/field-partials/file-field.md +0 -1
- data/docs/field-partials.md +6 -3
- data/docs/getting-started.md +2 -3
- data/docs/modeling.md +1 -1
- data/docs/super-scaffolding/delegated-types.md +1 -1
- data/docs/super-scaffolding.md +40 -52
- data/lib/bullet_train/version.rb +1 -1
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad66dfb9f1f68917815903fff1025c7fae9f2ad0b42c5153a5a2dc5cd5083451
|
4
|
+
data.tar.gz: 883cdad4a79582fe2728a9494f34802de6446b5a5632de08ebbe7e6cdce82e1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb4eb27a14a826441fb0b89e7ca2d0729315d74f6d4907c65a5bd109ddc5688d1b1c77954972413cf7ff793e4221a7d09ba556e917d3cd87c5dbd72c3cd985b2
|
7
|
+
data.tar.gz: 302b5c11d27082c17f7747b31431b19605cc09d97207614ef6ee23019cf68a6a11293787c6d700df555adaa8471fea1ceb60b68fe6d161396186351a69226929
|
data/docs/action-models.md
CHANGED
@@ -73,7 +73,6 @@ bin/super-scaffold action-model:targets-one-parent
|
|
73
73
|
### 1. Generate and scaffold an example `Project` model.
|
74
74
|
|
75
75
|
```
|
76
|
-
rails g model Project team:references name:string
|
77
76
|
bin/super-scaffold crud Project Team name:text_field
|
78
77
|
```
|
79
78
|
|
@@ -104,7 +103,6 @@ Because Action Models are just regular models, you can add new fields to them wi
|
|
104
103
|
For example:
|
105
104
|
|
106
105
|
```
|
107
|
-
rails g migration add_notify_users_to_projects_archive_actions notify_users:boolean
|
108
106
|
# side quest: update the generated migration with `default: false` on the new boolean field.
|
109
107
|
bin/super-scaffold crud-field Projects::ArchiveAction notify_users:boolean
|
110
108
|
```
|
@@ -47,6 +47,5 @@ Run the following command to generate the scaffolding for the `documents` field
|
|
47
47
|
If you're starting fresh, and don't have an existing model you can do something like this:
|
48
48
|
|
49
49
|
```
|
50
|
-
rails g model Project team:references name:string specification:attachment documents:attachments
|
51
50
|
bin/super-scaffold crud Project Team name:text_field specification:file_field documents:file_field{multiple}
|
52
51
|
```
|
data/docs/field-partials.md
CHANGED
@@ -147,12 +147,15 @@ Certain form field partials like `buttons` and `super_select` can also have thei
|
|
147
147
|
For Cloudinary you should use `string`, and for ActiveStorage you should use `attachment`.
|
148
148
|
|
149
149
|
## A Note On Data Types
|
150
|
-
|
150
|
+
When creating a `multiple` option attribute, Bullet Train generates these values as a `jsonb`.
|
151
151
|
```
|
152
|
-
|
153
|
-
> bin/super-scaffold crud Project Team multiple_buttons:buttons{multiple}
|
152
|
+
bin/super-scaffold crud Project Team multiple_buttons:buttons{multiple}
|
154
153
|
```
|
155
154
|
|
155
|
+
This will run the following rails command.
|
156
|
+
```
|
157
|
+
rails generate model Project team:references multiple_buttons:jsonb
|
158
|
+
```
|
156
159
|
## Formating `date` and `date_and_time`
|
157
160
|
After Super Scaffolding a `date` or `date_and_time` field, you can pass a format for the object like so:
|
158
161
|
|
data/docs/getting-started.md
CHANGED
@@ -8,16 +8,15 @@ Whether you want to build a new application with Bullet Train or contribute to B
|
|
8
8
|
|
9
9
|
If you're using Bullet Train for the first time, begin by learning these five important techniques:
|
10
10
|
|
11
|
-
1. Use `
|
11
|
+
1. Use `bin/super-scaffold crud` to scaffold a new model:
|
12
12
|
|
13
13
|
```
|
14
|
-
rails g model Project team:references name:string
|
15
14
|
bin/super-scaffold crud Project Team name:text_field
|
16
15
|
```
|
17
16
|
|
18
17
|
In this example, `Team` refers to the immediate parent of the `Project` resource. For more details, just run `bin/super-scaffold` or [read the documentation](/docs/super-scaffolding.md).
|
19
18
|
|
20
|
-
2. Use `
|
19
|
+
2. Use `bin/super-scaffold crud-field` to add a new field to a model you've already scaffolded:
|
21
20
|
|
22
21
|
```
|
23
22
|
rails g migration add_description_to_projects description:text
|
data/docs/modeling.md
CHANGED
@@ -68,7 +68,7 @@ Even if you know there's an attribute or model that you're going to want to poli
|
|
68
68
|
|
69
69
|
## A Systematic Approach
|
70
70
|
|
71
|
-
### 1. Write `
|
71
|
+
### 1. Write `bin/super-scaffold` commands in a scratch file.
|
72
72
|
|
73
73
|
See the [Super Scaffolding documentation](/docs/super-scaffolding.md) for more specific guidance. Leave plenty of comments in your scratch file describing anything that isn't obvious and providing examples of values that might populate attributes.
|
74
74
|
|
@@ -39,7 +39,7 @@ Note that in this specific approach we don't need a `team:references` on `Messag
|
|
39
39
|
### 2. Super Scaffolding for `Entry`
|
40
40
|
|
41
41
|
```
|
42
|
-
bin/super-scaffold crud Entry Team entryable_type:buttons
|
42
|
+
bin/super-scaffold crud Entry Team entryable_type:buttons --skip-migration-generation
|
43
43
|
```
|
44
44
|
|
45
45
|
We use `entryable_type:buttons` because we're going to allow people to choose which type of `Entry` they're creating with a list of buttons. This isn't the only option available to us, but it's the easiest to implement for now.
|
data/docs/super-scaffolding.md
CHANGED
@@ -41,25 +41,28 @@ Let's implement the following feature:
|
|
41
41
|
|
42
42
|
> An organization has many projects.
|
43
43
|
|
44
|
-
First,
|
44
|
+
First, run the `crud` scaffolder:
|
45
|
+
```
|
46
|
+
bin/super-scaffold crud Project Team name:text_field
|
47
|
+
rake db:migrate
|
48
|
+
```
|
49
|
+
|
50
|
+
In the above example, `team` represents the model that a `Project` primarily belongs to. Also, `text_field` was selected from [the list of available field partials](/docs/field-partials.md). We'll show examples with `trix_editor` and `super_select` later.
|
51
|
+
|
52
|
+
Super Scaffolding automatically generates models for you. However, if you want to split this process, you can pass the `--skip-migration-generation` to the command.
|
45
53
|
|
54
|
+
For example, generate the model with the standard Rails generator:
|
46
55
|
```
|
47
56
|
rails g model Project team:references name:string
|
48
57
|
```
|
49
58
|
|
50
|
-
In the above example, `team` represents the model that a `Project` primarily belongs to.
|
51
|
-
|
52
59
|
⚠️ Don't run migrations right away. It would be fine in this case, but sometimes the subsequent Super Scaffolding step actually updates the migration as part of its magic.
|
53
60
|
|
54
|
-
|
55
|
-
|
61
|
+
Then you can run the scaffolder with the flag:
|
56
62
|
```
|
57
|
-
bin/super-scaffold crud Project Team name:text_field
|
58
|
-
rake db:migrate
|
63
|
+
bin/super-scaffold crud Project Team name:text_field --skip-migration-generation
|
59
64
|
```
|
60
65
|
|
61
|
-
In the above example, `text_field` was selected from [the list of available field partials](/docs/field-partials.md). We'll show examples with `trix_editor` and `super_select` later.
|
62
|
-
|
63
66
|
### 2. Nested CRUD Scaffolding with `crud`
|
64
67
|
|
65
68
|
Building on that example, let's implement the following feature:
|
@@ -68,22 +71,14 @@ Building on that example, let's implement the following feature:
|
|
68
71
|
A project has many goals.
|
69
72
|
```
|
70
73
|
|
71
|
-
|
72
|
-
|
73
|
-
```
|
74
|
-
rails g model Goal project:references description:string
|
75
|
-
```
|
76
|
-
|
77
|
-
You can see in the example above that there is no direct reference to team, but to `project` instead, since that's where a `Goal` belongs.
|
78
|
-
|
79
|
-
Now, run the `crud` scaffolder:
|
74
|
+
First, run the `crud` scaffolder:
|
80
75
|
|
81
76
|
```
|
82
77
|
bin/super-scaffold crud Goal Project,Team description:text_field
|
83
78
|
rake db:migrate
|
84
79
|
```
|
85
80
|
|
86
|
-
You can see in the example above how we've specified `Project,Team`, because we want to specify the entire chain of ownership back to the `Team`. This allows Super Scaffolding to automatically generate the required permissions.
|
81
|
+
You can see in the example above how we've specified `Project,Team`, because we want to specify the entire chain of ownership back to the `Team`. This allows Super Scaffolding to automatically generate the required permissions. Take note that this generates a foreign key for `Project` and not for `Team`.
|
87
82
|
|
88
83
|
### 3. Adding New Fields with `crud-field`
|
89
84
|
|
@@ -93,13 +88,7 @@ Building on the earlier example, consider the following new requirement:
|
|
93
88
|
|
94
89
|
> In addition to a name, a project can have a description.
|
95
90
|
|
96
|
-
|
97
|
-
|
98
|
-
```
|
99
|
-
rails g migration add_description_to_projects description:text
|
100
|
-
```
|
101
|
-
|
102
|
-
Then, use the `crud-field` scaffolder to add it throughout the application:
|
91
|
+
Use the `crud-field` scaffolder to add it throughout the application:
|
103
92
|
|
104
93
|
```
|
105
94
|
bin/super-scaffold crud-field Project description:trix_editor
|
@@ -113,6 +102,11 @@ If you want to scaffold a new field to use for read-only purposes, add the follo
|
|
113
102
|
bin/super-scaffold crud-field Project description:trix_editor{readonly}
|
114
103
|
```
|
115
104
|
|
105
|
+
Again, if you would like to automatically generate the migration on your own, pass the `--skip-migration-generation` flag:
|
106
|
+
```
|
107
|
+
bin/super-scaffold crud-field Project description:trix_editor --skip-migration-generation
|
108
|
+
```
|
109
|
+
|
116
110
|
### 4. Adding Option Fields with Fixed, Translatable Options
|
117
111
|
|
118
112
|
Continuing with the earlier example, let's address the following new requirement:
|
@@ -124,7 +118,6 @@ We have multiple [field partials](/docs/field-partials.md) that we could use for
|
|
124
118
|
In this example, let's add a status attribute and present it as buttons:
|
125
119
|
|
126
120
|
```
|
127
|
-
rails g migration add_status_to_projects status:string
|
128
121
|
bin/super-scaffold crud-field Project status:buttons
|
129
122
|
```
|
130
123
|
|
@@ -152,21 +145,16 @@ Although you might think this calls for a reference to `User`, we've learned the
|
|
152
145
|
|
153
146
|
We can accomplish this like so:
|
154
147
|
|
155
|
-
```
|
156
|
-
rails g migration add_lead_to_projects lead:references
|
157
|
-
```
|
158
|
-
|
159
|
-
Then, to add the field, we specify the following:
|
160
|
-
|
161
148
|
```
|
162
149
|
bin/super-scaffold crud-field Project lead_id:super_select{class_name=Membership}
|
163
150
|
rake db:migrate
|
164
151
|
```
|
165
152
|
|
166
|
-
There are
|
153
|
+
There are three important things to point out here:
|
167
154
|
|
168
|
-
1.
|
169
|
-
2.
|
155
|
+
1. The scaffolder automatically adds a foreign key for `lead` to `Project`.
|
156
|
+
2. When adding this foreign key the `references` column is generated under the name `lead`, but when we're specifying the _field_ we want to scaffold, we specify it as `lead_id`, because that's the name of the attribute on the form, in strong parameters, etc.
|
157
|
+
3. We have to specify the model name with the `class_name` option so that Super Scaffolding can fully work it's magic. We can't reflect on the association, because at this point the association isn't properly defined yet. With this information, Super Scaffolding can handle that step for you.
|
170
158
|
|
171
159
|
Finally, Super Scaffolding will prompt you to edit `app/models/project.rb` and implement the required logic in the `valid_leads` method. This is a template method that will be used to both populate the select field on the `Project` form, but also enforce some important security concerns in this multi-tenant system. In this case, you can define it as:
|
172
160
|
|
@@ -189,17 +177,12 @@ We can accomplish this with a new model, a new join model, and a `super_select`
|
|
189
177
|
First, let's create the tag model:
|
190
178
|
|
191
179
|
```
|
192
|
-
rails g model Projects::Tag team:references name:string
|
193
180
|
bin/super-scaffold crud Projects::Tag Team name:text_field
|
194
181
|
```
|
195
182
|
|
196
183
|
Note that project tags are specifically defined at the `Team` level. The same tag can be applied to multiple `Project` models.
|
197
184
|
|
198
|
-
Now, let's create a join model for the has-many-through association
|
199
|
-
|
200
|
-
```
|
201
|
-
rails g model Projects::AppliedTag project:references tag:references
|
202
|
-
```
|
185
|
+
Now, let's create a join model for the has-many-through association.
|
203
186
|
|
204
187
|
We're not going to scaffold this model with the typical `crud` scaffolder, but some preparation is needed before we can use it with the `crud-field` scaffolder, so we need to do the following:
|
205
188
|
|
@@ -237,34 +220,39 @@ Bullet Train comes with two different ways to handle image uploads.
|
|
237
220
|
|
238
221
|
#### Scaffolding images with Cloudinary
|
239
222
|
|
240
|
-
When you scaffold your model
|
223
|
+
When you scaffold your model a `string` is generated where Cloudinary can store a reference to the image.
|
224
|
+
|
225
|
+
Make sure you have the `CLOUDINARY_URL` environment variable to use Cloudinary for your images.
|
241
226
|
|
242
227
|
For instance to scaffold a `Project` model with a `logo` image upload.
|
228
|
+
Use `image` as a field type for super scaffolding:
|
243
229
|
|
244
230
|
```
|
245
|
-
|
231
|
+
bin/super-scaffold crud Project Team name:text_field logo:image
|
232
|
+
rake db:migrate
|
246
233
|
```
|
247
234
|
|
248
|
-
|
249
|
-
|
235
|
+
Under the hood, Bullet Train will generate your model with the following command:
|
250
236
|
```
|
251
|
-
bin/super-scaffold crud Project Team name:text_field
|
237
|
+
bin/super-scaffold crud Project Team name:text_field
|
252
238
|
rake db:migrate
|
253
239
|
```
|
240
|
+
|
254
241
|
#### Scaffolding images with ActiveStorage
|
255
242
|
|
256
|
-
When you scaffold your model
|
243
|
+
When you scaffold your model we generate an `attachment` type attribute.
|
257
244
|
|
258
245
|
For instance to scaffold a `Project` model with a `logo` image upload.
|
246
|
+
Use `image` as a field type for super scaffolding:
|
259
247
|
|
260
248
|
```
|
261
|
-
|
249
|
+
bin/super-scaffold crud Project Team name:text_field logo:image
|
250
|
+
rake db:migrate
|
262
251
|
```
|
263
252
|
|
264
|
-
|
265
|
-
|
253
|
+
Under the hood, Bullet Train will generate your model with the following command:
|
266
254
|
```
|
267
|
-
bin/super-scaffold crud Project Team name:text_field
|
255
|
+
bin/super-scaffold crud Project Team name:text_field
|
268
256
|
rake db:migrate
|
269
257
|
```
|
270
258
|
|
data/lib/bullet_train/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bullet_train
|
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
|
@@ -164,20 +164,6 @@ dependencies:
|
|
164
164
|
- - ">="
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0'
|
167
|
-
- !ruby/object:Gem::Dependency
|
168
|
-
name: masamune-ast
|
169
|
-
requirement: !ruby/object:Gem::Requirement
|
170
|
-
requirements:
|
171
|
-
- - ">="
|
172
|
-
- !ruby/object:Gem::Version
|
173
|
-
version: 1.2.0
|
174
|
-
type: :runtime
|
175
|
-
prerelease: false
|
176
|
-
version_requirements: !ruby/object:Gem::Requirement
|
177
|
-
requirements:
|
178
|
-
- - ">="
|
179
|
-
- !ruby/object:Gem::Version
|
180
|
-
version: 1.2.0
|
181
167
|
- !ruby/object:Gem::Dependency
|
182
168
|
name: image_processing
|
183
169
|
requirement: !ruby/object:Gem::Requirement
|