-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from g10/feature/haml-coffee-option
Feature: haml coffee option
- Loading branch information
Showing
5 changed files
with
100 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": { | ||
|
@@ -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" | ||
|
@@ -27,6 +29,10 @@ | |
{ | ||
"name": "Marian Ondrasak", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Giovanni Carnel", | ||
"email": "[email protected]" | ||
} | ||
] | ||
} |