0.5.4 • Published 5 years ago

barhandles v0.5.4

Weekly downloads
378
License
ISC
Repository
github
Last release
5 years ago

README

npm version Build Status

A proof of concept to check how hard it would be to extract variable references from Handlebars templates.

One Minute Overview

barhandles = require('barhandles');

barhandles.extract('{{foo.bar}}', callback);
// Callback will be invoked with ['foo', 'bar'], false

barhandles.extract('{{#with foo}}{{bar}}{{/with}}', callback);
// Callback will be invoked with ['foo', 'bar'], false

barhandles.extract('{{#each foo}}{{bar}}{{/each}}', callback);
// Callback will be invoked with ['foo', '#', 'bar'], false

barhandles.extract('{{#with foo}}{{#each bar}}{{../baz}}{{/each}}{{/with}}', callback);
// Callback will be invoked with ['foo','baz'], false

The second parameter passed to the callback is only present in version 0.4.0 and upwards. It indicates if the field is considered to be optional. Barhandles by default assumes everything is required. Only in case of conditional sections such as when using {{#if}}…{{/if}} it will mark attributs to be optional.

Barhandles also allows you to generate a hierarchical schema from your object model.

barhandlers.extractSchema('{{foo.bar}}');

will produce:

{
  "foo": {
    "_type": "object",
    "_optional": false,
    "bar": {
      "_type": "any",
      "_optional": false
    }
  }
}  

Change log

  • v0.4.3: Bug fixes
  • v0.4.1: Add support for adding behaviour of other directives
  • v0.4.0: Support for {{#if}} and optionals.
  • v0.3.0: Support for extracting a schema.
  • v0.2.0: Initial version
0.5.4

5 years ago

0.5.3

7 years ago

0.5.2

7 years ago

0.5.0

8 years ago

0.4.5

8 years ago

0.4.4

8 years ago

0.4.3

9 years ago

0.4.2

9 years ago

0.4.1

9 years ago

0.4.0

9 years ago

0.3.1

9 years ago

0.3.0

9 years ago

0.2.0

9 years ago

0.1.0

9 years ago