cartero-express-middleware
Express middleware for cartero. Overrides res.render with a method that accepts an additional argument, the path to a parcel.
res.locals.cartero_js
is populated with the script
tags for to load the js for the parcel.res.locals.cartero_css
is populated with the link
tags for to load the css for the parcel.
The path of the parcel defaults to the directory of the view that is being rendered, so if you use your views folder to hold your parcels as recommended in the cartero docs and tutorial, the variables are set to the appropriate values for parcel of the view being rendered.
Installation
$ npm install cartero-express-middleware
Usage
After runnning cartero, initialize an instance of the cartero node hook, and then install the middleware, passing it the hook instance.
var app = express();
var hook = require( "cartero-node-hook" );
var carteroMiddleware = require( "cartero-express-middleware" );
app.configure( function() {
app.set( "port" , process.env.PORT || 3000 );
app.set( "views" , path.join( __dirname, "views" ) );
app.use( express.static( path.join( __dirname, "static" ) ) );
var h = hook(
path.join( __dirname, "views" ),
path.join( __dirname, "static/assets" ),
{ outputDirUrl : 'assets/' }
);
app.use( carteroMiddleware( h ) );
app.get( '/hello', function( req, res ) {
res.render( 'hello/hello.jade', {}, '/usr/parcels/hello' );
} );
} );
The middleware sets the res.locals.cartero_js
and res.locals.cartero_css
properties on res.locals
. Templates can then just dump cartero_js
and cartero_css
to load all the js / css assets they require.
doctype 5
html(lang="en")
head
title login
| !{cartero_js}
| !{cartero_css}
body
h1 People List
// ...
Contributors
License
MIT