How to use the consolidate.handlebars function in consolidate

To help you get started, we’ve selected a few consolidate examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github leecade / fe / src / utils / generate.js View on Github external
}
  const fileNames = Object.keys(files)
  Object.keys(filters).forEach(glob => {
    fileNames.forEach(file => {
      if (minimatch(file, glob, { dot: true })) {
        const condition = filters[glob]
        if (!evaluate(condition, data)) {
          delete files[file]
        }
      }
    })
  })
  done()
}

const render = consolidate.handlebars.render

// register handlebars helper
Handlebars.registerHelper('if_eq', function (a, b, opts) {
  return a === b
    ? opts.fn(this)
    : opts.inverse(this)
})

Handlebars.registerHelper('unless_eq', function (a, b, opts) {
  return a === b
    ? opts.inverse(this)
    : opts.fn(this)
})

/**
 * Generate a template given a `src` and `dest`.
github forwardemail / email-templates / src / template-manager.js View on Github external
/**
 * Small utility module for compling HTML templates or pre-processed CSS.
 *
 * @author: [@jasonsims]('https://github.com/jasonsims')
 */

import {extname, dirname, basename} from 'path'
import cons from 'consolidate'
import P from 'bluebird'

var engineMap = {
  // HTML Template engines
  'html': renderDefault,
  'hbs': cons.handlebars.render,
  'njk': cons.nunjucks.render,
  'emblem': renderEmblem,
  // CSS pre-processors
  'less': renderLess,
  'stylus': renderStylus,
  'styl': renderStyl,
  'sass': renderSass,
  'scss': renderSass,
  // Handle plain CSS also
  'css': renderDefault,
  // Handle plain text
  'txt': renderDefault,
  // Handle missing extension
  '': renderDefault
}
github vshjxyz / es6-react-redux-universal-template / server / server.js View on Github external
import express from 'express';
import httpProxy from 'http-proxy';
import errorHandler from 'errorhandler';
import path from 'path';
import consolidate from 'consolidate';
import { RouteErrors } from  '../app/core/constants';
import { routeUrl, renderRouter } from './react-renderer';

const app = express();
let server;

app.engine('hbs', consolidate.handlebars);
app.set('views', __dirname + '/views');
app.set('view engine', 'hbs');

app.use(errorHandler({
    dumpExceptions: true,
    showStack: true
}));

app.get('/assets*', function (req, res) {
    if (process.env.NODE_ENV == 'development') {
        // When webpack is running
        let proxy = httpProxy.createProxyServer();
        proxy.web(req, res, {target: 'http://localhost:3001'});
    } else {
        res.sendFile(req.path.substr(7), { root: path.join(__dirname + '/../dist') });
    }
github dylants / universal / app / config / express.js View on Github external
const APP_ROOT = path.join(__dirname, '../../');
const IS_DEVELOPMENT = process.env.NODE_ENV === 'development';
const IS_PRODUCTION = process.env.NODE_ENV === 'production';

const app = express();

app.use(compression());
app.use(bodyParser.json());

/* ------------------------------------------ *
 * Rendering configuration
 * ------------------------------------------ */

// use handlebars as the html engine renderer
app.engine('hbs', consolidate.handlebars);
app.set('view engine', 'hbs');
/*
 * Notice that the views is set within the 'build' directory. This
 * was done to use the files that have been processed by Webpack
 * (which occurs in both the development and production environments).
 */
app.set('views', path.join(APP_ROOT, 'build', 'views'));

// this is required to get babel (server side) to process css-modules
hook({
  extensions: ['.scss', '.css'],
  generateScopedName: config.webpack.localIdentName,
  preprocessCss: (data, file) => sass.renderSync({ file }).css,
});
github UXFoundry / hashdo / lib / template.js View on Github external
return Path.basename(file, Path.extname(file)) === 'footer';
  });

  if (header) {
    viewModel.partials.header = getRelativePartial(header);
  }

  if (content) {
    viewModel.partials.content = getRelativePartial(content);
  }

  if (footer) {
    viewModel.partials.footer = getRelativePartial(footer);
  }

  Consolidate.handlebars(Path.join(hbTemplatePath, 'card.hbs'), viewModel, function (err, html) {
    if (!err) {
      callback && callback(html);
    }
    else {
      console.error('TEMPLATES: Error generating view from Handlebars file card.hbs', err);
      callback && callback();
    }
  });
}
github cjihrig / swagger-jacker / lib / index.js View on Github external
return function documentation (req, res, next) {
    Consolidate.handlebars(template, context, function renderCb (err, html) {
      if (err) {
        return next(err);
      }

      res.send(html);
    });
  };
}
github zhex / fe-dev-server / handlers / error-handler.js View on Github external
module.exports = function (err, req, res, next) {
	var tpl = path.resolve(__dirname, '../views/error.hbs');

	var data = {
		error: err,
		route: req._fds.route,
		method: req.method,
		query: req.query,
		match: req._fds.match,
		config: req._fds.config
	};

	cons.handlebars(tpl, data, function (err, html) {
		res.status(req._err || 500).send(html);
	});
};
github xtemplate / xtpl / benchmark / defer.js View on Github external
'fn': function (deferred) {
            consolidate.handlebars(path.join(__dirname, 'views/includes/handlebars.html'), getData(), function (err, html) {
                if (err) {
                    throw err;
                }
                deferred.resolve();
            });
        }
    });

consolidate

Modern and maintained fork of the template engine consolidation library. Maintained and supported by Forward Email <https://forwardemail.net>, the 100% open-source and privacy-focused email service.

MIT
Latest version published 4 months ago

Package Health Score

81 / 100
Full package analysis