Subramanya Sastry has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/86692


Change subject: Added utility method to process content in pipeline.
......................................................................

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
---
M js/lib/ext.Cite.js
M js/lib/ext.core.TemplateHandler.js
M js/lib/mediawiki.Util.js
3 files changed, 72 insertions(+), 59 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Parsoid 
refs/changes/92/86692/1

diff --git a/js/lib/ext.Cite.js b/js/lib/ext.Cite.js
index d7deddc..9eb44b9 100644
--- a/js/lib/ext.Cite.js
+++ b/js/lib/ext.Cite.js
@@ -13,6 +13,7 @@
 
 // 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 @@
                // 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
+               );
        }
 }
 
diff --git a/js/lib/ext.core.TemplateHandler.js 
b/js/lib/ext.core.TemplateHandler.js
index c4c1e1a..0919b21 100644
--- a/js/lib/ext.core.TemplateHandler.js
+++ b/js/lib/ext.core.TemplateHandler.js
@@ -502,25 +502,23 @@
                src = '';
                //this.manager.env.errCB(err);
        }
-       // Pipeline for processing ext-content
-       var pipeline = this.manager.pipeFactory.getPipeline(
-                       // Full pipeline all the way to DOM
-                       'text/x-mediawiki/full',
-                       {
-                               isInclude: true,
-                               // we *might* be able to get away without this 
if we transfer
-                               // more than just the about when unwrapping
-                               wrapTemplates: false,
-                               // suppress paragraphs
-                               // Should this be the default in all cases?
-                               inBlockToken: true
-                       });
-       pipeline.setFrame( this.manager.frame, tplArgs.name, tplArgs.attribs );
-       state.tokenTarget = tplArgs.name;
 
-       pipeline.addListener('document', this._onDocument.bind(this, state, 
cb));
        this.manager.env.dp( 'TemplateHandler._startDocumentPipeline', 
tplArgs.name, tplArgs.attribs );
-       pipeline.process ( src, tplArgs.cacheKey );
+       Util.processContentInPipeline(this.manager, src,  {
+               // Full pipeline all the way to DOM
+               pipelineType: 'text/x-mediawiki/full',
+               pipelineOpts: {
+                       isInclude: true,
+                       // we *might* be able to get away without this if we 
transfer
+                       // more than just the about when unwrapping
+                       wrapTemplates: false,
+                       // suppress paragraphs
+                       // Should this be the default in all cases?
+                       inBlockToken: true
+               },
+               tplArgs: tplArgs,
+               documentCB: this._onDocument.bind(this, state, cb)
+       });
 };
 
 /**
@@ -551,29 +549,24 @@
                console.log( "---------------------------------");
        }
 
+       this.manager.env.dp( 'TemplateHandler._startTokenPipeline', 
tplArgs.name, tplArgs.attribs );
+
        // Get a nested transformation pipeline for the input type. The input
        // pipeline includes the tokenizer, synchronous stage-1 transforms for
        // 'text/wiki' input and asynchronous stage-2 transforms).
-       //
-       // NOTE: No template wrapping required for nested templates.
-       var pipelineOpts = {
-               inTemplate: true,
-               isInclude: true,
-               wrapTemplates: false,
-               extTag: this.options.extTag
-       };
-       var pipeline = this.manager.pipeFactory.getPipeline(
-               type || 'text/x-mediawiki', pipelineOpts
-       );
-
-       pipeline.setFrame( this.manager.frame, tplArgs.name, tplArgs.attribs );
-
-       // Hook up the inputPipeline output events to our handlers
-       pipeline.addListener( 'chunk', this._onChunk.bind ( this, state, cb ) );
-       pipeline.addListener( 'end', this._onEnd.bind ( this, state, cb ) );
-       // Feed the pipeline. XXX: Support different formats.
-       this.manager.env.dp( 'TemplateHandler._startTokenPipeline', 
tplArgs.name, tplArgs.attribs );
-       pipeline.process ( src, tplArgs.cacheKey );
+       Util.processContentInPipeline(this.manager, src, {
+               pipelineType: type || 'text/x-mediawiki',
+               pipelineOpts: {
+                       inTemplate: true,
+                       isInclude: true,
+                       // NOTE: No template wrapping required for nested 
templates.
+                       wrapTemplates: false,
+                       extTag: this.options.extTag
+               },
+               tplArgs: tplArgs,
+               chunkCB: this._onChunk.bind ( this, state, cb ),
+               endCB: this._onEnd.bind ( this, state, cb )
+       });
 };
 
 TemplateHandler.prototype.addAboutToTableElements = function ( state, tokens ) 
{
diff --git a/js/lib/mediawiki.Util.js b/js/lib/mediawiki.Util.js
index 192a5c7..bb51048 100644
--- a/js/lib/mediawiki.Util.js
+++ b/js/lib/mediawiki.Util.js
@@ -797,6 +797,38 @@
         }
     },
 
+       processContentInPipeline: function(manager, content, opts) {
+               // Build a pipeline
+               var pipeline = manager.pipeFactory.getPipeline(
+                       opts.pipelineType,
+                       opts.pipelineOpts
+               );
+
+               // Set frame if necessary
+               if (opts.tplArgs) {
+                       pipeline.setFrame(manager.frame, opts.tplArgs.name, 
opts.tplArgs.attribs);
+               }
+
+               // Set source offsets for this pipeline's content
+               if (opts.srcOffsets) {
+                       pipeline.setSourceOffsets(opts.srcOffsets[0], 
opts.srcOffsets[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, opts.tplArgs ? opts.tplArgs.cacheKey 
: undefined);
+       },
+
        extractExtBody: function(extName, extTagSrc) {
                var re = "<" + extName + "[^>]*/?>([\\s\\S]*)";
                return extTagSrc.replace(new RegExp(re, "mi"), function() {

-- 
To view, visit https://gerrit.wikimedia.org/r/86692
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I383ed253a2fa20c1b7429689d17cde176751e29a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Parsoid
Gerrit-Branch: master
Gerrit-Owner: Subramanya Sastry <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to