Skip to content

Commit

Permalink
Add initial implementation, based on last version in Broccoli core
Browse files Browse the repository at this point in the history
  • Loading branch information
joliss committed Dec 27, 2013
1 parent 6b8bd81 commit 1c4e311
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2013 Jo Liss

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# broccoli-coffee

A CoffeeScript preprocessor for Broccoli.

## Usage

```js
var CoffeeScriptPreprocessor = require('broccoli-coffee')(broccoli);
preprocessorPipeline.addPreprocessor(new CoffeeScriptPreprocessor);
```

### Options

#### bare

If `bare` is true, the CoffeeScript compiler will not emit a top-level
function wrapper:

```js
new CoffeeScriptPreprocessor({
bare: true
})
```
30 changes: 30 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module.exports = function (broccoli) {
CoffeeScriptPreprocessor.prototype = Object.create(broccoli.Preprocessor.prototype)
CoffeeScriptPreprocessor.prototype.constructor = CoffeeScriptPreprocessor
function CoffeeScriptPreprocessor (options) {
this.options = options || {}
}

CoffeeScriptPreprocessor.prototype.extensions = ['coffee']
CoffeeScriptPreprocessor.prototype.targetExtension = 'js'

CoffeeScriptPreprocessor.prototype.processString = function (string, info, callback) {
// We must be careful to create a fresh options hash every time.
// https://github.com/jashkenas/coffee-script/issues/1924#issuecomment-28157026
var options = {
bare: this.options.bare
}
var output
try {
output = require('coffee-script').compile(string, options)
} catch (err) {
err.line = err.location && err.location.first_line
err.column = err.location && err.location.first_column
callback(err)
return
}
callback(null, output)
}

return CoffeeScriptPreprocessor
}
15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "broccoli-coffee",
"description": "CoffeeScript preprocessor for Broccoli",
"version": "0.0.1",
"author": "Jo Liss <[email protected]>",
"main": "index.js",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/joliss/broccoli-coffee"
},
"dependencies": {
"coffee-script": "~1.6.3"
}
}

0 comments on commit 1c4e311

Please sign in to comment.