Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rwdaigle/exgen
A templating library for generating reusable Elixir projects
https://github.com/rwdaigle/exgen
elixir mix template
Last synced: about 1 month ago
JSON representation
A templating library for generating reusable Elixir projects
- Host: GitHub
- URL: https://github.com/rwdaigle/exgen
- Owner: rwdaigle
- License: mit
- Created: 2016-07-25T20:11:14.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-01-16T19:41:32.000Z (almost 5 years ago)
- Last Synced: 2024-04-22T13:33:53.396Z (8 months ago)
- Topics: elixir, mix, template
- Language: Elixir
- Homepage:
- Size: 95.7 KB
- Stars: 35
- Watchers: 3
- Forks: 8
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- freaking_awesome_elixir - Elixir - A templating library for quickly generating Elixir projects. (Templating)
- fucking-awesome-elixir - exgen - A templating library for quickly generating Elixir projects. (Templating)
- beamtoolbox - [ex
- awesome-elixir - exgen - A templating library for quickly generating Elixir projects. (Templating)
README
# Exgen
Quickly generate Elixir apps from templates.
```bash
$ mix exgen.new some_app -t https://github.com/rwdaigle/exgen-plug-simple.git --app-name some_app --module SomeApp
* creating some_app/lib/some_app.ex
* creating some_app/lib/some_app/router.ex
```## Overview
Templates are just [EEx](http://elixir-lang.org/docs/stable/eex/EEx.html) files that are evaluated at runtime. A simple template might be a single file with a variable substitution in EEx form:
```elixir
defmodule <%= module %>.Router do
end
```Use Exgen's simple CLI to create a new app from this template:
```bash
$ mix exgen.new target_dir -t /path/to/template --module MyApp
```Which will create a single file in the `target_dir` with the following contents:
```elixir
defmodule MyApp.Router do
end
```## Installation
Exgen is distributed as a set of Mix tasks (much like Phoenix generators). Install them via Mix:
```bash
$ mix archive.install https://github.com/rwdaigle/exgen/raw/master/archives/exgen-0.5.1.ez
```The tasks will then be available in Mix under the `exgen` namespace:
```bash
$ mix -h | grep "exgen."
mix exgen.new # Generate a new project from a template
```## Usage
Exgen operates by fetching a templatized app from a remote git repo or a local source. For instance, to quickly generate a basic Plug web app from this [template](https://github.com/rwdaigle/exgen-plug-simple):
```bash
$ mix exgen.new some_app -t https://github.com/rwdaigle/exgen-plug-simple.git --app-name some_app --module SomeApp
* creating some_app/lib/some_app.ex
* creating some_app/lib/some_app/router.ex
```If you have an app template on your local filesystem you can just point to its path:
```bash
$ mix exgen.new some_app -t ~/dev/exgen-templates/exgen-plug-simple --app-name some_app --module SomeApp
* creating some_app/lib/some_app.ex
* creating some_app/lib/some_app/router.ex
```Any variables needed by the template can be passed in from the CLI using switches. So if a template requires the `app_name` and `module` variables, use the `--app-name` and `--module` switches as above (switches are automatically underscored before being exposed to the template EEx context).
## Creating templates
For easy consistency and recognition, templates should be named with the following structure: `exgen-category-purpose`. For instance, a simple web app using only Plug is called `exgen-plug-simple`.
A template is just a set of EEx files with `<%= variable %>` statements in the file bodies (and even the file names themselves).
```text
|- <%= app_name %>.ex
|- mix.exs
|- <%= app_name %>
|- router.ex
```This template generated with the `--app-name my_app` switch will result in the following file structure:
```text
|- my_app.ex
|- mix.exs
|- my_app
|- router.ex
```## Templates
The following exgen templates are available from the community:
_If you would like yours listed here, edit this file and submit a PR_
App | Command w/ switches
----|--------------------
[Simple Plug web app](https://github.com/rwdaigle/exgen-plug-simple) | `$ mix exgen.new -t https://github.com/rwdaigle/exgen-plug-simple.git --app-name my_app --module MyApp`## Contributing
### Testing
Run automated tests:
```bash
$ mix test
```You can also manually test the tasks by installing the archive locally:
```bash
$ mix do archive.build, archive.install
```### Release
Exgen is distributed as a mix archive. Build the archive with:
```bash
$ mix archive.build
$ mv exgen-*.ez archives/
```## Todo
Some things I'd like to add include:
* Support testing workflow for template authors
* Silence git output (in tests at least)
* Use test tags to segment tests by remote/local## Contributors
Code contributors include:
* [jknipp](https://github.com/jknipp)
## Changelog
### 0.5.2
* Support dynamic switch in Elixir 1.4