anyfetch-handlebars
> Visit http://anyfetch.com for details about AnyFetch.
Last updated 5 years ago by matthieu.bacconnier .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install anyfetch-handlebars 
SYNC missed versions from official npm registry.

Anyfetch-Handlebars

Visit http://anyfetch.com for details about AnyFetch.

Inject new helpers in handlebars.

How to install?

npm install

Check everything is working with npm test.

How to use it

var hbs = require('anyfetch-handlebars');
hbs.loadAnyfetchHelpers(/* Your context */);

Example

var hbs = require('anyfetch-handlebars');

// An example of context
var rawDocument = {
  data: {
    text: 'Test of document'
  },
  metadata: {
    path: '/test/document.txt'
  },
  highlight: {}
};

hbs.loadAnyfetchHelpers(rawDocument);

var compiled = hbs.compile("{ \
  \"title\": \
    {{#if metadata.title}} \
      \"{{attr 'title'}}\" \
    {{else}} \
      {{#if metadata.path}} \
        \"{{extractFilename metadata.path}}\" \
      {{else}} \
        \"Unknown document: no path.\" \
      {{/if}} \
    {{/if~}}, \
  \"path\": \"{{attr 'path'}}\", \
  \"snippet\": \"{{#trim .}}{{shortAttr 'text'}}{{/trim}}\" \
}");

var json = compiled(rawDocument);

// Beautify JSON
json = JSON.stringify(JSON.parse(json), null, 4);

This results in:

{
  "title": "document",
  "path": "/test/document.txt",
  "snippet": "Test of document"
}

Contributing to anyfetch-handlebars

This repo is used extensively by AnyFetch. If your document-type needs a custom handlebars helper, you're welcome to fork. See Contributing for details.

master

Support: support@anyfetch.com.

Current Tags

  • 1.0.7                                ...           latest (5 years ago)

8 Versions

  • 1.0.7                                ...           5 years ago
  • 1.0.6                                ...           5 years ago
  • 1.0.5                                ...           5 years ago
  • 1.0.4                                ...           5 years ago
  • 1.0.3                                ...           5 years ago
  • 1.0.2                                ...           5 years ago
  • 1.0.1                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (6)
Dev Dependencies (4)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |