An open API service indexing awesome lists of open source software.

https://github.com/jzwood/pauperjs

A poor man's client-side templating engine
https://github.com/jzwood/pauperjs

micro-library templating templating-engine

Last synced: about 1 year ago
JSON representation

A poor man's client-side templating engine

Awesome Lists containing this project

README

          

# PauperJs
is a micro-library for client-side templating.

![license](https://img.shields.io/github/license/mashape/apistatus.svg?style=for-the-badge)

## API
Pauper transforms the [textContent](https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent) of every `` element in your markup into a _function_ and replaces the [innerHTML](https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML) of that element with the returned value of that _function_ (see [demo](https://jzwood.github.io/PauperJs/demo/)).

To illustrate, consider the following markup:
```



const today = (new Date()).getDay();
const week = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
const party = today === 0 || today === 6;
return `It's ${week[today]}${party ? '— gotta party! 🍹' : '. Got to work. 🖨'}`;


```

on Saturday this would render as
```


It's Saturday — gotta party! 🍹


```
and on Monday as
```


It's Monday. Got to work. 🖨


```

## Promises
Want to render async data? No problem. Pauper will correctly populate the render field if the `` function returns a promise.

## No Javascript
Browsers usually have Javascript turned on but when they don't you want to be prepared. To do this you can place static fallback copy inside of a `` element.

```

Welcome to my webpage!
Plz turn on JavaScript to get the best experience!
return ajax('get:puppy_pics:all');


```

When Javascript is disabled in the client's browser PauperJs won't run (_obviously_) which means that in order for the fallback to work correctly the following css must be added to the project manually.

```css
render:not(.rendered) {
display: none;
}
```

When the render tags are being rendered PauperJs adds the class `rendered` which will allow them to avoid the `display: none;` selector. PauperJs will handle removing the `` tags.