Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

component-builder-handlebars

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

component-builder-handlebars - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

.editorconfig

75

index.js

@@ -1,1 +0,74 @@

module.exports = require('./lib/plugin');
'use strict';
var path = require('path');
var join = path.join;
var fs = require('fs');
var exists = fs.existsSync;
var read = fs.readFileSync;
var defaults = require('defaults');
var Handlebars = require('handlebars');
var partials = [];
var runtime = runtimeFile();
exports = module.exports = function(opts) {
opts = defaults(opts, {
extname: 'hbs',
partialRegex: /^_/
});
partials = [];
return function builderHandlebars(file, done) {
if (file.extension !== opts.extname) return done();
file.read(function(err, string) {
if (err) return done(err);
var filename = path.basename(file.path, '.' + file.extension);
var compiled = Handlebars.precompile(string);
var output = 'Handlebars.template(' + compiled + ')';
if (opts.partialRegex.test(filename)) {
// Register the partial as: moduleName/_fileName
output = 'Handlebars.registerPartial("'
+ file.branch.name + '/' + file.path.replace('.' + file.extension, '')
+ '", ' + output + ');\n';
partials.push(file.branch.canonical + '/' + file.path);
} else {
output = 'module.exports = ' + output;
}
file.string = output;
done();
});
};
};
exports.includeRuntime = function includeRuntime() {
var string = runtime;
string += 'this.Handlebars = window.Handlebars = Handlebars;\n';
if (!partials.length) return string;
// Auto requires partials.
partials.forEach(function(p) {
string += 'require("' + p + '");\n';
});
return string;
};
function runtimeFile() {
var runtimePath = join(__dirname, 'node_modules/handlebars/dist/handlebars.runtime.js');
if (!exists(runtimePath)) {
runtimePath = join(__dirname, 'handlebars.runtime.js');
}
return read(runtimePath, 'utf-8');
}

28

package.json
{
"name": "component-builder-handlebars",
"version": "0.3.0",
"version": "0.4.0",
"description": "Builder.js plugin to precompile Handlebars templates",
"author": "Antoine Lehurt <keuwah@gmail.com>",
"author": {
"name": "Antoine Lehurt",
"email": "hello@kewah.com",
"url": "http://kewah.com"
},
"main": "index.js",
"scripts": {
"test": "make test"
"test": "./node_modules/mocha/bin/mocha --reporter spec",
"watch": "./node_modules/mocha/bin/mocha --watch --reporter spec",
"example": "node ./example/builder.js && node ./example/server.js"
},

@@ -20,3 +26,3 @@ "repository": {

"component.js",
"builder",
"builder2",
"handlebars",

@@ -26,10 +32,12 @@ "precompile"

"dependencies": {
"handlebars": "~1.0.8"
"defaults": "^1.0.0",
"handlebars": "^1.3.0"
},
"devDependencies": {
"mocha": "~1.8.1",
"should": "~1.2.1",
"component-builder": "~0.12.0",
"jshint": "~0.9.1"
"component-builder": "^1.1.5",
"component-resolver": "^1.1.5",
"express": "^3.4.8",
"fs-extra": "^0.9.1",
"mocha": "*"
}
}
}

@@ -1,32 +0,44 @@

# component-builder-handlebars
# component-builder-handlebars [![Build Status](https://travis-ci.org/kewah/component-builder-handlebars.svg?branch=master)](https://travis-ci.org/kewah/component-builder-handlebars)
> [Builder.js](https://github.com/component/builder.js) plugin to precompile Handlebars templates to [Component.js](https://github.com/component/component) modules.
> [Builder2.js](https://github.com/component/builder2.js) plugin to precompile Handlebars templates to [Component.js](https://github.com/component/component) modules.
## Install
With [npm](http://npmjs.org) do:
```bash
$ npm install component-builder-handlebars --save-dev
```
## Usage
```javascript
var handlebarsPlugin = require('component-builder-handlebars');
var builder = new Builder('test/fixtures');
builder.use(handlebarsPlugin({
extname: '.hbs',
### Build
```js
var builder = require('component-builder');
var hbs = require('component-builder-handlebars');
var options = {
extname: 'hbs',
partialRegex: /^_/
}));
};
builder.scripts(tree)
.use('scripts', Builder.plugins.js())
.use('templates', hbs(options))
.end(function(err, string) {
fs.writeFileSync(dest, string);
});
```
Or with [grunt-component-build](https://github.com/anthonyshort/grunt-component-build):
```javascript
component: {
app: {
output: './build/',
scripts: true,
configure: function(builder) {
builder.use(handlebarsPlugin({
extname: '.hbs',
partialRegex: /^_/
}));
}
}
}
### Partials
To include a partial inside a template:
```html
{{> componentName/path/to/_partial }}
```
For [instance](test/fixture/with-partials/_nav.hbs).
## Options

@@ -47,38 +59,12 @@

```html
[componentName/path/to/_navPartial.hbs]
See [example](example) folder.
<nav>
<ul>
<li>…</li>
...
</ul>
</nav>
```
To build it:
```html
[componentName/path/to/myTemplate.hbs]
<h1>{{title}}</h1>
<!-- When you include a partial don't use the prefix -->
{{> componentName/path/to/navPartial}}
```bash
$ npm run example
```
```javascript
[componentName/path/to/module.js]
var myTpl = require('./myTemplate');
var output = myTpl({
title: 'Ready to start'
});
```
## Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.
## License
Copyright (c) 2013 Antoine Lehurt
Licensed under the MIT license.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc