Socket
Book a DemoInstallSign in
Socket

anyfetch-handlebars

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

anyfetch-handlebars

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

1.0.7
latest
Source
npmnpm
Version published
Weekly downloads
2
-50%
Maintainers
2
Weekly downloads
 
Created
Source

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.

Keywords

anyfetch

FAQs

Package last updated on 19 Feb 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.