Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why won't Jade format its output correctly in Express.js

I am using Jade in Express.js and I noticed that the html output is all in one line. On the Jade website ( http://scalate.fusesource.org/documentation/jade-syntax.html ) it says that formatted output is standard and that the options are ScamlOptions.nl and ScamlOptions.indent, but I can't find those options anywhere to see if they are set incorrectly. Does anyone know where I can find those options or is there another way to force clean formatting?

Thanks!

This thread didn't help: How to output pretty html in Express?

like image 915
Ben Avatar asked Aug 27 '11 20:08

Ben


2 Answers

In Express 3, the api has changed for (at least) this view option.

I set app.locals.pretty and it seems to be working just fine. I call it within my app.js (or server.js) right after I set the view engine in app.configure()

app.use(function(req, res, next) {
  app.locals.pretty = true;
  next();
});
like image 59
electblake Avatar answered Sep 22 '22 17:09

electblake


  1. Scalate != Jade

Also, Jade is not designed to create human-readable output. All the indention and new lines are just wasting space and are not important for any browser to process you HTML. But you could try:

  1. Try: app.set('view options', { pretty: true });
  2. Use Firebug or Chrome Inspector to view your HTML ;-)
  3. Use any HTML cleanup tool.
like image 31
TheHippo Avatar answered Sep 25 '22 17:09

TheHippo