[Pkg-javascript-commits] [node-jade] 10/72: feat(inputformats): Add inputFormats to JS Transformers

Jelmer Vernooij jelmer at moszumanska.debian.org
Sun Jul 3 18:03:24 UTC 2016


This is an automated email from the git hooks/post-receive script.

jelmer pushed a commit to annotated tag upstream/1.0.0
in repository node-jade.

commit d04a69a508c84c7066ee178f78566b7bc77048a6
Author: Rob Loach <robloach at gmail.com>
Date:   Sun Mar 1 00:29:20 2015 -0500

    feat(inputformats): Add inputFormats to JS Transformers
---
 README.md            |  9 +++++++++
 index.js             |  7 +++++++
 test/index.js        |  1 +
 test/input-format.js | 31 +++++++++++++++++++++++++++++++
 4 files changed, 48 insertions(+)

diff --git a/README.md b/README.md
index 2da534e..f149b9c 100644
--- a/README.md
+++ b/README.md
@@ -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
diff --git a/index.js b/index.js
index c095540..576d4b7 100644
--- a/index.js
+++ b/index.js
@@ -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];
+};
diff --git a/test/index.js b/test/index.js
index d7e7567..0fefd3d 100644
--- a/test/index.js
+++ b/test/index.js
@@ -38,3 +38,4 @@ require('./compile-file-client');
 require('./compile-file-client-async');
 require('./render');
 require('./render-async');
+require('./input-format');
diff --git a/test/input-format.js b/test/input-format.js
new file mode 100644
index 0000000..d2f836a
--- /dev/null
+++ b/test/input-format.js
@@ -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']);
+});

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-jade.git



More information about the Pkg-javascript-commits mailing list