Torch v1.0.0-rc.2 Mix.Tasks.Torch.Gen

Generates a Torch admin section for a given Ecto Schema. The following parameters should be passed in order, without flags.

Format

The first argument is the templating language that the generated templates should use. Either “eex” or “slim”.

Namespace

The Elixir namespace you want all the code to be generated within. For example, if your app is named MyApp, and you want to put all the admin code under MyApp.Admin, you’d pass in “Admin” here.

Singular Schema Name

The singular and capitalized version of the schema name. For example, “Post”.

Plural Schema Name

The snake case and pluralized version of the schema name. For example, “posts”.

Schema Fields

Space separated fields and types, describing which fields of the schema you want to appear in the generated tables and forms. These are in the format field_name:type.

  • field_name:string: Torch will use a text_input to represent the field.

  • field_name:text: Torch will use a textarea to represent the field.

  • field_name:(integer|float|decimal): Torch will use a number_input to represent the field.

  • field_name:boolean: Torch will use a select with the options “Choose one”, “True” and “False” to represent the field.

  • field_name:date: Torch will use a Pikaday datepicker input to represent the field. If the field name is inserted_at or updated_at, the field will only be displayed in the filter sidebar, not the new/edit forms.

  • field_name:references:assoc,assocs:primary_key,display_name: Torch will set up filtering and form fields for a belongs_to relationship on the schema. For example, if your Post schema looked like this:

    schema "posts" do
      belongs_to :category, Example.Category
    
      # ...
    end

    You could use the following references field in your mix torch.gen call:

    category_id:references:category,categories:id,name

    This would tell Torch that:

    • The Post schema has a belongs_to relationship on category_id.

    • The relationship is called :category.

    • The plural name of the relationship is “categories”.

    • The <select> box it generates should use the category id field as the value and the category name field as the value.

Example

mix torch.gen eex Admin Post posts category_id:references:category,categories:id,name title:string body:text