1.1.0 • Published 3 years ago

ttfl v1.1.0

Weekly downloads
4
License
ISC
Repository
gitlab
Last release
3 years ago

Template Tag For Later

Tag your templates but defer the choice of tag function until a later date.

Great for library authors who want to allow consumers to select their own tag functions.

// horses.js
import html from 'ttfl';

const template = html`<marquee>${'I <3 horses, best of all the animals'}</marquee>`;

export default template;
import html from 'escape-html-template-tag';
import horseTemplate from './horses.js';

console.log(html(horseTemplate).toString());

You can also nest the templates for extra fun:

import sql from 'ttfl';

const s1 = sql`SELECT author_id, count(*) as total FROM books GROUP BY author_id`;
const s2 = sql`SELECT * FROM (${s1}) AS books LEFT JOIN authors ON(authors.id=books.author_id);`

import sqlTag from 'sql-template-tag';

export default s2(sqlTag);

Members

Functions

Typedefs

ttfl ⇒ tagged

Tag a template for later. Returns a function that you can pass the real tag function to. If any of the template values are ttfl functions, the tag will be applied to them too. You can also call ttfl as a regular function - in which case nested ttfls will not be altered.

ParamTypeDescription
litsStringTemplate literal
...valuesanyTempalte values

join(parts, joiner) ⇒ tagged

Join an array of parts into a single value

ParamTypeDescription
partsArrayParts to join together
joiner*Value to use to join the parts together

tagged : function

A tagged template callback, ready to be used

ParamTypeDescription
tagfunctionA template tagging function to pass the saved template to.
1.1.0

3 years ago

1.0.0

3 years ago