# masterpg
## Overview
The `masterpg` utility composes files - usually static HTML files - as an alternative to a missing
`
An input file can contain more than one `<+master ...>` tags.
> `<+placeholder tag_name/>` :
>> indicates that this placeholder has to be replaced by the content of an `<+actual>` tag having the same tag name.
> `<+actual tag_name>`...`+actual>` :
>> the actual content to replace placeholders with having the same tag name.
> `<+comment>`...`` :
>> will be removed from the output.
> `<+timestamp/>` :
>> produces a timestamp in the form of `ts=16548548678647` in the output text. The digits are
the number of milliseconds elapsed since the start of the Unix epoch.
> `<+calc tag_name [operator] [operand1] [operand2] [operand3] ... />` :
>> performs a calculation : it applies the operator +, -, *, / or others on one or more operands.
Note that these tags are case-insensitive.
## Calculations
The operands of a `<+calc ... />` tag can be either
- literal numerical values, or else
- tag names that refer to other `<+calc tag_name .../>` tags or `<+actual tag_name>` tags
having that tag name.
This means that `<+actual>` tags and `<+calc>` tags can't have the same tag name.
No units may be included in the operands : 10 is allowed, but not 10px.
Units, however, may follow immediately after `<+calc - .../>` or `<+placeholder .../>` tags. E.g.:
>`<+actual divHeight>30+actual>`
`<+actual goldenCut>1.618034+actual>`
`<+calc largeDivHeight * divHeight 2/>`
`<+calc largeDivWidth / largeDivHeight goldenCut />`
`...`
`<+placeholder largeDivWidth/>px`
`...`
`<+placeholder largeDivWidth/>px`
A `<+calc tag_name .../>` tag, when evaluated, will be replaced by an `<+/actual tag_name>result+actual>` tag, except when the tag name (the first word after `<+calc`) is `-`, in which case the result will be directly included in the output file :
>`<+actual price>200+actual>`
`<+actual commission>20+actual>`
`<+actual taxRate>0.20+actual>`
`<+calc amount + price commission/> ---> <+actual amount>220+actual>`
`<+calc tax * amount taxRate/> ---> <+actual>44+actual>`
`<+calc - + amount tax/> $ ---> 264 $`
`<+calc>` tags handle the below operators :
- `+` : addition
- `-` : subtraction
- `*` : multiplication
- `x` : multiplication also
- `/` : division
- `:` : division also
- `÷` : division also
- `%` : remainder
- `min` : get smallest of given operands
- `max` : get greatest of given operands
- `abs` : absolute value
- `^` : power
- `**` : power also
- `pow` : power also
- `exp` : power also
- `sign` : the sign of the first operand.
- `round` : rounding around 0
- `trunc` : removing fractal value, towards 0,
- `floor` : removing fractal value, towards -∞
- `ceiling` : removing fractal value, towards +∞
> These operators are case-insensitive.
> `<+calc>`, `<+actual>` and `<+placeholder>` tags may reside in the same file, in a master
file or in a client file referring to a master file. As `masterpg` operates by joining all
these files' contents to one text before resolving the said tags, you are free to put these
tags wherever they serve your purpose.
## How input files are processed
masterpg works by :
- handling all the input files given on its command line;
- executing the below steps for every input file given on the the command line :
- finding the first `<+output>` tag and storing the output file path in a variable;
- then reading an input file in a string and replacing all `<+master />`-tags in this string with the content of the entire file indicated, and even doing this recursively, so even master page files can contain their own `<+master />`-tags;
- then, in the resulting string, replacing
- all `<+calc>` tags with `<+actual>` tags holding the calculated value;
- all `<+placeholder>` tags with the content of the corresponding `<+actual>` tags;
- all `
`<+actual author>Lenny Baxter+actual>`
### Given general.mpx :
`<+master consts.mpm/>`
``
``
`
Welcome to my <+placeholder siteName/> site !
`I'm <+placeholder author/> and I'm just testing the masterpg module.
`Bye for now !
`Welcome to my Test Pages site !
`I'm Lenny Baxter and I'm just testing the masterpg module.
`Bye for now !
`