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

htmling

v0.0.8

Published

Polymer compatible HTML5 based templating syntax for node.js.

Downloads

2,288

Readme

HTMLing

Build Status

Polymer compatible HTML5 based templating syntax for node.js. Render your templates server-side using the same syntax as in the browser, with no virtual DOM trickery required.

For a full demonstration, please see htmling-demo-app.

Installation

via npm

npm install htmling

Example

Turns this:

<!doctype html>
<html>
  <head>
    <title>{{title}}</title>
    <meta name="description" content="{{description}}">
  </head>
  <body>
    <h1>{{title}}</h1>
    <ul>
    <template repeat="{{user in users}}">
      <li>{{user.name}}</li>
    </template>
    </ul>
  </body>
</html>

plus this:

{
  "title": "User List",
  "description": "A list of users",
  "users": [
    {
      "name": "Alice"
    },
    {
      "name": "George"
    }
  ]
}

into this:

<!doctype html>
<html>
  <head>
    <title>User List</title>
    <meta name="description" content="A list of users">
  </head>
  <body>
    <h1>User List</h1>
    <ul>
      <li>Alice</li>
      <li>George</li>
    </ul>
  </body>
</html>

How it works

Unlike similar libraries, HTMLing does not require a virtual DOM such as jsDOM. Instead, HTMLing parses .html files and transforms them into very efficient executable JavaScript functions. It uses a parser written in PEG.js which emits a standard Mozilla Parser API AST with some custom node types. The compiler then uses estraverse to convert these custom node types to standard JavaScript expressions. Finally, the result is passed to escodegen which converts the AST into executable JavaScript.

This compilation process happens only once, and the resulting JavaScript is extremely efficient.

Usage

HTMLing is easy to integrate with your existing build process, either via the command line or library interfaces.

CLI

HTMLing ships with a small command line interface:

Compile an individual file

The compiled output will be written to STDOUT

htmling ./file.html

Compile an individual file to a destination

The compiled output will be written to compiled.js.

htmling -o ./compiled.js ./file.html

Compile a directory hierarchy

Compile a nested directory structure to a directory called compiled. The output directory will be created if it does not already exist, and the resulting folder structure will match that of the input.

htmling -o ./compiled ./pages

Compile a directory hierarchy to a single file

Compile a nested directory structure to a single called compiled.js

htmling -c -o ./compiled.js ./pages

As a Library

It's also possible to use HTMLing as a library:

Compile a string

var HTMLing = require('htmling');

var template = HTMLing.string('Hello {{name}}');

console.log(template.render({name: 'Charles'})); // "Hello Charles"

Compile a file

var template = HTMLing.file('./index.html');
console.log(template.render());

Compile a directory

var templates = HTMLing.dir('./pages');
console.log(templates.render('index.html', {}))

Using as an express view engine

HTMLing has support for express.js.

var HTMLing = require('htmling');
app.configure(function(){
  app.engine('html', HTMLing.express(__dirname + '/views/'));
  app.set('view engine', 'html');
});

In development mode, you'll probably want to enable the watch option. This will reload your templates when they change on disk:

var HTMLing = require('htmling');
app.configure(function(){
  app.engine('html', HTMLing.express(__dirname + '/views/', {watch: true}));
  app.set('view engine', 'html');
});

License

MIT, see LICENSE.md.

Docker environment

All you need is Docker with docker-compose available from your terminal.

We have a fancy shortcut to get your application up and running, and you also get access to the container terminal:

$ make build
$ make run

From this point, it's just a matter of starting the application from within the container shell:

htmling:~/app(master)$ npm test

Other fancy shortcuts we have for Docker fans

  • $ make in to open a new container terminal
  • $ make stop to stop all containers
  • $ make clean to clean the Docker environment