2012-02-01 17:03:08 +00:00
|
|
|
/**
|
|
|
|
* Constructors for different token types. Plain text is represented as simple
|
|
|
|
* strings or String objects (if attributes are needed).
|
|
|
|
*/
|
2012-02-13 17:02:23 +00:00
|
|
|
|
2012-03-13 12:32:31 +00:00
|
|
|
var toString = function() { return JSON.stringify( this ); };
|
2012-02-13 17:02:23 +00:00
|
|
|
|
2012-03-13 12:32:31 +00:00
|
|
|
function TagTk( name, attribs, dataAttribs ) {
|
2012-02-01 18:37:48 +00:00
|
|
|
//this.type = 'TAG';
|
2012-02-01 17:03:08 +00:00
|
|
|
this.name = name;
|
|
|
|
this.attribs = attribs || [];
|
2012-03-13 12:32:31 +00:00
|
|
|
this.dataAttribs = dataAttribs || {};
|
2012-02-01 17:03:08 +00:00
|
|
|
}
|
2012-03-13 12:32:31 +00:00
|
|
|
TagTk.prototype = {};
|
2012-02-03 13:09:01 +00:00
|
|
|
TagTk.prototype.toJSON = function () {
|
2012-02-06 19:12:29 +00:00
|
|
|
return $.extend( { type: 'TagTk' }, this );
|
2012-02-03 13:09:01 +00:00
|
|
|
};
|
2012-02-13 17:02:23 +00:00
|
|
|
TagTk.prototype.constructor = TagTk;
|
|
|
|
TagTk.prototype.toString = toString;
|
2012-02-03 13:09:01 +00:00
|
|
|
|
2012-03-13 12:32:31 +00:00
|
|
|
function EndTagTk( name, attribs, dataAttribs ) {
|
2012-02-01 17:03:08 +00:00
|
|
|
this.name = name;
|
|
|
|
this.attribs = attribs || [];
|
2012-03-13 12:32:31 +00:00
|
|
|
this.dataAttribs = dataAttribs || {};
|
2012-02-01 17:03:08 +00:00
|
|
|
}
|
2012-03-13 12:32:31 +00:00
|
|
|
EndTagTk.prototype = {};
|
2012-02-03 13:09:01 +00:00
|
|
|
EndTagTk.prototype.toJSON = function () {
|
2012-02-06 19:12:29 +00:00
|
|
|
return $.extend( { type: 'EndTagTk' }, this );
|
2012-02-03 13:09:01 +00:00
|
|
|
};
|
2012-02-13 17:02:23 +00:00
|
|
|
EndTagTk.prototype.constructor = EndTagTk;
|
|
|
|
EndTagTk.prototype.toString = toString;
|
2012-02-03 13:09:01 +00:00
|
|
|
|
2012-03-13 12:32:31 +00:00
|
|
|
function SelfclosingTagTk( name, attribs, dataAttribs ) {
|
2012-02-01 18:37:48 +00:00
|
|
|
//this.type = 'SELFCLOSINGTAG';
|
2012-02-01 17:03:08 +00:00
|
|
|
this.name = name;
|
|
|
|
this.attribs = attribs || [];
|
2012-03-13 12:32:31 +00:00
|
|
|
this.dataAttribs = dataAttribs || {};
|
2012-02-01 17:03:08 +00:00
|
|
|
}
|
2012-03-13 12:32:31 +00:00
|
|
|
SelfclosingTagTk.prototype = {};
|
2012-02-03 13:09:01 +00:00
|
|
|
SelfclosingTagTk.prototype.toJSON = function () {
|
2012-02-06 19:12:29 +00:00
|
|
|
return $.extend( { type: 'SelfclosingTagTk' }, this );
|
2012-02-03 13:09:01 +00:00
|
|
|
};
|
2012-02-13 17:02:23 +00:00
|
|
|
SelfclosingTagTk.prototype.constructor = SelfclosingTagTk;
|
|
|
|
SelfclosingTagTk.prototype.toString = toString;
|
2012-02-03 13:09:01 +00:00
|
|
|
|
2012-02-01 17:03:08 +00:00
|
|
|
function NlTk( ) {
|
|
|
|
//this.type = 'NEWLINE';
|
|
|
|
}
|
2012-03-13 12:32:31 +00:00
|
|
|
NlTk.prototype = {};
|
2012-02-03 13:09:01 +00:00
|
|
|
NlTk.prototype.toJSON = function () {
|
2012-02-06 19:12:29 +00:00
|
|
|
return $.extend( { type: 'NlTk' }, this );
|
2012-02-03 13:09:01 +00:00
|
|
|
};
|
2012-02-13 17:02:23 +00:00
|
|
|
NlTk.prototype.constructor = NlTk;
|
|
|
|
NlTk.prototype.toString = toString;
|
2012-02-03 13:09:01 +00:00
|
|
|
|
2012-02-01 17:03:08 +00:00
|
|
|
function CommentTk( value ) {
|
|
|
|
this.value = value;
|
|
|
|
}
|
2012-03-13 12:32:31 +00:00
|
|
|
CommentTk.prototype = {};
|
2012-02-03 13:09:01 +00:00
|
|
|
CommentTk.prototype.toJSON = function () {
|
2012-02-06 19:12:29 +00:00
|
|
|
return $.extend( { type: 'COMMENT' }, this );
|
2012-02-03 13:09:01 +00:00
|
|
|
};
|
2012-02-13 17:02:23 +00:00
|
|
|
CommentTk.prototype.constructor = CommentTk;
|
|
|
|
CommentTk.prototype.toString = toString;
|
|
|
|
|
2012-03-07 20:06:54 +00:00
|
|
|
function EOFTk( ) { }
|
2012-03-13 12:32:31 +00:00
|
|
|
EOFTk.prototype = {};
|
2012-02-03 13:09:01 +00:00
|
|
|
EOFTk.prototype.toJSON = function () {
|
2012-02-06 19:12:29 +00:00
|
|
|
return $.extend( { type: 'EOFTk' }, this );
|
2012-02-03 13:09:01 +00:00
|
|
|
};
|
2012-02-13 17:02:23 +00:00
|
|
|
EOFTk.prototype.constructor = EOFTk;
|
|
|
|
EOFTk.prototype.toString = toString;
|
|
|
|
|
|
|
|
|
2012-02-01 17:03:08 +00:00
|
|
|
|
|
|
|
// A key-value pair
|
|
|
|
function KV ( k, v ) {
|
|
|
|
this.k = k;
|
|
|
|
this.v = v;
|
|
|
|
}
|
|
|
|
|
2012-04-25 14:35:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A parameter object wrapper, essentially an array of key/value pairs with a
|
|
|
|
* few extra methods.
|
|
|
|
*
|
|
|
|
* It might make sense to wrap array results of array methods such as slice
|
|
|
|
* into a params object too, so that users are not surprised by losing the
|
|
|
|
* custom methods. Alternatively, the object could be made more abstract with
|
|
|
|
* a separate .array method that just returns the plain array.
|
|
|
|
*/
|
|
|
|
function Params ( env, params ) {
|
|
|
|
this.env = env;
|
|
|
|
this.push.apply( this, params );
|
|
|
|
}
|
|
|
|
|
|
|
|
Params.prototype = [];
|
|
|
|
Params.prototype.constructor = Params;
|
|
|
|
|
|
|
|
Params.prototype.toString = function () {
|
|
|
|
return this.slice(0).toString();
|
|
|
|
};
|
|
|
|
|
|
|
|
Params.prototype.dict = function () {
|
|
|
|
var res = {};
|
|
|
|
for ( var i = 0, l = this.length; i < l; i++ ) {
|
|
|
|
var kv = this[i],
|
|
|
|
key = this.env.tokensToString( kv.k ).trim();
|
|
|
|
res[key] = kv.v;
|
|
|
|
}
|
|
|
|
//console.warn( 'KVtoHash: ' + JSON.stringify( res ));
|
|
|
|
return res;
|
|
|
|
};
|
|
|
|
|
|
|
|
Params.prototype.named = function () {
|
|
|
|
var n = 1,
|
|
|
|
out = {};
|
|
|
|
for ( var i = 0, l = this.length; i < l; i++ ) {
|
|
|
|
// FIXME: Also check for whitespace-only named args!
|
|
|
|
var k = this[i].k;
|
|
|
|
if ( k.constructor === String ) {
|
|
|
|
k = k.trim();
|
|
|
|
}
|
|
|
|
if ( ! k.length ) {
|
|
|
|
out[n.toString()] = this[i].v;
|
|
|
|
n++;
|
|
|
|
} else if ( k.constructor === String ) {
|
|
|
|
out[k] = this[i].v;
|
|
|
|
} else {
|
|
|
|
out[this.env.tokensToString( k ).trim()] = this[i].v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return out;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function ParamValue ( chunk, manager ) {
|
|
|
|
this.chunk = chunk;
|
|
|
|
this.manager = manager;
|
|
|
|
this.cache = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
ParamValue.prototype.expanded = function ( format, cb ) {
|
|
|
|
if ( format === tokens ) {
|
|
|
|
if ( this.cache.tokens ) {
|
|
|
|
cb( this.cache.tokens );
|
|
|
|
} else {
|
|
|
|
var pipeline = this.manager.pipeFactory.getPipeline(
|
|
|
|
this.manager.attributeType || 'tokens/wiki', true
|
|
|
|
);
|
|
|
|
pipeline.setFrame( this.manager.frame, null );
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
throw "ParamValue.expanded: Unsupported format " + format;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-02-01 17:03:08 +00:00
|
|
|
if (typeof module == "object") {
|
|
|
|
module.exports = {};
|
|
|
|
global.TagTk = TagTk;
|
|
|
|
global.EndTagTk = EndTagTk;
|
|
|
|
global.SelfclosingTagTk = SelfclosingTagTk;
|
|
|
|
global.NlTk = NlTk;
|
|
|
|
global.CommentTk = CommentTk;
|
|
|
|
global.EOFTk = EOFTk;
|
|
|
|
global.KV = KV;
|
2012-04-25 14:35:59 +00:00
|
|
|
global.Params = Params;
|
2012-02-01 17:03:08 +00:00
|
|
|
}
|