npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

backticks

v0.2.0

Published

Express engine creator for the basic use of ES6 template literals (backticks) for templating

Downloads

21

Readme

Backticks

An Express view engine for using ES2015 Template Literals.

Installation

$ npm i backticks

Features

  • Compiled and interpreted by V8 (minimun overhead to the project)
  • Learning new syntax is not required
  • Niceties like automatic escaping & automatic array joining
  • Support for layout using generator functions

Usage

Basic Usage

The basics required to integrate backticks renderer are:

var express = require('express'),
  backticks = require('backticks'),
  app = express();
  
app.engine('html', backticks());
app.set('views', 'views');
app.set('view engine', 'html');

app.get('/', function(req, res) {
  res.render('index', {title: 'Welcome', message: "Hello World"});
});

app.listen(3000);

Before Express can render template files, the following application settings must be set:

  • views, the directory where the template files are located. Eg: app.set('views', './views')
  • view engine, the template engine to use. Eg: app.set('view engine', 'html')

HTML template file named index.html in the views directory is needed, with the following content:

<!DOCTYPE html>
<html>
<head>
    <title>${title}</title>
</head>
<body>
    <h1>${message}</h1>
</body>
</html>

Using a Layout file

Backticks supports the usage of a layout file. The layout is processed in a generator function, so you have access to yield Within it.

By default, Backticks will try to load a "layout" file using the same folder and extension of your views.

Example:

var express = require('express'),
  backticks = require('backticks'),
  app = express();

app.engine('html', backticks({
  caching: true
}));
app.set('views', 'views');
app.set('view engine', 'html');


app.get('/', function(req, res) {
  res.render('index', {message: "Hello World"});
});

app.listen(3000);

views/layout.html:

<html>
  <head>
    <title>Hey, up here!</title>
  </head>
  <body>
    <div id="page">
      ${yield}
    </div>
  </body>
</html>

Template:

<div>
  <h1>${message}</h1>
</div>

Settings

These are the available options when instantiating backticks:

| Option | Description | Default Value |---|---|---| | caching | Wheter or not Backticks should cache views | false | | layoutFile | File to use as layout for views | [views folder]/layout.[view engine] | fnWhitelist | By default, values returned from functions provided in locals are automatically escaped. You can whitelist functions to avoid auto escaping | [Array.prototype]

Should I use this in production code?

Use Backticks if you need something quick and simple. It is not as readable as the template syntax supported by Handlebars.js and similar templating engines. On the other hand, it is lightweight and new syntax is introduced: It's just JavaScript.