ttfl
v1.1.0
Published
Tag your templates but defer the choice of tag function until a later date.
Downloads
2
Maintainers
Readme
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.
| Param | Type | Description | | --- | --- | --- | | lits | String | Template literal | | ...values | any | Tempalte values |
join(parts, joiner) ⇒ tagged
Join an array of parts into a single value
| Param | Type | Description | | --- | --- | --- | | parts | Array | Parts to join together | | joiner | * | Value to use to join the parts together |
tagged : function
A tagged template callback, ready to be used
| Param | Type | Description | | --- | --- | --- | | tag | function | A template tagging function to pass the saved template to. |