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

koa-jade-render

v1.0.0

Published

Jade for Koa with Spice.

Downloads

12

Readme

koa-jade-render

Jade for Koa with Spice.

Build Status Dependency Status License Status Downloads Version

Usage

npm install --save koa-jade-render

Note: I have not tested legacy but in theory it should work. Please report any bugs if encountered or create a pull request to add tests.

Legacy (< 2.0.0-alpha)

var koa = require('koa');
var app = koa();
var jade = require('koa-jade-render');
var path = require('path');

//set jade
app.use(jade(path.join(__dirname, 'views')));

//then render!
app.use(function*(next){
    yield this.render('index.jade');
});

app.listen(3000);

Modern (>= 2.0.0-alpha)

var Koa = require('koa');
var app = new Koa();
var jade = require('koa-jade-render');
var path = require('path');

//set jade
app.use(jade(path.join(__dirname, 'views')));

//then render!
app.use((self, next) => {
    return next().then(()=>{
        self.render('index.jade');
    });
});

app.listen(3000);

Note: You can still pass locals if you like:

Example:

app.use((self, next) => {
    return next().then(()=>{
        self.render('index.jade', {title:'BOOM!'});
    });
});

//the api is:
this.render(filename, opt, locals);
//note that opt and locals will be merged
//see example at https://github.com/jadejs/jade#api

Note: Jade uses jade.renderFile to render its views. If you would like override the renderer, you can create a plugin and pass it into Jade.

Example:

//...

//Jade takes two arguments, (opt, fn)
//where opt is a String, PlainObject, or Function
//and fn is a Function.
app.use(jade(function(file, opt, locals){
    //In this function, Koa's ctx is 
    //available at your disposal
    //Also for convenience, jade and 
    //options (global) are attached to ctx.
    var opt = this.jade.options;
    this.body = this.jade.compile(/*whatever you want to do*/);
    this.text = 'text/html';
}))

app.use((self, next) =>{
    //works as you would expect.
    next().then(()=>{
        this.render('file');
    });
});

Static API

jade.compile - see http://jade-lang.com/api/

jade.render - see http://jade-lang.com/api/

jade.renderFile - see http://jade-lang.com/api/

##Why another Jade middleware for Koa?

Because this middleware supports koa's this.state and the code size is very small (~110 lines with beautiful comments!) so it's easier to maintain or contribute. Also, you're free to override or even create bad-to-the-bone plugins. Just name it something like koa-jade-render-MyAwesomePlugin.

Example

An example is available. See the example folder.

Contribute

You're more than welcome to contribute. This project isn't really a priority for me right now as I am working on another project where I am doing a major overhaul but if you would like to contribute, just do the standard Fork and Pull! Happy Coding!