Skip to content

Commit

Permalink
More documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
brett-smith committed Mar 7, 2024
1 parent 719f7cb commit 5c72829
Showing 1 changed file with 39 additions and 6 deletions.
45 changes: 39 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,18 @@ Feature complete. Just some test coverage to complete and addition of Javadoc.
## Features

* No dependencies, JPMS compliant, Graal Native Image friendly
* Fast. Single pass parser, use lambdas to compute template components only when
they are actually needed.
* Fast. See Design Choices.
* Simple Java. Public API consists of just 2 main classes, `TemplateModel` and `TemplateProcessor`.
* Simple Content. Just `<t:if>` (and `<t:else>`), `<t:include>`, `<t:template>` and `<t:list>`. Bash like variable such as `${myVar}`.
* Internationalisation features.
* Internationalisation features.

## Design Choices

* No reflection. Better performance.
* No expression language. All conditions are *named*, with the condition calculated in Java code.
* Focus on HTML.
* Avoids `String.replace()` and friends.
* Single pass parser, use lambdas to compute template components only when they are actually needed.

## Quick Start

Expand Down Expand Up @@ -135,27 +142,53 @@ TinyTemplate supports a sort-of-like-Bash syntax for variable expansion. The exa
behaviour of each *string* replacement depends on a *parameter* and an *operator*.

The general syntax is `${parameter[<options>]}`. The *parameter* and any options are evaluated, then all text starting
with the `$` and ending with the `}` is substituted with the result.
with the `$` and ending with the `}` is substituted with the result.

Most patterns evaluate a named *parameter*. This can be any *condition*, *variable* or other type.

* Evaluates to `true` when a *condition* of the same name evaluates to `true`
* Evaluates to `true` when a *variable* of the same name exists and is not an empty string.
* Evaluates to `true` when any other type exists.

### ${parameter}

Simplest type. Just always substitute with with value of a *variable* from the model.

```
${todaysDate}
```

### ${parameter:?string:otherString}

If *parameter* evaluates to false as either a *variable* or *condition*, the expansion of *otherString*
is substituted. Otherwise, the expansion of *string* is substituted.
is substituted. Otherwise, the expansion of *string* is substituted.

```
${isPM:?Post Meridiem:Ante Meridiem noon}
```

### ${parameter:-string}

If *parameter* evaluates to false as either a *variable* or *condition*, the expansion of *string* is substituted.
Otherwise, the value of *parameter* is substituted.

```
${location:-Unknown Location}
```

### ${parameter:+string}

If *parameter* evaluates to false as either a *variable* or *condition*, an empty string is substituted, otherwise
the expansion of *string* is substituted.

```
<input type="checked" ${selected:+checked} name="selected">
```

### ${parameter:=word}

If *parameter* evaluates to false as either a *variable* or *condition*, the expansion of word is substituted, otherwise an empty string is substituted.
If *parameter* evaluates to false as either a *variable* or *condition*, the expansion of word is substituted, otherwise an empty string is substituted.

```
<button type="button" ${clipboard-empty:=disabled} id="paste">Paste</button>
```

0 comments on commit 5c72829

Please sign in to comment.