Skip to content

Commit

Permalink
Merge pull request #2 from g10/feature/haml-coffee-option
Browse files Browse the repository at this point in the history
Feature: haml coffee option
  • Loading branch information
ondrasak committed Aug 11, 2014
2 parents de06433 + c6f78ee commit c898be0
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 10 deletions.
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# OSX
.DS_Store


#
# IDE
#

# Eclipse
.classpath
.project
.settings/

# IntelliJ
*.iml
.idea/

# Sublime Text
*.sublime-project
*.sublime-workspace
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.*
34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ karma-preprocessor-haml
=======================
> A Karma preprocessor that Compile haml script to html.
**Supports [haml-js][] and [haml-coffee][] as language compilers**

[haml-coffee]: https://github.com/netzpirat/haml-coffee
[haml-js]: https://github.com/creationix/haml-js

## Installation

The easiest way is to keep `karma-haml-preprocessor` as a devDependency in your `package.json`.
```json
{
"devDependencies": {
"karma-haml-preprocessor": "~0.1"
"karma-haml-preprocessor": "~0.2"
}
}
```
Expand All @@ -32,3 +37,30 @@ module.exports = function(config) {
});
};
```

### Options


```js
// karma.conf.js
module.exports = function(config) {
config.set({
...
hamlPreprocessor: {
options: {
language: 'coffee'
}
}
});
};
```


#### language

Type: `string`
Default: `js`
Accepted values: `js`, `coffee`

Specifies the script language and compiler to use alongside HAML.
`js` will use [haml-js][], `coffee` uses [haml-coffee][]
43 changes: 37 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,50 @@
var haml = require('haml');

var createHamlPreprocessor = function(args, config, logger, helper) {
config = config || {};
var log = logger.create('preprocessor.haml');

var defaultOptions = {
language: 'js'
};
var options = helper.merge(defaultOptions, args.options || {}, config.options || {});

//

var transpileJS = function(content, file, done) {
var haml = require('haml');

var compiled = haml.compile(content);
done(eval(compiled));
};

var transpileCoffee = function(content, file, done) {
var hamlc = require('haml-coffee');

var compiled = hamlc.compile(content)();
done(compiled);
};

//

return function(content, file, done) {
log.debug('Processing "%s".', file.originalPath);
var compiled = haml.compile(content);
done(eval(compiled))

switch(options.language) {
case 'js' :
transpileJS(content, file, done);
break;
case 'coffee' :
transpileCoffee(content, file, done);
break;
default :
log.error('Language "%s" is not a valid source language for the hamlPreprocessor. Available options are `js` and `coffee`.', options.language);
}

};
};

createHamlPreprocessor.$inject = ['args', 'config', 'logger', 'helper'];
createHamlPreprocessor.$inject = ['args', 'config.hamlPreprocessor', 'logger', 'helper'];

// PUBLISH DI MODULE
module.exports = {
'preprocessor:haml': ['factory', createHamlPreprocessor]
};
};
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "karma-haml-preprocessor",
"version": "0.1.0",
"version": "0.2.0",
"description": "A Karma plugin. Compile haml script to html",
"main": "index.js",
"repository": {
Expand All @@ -10,14 +10,16 @@
"keywords": [
"haml-plugin",
"haml-preprocessor",
"haml"
"haml",
"haml-coffee"
],
"author": {
"name": "subteca",
"email": "[email protected]"
},
"dependencies": {
"haml": "0.4.3"
"haml": "0.4.3",
"haml-coffee": "1.14.x"
},
"peerDependencies": {
"karma": ">=0.9"
Expand All @@ -27,6 +29,10 @@
{
"name": "Marian Ondrasak",
"email": "[email protected]"
},
{
"name": "Giovanni Carnel",
"email": "[email protected]"
}
]
}

0 comments on commit c898be0

Please sign in to comment.