# wge

> A very cool node HTML templating engine.

Latest version **0.0.5** (published 2020-11-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install wge
pnpm add wge
yarn add wge
bun add wge
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.5 |
| Published | 2020-11-27 |
| First published | 2020-11-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 12.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | str1z |
| Maintainers | str1z |
| Keywords | html, template, engine, wagon |

## Links

- npm: https://www.npmjs.com/package/wge
- Repository: https://github.com/str1z/wagon-engine
- Homepage: https://github.com/str1z/wagon-engine#readme
- Issues: https://github.com/str1z/wagon-engine/issues
- npm.io page: https://npm.io/package/wge

## Alternatives

- [@tsparticles/shape-image](https://npm.io/package/@tsparticles/shape-image.md) — 303.7K weekly downloads
- [@tsparticles/shape-line](https://npm.io/package/@tsparticles/shape-line.md) — 233.7K weekly downloads
- [stringify-attributes](https://npm.io/package/stringify-attributes.md) — 58.6K weekly downloads
- [mobile-drag-drop](https://npm.io/package/mobile-drag-drop.md) — 46.3K weekly downloads
- [@comunica/actor-rdf-parse-html](https://npm.io/package/@comunica/actor-rdf-parse-html.md) — 29.2K weekly downloads

## Recent versions

- 0.0.5 (latest) — 2020-11-27
- 0.0.4 — 2020-11-25
- 0.0.3 — 2020-11-24
- 0.0.2 — 2020-11-24
- 0.0.1 — 2020-11-23

## README

# Wagon Engine

Wagon is a very fast and cool templating engine for fast development.

Here is quick example on the syntax.

```
<div id="myDiv">
    {#if (usingWagon === true)}
        {niceMessage()}
    {:else}
        Use it because it is cool.
    {/if}
</div>
```

As you can see, it is literally javascript in html.

Now lets try to compile this template.

```js
let renderer = Template.fromFile("fullPathToTemplate.html").compile();
console.log(
  renderer({
    usingWagon: true,
    niceMessage: () => "Yay, you are using Wagon!",
  })
);
```

Ouputs

```html
<div id="myDiv">Yay, you are using Wagon!</div>
```

Time to spice things up!

with for loops...

```
{#for (let i = 0; i < 10; i ++>)}
    {i}
{/for}
```

Outputs...

```
0 1 2 3 4 5 6 7 8 9
```

with while loops...

```
{#while (true)}
    Oops no good
{/while}
```

Outputs...

Nothing just like any javascript never ending loop.

with literally javascript code...

```
{%
    class Human {
        constructor(name, age) {
            this.name = name;
            this.age = age;
        }
        greet() {
            return `Hello, my name is ${this.name} and I am ${this.age}.`
        }
    }
}
{new Human("Bob", 20).greet()}
```

Outputs...

```
Hello, my name is Bob and I am 20
```

### Very simple syntax...

| syntax                | description                   | example                              |
| --------------------- | ----------------------------- | ------------------------------------ |
| `{code}`              | Evaluated and displayed       | `{"You will see me"}`                |
| `{% code}`            | Evaluated, but not displayed  | `{% let m = "You will not"}`         |
| `{# block statement}` | Open a block statement        | `{# if (true)}`                      |
| `{: block statement}` | Chains a block statement      | `{: else if (true)}`                 |
| `{/...}`              | Closes a block statement      | `{/ if}`                             |
| `{@ code}`            | Evaluated during compile time | `{@ this.include("./partial.html")}` |

### Render time variables

| name    | description                    |
| ------- | ------------------------------ |
| `$main` | Root template name (full path) |
| `$html` | In generation HTML             |
| `$code` | Generated code                 |
| `data`  | Props passed from the renderer |

`$html` can be modified by the template.

So...

```
{% $html += "Hello world"}
```

will be the same as...

```
{"Hello world"}
```

or even simpler...

```
Hello world
```

### Compile time variables and methods

| name                                  | description                                 |
| ------------------------------------- | ------------------------------------------- |
| `this.main`                           | Root template name (full path)              |
| `this.name`                           | Current template name (full path)           |
| `this.raw`                            | Raw template                                |
| `this.code`                           | In genration code                           |
| `this.vars`                           | Render time variable names. eg. `$html`     |
| `this.define(string name, any value)` | Define a constant                           |
| `this.include(string relativePath)`   | Inserts compiled code from another template |
| `this.add(string code)`               | Inserts code during compile time            |

### Syntax highlighting

There is syntax highlighter in the VScode Marketplace.
https://marketplace.visualstudio.com/items?itemName=str1z.html-wagon-syntax-highlighting

---
_Source: https://npm.io/package/wge · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
