0

Is there a way to have your HTML output that comes from a Jade template be beautified? Something similar to Express's app.locals.pretty = true; ? I'm using koa-router and koa-views if that is relevant.

server.js

const koa = require('koa');
const views = require('koa-views');
const serve = require('koa-static');
const router = require('./routes');

const app = koa();

app.use(serve(`${__dirname}/public`));
app.use(views(`${__dirname}/views`, { extension: 'jade' }));
app.use(router.routes());

app.listen(3000, () => {
  console.log('Server listening at http://localhost:3000');
});

routes/index.js

const router = require('koa-router')();

router.get('/', function *() {
  yield this.render('index');
});

module.exports = router;

views/index.jade

html
  head
    title Hello
    meta(charset='utf-8')
    meta(name='viewport', content='width=device-width, initial-scale=1.0')
    link(type='text/css', rel='stylesheet', href='css/style.css')

  body
    h1 Hi
Saad
  • 49,729
  • 21
  • 73
  • 112

1 Answers1

0

you could try:

app.use(views(`${__dirname}/views`, { extension: 'jade', pretty:true}));

that should do the trick... on the other hand, i use koa-jade instead of koa-views. My current code looks like this:

var Jade  = require('koa-jade');

var jade = new Jade({
    viewPath: path.resolve(__dirname,"jade"),
    debug: true,
    pretty: true,
    compileDebug: true,
    basedir: path.resolve(__dirname,"jade"),
    app:app
  })

in production mode i just set pretty to false...

HTH

Holger Will
  • 7,228
  • 1
  • 31
  • 39
  • Unfortunately there is no pretty option for `koa-views` :( I guess I'll have to try out koa-jade, thanks. – Saad May 03 '16 at 16:16