Added utility method to process content in pipeline.

* This eliminates repetitive code from a few places and might be
  useful for future patches as well.

Change-Id: I383ed253a2fa20c1b7429689d17cde176751e29a
This commit is contained in:
Subramanya Sastry 2013-09-30 12:37:07 -05:00
parent d6fb0fabb6
commit bd680c2e64

View file

@ -13,6 +13,7 @@ var Util = require( './mediawiki.Util.js' ).Util,
// define some constructor shortcuts
var KV = defines.KV,
EOFTk = defines.EOFTk,
SelfclosingTagTk = defines.SelfclosingTagTk;
// FIXME: Move out to some common helper file?
@ -44,31 +45,18 @@ function processExtSource(manager, extToken, opts) {
// Pass an async signal since the ext-content is not processed completely.
opts.parentCB({tokens: opts.res, async: true});
// Pipeline for processing ext-content
var pipeline = manager.pipeFactory.getPipeline(
opts.pipelineType,
Util.extendProps({}, opts.pipelineOpts, {
wrapTemplates: true
})
);
// Wrap templates always
opts.pipelineOpts = Util.extendProps({}, opts.pipelineOpts, { wrapTemplates: true });
// Set source offsets for this pipeline's content
var tsr = extToken.dataAttribs.tsr;
pipeline.setSourceOffsets(tsr[0]+tagWidths[0]+leadingWS.length, tsr[1]-tagWidths[1]);
opts.srcOffsets = [ tsr[0]+tagWidths[0]+leadingWS.length, tsr[1]-tagWidths[1] ];
// Set up provided callbacks
if (opts.chunkCB) {
pipeline.addListener('chunk', opts.chunkCB);
}
if (opts.endCB) {
pipeline.addListener('end', opts.endCB);
}
if (opts.documentCB) {
pipeline.addListener('document', opts.documentCB);
}
// Off the starting block ... ready, set, go!
pipeline.process(content);
// Process ref content
Util.processContentInPipeline(
manager,
content.concat([new EOFTk()]),
opts
);
}
}