Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
maxparm committed Jan 13, 2015
2 parents ed923aa + 0fa28e7 commit b85b61e
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 17 deletions.
53 changes: 45 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# node-underscorify

Underscore precompiler plugin for Browserify v2.
Underscore precompiler plugin for Browserify.

Inspired and based on [node-hbsfy](https://github.com/epeli/node-hbsfy)

Expand All @@ -14,9 +14,52 @@ Then use the node-underscorify within the browserify command line transform opti

`browserify -t node-underscorify main.js > bundle.js`

Or add the transform to your `package.json`:

```json
{
"browserify": {
"transform": ["node-underscorify"]
}
}
```

### Custom options

You can configure underscorify via command line options, `package.json` or Javascript API.

On the command line:

```
browserify -t [ node-underscorify --extensions ejs ] main.js > bundle.js
browserify -t [ node-underscorify --extensions html,ejs ] main.js > bundle.js
```

Or in `package.json`:

```json
{
"browserify": {
"transform": [
["node-underscorify", {
"extensions": ["jst", "ejs"],
"requires": [{"variable": "_", "module": "underscore"}]
}]
]
}
}
```

### Accepted options

- `extensions`: array of file extensions that will be considered as underscore
templates
- `templateSettings`: underscore [template settings](http://underscorejs.org/#template)
- `requires`: array of modules to import. Example: `requires:[{variable: '_', module: 'underscore'}]`

### Advanced setup thru API

node-underscorify can accept custom options unsing browserify API:
node-underscorify can accept custom options using browserify API:

```js
var b = require('browserify')();
Expand All @@ -30,12 +73,6 @@ b.add('./browser/main.js');
b.bundle().pipe(process.stdout);
```

Accepted options:
- `extensions`: array of file extensions that will be considered as underscore
templates
- `templateSettings`: underscore [template settings](http://underscorejs.org/#template)
- `requires`: array of modules to import. Example: `requires:[{variable: '_', module: 'underscore'}]`

## Usage

##### template.html
Expand Down
10 changes: 7 additions & 3 deletions index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ defaultOptions =
htmlMinifier: false
requires: []

transform = (options) ->
options = _.defaults(options || {}, defaultOptions)
transform = (instance_opts) ->
instance_opts = _.defaults(instance_opts || {}, defaultOptions)

return (file, opts) ->
if typeof(opts['extensions']) is 'string'
opts['extensions'] = opts['extensions'].split ','
options = _.defaults(opts || {}, instance_opts)

return (file) ->
isTemplate = _.some options.extensions, (ext) ->
path.extname(file) is '.'+ext

Expand Down
14 changes: 9 additions & 5 deletions index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-underscorify",
"version": "0.0.13",
"version": "0.0.14",
"description": "Underscore precompiler plugin for Browserify v2",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit b85b61e

Please sign in to comment.