View Source ElixirScribe (Elixir Scribe v0.3.0)
The Elixir Scribe Generator configuration and defaults.
Some of the defaults will be possible to customize via your app configuration:
- Configure Default Resource Actions - Provide your own list of built-in default actions that will be used each time you invoke one of the generators.
- Configure Default Resource Actions Aliases - Use aliases to rename the built-in default actions to your preferred names.
- Configure Default Source Code Templates - Provide your own source code templates to be used by the Elixir Scribe generators
Private Module
All functions in this module lack documentation because they MUST be considered private and used internally only.
Configure Default Resource Actions
The default actions supported by scribe.gen.domain
and scribe.gen.html
:
list
- Lists all items of a Resource in the databasenew
- Builds a new changeset for a Resourceread
- Reads a specific Resource from the databaseedit
- Builds a changeset to track changes made to a Resourcecreate
- Creates a new Resource in the databaseupdate
- Updates an existing Resourcedelete
- Deletes an existing Resource
For example, for an API you can discard the default resource actions new
and edit
:
config :elixir_scribe,
default_resource_actions: ["list", "read", "create", "update", "delete"]
Or, maybe you want to use the default resource actions, plus some other ones that you always need when creating a new resource:
config :elixir_scribe,
default_resource_actions: ["import", "export", "list", "new", "read", "edit", "create", "update", "delete"]
Custom Resource Actions Order
Order of actions MATTERS, otherwise routes will not work as expected.
Note how
import
andexport
were added to the begin of the list to ensure they are matched correctly by the router when serving theGET
request.
Custom Resource Actions
Any custom action name provided via the configuration will be mapped to a default template, unless you provide your custom template(s) for it at the correct path in your app
priv/templates/*
. Check how to customize the templates at Configure Default Source Code Templates.This custom action names will be added to your router as
GET
requests. You need to customize the router as needed.
Configure Resource Actions Aliases
In your app configuration for :elixir_scribe
you can map any of the built-in default actions to actions names of your preference, which it's the same as renaming them.
The below example maps the built-in default actions read
to show
and list
to index
.
config :elixir_scribe,
resource_actions_aliases: %{
"read" => "show",
"list" => "index",
}
Configure Default Source Code Templates
The paths to look for template files for generators defaults to checking the current app's priv
directory, and falls back to Elixir Scribe and Phoenix's priv
directory:
priv/templates/*
elixir_scribe/priv/templates/*
phoenix/priv/templates/*
Provide your own templates to customize the functionality offered by the built-in ones by copying them to your priv/templates/*
directory, and then modify them as you see fit.
For example, when using custom resource actions, the Elixir Scribe generators will default to generating code that raises an error with a message alerting you that the logic hasn’t been implemented yet. You can avoid this by providing your own custom source code template for each of your custom actions.