Ghost/ghost/tpl
Hannah Wolfe c886738bbc Added README.md and one extra test
- Try to make sure it's clear how to make interpolation work when working with handlebars helpers
2021-09-30 16:17:56 +01:00
..
lib Added new tests & missing return type to tpl 2021-06-09 12:25:45 +01:00
test Added README.md and one extra test 2021-09-30 16:17:56 +01:00
.eslintrc.js Added minimal tpl() template helper 2021-06-09 10:04:49 +01:00
index.js Added minimal tpl() template helper 2021-06-09 10:04:49 +01:00
LICENSE Added minimal tpl() template helper 2021-06-09 10:04:49 +01:00
package.json Update dependency mocha to v9.1.2 2021-09-27 01:04:25 +00:00
README.md Added README.md and one extra test 2021-09-30 16:17:56 +01:00

Tpl

Install

npm install @tryghost/tpl --save

or

yarn add @tryghost/tpl

Usage

const tpl = require('@tryghost/tpl');
messages = {
    myError: 'Something terrible happened to {something}'
};

console.error(tpl(messages.myError, {something: 'The thing'}));
  • Takes strings like 'Your site is now available on {url}' and interpolates them with passed in data
  • Will ignore double or triple braces like {{get}} or {{{content}}}
  • Can handle escaped braces e.g. \\{\\{{helpername}\\}\\}
  • There's a simple bare minimum escaping needed to make {{{helpername}}} work with interpolation e.g. {\\{{helpername}}}

Develop

This is a mono repository, managed with lerna.

Follow the instructions for the top-level repo.

  1. git clone this repo & cd into it as usual
  2. Run yarn to install top-level dependencies.

Run

  • yarn dev

Test

  • yarn lint run just eslint
  • yarn test run lint and tests

Copyright & License

Copyright (c) 2013-2021 Ghost Foundation - Released under the MIT license.