Giter Club home page Giter Club logo

express-dust's Introduction

Dust Template Engine for ExpressJS

This express module allows you to use Dust as your template engine.

Install

npm install express-dust

Async Rendering

Express does not support async rendering, so with this module installed you will only be able to use Dust as your renderer in your app. We have to override the render/partial methods on the prototype of the ServerResponse object in order to support the async nature of Dust.

If the callback is ommitted to render/partial the response will automatically be passed to res.send when the Dust operation is completed.

Usage

There is a simple example included in this repo under ./examples.

server.js

var app = require('express').createServer();
var dust = require('../lib/dust');

//Sets up Global Variables to be used in all views
dust.makeBase({
    copy: '© 2011 Nobody LLC'
});

app.get('/', function(req, res, next) {
    res.render('index', {
        //Local Variables for this view
        title: 'This is a test'
    });
});

app.listen(8000);

views/layouts/main.dust

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>{+title}My Site{/title}</title>
</head>
<body>
{>"partials/nav"/}

{+html_body}
{/html_body}
<div id="footer">{+copy}Copyright{/copy}</footer>
</body>
</html>

views/index.dust

{>"layouts/main"/}

{<title}Foo {title}{/title}


{<html_body}
    <p>This is my index.dust main body {title}</p>
{/html_body}

{<copy}{copy|s}{/copy}

express-dust's People

Contributors

davglass avatar swider avatar stonecobra avatar

Stargazers

Oris Alicia Apolayo Campos avatar satyendra gupta avatar Erik Henrique avatar  avatar Royce Aquino avatar Yuske Fukuyama avatar José Salgado avatar Suvi-Tuuli Allan avatar  avatar Zuriel Barron avatar wei yan avatar node-migrator-bot avatar Peter Marton avatar Hannes Landstedt avatar  avatar Gary Cheeseman avatar Sheng-Ho Yuan avatar Joshua Chaitin-Pollak avatar

Watchers

 avatar James Cloos avatar

Forkers

nelsonic

express-dust's Issues

Not supported

When installing I get this error:

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\Gilbert>cd webstormprojects/maths4me

C:\Users\Gilbert\WebstormProjects\maths4me>npm install express-dust
npm http GET http://85.10.209.91/express-dust
npm http 200 http://85.10.209.91/express-dust
npm ERR! notsup Unsupported
npm ERR! notsup Not compatible with your operating system or architecture: expre
[email protected]
npm ERR! notsup Valid OS:    darwin,linux
npm ERR! notsup Valid Arch:  any
npm ERR! notsup Actual OS:   win32
npm ERR! notsup Actual Arch: ia32

npm ERR! System Windows_NT 6.1.7601
npm ERR! command "C:\\Program Files (x86)\\nodejs\\\\node.exe" "C:\\Program File
s (x86)\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "express-dust"
npm ERR! cwd C:\Users\Gilbert\WebstormProjects\maths4me
npm ERR! node -v v0.8.1
npm ERR! npm -v 1.1.33
npm ERR! code EBADPLATFORM
npm ERR! message Unsupported
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     C:\Users\Gilbert\WebstormProjects\maths4me\npm-debug.log
npm ERR! not ok code 0

C:\Users\Gilbert\WebstormProjects\maths4me>

/examples/server.js does not work. :-(

Hi Nick,
When was the last time you tried to run /examples/server.js

I just tried node /examples/server.js and got the following warning:

Warning: express.createServer() is deprecated, express
applications no longer inherit from http.Server,
please use:

  var express = require("express");
  var app = express();

I made that basic change to ./example/server.js and then I get the following error:

App listening at: http://localhost:8000/
Error: No default engine was specified and no extension was provided.

see: https://github.com/nelsonic/express-dust/blob/master/examples/server2.js

Added the line:

app.set('view engine', 'dust');

now I get:

Error: Cannot find module 'dust'

Tried changing the line to:

app.set('view engine', dust);

and get:

Error: Cannot find module '[object Object]'

Any chance you can update this so new people can learn/use your module?
or if you are no longer using this module yourself, what are you using?
Thanks.

Fix for Dust path evaluation when used with Express >=2.5.9

Originally opened by @totherik against davglass/express-dust with a proposed fix

It may be broken in earlier versions, too, but in Express 2.5.9 res.locals isn't an object reference, but instead a getter. The action of pushing the getter method onto the context created a subtle bug where standard replacements worked, but paths did not. e.g. {foo} works, {foo.bar} fails.

The suggested fix should be backward compatible.

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.