Helps setup your front end.
While upfront doesn't require express-expose, it's mostly useless without it. I figure you could use Browserify as well, but I haven't tested that yet.
Upfront also pairs well with Mike Frey's UTML module, which lets you use underscore templates server side. Use upfront to send your templates up to your front-end and then you can use the same templates on the server and in the browser if you're builing a Backbone app.
This will send every template you have to the front end. Useful for fat clients.
var upfront = require('upfront');
upfront.setup(app, function(err){
if (err) throw new Error(err);
upfront.compile(function(err, done){
if (err) throw new Error(err);
app.expose(app.settings.templates, "Templates");
});
});
In your layout, assuming you're using express-expose, put this right before the closing </body>
tag:
<body>
<!-- ... -->
<script type="text/javascript"><%= javascript %></script>
</body>
There are a few ways to configure upfront to your liking.
- Create an upfront.json file in your views folder.
- Pass a string with the path name to a custom configuration file.
- Pass in an object containing your configuration options.
upfront.setup({app:app, config: __dirname + '/config/upfront.json'}, function(err){
// ...
});
var cfg = {
"ignore" : [ "file_names", "excluding_extension" ],
"extensions": [ "jade", "md" ]
};
upfront.setup({app:app, config:cfg}, function(err){
// ...
});
- Stuff to ignore. If, for example, you don't want to include your layout, simply add it's filename, excluding the extension, to an array called "ignore".
- Extensions you care about. Defaults to html and utml. Set this to whatever you want.
{
"ignore" : [ "layout", "ignore", "whatever", "you", "want" ],
"extensions": [ "html", "jade", "md", "utml" ]
}