https://github.com/ianfabs/frenchie
A tiny and very crude pastiche of mustache templating for deno. Not recommended for production.
https://github.com/ianfabs/frenchie
deno javascript template-engine typescript
Last synced: about 2 months ago
JSON representation
A tiny and very crude pastiche of mustache templating for deno. Not recommended for production.
- Host: GitHub
- URL: https://github.com/ianfabs/frenchie
- Owner: ianfabs
- Created: 2020-02-04T14:53:05.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-03-02T02:02:16.000Z (over 6 years ago)
- Last Synced: 2024-10-19T07:14:59.946Z (over 1 year ago)
- Topics: deno, javascript, template-engine, typescript
- Language: TypeScript
- Size: 3.91 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Frenchie
A tiny and very crude pastiche of mustache templating for deno. Not recommended for production.
## Usage
With a string
```ts
import { parse } from "https://deno.land/x/frenchie/mod.ts";
const template = "
Hello there, {{name}}
";
parse(template, {name: "Wes Bos"}); // => "Hello there, Wes Bos
"
```
With a file:
*index.hbs*
```hbs
Hello there, {{name}}
```
*app.ts*
```ts
import { parse } from "https://deno.land/x/frenchie/mod.ts";
import { readFileStrSync } from "https://deno.land/std/fs/mod.ts";
let file = readFileStrSync(Deno.cwd() + "index.hbs", {encoding: 'utf8'});
parse(file, {name: "Ry"}) // => "
Hello there, Ry
"
```
## Concepts
There are two basic concepts to try and mimic hbs as lazily as possible: **blocks** and **void blocks**.
### Blocks
A block is any `{{}}` region that *will* return a value.
### Void Blocks
A **void** block is a block that *does not* return anything, beause it's encasing function is `void`.
These blocks are created by writing `{{#}}` with whatever you would like after the `#`. Technically, because I'm a terrible programmer,
you could also return code from these blocks. Maybe I'll fix that, or maybe I'll just call it a feature.
## Security Concerns
To make things easier on myself, I used an insecure feature of javascript. It made writing this code a ***lot** easier. I do have plans to think of a way around this limitation in the future. Currently, I don't know any better methods for accomplishing this, so any support is greatly appreciated.
## Neat Examples
```hbs
{{# egg = true }}
{{egg}}
```
```hbs
{{#if (1 < 2) return "fish"; }}
```