![kojo](images/kojo.png) Kojo Configuration Ninja ================================================== [![Gem Version](https://badge.fury.io/rb/kojo.svg)](https://badge.fury.io/rb/kojo) [![Build Status](https://travis-ci.com/DannyBen/kojo.svg?branch=master)](https://travis-ci.com/DannyBen/kojo) [![Maintainability](https://api.codeclimate.com/v1/badges/f24566ad04b5054a2251/maintainability)](https://codeclimate.com/github/DannyBen/kojo/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/f24566ad04b5054a2251/test_coverage)](https://codeclimate.com/github/DannyBen/kojo/test_coverage) Kojo helps you generate configuration files from templates, using variables and definition files. It is a command line utility, and it works on any text file format.

Table of Contents


Installation

$ gem install kojo

Usage

If you prefer to learn by example, see the examples folder for several use cases. Each example subfolder contains the command to run, the relevant files, and the expected output.

Variables

kojo

Include variables in your configuration templates using this syntax:

%{varname}
  • Variables can be provided through the command line, or when using @import.
  • Variables from the top level will be forwarded downstream, and aggregated with any additional variables that are defined in subsequent @imports.

Import

kojo

Use the @import filename directive anywhere to include another file in the resulting configuration file.

  • The @import directive should be the only thing in the line.
  • The indentation will be respected when importing.
  • The filename parameter does not have to include an extension - Kojo will use the same extension as the parent file.
  • The included file will be searched for relative to the file it is included in.
  • Arguments can be passed down to the included template by using this syntax:
@import filename (arg: "value", arg2: "value")

The space after filename is optional.

Compile an Entire Folder

kojo

Process a folder containing templates and @imports, and generate a mirror output folder, with all the variables and @imports evaluated.

One to Many Generation

kojo

Using the kojo config command together with a simple definitions file, you can:

  1. Generate multiple output files based on a single template file
  2. Generate multiple output directories, based on a single source directory.

To achieve this, you need to:

  1. Create the configuration template or directory of templates.
  2. Create a configuration YAML file using this syntax:
input: base-template.yml

output:
  outfile1.yml:
    argument1: value
    argument2: value

  outfile2.yml:
    argument1: value
    argument2: value

When using a folder as input, simply provide the folder name in the input property, and instead of providing desired output filenames in the output property, provide desired output directories:

input: base

output:
  app1:
    argument1: value
    argument2: value

  app2:
    argument1: value
    argument2: value

Conditions and Loops with ERB

kojo

Template files are evaluated using ERB, so you can use any Ruby code for more advanced templates (for conditions, loops etc.).

Use this syntax for ruby code:

<%- ruby code here -%>     # for code that should not be printed
<%= ruby code here -%>     # for code that should be printed