Skip to content

Commit

Permalink
better getting started & correction
Browse files Browse the repository at this point in the history
  • Loading branch information
itsarnaud committed Apr 15, 2024
1 parent fa6b439 commit 5e7f17d
Show file tree
Hide file tree
Showing 12 changed files with 136 additions and 92 deletions.
2 changes: 1 addition & 1 deletion docs/_coverpage.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![logo](_media/icon.png)

# igo dust <small>0.3.5</small>
# Igo Dust.js <small>0.3.5</small>

> Simple JavaScript templating, inspired by [Dust.js](https://github.com/linkedin/dustjs).
Expand Down
Binary file added docs/_media/favicon.ico
Binary file not shown.
4 changes: 3 additions & 1 deletion docs/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@
- [Filters](guide/filters)
- [Include](guide/include)
- [Stream](guide/stream)
- [API](guide/api)

- [**Playground**](playground/)
- [**Playground**](playground/)
- [**Release Notes**](release/)
68 changes: 54 additions & 14 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,74 @@
# Getting Started
![Build Status](https://github.com/igocreate/igo-dust/actions/workflows/node.js.yml/badge.svg) ![npm](https://img.shields.io/badge/version-0.3.5-0879BA) ![npm](https://img.shields.io/npm/dt/igo-dust)


# Igo Dust.js

## Introduction

Igo Dust.js is a high-performance templating library built on Dust.js, offering simplicity and efficiency in rendering dynamic content. With its clean syntax and seamless integration with Express, Igo Dust.js simplifies template creation, ensuring fast and responsive user experiences for web applications.

> IGO DUST is a high-performance templating library built on Dust.js, offering simplicity and efficiency in rendering dynamic content. With its clean syntax and seamless integration with Express, Igo Dust simplifies template creation, ensuring fast and responsive user experiences for web applications.

## Installation

**1. Install Igo Dust in your project via npm:**
### Differences from Dust.js

* **Simpler Syntax**: Igo Dust.js offers a simpler syntax compared to Dust.js, making it easier to create and manage templates.
* **Improved Performance**: Igo Dust.js is optimized for performance, ensuring fast rendering of dynamic content.
* **Modern JavaScript**: Igo Dust.js is built using modern JavaScript, offering compatibility with the latest ECMAScript standards.

> Note: The VSCode extension for Igo Dust.js is available [here](https://marketplace.visualstudio.com/items?itemName=IGOCREATE.igo-dust-language-support).
<!-- > Benchmark [here](https://www.example.com) -->

## Installation

```bash
npm install --save igo-dust
```

**2. Create a Template file**
## Using Express

You can use Igo Dust.js with Express by setting the view engine to `dust` and rendering templates using the `res.render` method.

```js
const express = require('express');
const app = express();

Create a template file with the `.dust` extension. For example, `index.dust`:
// Igo Dust configuration
const igodust = require('igo-dust');

```dust
<h1>Hello, {name}!</h1>
app.engine('dust', igodust.engine);
app.set('view engine', 'dust');
app.set('views', './views');

app.get('/', (req, res) => {
// renders ./views/welcome/index.dust
res.render('welcome/index');
});

app.listen(3000, () => {
console.log(`Example app listening on port 3000`)
});
```

**3. Compile the Template**
That's it! You have now successfully set up Igo Dust.js with Express.


## Using API

You can also use Igo Dust.js without Express by rendering templates using the `render` and `renderFile` methods:

Compile the template using the `igo-dust` library:
```js
const igodust = require('igo-dust');

```javascript
const dust = require('igo-dust');
const html = dust.renderFile('index.dust', { name: 'World' });
igodust.render('<h1>Hello, {name}!</h1>', { name: 'World' });
// => <h1>Hello, World!</h1>

igodust.renderFile('template.dust', { name: 'World' });
// => <h1>Hello, World!</h1>
```

That's it! You have now successfully installed Igo Dust and rendered your first template.
That's it! You have now successfully rendered a template using Igo Dust.js.



---
13 changes: 0 additions & 13 deletions docs/guide/api.md
Original file line number Diff line number Diff line change
@@ -1,13 +0,0 @@
## Line feed management

Preserve line returns if the htmltrim option is disabled.

```js
// Template
Hello \r\n World \r\n<meta name="description" content="{+description/}">\r\n OK.

// Data
{ }

// Output
Hello \r\n World \r\n<meta name="description" content="">\r\n OK.
6 changes: 3 additions & 3 deletions docs/guide/basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Hello, {w}!
Hello, world!
```

Igo Dust will not crash when a key is missing in the data object.
Igo Dust.js will not crash when a key is missing in the data object.

```js
// Template
Expand Down Expand Up @@ -47,7 +47,7 @@ Hello, {! comment !}world!
Hello, world!
```

Igo Dust will ignore data that are inside comments.
Igo Dust.js will ignore data that are inside comments.

```js
// Template
Expand Down Expand Up @@ -77,7 +77,7 @@ Hello, \' \\ " " World!
Hello, ' \ " " World!
```

You can also use special tags to escape Igo Dust tags.
You can also use special tags to escape Igo Dust.js tags.

```js
// Template
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Filters are attached to a Dust reference by adding a pipe `|` and the filter nam
* `js` – JSON.stringify
* `jp` – JSON.parse

> Dust applies the `h` filter to all references by default, ensuring that variables are HTML-escaped. You can undo this autoescaping by appending the `s` filter.
!> Dust applies the `h` filter to all references by default, ensuring that variables are HTML-escaped. You can undo this autoescaping by appending the `s` filter.

## Examples

Expand Down
3 changes: 1 addition & 2 deletions docs/guide/helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ Render content if the key is less than the specified value.
// Output
Hello World
```

> Note: You can use `@lte` to render content if the key is less than or equal to the specified value !
## Else
Expand All @@ -100,7 +99,7 @@ Hello Planet

## Custom Helpers

You can define `custom helpers` to extend the functionality of Igo Dust.
You can define `custom helpers` to extend the functionality of Igo Dust.js.

```js
// Define custom helpers
Expand Down
33 changes: 21 additions & 12 deletions docs/guide/logic.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@

---

* If-Else Conditions: Use `{?}` and `{:else}` to create conditional statements. <br/>
* Existence Check: Employ `{?}` to check if a key exists in the context. <br/>
* Negation Check: Use `{^}` to check if a key does not exist in the context. <br/>
* If-Else Conditions: Use `{?}` and `{:else}` to create conditional statements based on truthy values. <br />
* Existence Check: Employ `{?}` to check if a key exists in the context by evaluating its truthy value. <br />
* Negation Check: Utilize `{^}` to verify if a key does not exist in the context or if its value is falsy.

!> Note: In Igo Dust.js, an empty array `[]` evaluates to false in conditional statements.








## Simple conditions

Expand All @@ -14,7 +23,7 @@ Render a section of text based on a simple condition.
// Template
Hello {?test}World{/test} OK.

// Date
// Data
{
test: true
}
Expand All @@ -29,7 +38,7 @@ You can also render a section of text based on a condition applied to an attribu
// Template
Hello {?test.a}World{/test.a} OK.

// Date
// Data
{
test: { a: true }
}
Expand All @@ -46,7 +55,7 @@ Render nested conditions based on multiple conditions.
// Template
{?world}World{?ok} OK{/ok}{/world}

// Date
// Data
{
world: true,
ok: true
Expand All @@ -64,7 +73,7 @@ Render different text based on a condition, with an alternative if the condition
// Template
Hello {?test}World{:else}Good bye{/test} OK.

// Date
// Data
{
test: false
}
Expand All @@ -81,7 +90,7 @@ Render a section of text based on the absence of an attribute in the context.
// Template
Hello {^test.a}World{/test.a} OK.

// Date
// Data
{
test: false
}
Expand All @@ -95,7 +104,7 @@ You can also use `else` with the ^ condition.
// Template
Hello {^test.a}World{:else}Planet{/test.a}.

// Date
// Data
{
test: { a: true }
}
Expand All @@ -112,7 +121,7 @@ Execute a function as a condition and render text based on its result.
// Template
Hello{?test world=w} World{/test}.

// Date
// Data
{
w: true,
test: (locals) => locals.world
Expand All @@ -124,13 +133,13 @@ Hello World.
## Array
Igo Dust consider empty arrays as `false`.
Igo Dust.js consider empty arrays as `false`.
```js
// Template
OK {?users}{users.length} users{/users}.

// Date
// Data
{
users: []
}
Expand Down
46 changes: 4 additions & 42 deletions docs/guide/loops.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Hello a1

## Else

Render different text if the input is null.
Render different text if the input is a falsy value.

```js
// Template
Expand All @@ -73,21 +73,7 @@ Hello {#COL1}a{:else}b{/COL1}
// Output
Hello b
```

Render different text if the input is an empty array.

```js
// Template
Hello {#COL1}a{:else}b{/COL1}

// Data
{
COL1: []
}

// Output
Hello b
```
!> Note: In Igo Dust.js, an empty array `[]` evaluates to false in conditional statements.

## Check

Expand Down Expand Up @@ -275,11 +261,11 @@ Sections are used to conditionally render blocks of content based on the value o
```js
// Template
{! Outside of the section, Igo Dust looks for values at the root of the JSON context !}
{! Outside of the section, Igo Dust.js looks for values at the root of the JSON context !}
The value of name is: {name} <br/>

{#extraData }
{! Inside this section, Igo Dust looks for values within the extraData object !}
{! Inside this section, Igo Dust.js looks for values within the extraData object !}
Inside the section, the value of name is: {.name} <br/>
{/extraData}

Expand Down Expand Up @@ -345,30 +331,6 @@ Hello {#users it="user"}#{user.id}: {#user.friends it="friend"}{friend.name}{@se
Hello #1: Gates Lewis, Britt Stokes #1<br/>#2: Gardner Alvarez #2
```
You can rename only the first occurrence of the "it" attribute in a loop.
```js
// Template
Hello {#users it="user"}#{user.id}: {#user.friends}{.name}{@sep}, {/sep}{/user.friends} #{user.id}{@sep}<br/>{/sep}{/users}

// Data
{
user: [{
id: 1,
name: 'Gardner Alvarez',
friends: [{'name': 'Gates Lewis'},{'name': 'Britt Stokes'}]
},{
id: 2,
name: 'Gates Lewis',
friends: [{'name': 'Gardner Alvarez'}]
}]
}

// Output
Hello #1: Gates Lewis, Britt Stokes #1<br/>#2: Gardner Alvarez #2
```
Expand Down
8 changes: 5 additions & 3 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<title>Igo Dust.js</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="description" content="Description">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify/themes/vue.css" />
<link rel="icon" href="_media/favicon.ico" type="image/x-icon">


</head>
Expand All @@ -15,11 +16,12 @@
<div id="app"></div>
<script>
window.$docsify = {
name: 'Igo Dust',
name: 'Igo Dust.js',
repo: 'https://github.com/igocreate/igo-dust',
loadSidebar: true,
coverpage: true,
homepage: 'getting-started.md',


auto2top: true,
maxLevel: 2,
Expand All @@ -34,7 +36,7 @@
noData: 'No Results!',
// Headline depth, 1 - 6
depth: 6,
hideOtherSidebarContent: false, // whether or not to hide other sidebar content
hideOtherSidebarContent: true, // whether or not to hide other sidebar content
}
}
</script>
Expand Down
Loading

0 comments on commit 5e7f17d

Please sign in to comment.