- CONSOLIDATE: Whole directory includes for any (text based) file type
- TEMPLATE: Propagate templates with data from a collection of JSON files
- PRODUCE: Produce multiple files based off a single template file
GMAB is a self contained NodeJS file that has no dependencies on outside modules or code libraries.
In its simplist form, GMAB can be run with no parameters:
GMAB.js
If this is run, 4 things are assumed:
- You only want to compile once.
- Your input directory is called "GMAB" and is in the current working directory.
- The source directory is called "src" and is also in the current working directory.
- Your output directory is the current working directory itself.
All parameters are optional.
GMAB.js [listen] [outputPath] [inputPath] [sourceDirectory]
The source parameter is the path to the directory of files that you want to include other files into.
The input parameter is the path to the directory of templates, JSON data files, and or files that you want to include into the files in the source directory.
The output parameter is the path to the directory where your generated/compiled files are placed when done.
GMAB can listen for changes and auto-compile in real time.
You can enable this by setting the listen parameter to true.
GMAB.js true
If you only want it to run once, you can specify false:
GMAB.js false
Concatenate all files in this directory and replace this text with the result
${directoryName}
Get all json files from this directory and for each file... replace anything wrapped in {{property}} with the value of the property in the JSON file.
$~directoryName~
{{prop}}
{{anotherProp}}
The name of each file created will be the same as the name of the json file it's using unless you specify a file name. You can do so by setting FILENAME in the json file like so:
{
"FILENAME":"myfile.html",
"prop":"my property value",
"anotherProp":"another value"
}
A template returns a collection of copies of a template file (1 for each JSON file in the "source directory", specified in the template.json file) where in each copy has its placeholders (e.g. {{property}} ) replaced by the values in the JSON file that matches the copy's index. In other words,
- It loops through each JSON file in a specified directory
- Creates a copy of the template file for each one and replaces its placeholders with the corresponding values
- Concatenates them all together
- And returns the result
${test_template}
To create a template you must create a template folder that ends with "_template", for example: "test_template". In that directory, create two files: a tempalte.whatever file (template.html) and a template.json file (specifically: template.json).
The JSON file must contain source and has the option to contain a "max" value:
{
"source" : "posts",
"max" : 5
}
The template file can contain anything you want and anything wrapped in {{property}} will be replaced by the value of the property for each JSON file.