Giter Club home page Giter Club logo

express-template-demo's People

Contributors

anthonyettinger avatar calvinf avatar chovy avatar kethinov avatar ralyodio avatar thefourtheye avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

express-template-demo's Issues

Add nunjucks example

Hey,

You can find code for integrating it here: http://nunjucks.jlongster.com/home#Express

It basically looks like this:

var nunjucks = require('nunjucks');
var express = require('express');

var env = new nunjucks.Environment(new nunjucks.FileSystemLoader('views'));
env.express(app);

You pass the path of your templates to the FileSystemLoader. You can ignore all the app.set("views") crap and other settings.

add swig example

var consolidate = require('consolidate'),
    swig = require('swig');

app.set('view engine', 'html');
app.set('views', __dirname + '/views');
app.engine('.html', consolidate.swig);

app.get('/test', function(req, res) {
    res.render('two');
});

/* Tell swig where to look for templates when one extends another. */
swig.init({ root: __dirname + '/views' });

npm install Failure

I don't know why but my computer (OS: Ubuntu 20.04 LTS) is hanging in the middle of npm install. I had to power-button-force-shutdown twice by now.

How to add custom helpers?

I would like to use DustJS in an expressJS application but I don't know how to add custom helpers to use in my templates.

From the DustJS docs I guess I need to implement code like this:

 dust.helpers.myHelper = function(chunk, context, bodies, params) {
      code of the helper
    }

My problem is when to apply this code.
I've read the consolidate.js code and found that they are caching dustJS module internally, so the helpers I add in my application are not available in the templates.
Code form consolidate:

exports.dust.render = function(str, options, fn){
  var engine = requires.dust;
  if (!engine) {
    try {
      engine = requires.dust = require('dust');
    } catch (err) {
      try {
        engine = requires.dust = require('dustjs-helpers');
      } catch (err) {
        engine = requires.dust = require('dustjs-linkedin');
      }
    }
  }

  var ext = 'dust'
    , views = '.';

  if (options) {
    if (options.ext) ext = options.ext;
    if (options.views) views = options.views;
    if (options.settings && options.settings.views) views = options.settings.views;
  }
  if (!options || (options && !options.cache)) engine.cache = {};

  engine.onLoad = function(path, callback){
    if ('' == extname(path)) path += '.' + ext;
    if ('/' !== path[0]) path = views + '/' + path;
    read(path, options, callback);
  };

  try {
    var tmpl = cache(options) || cache(options, engine.compileFn(str));
    tmpl(options, fn);
  } catch (err) {
    fn(err);
  }
};

So, how can I add custom helpers to dust in order for them to be available in templates?

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.