GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - theJian/tljs: Tiny template engine powered by es6 template literals

BranchesTags
Open more actions menu

Latest commit

 

History

21 Commits
21 Commits

Folders and files

NameName
Last commit message
Last commit date
__tests__
__tests__
 
 
fixtures
fixtures
 
 
src
src
 
 
.babelrc
.babelrc
 
 
.gitignore
.gitignore
 
 
.travis.yml
.travis.yml
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
package.json
package.json
 
 
renovate.json
renovate.json
 
 
yarn.lock
yarn.lock
 
 

Repository files navigation

tljs

Travis npm

Tiny template engine powered by es6 template literals

  • Super small (< 30 lines).
  • Pure JavaScript syntax.
  • Template includes

Install

npm install tljs

Usage

import tl from 'tljs';

// template
const t = tl`
<div>
${' if (username) { '}
  <p>${' echo(username) '}</p>
${' } '}
</div>`;

// render
t({ username: 'theJian' });

  
// output
<div>

  <p>theJian</p>
  
</div>


/////////////////////////// Generate JSON ////////////////////////////////

const jsonTl = tl`
{
  username: ${' echo(username) '}
}`;

jsonTl({ username: 'theJian' });

API

Echo

Instead of defining some fancy syntax for inserting variables to the output, echo, a good old JavaScript function, has provided to handle this job.

`Here is the ${' echo(username) '}`

Include

To insert contents from another file.

<div>
${' include("./header.js", { title: title }) '}
${' posts.forEach(post => { '}
  <p>
  ${ 'include("./post.js", { post: post }) '}
  </p>
${' } '}
</div>

To use this feature you have to pass a require function when rendering. See Example. The first argument is the path of included file, the second is the values passed to it.

License

MIT@theJian

About

Tiny template engine powered by es6 template literals

Topics

template-engine

Resources

Readme
MIT license
Activity

Stars

17 stars

Watchers

0 watching

Forks

1 fork
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.