Generate
One day to design and code...
The generators in amber are a great way to get an application up and running quickly. In addition, they help keep code consistent and following convention.

Example Usage

You can always see the available generators by running amber generate as below:
1
$ amber generate
2
Parsing Error: The TYPE argument is required.
3
4
amber generate [OPTIONS] TYPE NAME [FIELDS1 FIELDS2...]
5
6
Arguments:
7
FIELDS (multiple) user:reference name:string body:text age:integer published:bool
8
NAME name of resource
9
TYPE scaffold, model, controller, migration, mailer, socket, channel, auth
10
11
Options:
12
--no-color Disable colored output
Copied!
Generators can be used multi-word names, the class names will be CamelCase and file names will be snake_case, the command line input can be either:
1
$ amber generate [TYPE] MultiWordName [FIELD1 FIELD2 ...]
2
# OR
3
$ amber generate [TYPE] multi_word_name [FIELD1 FIELD2 ...]
Copied!
See Scaffolding below for full example.
Examples of Usage

Scaffolding

Scaffolding will create the model (and specs), views, controller (and specs) and migrations for a resource. Additionally, it will add the new resource to the nav bar and
1
$ amber generate scaffold Post title body:text
Copied!
1
Rendering Scaffold post
2
new db/migrations/20171114103058417_create_post.sql
3
new spec/models/spec_helper.cr
4
new spec/models/post_spec.cr
5
new src/models/post.cr
6
new spec/controllers/spec_helper.cr
7
new spec/controllers/post_controller_spec.cr
8
new src/controllers/post_controller.cr
9
rewritten src/views/layouts/_nav.slang
10
new src/views/post/_form.slang
11
new src/views/post/edit.slang
12
new src/views/post/index.slang
13
new src/views/post/new.slang
14
new src/views/post/show.slang
Copied!
If you scaffold a multi-word resource, the class names will be CamelCase and file names will be snake_case, the command line input can be either:
1
$ amber generate scaffold PostComment post:reference body:text
2
# OR
3
$ amber generate scaffold post_comment post:reference body:text
Copied!
1
Rendering Scaffold post_comment
2
new db/migrations/20171114103306763_create_post_comment.sql
3
skipped spec/models/spec_helper.cr
4
new spec/models/post_comment_spec.cr
5
new src/models/post_comment.cr
6
skipped spec/controllers/spec_helper.cr
7
new spec/controllers/post_comment_controller_spec.cr
8
new src/controllers/post_comment_controller.cr
9
rewritten src/views/layouts/_nav.slang
10
new src/views/post_comment/_form.slang
11
new src/views/post_comment/edit.slang
12
new src/views/post_comment/index.slang
13
new src/views/post_comment/new.slang
14
new src/views/post_comment/show.slang
Copied!

Auth

1
$ amber g auth User
Copied!
1
Rendering Auth user
2
new db/migrations/20171019214851_create_user.sql
3
new db/seeds.cr
4
new spec/controllers/spec_helper.cr
5
new spec/models/spec_helper.cr
6
new spec/models/user_spec.cr
7
new src/controllers/registration_controller.cr
8
new src/controllers/session_controller.cr
9
new src/handlers/authenticate.cr
10
new src/models/user.cr
11
rewritten src/views/layouts/_nav.slang
12
new src/views/registration/new.slang
13
new src/views/session/new.slang
Copied!

Model

1
$ amber g model Person name:string age:integer
Copied!
1
Rendering Model person
2
new db/migrations/20171019214940_create_person.sql
3
skipped spec/models/spec_helper.cr
4
new spec/models/person_spec.cr
5
new src/models/person.cr
Copied!

Controller

1
$ amber g controller Person index:get show:get create:post update:patch
Copied!
1
Rendering Controller person
2
skipped spec/controllers/spec_helper.cr
3
new spec/controllers/person_controller_spec.cr
4
new src/controllers/person_controller.cr
Copied!

API

1
$ amber g api Person name:string age:integer
Copied!
1
04:09:54 Generate | (INFO) Generating Amber::CLI::Api
2
04:09:54 Generate | (INFO) new spec/models/person_spec.cr
3
04:09:54 Generate | (INFO) identical spec/models/spec_helper.cr
4
04:09:54 Generate | (INFO) new src/models/person.cr
5
04:09:54 Generate | (INFO) new db/migrations/20191031160954280_create_person.sql
6
Format ./config/routes.cr
7
04:09:54 Generate | (INFO) new spec/controllers/person_controller_spec.cr
8
04:09:54 Generate | (INFO) identical spec/controllers/spec_helper.cr
9
04:09:54 Generate | (INFO) new
Copied!

Recipes

Recipes are available to generate Scaffolding, Controller and Model artifacts in ways that vary from the standard built in generator. See the Recipes option of the Command Line Tool for more information about using recipes to generate applications.
Last modified 2yr ago