2012-05-05 10:24:45 +00:00
|
|
|
/*\
|
2012-07-14 14:46:01 +00:00
|
|
|
title: $:/core/modules/macros/serialize.js
|
2012-05-05 10:24:45 +00:00
|
|
|
type: application/javascript
|
|
|
|
module-type: macro
|
|
|
|
|
2012-07-14 14:46:01 +00:00
|
|
|
Serialize macro
|
2012-05-19 17:23:14 +00:00
|
|
|
|
2012-05-05 10:24:45 +00:00
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
exports.info = {
|
2012-07-14 14:46:01 +00:00
|
|
|
name: "serialize",
|
2012-05-05 10:57:08 +00:00
|
|
|
params: {
|
2012-05-05 12:15:59 +00:00
|
|
|
filter: {byPos: 0, type: "filter"},
|
2012-05-29 20:59:14 +00:00
|
|
|
as: {byPos: 1, type: "text"},
|
|
|
|
removePrefix: {byName: true, type: "text"}
|
2012-05-05 10:57:08 +00:00
|
|
|
}
|
2012-05-05 10:24:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.executeMacro = function() {
|
2012-05-08 14:11:53 +00:00
|
|
|
var as = this.params.as || "text/plain",
|
2012-05-29 20:59:14 +00:00
|
|
|
t;
|
2012-05-05 12:15:59 +00:00
|
|
|
if(this.hasParameter("filter")) {
|
2012-06-06 11:07:33 +00:00
|
|
|
var titles = this.wiki.filterTiddlers(this.params.filter),
|
2012-05-05 12:15:59 +00:00
|
|
|
result = [];
|
2012-05-29 20:59:14 +00:00
|
|
|
if(this.hasParameter("removePrefix")) {
|
|
|
|
for(t=0; t<titles.length; t++) {
|
|
|
|
var originalTiddler = this.wiki.getTiddler(titles[t]),
|
|
|
|
title = titles[t];
|
|
|
|
if(title.indexOf(this.params.removePrefix) === 0) {
|
|
|
|
title = title.substr(this.params.removePrefix.length);
|
|
|
|
var modifiedTiddler = new $tw.Tiddler(originalTiddler,{title: title});
|
|
|
|
result.push(this.wiki.serializeTiddler(modifiedTiddler,as));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for(t=0; t<titles.length; t++) {
|
|
|
|
result.push(this.wiki.serializeTiddler(titles[t],as));
|
|
|
|
}
|
2012-05-05 10:57:08 +00:00
|
|
|
}
|
2012-06-09 17:36:32 +00:00
|
|
|
return $tw.Tree.Element("pre",{},[
|
2012-05-05 12:15:59 +00:00
|
|
|
$tw.Tree.Text(result.join("\n"))
|
2012-06-09 17:36:32 +00:00
|
|
|
]);
|
2012-05-05 10:57:08 +00:00
|
|
|
}
|
2012-06-09 17:36:32 +00:00
|
|
|
return null;
|
2012-05-05 10:24:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
})();
|