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

hyte

v0.0.5

Published

HYbrid TEmplating for the browser and Node.

Downloads

15

Readme

hyte

HYbrid TEmplating for the browser and Node. Using Hogan.js (based on mustache) as templating engine.

Installation

npm install
node server.js

You can now browse to http://localhost:3000/index.html for a demo.

Quick overview

The included server provides:

  • All your pre-compiled templates at /compiled.js
  • Pre-compile separate templates via /compile/[template]
  • Server-side rendering of templates via /render/[template]/[encoded-endpoint-url]
  • Render template server-side using POST data at /render/[template]

The hyte module can also be integrated stand-alone using this API:

  • hyte.compile(template)
  • hyte.compileAll()
  • hyte.render(template, data, callback)
  • hyte.renderFromEndpoint(template, url, callback)

On the client, pre-compiled templates can be rendered...

  • var renderedTemplate = compiledTemplate.render(data);

...or just, when pre-rendered on the server...

  • $('#placeholder).html(renderedTemplate);

Services

Running the server will give you services at http://localhost:3000 to:

Pre-compiled concatenated templates

All templates at /public/views/*.html are pre-compiled and concatenated to JS and available at /compiled.js. This file itself is also using a template: /public/views/compiled.template.mustache.

Example result for /compiled.js (object property keys directly taken from filename):

window.app.templates = {
	"list": new Hogan.Template(function(c,p,i){}),
	"paragraph": new Hogan.Template(function(c,p,i){})
};

This can then be used like this:

var data = {"message": "This is rendered client-side in a pre-compiled template"}
var html = app.templates['list'].render(data);
$('#placeholder').append(html);

Location: (GET) http://localhost:3000/compiled.js

Suggested usage: make sure the first and/or most used templates are pre-compiled like this.

Pre-compile separate templates

Pre-compiled templates are available at /compile/[template]. Compiled to JS in AMD style from /public/views/[template].html.

define(new Hogan.Template(function(c,p,i){}))

So you can use it like this:

require(['/compile/paragraph'], function(compiledTemplate) {
	var html = compiledTemplate.render({"message": "This is rendered client-side in a pre-compiled template"});
	$('#placeholder').append(html);
});

Location: (GET) http://localhost:3000//compile/[template]

Suggested usage: this usage can come in handy when the data is available client-side, and the template still needs to be fetched and compiled.

Render HTML completely server-side

By providing a reference to the template and a full URL to the data endpoint, this service returns pre-rendered HTML.

For example:

http://localhost:3000/render/paragraph/http%3A%2F%2Flocalhost%3A3000%2Fdata%2Fparagraph.json

returns an HTML string ready to be inserted in the page:

<p>This is data in a JSON resource</p>

For now, the data endpoint should deliver JSON that is tailored to the template (no intermediate parsing of data).

Location: (GET) http://localhost:3000/render/[template]/[encoded-endpoint-url]

Suggested usage: this is the best usage performance-wise, just make sure template and data (JSON) match directly.

Render POSTed data

Get pre-rendered HTML from server by providing reference to template and POST data (no processing client-side)

var data = {"message": "This is pre-rendered server-side"};
$.post('/render/paragraph', data, function(renderedTemplate) {
	$('#placeholder').append(renderedTemplate);
});

Location: (POST) http://localhost:3000/render/[template]

Suggested usage: the data is available client-side, but the compiled template is not.

Static server

Static files from /public are available from the root url. E.g. /index.html is served from /public/index.html.

Shouts / dependencies

Many thanks to anyone that contributed to the libraries used in this tool: