helper-resolve
Template helper to resolve the path to a file in node_modules. This is mostly useful during development.
Last updated 5 years ago by jonschlinkert .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install helper-resolve 
SYNC missed versions from official npm registry.

helper-resolve NPM version Build Status

Template helper to resolve the path to a file in node_modules. This is mostly useful during development.

Refactored to return an object, so the results of the helper can be passed to other helpers that require more information.

Install with npm

npm i helper-resolve --save

Usage

var resolve = require('helper-resolve');
var Handlebars = require('handlebars');

handlebars.registerHelper('resolve', function (name, key) {
  return resolve.sync(fp)[typeof key === 'string' ? key : 'main'];
});
handlebars.compile('<script src=\"{{resolve "jquery" "main"}}\"></script>')().
//=> '<script src="node_modules/jquery/dist/jquery.js"></script>'

handlebars.compile('{{resolve "jquery" "homepage"}}')().
//=> 'http://jquery.com'

Assemble example

Register the helper with assemble v0.6.x to use with any template engine:

var assemble = require('assemble');
assemble.helper('resolve', function (name, key) {
  return resolve.sync(fp)[typeof key === 'string' ? key : 'main'];
});

async helper

assemble.asyncHelper('resolve', function (name, key, cb) {
  if (typeof key === 'function') {
    cb = key;
    key = 'main';
  }

  resolve(name, function (err, res) {
    cb(null, res[key]);
  });
});

Run tests

Install dev dependencies:

npm i -d && npm test

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue

Author

Jon Schlinkert

License

Copyright (c) 2015 Jon Schlinkert
Released under the MIT license


This file was generated by verb-cli on April 19, 2015.

Current Tags

  • 0.3.1                                ...           latest (5 years ago)

6 Versions

  • 0.3.1                                ...           5 years ago
  • 0.3.0                                ...           5 years ago
  • 0.2.0                                ...           6 years ago
  • 0.1.2                                ...           6 years ago
  • 0.1.1                                ...           6 years ago
  • 0.1.0                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 58
This Month 122
Last Day 0
Last Week 30
Last Month 98
Dependencies (3)
Dev Dependencies (6)

Copyright 2014 - 2017 © taobao.org |