diff --git a/.gitignore b/.gitignore
index 5ad2150..f7764ba 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
.c9*
.settings
node_modules
+.idea
diff --git a/README.md b/README.md
index 60d1d52..e1f73b4 100644
--- a/README.md
+++ b/README.md
@@ -52,6 +52,24 @@ var worker = tidy.createWorker(opts);
request.get('http://www.nodejs.org').pipe(worker).pipe(process.stdout);
```
+[Task runner](https://github.com/modulejs/modjs) support
+--------------------------------------------------------
+
+```javascript
+// Modfile
+module.exports = {
+ plugins: {
+ htmltidy: 'htmltidy'
+ },
+ tasks: {
+ htmltidy: {
+ src: ['foo.html', 'bar.html'],
+ dest: 'output/'
+ }
+ }
+};
+```
+
Platform support
----------------
* Linux
diff --git a/examples/Modfile b/examples/Modfile
new file mode 100644
index 0000000..00e3a9b
--- /dev/null
+++ b/examples/Modfile
@@ -0,0 +1,11 @@
+module.exports = {
+ plugins: {
+ htmltidy: '../htmltidy'
+ },
+ tasks: {
+ htmltidy: {
+ src: 'input/*.html',
+ dest: 'output/'
+ }
+ }
+};
\ No newline at end of file
diff --git a/examples/input/bar.html b/examples/input/bar.html
new file mode 100644
index 0000000..8128e30
--- /dev/null
+++ b/examples/input/bar.html
@@ -0,0 +1,2 @@
+
bar
+| badly formatted html |
\ No newline at end of file
diff --git a/examples/input/foo.html b/examples/input/foo.html
new file mode 100644
index 0000000..0b48a4f
--- /dev/null
+++ b/examples/input/foo.html
@@ -0,0 +1,2 @@
+foo
+| badly formatted html |
\ No newline at end of file
diff --git a/htmltidy.js b/htmltidy.js
index 6e501da..85f3e75 100644
--- a/htmltidy.js
+++ b/htmltidy.js
@@ -194,5 +194,41 @@ function merge(obj1, obj2) {
return obj3;
}
+/**
+ * Task.JS API
+ * @param options
+ * @param done
+ * @see https://github.com/taskjs/spec
+ */
+function run(options, done){
+ var charset = options.charset;
+ var dest = options.dest;
+
+ delete options.src;
+ delete options.dest;
+ delete options.charset;
+
+ var async = exports.async;
+ var file = exports.file;
+
+ async.forEach(exports.files, function(inputFile, cb){
+ var outputFile = dest;
+ if(file.isFile(inputFile) && file.isDirFormat(dest)){
+ var filename = path.basename(inputFile);
+ outputFile = path.join(dest, filename);
+ }
+ var text = file.read(inputFile, charset);
+ tidy(text, options, function(err, html){
+ // output to file
+ if(html){
+ file.write(outputFile, html, charset);
+ exports.log(inputFile, '>', outputFile);
+ }
+ cb(err);
+ });
+ }, done);
+}
+
exports.createWorker = createWorker;
exports.tidy = tidy;
+exports.run = run;