mix_templates v0.1.1 MixTemplates

NOTE: This documentation is intended for folks who want to write their own templates. If you just want to use a template, then have a look at the README, or try mix help template and mix help gen.

This is the engine that supports templated directory trees.

A template is a trivial mix project. It contains a single source file in lib that contains metadata and option parsing. It also contains a top-level directory called template. The directories and files underneath template/ copied to the destination location.

The copying function tasks a map containing key-value pairs. This is passed to EEx, which is used to expand each individual file. Thus a template file for mix.exs may contain:

defmodule <%= @project_name_camel_case %>.Mixfile do
  use Mix.Project

  @name    :<%= @project_name %>
  @version "0.1.0"


The `<%= ... %>` constructs are expanded using the passed-in map.

In addition, the template looks for the string `$PROJECT_NAME$` in the
_names_ of files and directories. It replaces each occurrence with the
name of the project, taken from `assigns.project_name`.

Thus the directory structure for a standard Elixir project might be:

    template
    ├── $PROJECT_NAME$
    │   ├── README.md
    │   ├── config
    │   │   └── config.exs
    │   ├── lib
    │   │   └── $PROJECT_NAME$.ex
    │   ├── mix.exs
    │   └── test
    │       ├── $PROJECT_NAME$_test.exs
    │       └── test_helper.exs
    └── templates_project.ex

## Write a Template

Make sure you have the underlying tools installed:

    $ mix archive.install hex mix_templates
    $ mix archive.install hex mix_generator

Then install the template for templates (yup :).

    $ mix template.install hex gen_template_template

Now create your template project:

    $ mix gen template «your-template-name»

Wander into the directory that is created:

    $ cd «your project name»
    $ tree

Summary

Functions

find(name)
generate(template, map)