<commit_before># Mandrill Template Manager(CLI)

Manage [Mandrill Templates](https://mandrillapp.com/api/docs/templates.ruby.html) by CLI.

## Install

Add Gemfile and bundle.

```
gem 'mandrill-template-manager'

## Recommend for using multibyte language.
gem 'formatador', github: 'geemus/formatador'
gem 'unicode'
```

```
$ ./bin/mandrilltemplate
Commands:
  mandrilltemplate delete NAME                # delete template from remote.
  mandrilltemplate export NAME                # export template from remote to local files.
  mandrilltemplate generate NAME              # generate new template files.
  mandrilltemplate help [COMMAND]             # Describe available commands or one specific command
  mandrilltemplate list                       # show template list both of remote and local.
  mandrilltemplate publish NAME               # publish template from draft.
  mandrilltemplate render NAME [PARAMS_FILE]  # render mailbody from local template data. File should be Array. see https://mandrillapp.com/api/docs/templates.JSON.html#method=render.
  mandrilltemplate upload NAME                # upload template to remote as draft.

```

## Workflow

1. generate new or export exist template as local files.
2. modify and manage under version controle system.
3. upload template.
4. publish it.


## Setup

APIKEY is read from environment variable.

```
export MANDRILL_APIKEY='your api key'
```

Next, check by list subcommand.

```
$ mandrilltemplate list

Remote Templates
----------------------
  +----------+----------+----------+--------------+---------------------+---------------------+--------+---------------+-----------------+------------------+--------------------+-----------+-------------------+
  | has_diff | name     | slug     | publish_name | draft_updated_at    | published_at        | labels | subject       | publish_subject | from_email       | publish_from_email | from_name | publish_from_name |
  +----------+----------+----------+--------------+---------------------+---------------------+--------+---------------+-----------------+------------------+--------------------+-----------+-------------------+
  ... remote templates ...

Local Templates
----------------------
  +----------+----------+------------------+-----------+--------------------+------------------------+
  | name     | slug     | from_email       | from_name | subject            | labels                 |
  +----------+----------+------------------+-----------+--------------------+------------------------+
  ... local templates ...

```


## Template local files

Templates are stored into `templates/` directory.

```
templates/
├── ${template_name1}
│   ├── code         # code contents
│   ├── metadata.yml # metadata of template
│   └── text         # text contents
├── ${template_name2}
│   ├── code
│   ├── metadata.yml
│   └── text
└── ${template_name3}
    ├── code
    ├── metadata.yml
    └── text
```

example of metadata.yml

```
---
slug: mission
labels: []
subject: "Today's your mission"
from_email: <EMAIL>
from_name: Boss
```

## Optional: render suppots Handlebars preview.

If you would like to use handlebars template.
You should add handlebars rubygem to Gemfile.

```
gem 'mandrill-template-manager'<commit_msg>Minor changes for Readme<commit_after># Mandrill Template Manager (CLI)

Manage [Mandrill Templates](https://mandrillapp.com/api/docs/templates.ruby.html) by CLI.

## Install

Add Gemfile and bundle.

```
gem 'mandrill-template-manager'

## Recommend for using multibyte language.
gem 'formatador', github: 'geemus/formatador'
gem 'unicode'
```

```
$ bundle install
```

```
$ bundle exec mandrilltemplate
Commands:
  mandrilltemplate delete NAME                # delete template from remote.
  mandrilltemplate export NAME                # export template from remote to local files.
  mandrilltemplate generate NAME              # generate new template files.
  mandrilltemplate help [COMMAND]             # Describe available commands or one specific command
  mandrilltemplate list                       # show template list both of remote and local.
  mandrilltemplate publish NAME               # publish template from draft.
  mandrilltemplate render NAME [PARAMS_FILE]  # render mailbody from local template data. File should be Array. see https://mandrillapp.com/api/docs/templates.JSON.html#method=render.
  mandrilltemplate upload NAME                # upload template to remote as draft.

```

## Workflow

1. generate new or export exist template as local files.
2. modify and manage under version control system.
3. upload template.
4. publish it.


## Setup

APIKEY is read from environment variable.

```
export MANDRILL_APIKEY='your api key'
```

Next, check by list subcommand.

```
$ mandrilltemplate list

Remote Templates
----------------------
  +----------+----------+----------+--------------+---------------------+---------------------+--------+---------------+-----------------+------------------+--------------------+-----------+-------------------+
  | has_diff | name     | slug     | publish_name | draft_updated_at    | published_at        | labels | subject       | publish_subject | from_email       | publish_from_email | from_name | publish_from_name |
  +----------+----------+----------+--------------+---------------------+---------------------+--------+---------------+-----------------+------------------+--------------------+-----------+-------------------+
  ... remote templates ...

Local Templates
----------------------
  +----------+----------+------------------+-----------+--------------------+------------------------+
  | name     | slug     | from_email       | from_name | subject            | labels                 |
  +----------+----------+------------------+-----------+--------------------+------------------------+
  ... local templates ...

```


## Template local files

Templates are stored into `templates/` directory.

```
templates/
├── ${template_name1}
│   ├── code         # code contents
│   ├── metadata.yml # metadata of template
│   └── text         # text contents
├── ${template_name2}
│   ├── code
│   ├── metadata.yml
│   └── text
└── ${template_name3}
    ├── code
    ├── metadata.yml
    └── text
```

example of metadata.yml

```
---
slug: mission
labels: []
subject: "Today's your mission"
from_email: <EMAIL>
from_name: Boss
```

## Optional: render supports Handlebars preview.

If you would like to use handlebars template.
You should add handlebars rubygem to Gemfile.

```
gem 'mandrill-template-manager'
{'fraction_non_alphanumeric': 0.28103975535168196, 'fraction_numerical': 0.0021406727828746177, 'mean_word_length': 1.5293890177880898, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6998308', 'n_tokens_mistral': 1664, 'n_tokens_neox': 1549, 'n_words': 523}