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 // define some constructor shortcuts
var KV = defines.KV, var KV = defines.KV,
EOFTk = defines.EOFTk,
SelfclosingTagTk = defines.SelfclosingTagTk; SelfclosingTagTk = defines.SelfclosingTagTk;
// FIXME: Move out to some common helper file? // 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. // Pass an async signal since the ext-content is not processed completely.
opts.parentCB({tokens: opts.res, async: true}); opts.parentCB({tokens: opts.res, async: true});
// Pipeline for processing ext-content // Wrap templates always
var pipeline = manager.pipeFactory.getPipeline( opts.pipelineOpts = Util.extendProps({}, opts.pipelineOpts, { wrapTemplates: true });
opts.pipelineType,
Util.extendProps({}, opts.pipelineOpts, {
wrapTemplates: true
})
);
// Set source offsets for this pipeline's content
var tsr = extToken.dataAttribs.tsr; 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 // Process ref content
if (opts.chunkCB) { Util.processContentInPipeline(
pipeline.addListener('chunk', opts.chunkCB); manager,
} content.concat([new EOFTk()]),
if (opts.endCB) { opts
pipeline.addListener('end', opts.endCB); );
}
if (opts.documentCB) {
pipeline.addListener('document', opts.documentCB);
}
// Off the starting block ... ready, set, go!
pipeline.process(content);
} }
} }