Skip to content

Commit d51f8fb

Browse files
committed
add line and src to docObject returned by .code
1 parent 53b212e commit d51f8fb

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

lib/generators/html/build/make_helpers.md

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ every [documentjs.process.docObject docObject] keyed by its name.
99
@param {function():documentjs.process.docObject} getCurrent Returns the
1010
current [documentjs.process.docObject docObject] being rendered.
1111

12+
@param {documentjs.generators.html} helpers The default helpers object that
13+
the return value will be added to.
14+
15+
16+
1217
@return {Object<String,function>} A map of Handlebars function helpers
1318
that will be registered.
1419

lib/process/code.js

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ module.exports = function(options, callback){
3535
if(tag){
3636
docObject = tag.code(options.code, options.scope, options.docMap);
3737
}
38+
if(docObject && options.docObject) {
39+
_.defaults(docObject, options.docObject);
40+
}
3841
callback(docObject, docObject && tag.codeScope ? docObject : options.scope);
3942
};
4043

lib/process/process_test.js

+33
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ var process = require("./process"),
230230

231231
});
232232
});
233+
234+
233235

234236
var makeDescription = function( comment, cb ){
235237
var docMap = {Foo: {name: "Foo",type: "constructor"}},
@@ -426,5 +428,36 @@ var process = require("./process"),
426428
});
427429

428430
});
431+
432+
433+
it.only(".code keeps options.docObject's src and line", function(){
434+
var count = 0;
435+
tags.filetest = {
436+
add: function(line, curData, scope, docMap){
437+
this.type = "filetest";
438+
this.name ="filetest"+(++count);
439+
assert.ok(this.src,"a src");
440+
assert.equal(typeof this.line, "number","a line");
441+
},
442+
codeMatch: function( code ) {
443+
return true;
444+
},
445+
code: function( code, scope, docMap ) {
446+
return {
447+
type: "filetest"
448+
};
449+
}
450+
};
451+
452+
fs.readFile(path.join(__dirname,"test","filename_and_line.js"), function(err, data){
453+
if(err) {
454+
return done(err);
455+
}
456+
457+
var docMap = {};
458+
process.file(""+data,docMap,"utils/date-helpers.js");
459+
done();
460+
});
461+
});
429462

430463
});

0 commit comments

Comments
 (0)