Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/marpple/ttl-pug

ES6 tagged template literals like Pug
https://github.com/marpple/ttl-pug

Last synced: 4 days ago
JSON representation

ES6 tagged template literals like Pug

Awesome Lists containing this project

README

        

# ttl-pug
ES6 tagged template literals like Pug

## Getting Started

### 1. plain
```javascript
import pug, {html, escape, unescape, map, scat, el, elpug, elhtml} from '/ttl-pug/ttl-pug.js';

const links = [
{ name: 'MARPPLE', url: 'https://marpple.com', is_app: true },
{ name: 'abym', url: 'https://abym.co.kr', is_app: true },
{ name: 'blog', url: 'https://marpple.github.io' },
{ name: 'GitHub', url: 'https://github.com/marpple' }
];

let demo1 = document.createElement('div');
demo1.setAttribute('id', 'demo1');
demo1.innerHTML = `

1: Link



`;
document.querySelector('#content').appendChild(demo1);
```

```html


1: Link




```

### 2. with html
```javascript
let demo2 = document.createElement('div');
demo2.setAttribute('id', 'demo2');
demo2.innerHTML = html`

2: Link



`;
document.querySelector('#content').appendChild(demo2);
```

```html


2: Link




```

### 3. html, el
```javascript
var str = html`


3: Link




`;
var element = el(str);
document.querySelector('#content').appendChild(element);
```

```html


3: Link




```

### 4. elhtml
```javascript
document
.querySelector('#content')
.appendChild(elhtml`


4: Link




`);
```

```html


4: Link




```

### 5. pug, el
```javascript
var str = pug`
#demo5
h1 5: Link
ul.list
${links.map(link => pug`
li
a[href="${link.url}"] ${link.name}`
)}
`;
var element = el(str);
document.querySelector('#content').appendChild(element);
```

```html


5: Link




```

### 6. elpug
```javascript
document
.querySelector('#content')
.appendChild(elpug`
#demo6
h1 6: Link
ul.list
${links
.filter(link => link.is_app)
.map(link => pug`
li
a[href="${link.url}"] ${link.name}`
)}
`);
```

```html


6: Link




```

### 7. elpug, map(support array, array-like, Object, Set, Map, typeof list[Symbol.iterator] == 'function')
```javascript
var links2 = new Set(links);
document
.querySelector('#content')
.appendChild(elpug`
#demo7
h1 7: Link
ul.list
${map(links2, link => pug`
li
a[href="${link.url}"] ${link.name}`
)}
`);
```

```html


7: Link




```

### 8. plain, el, scat(support array, array-like, Object, Set, Map, typeof list[Symbol.iterator] == 'function')
```javascript
var links3 = {
MARPPLE: { name: 'MARPPLE', url: 'https://marpple.com', is_app: true },
abym: { name: 'abym', url: 'https://abym.co.kr', is_app: true },
blog: { name: 'blog', url: 'https://marpple.github.io' },
GitHub: { name: 'GitHub', url: 'https://github.com/marpple' }
};
document
.querySelector('#content')
.appendChild(el(`


8: Link




`));
```

```html


8: Link




```

### 9. escape, unescape
```javascript
var str = '

  • hi
';
document
.querySelector('#content')
.appendChild(el(`

9: escape, unescape


${escape(str)}

${unescape(escape(str))}


`));
```

```html


9: escape, unescape


<ul class="test"><li>hi</li></ul>



  • hi




```