mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-12-23 16:40:28 +00:00
Introduce setfield command
This new command will let us do the manipulations needed to set up external image tiddlers
This commit is contained in:
parent
460f476aef
commit
d2796d0c9c
18
core/language/en-GB/Help/setfield.tid
Normal file
18
core/language/en-GB/Help/setfield.tid
Normal file
@ -0,0 +1,18 @@
|
||||
title: $:/language/Help/setfield
|
||||
description: Prepares external tiddlers for use
|
||||
|
||||
//Note that this command is experimental and may change or be replaced during the TiddlyWiki version 5 beta//
|
||||
|
||||
Sets the specified field of a group of tiddlers to the result of wikifying a template tiddler with the `currentTiddler` variable set to the tiddler.
|
||||
|
||||
```
|
||||
--setfield <filter> <fieldname> <templatetitle> <rendertype>
|
||||
```
|
||||
|
||||
The parameters are:
|
||||
|
||||
* ''filter'' - filter identifying the tiddlers to be affected
|
||||
* ''fieldname'' - the field to modify (defaults to "text")
|
||||
* ''templatetitle'' - the tiddler to wikify into the specified field. If blank or missing then the specified field is deleted
|
||||
* ''type'' - the text type to render (defaults to "text/plain"; "text/html" can be used to include HTML tags)
|
||||
|
58
core/modules/commands/setfield.js
Normal file
58
core/modules/commands/setfield.js
Normal file
@ -0,0 +1,58 @@
|
||||
/*\
|
||||
title: $:/core/modules/commands/setfield.js
|
||||
type: application/javascript
|
||||
module-type: command
|
||||
|
||||
Command to modify selected tiddlers to set a field to the text of a template tiddler that has been wikified with the selected tiddler as the current tiddler.
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
var widget = require("$:/core/modules/widgets/widget.js");
|
||||
|
||||
exports.info = {
|
||||
name: "setfield",
|
||||
synchronous: true
|
||||
};
|
||||
|
||||
var Command = function(params,commander,callback) {
|
||||
this.params = params;
|
||||
this.commander = commander;
|
||||
this.callback = callback;
|
||||
};
|
||||
|
||||
Command.prototype.execute = function() {
|
||||
if(this.params.length < 4) {
|
||||
return "Missing parameters";
|
||||
}
|
||||
var self = this,
|
||||
wiki = this.commander.wiki,
|
||||
filter = this.params[0],
|
||||
fieldname = this.params[1] || "text",
|
||||
templatetitle = this.params[2],
|
||||
rendertype = this.params[3] || "text/plain",
|
||||
tiddlers = wiki.filterTiddlers(filter);
|
||||
$tw.utils.each(tiddlers,function(title) {
|
||||
var parser = wiki.parseTiddler(templatetitle),
|
||||
newFields = {},
|
||||
tiddler = wiki.getTiddler(title);
|
||||
if(parser) {
|
||||
var widgetNode = wiki.makeWidget(parser,{variables: {currentTiddler: title}});
|
||||
var container = $tw.fakeDocument.createElement("div");
|
||||
widgetNode.render(container,null);
|
||||
newFields[fieldname] = rendertype === "text/html" ? container.innerHTML : container.textContent;
|
||||
} else {
|
||||
newFields[fieldname] = undefined;
|
||||
}
|
||||
wiki.addTiddler(new $tw.Tiddler(tiddler,newFields));
|
||||
});
|
||||
return null;
|
||||
};
|
||||
|
||||
exports.Command = Command;
|
||||
|
||||
})();
|
10
core/templates/canonical-uri.tid
Normal file
10
core/templates/canonical-uri.tid
Normal file
@ -0,0 +1,10 @@
|
||||
title: $:/core/templates/canonical-uri
|
||||
|
||||
<!--
|
||||
|
||||
This template is used to assign the ''_canonical_uri'' field to external images.
|
||||
|
||||
Change the `./images/` part to a different base URI. The URI can be relative or absolute.
|
||||
|
||||
-->
|
||||
./images/<$view field="title" format="doubleurlencoded"/>
|
6
editions/tw5.com/tiddlers/commands/SetFieldCommand.tid
Normal file
6
editions/tw5.com/tiddlers/commands/SetFieldCommand.tid
Normal file
@ -0,0 +1,6 @@
|
||||
title: SetFieldCommand
|
||||
tags: command
|
||||
created: 20140609121606089
|
||||
modified: 20140609121606089
|
||||
|
||||
{{$:/language/Help/setfield}}
|
Loading…
Reference in New Issue
Block a user