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

jade-browser-middleware

v0.3.3

Published

Middleware precompiles Jade templates for execution in the browser

Downloads

10

Readme

Jade-Browser-Middleware

Jade-Browser-Middleware is a piece of middleware for express that precompiles your Jade templates on the fly and writes them to files in your chosen destination as functions you can execute in your client-side JS.

How it works

Request a compiled template, i.e., script src='/templates/my-jade-template.js', and if it does not yet exist, Jade-Browser-Middleware will look in your chosen src location for my-jade-template.jade. If it's found, a compiled version, my-jade-template.js will be created and written to an optional dest location or src.

If the template already exists, Jade-Browser-Middleware will check if the original template has been modified, and if so, will recompile the template.

When the template is compiled, the function will be assigned to a namespace (defaults to 'jadeTemplates') on the window object, i.e., window.jadeTemplates.my_jade_templates = function (...) {...};.

Then you can do window.jadeTemplates.my_jade_templates([locals]);, which returns the markup compiled with optional locals.

Setup

$ npm install jade-browser-middleware

In Node

var express = require('express'),
    jadeBrowserMiddleware = require('jade-browser-middleware'),
    app = express();

Use the middleware in your app and pass in options.

app.use(jadeBrowserMiddleware(__dirname + '/views/includes', {
    dest: __dirname + '/public/templates'
    namespace: 'templates',
    format: 'camelcase'
}));
  • src - (required) is the source location of the Jade templates you want to have compiled. For backwards-compatibility src can be defined as an option i.e., { src: '...' }

Options

  • dest- the destination for your compiled templates (defaults to src).
  • namespace - the namespace for your templates map in the browser (defaults to 'jadeTemplates').
  • format - the format of the function name added to the namespace for each template request (defaults to 'underscore').
format
  • 'underscore' - will convert spaces and hyphens to underscores i.e., my jade-template.jade becomes my_jade_template.jade
  • 'camelcase' - will convert strings to camelcase i.e., my jade-template.jade becomes myJadeTemplate.jade

In the browser

Get Jade runtime and include in your project, i.e., script src='lib/runtime.js'

Request a template i.e., script src='templates/my-jade-template.js' and if the equivalent jade template exists in your src location, it will be compiled and written to an optional dest location or src.

LICENSE

MIT