Mend is a simple HTML template processor designed to, but not limited to be used to generate static websites.
Caution
This project is currently in Beta, meaning that it is NOT production ready.
Download the latest release or install via the command line with:
go install github.com/bbfh-dev/mend.html
Run mend --help
to display usage information.
mend build -s '{"title":"Hello World!","filename":"index.html","items":[]}' example/index.html > dist/output.html
This command builds the example/index.html
file along with all its dependencies into dist/output.html
using the provided JSON parameters.
Note that mend build
outputs the result into Stdout, which is why >
operator is used to redirect output into a file.
Tip
In the documentation, [argument]
denotes required arguments and (argument)
denotes optional ones.
Mend processes a file's content unchanged until it encounters one of two types of mend statements:
Important
Mend comments must be on separate, single lines to be recognized and processed.
There are two types of comment statements:
<!-- @... -->
— A simple inline mend statement.<!-- #... -->
paired with<!-- /... -->
— A mend block used to wrap a section of content.
Syntax:
<!-- #extend [filename] (parameters) -->
... <!-- /extend -->
This statement extends a referenced file. Use the Slot statement within the parent file to define where the child content should be inserted.
Syntax:
<!-- #if [name] [operator] [value] -->
... <!-- /if -->
This block conditionally removes its enclosed content if the specified condition evaluates to false.
Supported Operators:
==
(equals)!=
(does not equal)has
(checks if an array contains a specified element)lacks
(checks if an array does not contain a specified element)
Syntax:
<!-- #range [parameter] -->
... <!-- /range -->
This block iterates over an array. To access properties of the current item, prefix the expression with #
(for example, {{ #.child_property }}
).
Syntax:
<!-- @include [filename] (parameters) -->
This inline statement inserts the contents of the referenced file directly into the current document.
Syntax:
<!-- @slot -->
This statement marks the insertion point for content when a file is extended. Note: Each file can declare only one slot.
Expression statements insert values directly into the output.
- An expression beginning with
.
accesses a property from the input JSON (e.g.{{ .path.to.name }}
retrieves the value atpath.to.name
). - Using just
.
outputs the entire JSON object (the root).
Expressions can also include modifiers, using the format: {{ modifier_name .path.to.property }}
.
Supported Modifiers:
length
,len
, orsize
— Returns the length of an array.quote
— Wraps the output value in double quotes.