jay

The hottest frontend wrapper around

jay

The hottest frontend wrapper around. Inspired by browserify, jay gives you a browser-side require() for javascript, css, & templates.

Jay allows you to componentize your frontend, breaking it up into a structure that makes the most sense to you.

Jay was originally built for use with express, but may be extended to other http servers.

npm install jay

kanye.js

 
/**
 * Module dependencies
 */
 
var $ = require('jquery');
 
/**
 * Require `Kanye` styling
 */
 
require('./kanye.css')
 
/**
 * Export `Kanye`
 */
 
var Kanye = module.exports = function() { ... };
 
/**
 * Add a (mustache) template
 */
 
Kanye.prototype.template = require('./kanye.mu');
 
/**
 * Render `Kanye` template
 */
 
Kanye.prototype.render = function(locals) {
  document.body.appendChild(locals);
};

jay.js

/**
 * Module dependencies
 */
 
var Kanye = require('./kanye');
 
var Jay = module.exports = function() { ... };
 
Jay.prototype.nextSong = function() {
  if(this.isTired()) {
    kanye = new Kanye();
    kanye.render({ sunglasses : 'Ray Ban', chains : true });
  }
}
var express = require('express'),
    jay = require('../../'),
    cons = require('consolidate'),
    app = express();
 
/**
 * Jay Configuration
 */
 
jay.root(__dirname)
   .build(join(__dirname, 'build'))
   .include('hogan.js', '/vendor/hogan.js');
 
/**
 * Configuration
 */
 
app.configure(function() {
  app.set('view engine', 'html');
  app.use(express['static'](join(__dirname, 'build')));
});
 
app.configure('development', function() {
  // Jay wraps around the templating engine, 
  // should only be wrapped during development 
  app.engine('html', jay(cons.hogan));
});
 
app.configure('production', function() {
  app.engine('html', cons.hogan);
});
 
...
 
app.listen(8080);

Required. The root directory for jay. Absolute paths map to the root, for example /models/user.js maps to $ROOT/models/user.js

jay.root(__dirname);

Where the build files are outputted. Defaults to $ROOT/build.

jay.build(path.join(__dirname, 'out'));

Alias an asset that has already been required by the view. Useful for creating shorter, perhaps more familiar routes.

Note: from is relative to jay's root, which may not be the same as the relative path from your server.

jay.alias('jquery', '/vendor/jquery.js')
   .alias('underscore', '/vendor/underscore.js')

Includes an asset that is not currently being required by the view. Useful for adding client-side templating libraries (hogan.js, jade.js) without requiring them explicitly.

If alias is used, it will also create an alias to that included asset.

Note: asset is relative to jay's root, which may not be the same as the relative path from your server.

jay.include('hogan.js', '/vendor/hogan.js');

Jay uses deputy for caching the require dependency tree. dir specifies where the cache is stored. Defaults to $HOME/.jay/cache.json.

jay.cache('.jay/app.json')

To turn off caching:

jay.cache(false);

Jay works with any supported express templating engine. You can even use your own templating language with jay as long as you follow the express engine function signature.

var supersizer = function(pathlocalsfn) {
  var str = fs.readFileSync(path, 'utf8');
  str = str.replace(/h(\d)/g, function(mp) {
    p = (> 1) ? p : 2;
    return 'h' + --p;
  });
  return fn(null, str);
};
 
app.engine('html', jay(supersizer));

Create a new instance of jay.

var jay = require('jay'),
    jay2 = jay.create();

Currently supports:

  • CSS
  • stylus
  • hogan
  • coffeescript
  • JSON

(The MIT License)

Copyright (c) 2012 Matt Mueller <mattmuelle@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.