amberframework / amber

A Crystal web framework that makes building applications fast, simple, and enjoyable. Get started with quick prototyping, less bugs, and blazing fast performance.
https://amberframework.org
MIT License
2.58k stars 208 forks source link

[CLI] - Batch generation from yaml file #773

Closed sumwatt closed 6 years ago

sumwatt commented 6 years ago

It would be nice to have a feature in the CLI whereby you can enter a command to parse a yaml file and generate multiple models, classes and views from the yaml file.

Example command:

amber batch mysite.yml

... that will process a file like:

Model:
  Post:
    - "title:string"
    - "body:text"
    - "user:reference"
  User:
    - "name:string"
    - "password:string"
  Comment:
    - "title:string"
    - "body:text"
    - "user:reference"

It will use the CLI generator to create all of the Models, Views, and Controllers in a single step.

An alternative syntax may be something like:

Post:
  Model:
      - "title:string"
      - "body:text"
      - "user:reference"
  Controller:
    {goes here}
  View:
    {goes here}
User:
  Model:
    - "name:string"
    - "password:string"
  Controller:
    {goes here}
  View:
    {goes here}
Comment:
  Model:
    - "title:string"
    - "body:text"
    - "user:reference"
  Controller:
    {goes here}
  View:
    {goes here}

Use case

I was looking at the RealWorld project and started mocking up a model based on API specs using Yaml as it allows me to visualize how the application needs to be modeled. Since YAML files generally have structure, it was visually helpful to see the application layout before generating.

But I thought it might also be useful for:

sumwatt commented 6 years ago

Rough exmple of what the a batch generator might look like. I purloined most of the code from the Generator class and made some modifications. I looked at YAML mapping but wasn't quite sure how to map unknown keys so I just cast each to the appropriate type. The branch code should work for model/controller/view/scaffold

eliasjpr commented 6 years ago

@sumwatt IMO this should most likely live on its own shard. I do not believe this should be embedded in the framework

faustinoaq commented 6 years ago

@sumwatt Yeah, I apologize for opening this issue in your repo, I thought this would be an interesting tool for amber cli, although this can live perfectly in his own shard :sweat_smile:

eliasjpr commented 6 years ago

Closing this issue since this we agree that this should live in its own shard