# ![](https://raw.githubusercontent.com/ugate/templeo/master/docs/public/favicon-32x32.png) `templeo`

[![npm version](https://badgen.net/npm/v/templeo?color=orange&icon=npm)](https://www.npmjs.com/package/templeo)
[![Inline docs](https://inch-ci.org/github/ugate/templeo.svg?branch=master)](https://inch-ci.org/github/ugate/templeo)

### Template Literals Engine
> ♌ `templeo` is a __0️⃣ dependency__ template engine that uses built-in JavaScript/ECMAScript [Template Literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals). __No [Regular Expressions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions) parsing or special syntax in templates here! Just 💯% _built-in_ ES Template Literals!__

For more details check out the tutorials and API docs!

* [The Basics](https://ugate.github.io/templeo/guide/1-basics)
* [Cache](https://ugate.github.io/templeo/guide/2-cache)
* [Examples](https://ugate.github.io/templeo/guide/3-examples)
* [API Docs](https://ugate.github.io/templeo/api/)

#### Features
- __💯% PURE__ <br>
No special syntax required! Everything is baked into the ECMAScript Template Literals specification itself! And since `templeo`/Template Literals are output-agnostic, a single `Engine` instance can output virtually any format (e.g. HTML, DOM Nodes, JSON, YAML, etc.).<br><br>
- __🌱 Grows with the language__ <br>
No need to update `templeo` when new features are added to the Template Literal spec. Any feature/syntax changes available within [Template Literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) are available for immediate use!<br><br>
- __🌐 Stand-Alone Rendering__ <br>
When a template is compiled into a rendering function it's no longer dependent upon `templeo` internals to render output - making rendering functions fully __portable__! Rendering functions can even be serverd from an HTTP server or any other source without any dependencies or references back to `templeo`!<br><br>
- __🛡️ Secure__ <br>
Since `templeo` does not have any special parsing syntax it does not suffer from syntax-specific injections. Compilation is also locally _sandboxed_ to ensure that scope is isolated to global variable access (and [require](https://nodejs.org/api/modules.html#modules_require) when available). Since rendering is _stand-alone_ and _portable_, it is completely isolated from any scope other than the scope in which it is ran!<br><br>
- __⛓️ Parameterized/Nested Includes__ <br>
Fragments are reusable and can be [included](https://ugate.github.io/templeo/guide/1-basics#include) at _compile-time_ and/or _render-time_ using simple [Tagged Template Literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#Tagged_templates). Also, supports [passing parameters](https://ugate.github.io/templeo/guide/1-basics#include-params) into included templates where the parameter scope is confined to the partial being included.<br><br>
- __🐞 Debugging__ <br>
Compiled templates are accessible directly via the VM `sourceURL` or through module [imports](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import)/[requires](https://nodejs.org/api/modules.html#modules_require) - allowing for seemless debugging capabilities. <br><br>
- __🧠 Extensible__ <br>
Template Literals naturally allow for any of your own helper functions to be accessible within the template literal itself as long as they are within scope of the `templeo` generated rendering function execution (or via registration). And since rendering functions are independent of `templeo`, included template content can evolve based upon a given `context` without having to be re-compiled!<br><br>
- __🛎️ Auto Fetch__ <br>
By default, template(s) and rendering context can be [fetched](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) __automatically__ at _compile-time_ and/or _render-time_ from an HTTP/S server. Also, render-time includes decouples the included template sources from the renderer allowing for newly dicovered template fragments to be included without re-compiling a new renderer!<br><br>
- __🏧 Caching__ <sub id="caching"></sub><br>
By default, templates are cached in-memory for the duration of the `Engine`/template lifespan. Concurrent reads, writes, and compiles are deduplicated, cache activity is available through `engine.cacheStats`, and optional LRU entry/byte limits plus idle TTL expiration can be configured. There are a few other extensions that may be more suitable depending upon your needs.
  - __[IndexedDB (Browser) / LevelDB (Node.js)](https://ugate.github.io/templeo/guide/2-cache#db)__<br>
  __Recommended when templates need to be persistent between usage.__ Compiled templates are cached in either an [IndexedDB](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API) store or a [LevelDB](https://www.npmjs.com/package/level) store.
  - __[File System (Node.js)](https://ugate.github.io/templeo/guide/2-cache#fs)__<br>
  __Recommended when running on the server.__ Compiled templates are cached within the [file system](https://nodejs.org/api/fs.html) and __are loaded as modules so they can be debugged just like any other module__. If template _partials_/fragments are used the corresponding files can be _registered_ by providing a _base_ directory to be _scanned_. The _base_ directory can also be [watched with native Node.js file-system watchers](https://ugate.github.io/templeo/guide/2-cache#watchers), automatically registering created or changed partials and unregistering removed partials and directories!

## Dev

```sh
git clone https://github.com/ugate/templeo.git
cd templeo
npm install
npm run test:browser:install
npm test
npm run audit:runtime
npm run docs:dev -- --host 0.0.0.0
```

The test suite uses Node.js version 24+ native test runner plus Playwright Chromium for the browser release gate. Install Chromium and its Linux system dependencies once with `npm run test:browser:install`, then run `npm test`. Browser tests use the same public imports as server-side code (`templeo` and `templeo/lib/*`) through native ESM, and exercise rendering, HTTP reads/writes, dynamic ESM helpers, IndexedDB persistence, and explicit incompatibility errors for Node-only filesystem APIs. No bundler or synthetic import rewriting is involved. API Markdown is rendered by the project-owned `docs/generate-api.mjs` script from JSDoc JSON doclets.

Templeo version 3+ defaults generated renderer modules to native ECMAScript modules (`.mjs`). Set `useCommonJs: true` when CommonJS (`.cjs`) output is required.

Release/publish new versions
```sh
# ensure package.json has the proper version bump, then run:
npm run release
```

## Local docs workflow

```bash
npm run docs:dev
```

Generate the API reference and build the site:

```bash
npm run docs:build
```
