-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored tiddler serialization and deserialization
Introduced TiddlerConverters, a sort of factory for them
- Loading branch information
Jeremy Ruston
committed
Dec 11, 2011
1 parent
d748d04
commit 4eb4645
Showing
7 changed files
with
185 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/*jslint node: true */ | ||
"use strict"; | ||
|
||
var TiddlerConverters = function() { | ||
this.serializers = {}; | ||
this.deserializers = {}; | ||
}; | ||
|
||
TiddlerConverters.prototype.registerSerializer = function(extension,mimeType,serializer) { | ||
this.serializers[extension] = serializer; | ||
this.serializers[mimeType] = serializer; | ||
}; | ||
|
||
TiddlerConverters.prototype.registerDeserializer = function(extension,mimeType,deserializer) { | ||
this.deserializers[extension] = deserializer; | ||
this.deserializers[mimeType] = deserializer; | ||
}; | ||
|
||
TiddlerConverters.prototype.serialize = function(type,tiddler) { | ||
var serializer = this.serializers[type]; | ||
if(serializer) { | ||
return serializer(tiddler); | ||
} else { | ||
return null; | ||
} | ||
}; | ||
|
||
TiddlerConverters.prototype.deserialize = function(type,text,srcFields) { | ||
var fields = {}, | ||
deserializer = this.deserializers[type], | ||
t; | ||
if(srcFields) { | ||
for(t in srcFields) { | ||
fields[t] = srcFields[t]; | ||
} | ||
} | ||
if(deserializer) { | ||
return deserializer(text,fields); | ||
} else { | ||
// Return a raw tiddler for unknown types | ||
fields.text = text; | ||
return [fields]; | ||
} | ||
}; | ||
|
||
exports.TiddlerConverters = TiddlerConverters; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.