Skip to content

Commit

Permalink
feat(inputformats): Add inputFormats to JS Transformers
Browse files Browse the repository at this point in the history
  • Loading branch information
RobLoach committed Mar 1, 2015
1 parent 5a6e5cd commit d04a69a
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ _requires the underlying transform to implement `.renderFileAsync`, `.renderFile

Transform a file asynchronously. If a callback is provided, it is called as `callback(err, data)`, otherwise a Promise is returned.

### `.inputFormats`

```js
var formats = transformer.inputFormats();
=> ['md', 'markdown']
```

Returns an array of strings representing potential input formats for the transform. If not provided directly by the transform, results in an array containing the name of the transform.

## License

MIT
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,10 @@ Transformer.prototype.renderFileAsync = function (filename, options, locals, cb)
}.bind(this)), cb);
}
};

/**
* inputFormats
*/
Transformer.prototype.inputFormats = function() {
return this._tr.inputFormats || [this._tr.name];
};
1 change: 1 addition & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ require('./compile-file-client');
require('./compile-file-client-async');
require('./render');
require('./render-async');
require('./input-format');
31 changes: 31 additions & 0 deletions test/input-format.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

var assert = require('assert');
var test = require('./test');
var createTransformer = require('../');

test('inputFormats - with tr.inputFormats', function (override) {
var tr = createTransformer({
name: 'test',
outputFormat: 'html',
inputFormats: [
'html',
'htm'
],
render: function (str, options) {
return str;
}
});
assert.deepEqual(tr.inputFormats(), ['html', 'htm']);
});

test('inputFormats - without tr.inputFormats', function (override) {
var tr = createTransformer({
name: 'test',
outputFormat: 'html',
render: function (str, options) {
return str;
}
});
assert.deepEqual(tr.inputFormats(), ['test']);
});

0 comments on commit d04a69a

Please sign in to comment.