Git Product home page Git Product logo

dustjs-onload-context's Introduction

dustjs-onload-context extends dustjs to support dust.onLoad callbacks which accept the current rendering context as the second parameter. This can be useful when it's necessary to resolve templates based on state in the render context.

Build Status

Example

'use strict';

var dust = require('dustjs-linkedin'),
    contextify = require('dustjs-onload-context');

var undo = contextify(dust);
dust.onLoad = function (name, context, cb) {
    var str;

    // context.get('foo');
    // do stuff ...

    cb(null, str);
};

NOTE: The dustjs-linkedin module is required, but is not an explicit dependency of this module.

Usage

To enable support for the context argument, simply require dustjs-onload-context and invoke the exported function (which will decorate dustjs). Then, you can assign a function which accepts three arguments to the onLoad dust property. Functions assigned to onLoad which only accept 2 arguments are considered a noop and are treated the same as the original dust onLoad API.

To revert dust back to its original functional, this module returns a function once invoked. Invoking this function will revert dust and onLoad to their original behavior.

var contextify = require('dustjs-onload-context');
contextify(dust, [onload]); // See below for supported options

Options

  • dust (Object) the dustjs module to be decorated

  • onload (Function, optional) Provides an alternate onLoad implementation to use instead of dust.onLoad. This could be useful for scenarios in which one wants to intercept calls to the default onLoad behavior, modify context and delegate to the default onLoad defined elsewhere in the application.

Tests

$ npm test

Coverage

$ npm run-script cover && open coverage/lcov-report/index.html
```

dustjs-onload-context's People

Contributors

pvenkatakrishnan avatar tlivings avatar totherik avatar

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.