Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 73f8112

Browse files
fix(doc-gen): correctly transform index files
Closes #3021
1 parent 71bc1b7 commit 73f8112

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

docs/spec/writerSpec.js

+32-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
1-
var writer = require('../src/writer.js');
1+
var writer,
2+
rewire = require('rewire');
3+
4+
function mockResolvedPromise(resolvedValue) {
5+
return {
6+
then: function(success, failure) {
7+
success(resolvedValue);
8+
}
9+
};
10+
}
11+
212
describe('writer', function() {
13+
14+
beforeEach(function() {
15+
writer = rewire('../src/writer.js');
16+
});
17+
318
describe('toString', function() {
4-
var toString = writer.toString;
19+
var toString;
20+
21+
beforeEach(function() {
22+
toString = writer.toString;
23+
});
524

625
it('should merge string', function() {
726
expect(toString('abc')).toEqual('abc');
@@ -31,4 +50,15 @@ describe('writer', function() {
3150
expect(content).toBe('ng super jqlite manifest');
3251
});
3352
});
53+
54+
describe('copy', function() {
55+
it('should call the transformation function', function() {
56+
var readMock = jasmine.createSpy('readMock').andReturn(mockResolvedPromise('DUMMY CONTENT'));
57+
writer.__set__("qfs.read", readMock);
58+
var transformationFn = jasmine.createSpy('transformationFn');
59+
writer.copy('from', 'to', transformationFn, 'arg1', 'arg2');
60+
expect(readMock).toHaveBeenCalled();
61+
expect(transformationFn).toHaveBeenCalledWith('DUMMY CONTENT', 'arg1', 'arg2');
62+
});
63+
});
3464
});

docs/src/writer.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,19 @@ exports.copyTemplate = function(filename) {
5151
* @param transform{function=} transfromation function to be applied before return
5252
*/
5353
exports.copy = function(from, to, transform) {
54+
var transformArgs = Array.prototype.slice.call(arguments, 3);
55+
5456
from = pathUtils.normalize(from);
5557
to = pathUtils.normalize(to);
5658

5759
// We have to use binary reading, Since some characters are unicode.
5860
return qfs.read(from, 'b').then(function(content) {
5961
if (transform) {
60-
content = transform.call(null, content.toString(), from, to, transform);
62+
// Pass any extra arguments, e.g.
63+
// `copy(from, to, transform, extra1, extra2, ...)`
64+
// to the transform function
65+
transformArgs.unshift(content.toString());
66+
content = transform.apply(null, transformArgs);
6167
}
6268
return output(to, content);
6369
});

0 commit comments

Comments
 (0)