Add .to('text/plain/expanded', cb) support and convert ifeq to use it

Change-Id: I99c78de12fed41ba36811402f7ecacb420391d70
This commit is contained in:
Gabriel Wicke 2012-04-27 12:18:30 +02:00
parent 30a83d7fd7
commit fd1a67aa16
2 changed files with 21 additions and 4 deletions

View file

@ -72,7 +72,7 @@ ParserFunctions.prototype._switchLookupFallback = function ( kvs, key, dict, cb,
} else if ( kv.v.constructor === String ) {
if ( kv.v.trim() !== key ) {
// Shortcut
continue
continue;
} else {
return this._switchLookupFallback( kvs.slice(i), key, dict, cb, kv.v );
}
@ -119,14 +119,25 @@ ParserFunctions.prototype['pf_#ifeq'] = function ( token, frame, cb, args ) {
if ( args.length < 3 ) {
cb( {} );
} else {
if ( args[0].k.trim() === this.env.tokensToString( args[1].v ).trim() ) {
cb( { tokens: ( args[2] && this._rejoinKV( args[2] ) || [] ) } );
var b = args[1].v;
if ( b.constructor === String ) {
this._ifeq_worker( cb, args, b );
} else {
cb( { tokens: ( args[3] && this._rejoinKV( args[3] ) || [] ) } );
cb( {async: true} );
args[1].v.to('text/plain/expanded', this._ifeq_worker.bind( this, cb, args ) );
}
}
};
ParserFunctions.prototype._ifeq_worker = function ( cb, args, b ) {
if ( args[0].k.trim() === b.trim() ) {
cb( { tokens: ( args[2] && this._rejoinKV( args[2] ) || [] ) } );
} else {
cb( { tokens: ( args[3] && this._rejoinKV( args[3] ) || [] ) } );
}
};
ParserFunctions.prototype['pf_#expr'] = function ( token, frame, cb, args ) {
var res,
target = args[0].k;

View file

@ -1109,6 +1109,12 @@ Frame.prototype._convertThunk = function ( chunk, format, cb ) {
pipeline.addListener( 'end',
this.onThunkEvent.bind( this, cacheIt, accum, false, cb ) );
pipeline.process( chunk.concat( [new EOFTk()] ), this.title );
} else if ( format === 'text/plain/expanded' ) {
// expand, and then convert to string
var self = this;
chunk.to('tokens/x-mediawiki/expanded', function( chunk ) {
cb( self.manager.env.tokensToString( chunk ) );
});
} else {
throw "Frame._convertThunk: Unsupported format " + format;
}