Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nknapp/handlebars-source-locators
Puts source-position markers into the Handlebars output
https://github.com/nknapp/handlebars-source-locators
handlebars source-maps
Last synced: 20 days ago
JSON representation
Puts source-position markers into the Handlebars output
- Host: GitHub
- URL: https://github.com/nknapp/handlebars-source-locators
- Owner: nknapp
- License: mit
- Created: 2017-03-12T20:24:00.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-03-16T20:13:09.000Z (over 7 years ago)
- Last Synced: 2024-10-14T20:01:52.065Z (about 1 month ago)
- Topics: handlebars, source-maps
- Language: JavaScript
- Size: 16.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# handlebars-source-locators
[![NPM version](https://badge.fury.io/js/handlebars-source-locators.svg)](http://badge.fury.io/js/handlebars-source-locators)
[![Travis Build Status](https://travis-ci.org/nknapp/handlebars-source-locators.svg?branch=master)](https://travis-ci.org/nknapp/handlebars-source-locators)
[![Coverage Status](https://img.shields.io/coveralls/nknapp/handlebars-source-locators.svg)](https://coveralls.io/r/nknapp/handlebars-source-locators)> Puts source-position markers into the Handlebars output
# Installation
```
npm install handlebars-source-locators
```
## UsageThe following example demonstrates how to use this module:
```js
const Handlebars = require('handlebars')
const addSourceLocators = require('handlebars-source-locators')// Create a new Handlebars environment and add source-locators
const hbs = addSourceLocators(Handlebars.create())hbs.registerPartial('info', `
Name: {{name}}
City: {{city}}
`)hbs.registerPartial('hobbies', `
{{#each hobbies}}
- {{.}}
{{/each}}
`)const template = hbs.compile(`
Info:
-----
{{> info}}Hobbies:
-----
{{> hobbies}}
`)console.log(template({
name: 'Nils Knappmeier',
city: 'Darmstadt',
hobbies: [
'Aikido',
'Programming',
'Theater',
'Music'
]
}))
```This will generate the following output
```
Info:
-----Name: Nils Knappmeier
City: DarmstadtHobbies:
------ Aikido
- Programming
- Theater
- Music```
## API-reference
## addSourceLocators(handlebarsEnvironment)
Adds source-locators to a Handlebars-environment. The template-output
will include tags of the form ``The meaning is that the output directly after this tag originates from the
line/column in the tag. If the "partial" is not set, the output originates from the
main-template.The "line"-property is based off 1. The "col"-property is based off 0.
This is consistent with the output of the "Handlebars.parse()"-function.**Kind**: global function
**Throws**:- Error if `handlebarsEnvironment` is the default Handlebars-environment.
Please use "Handlebars.create" to create a new environment and pass that to this function.
The default instance may be used in many places of the dependency tree. Modifying it may
cause unexpected behavior in other libraries that seem not connected to this one at all.**Access:** public
| Param | Type | Description |
| --- | --- | --- |
| handlebarsEnvironment |Handlebars
| the Handlebars environment to modify |## License
`handlebars-source-locators` is published under the MIT-license.
See [LICENSE.md](LICENSE.md) for details.## Release-Notes
For release notes, see [CHANGELOG.md](CHANGELOG.md)
## Contributing guidelinesSee [CONTRIBUTING.md](CONTRIBUTING.md).