This package has been deprecated

Author message:

vulnurable and unmaintained

deface

0.0.1 • Public • Published

node-deface

node-deface is a port of https://github.com/spree/deface to node.js and express.

It allows developers to customize node.js HTML views without requiring partials or editing the underlying view.

You can use any template library. node-deface works by extending res.render to look up override scripts and apply them after template rendering.

Overrides use css selectors to find what to replace and use path to determine which view to apply to.

The text inside the override can be specified by whichever template library is passed to deface.override(app,template_library,folder) .

The interface for the template_libray object is:

engine.compile(body) which returns a function(options)

TODO

These need to be done before considering node-deface usable:

  • Add benchmarks to show differences in speed.
  • Add documentation of speed differences.
  • Add support for multiline strings (coffeescript can do this. We can make our overrides coffeescript and the rest plain node.js)
  • (COMPLETED) Replacement text in Deface.override isn't processed as template yet, only string (IMPORTANT for making this usable)
  • (COMPLETED) If you don't have an override for a specific view, the processing fails. (IMPORTANT for making this usable)
  • (COMPLETED) Overrides are loaded every request. They should only be loaded at startup. (IMPORTANT for speed)

Usage

overrides/index_override.js:

module.exports = function(Deface) {
    return Deface.override({
        path: "index", //view name without the file extension.
        replace: "[data-hook=...]", // any CSS selector.
        text: "<p>Title: {{title}}</p>" // any HTML text.
    })
}

views/index.html:

<div>
    <p>Welcome to deface. Title: {{title}}</p>
    <div data-hook="...">
        <p>This content will be overriden.</p>
    </div>
</div>

Express

app.js: var template_lib = require('any-template-library') var deface = require('deface')

app.configure(function(){
    ...
//attach deface middleware using folder name 'overrides'
    app.use(deface.override(app,template_lib,'overrides'))         
...
    app.use(app.router);
    ...
});

Readme

Keywords

none

Package Sidebar

Install

npm i deface

Weekly Downloads

2

Version

0.0.1

License

none

Last publish

Collaborators

  • npm