1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-10-01 00:10:45 +00:00

Added the image macro

This commit is contained in:
Jeremy Ruston 2012-01-15 14:37:49 +00:00
parent 4df13a3e24
commit 606374e563
6 changed files with 52 additions and 12 deletions

View File

@ -89,6 +89,7 @@ var App = function() {
}
// Bit of a hack to set up the macros
this.store.installMacro(require("./macros/echo.js").macro);
this.store.installMacro(require("./macros/image.js").macro);
this.store.installMacro(require("./macros/info.js").macro);
this.store.installMacro(require("./macros/link.js").macro);
this.store.installMacro(require("./macros/list.js").macro);

View File

@ -253,18 +253,20 @@ utils.stitchElement = function(element,attributes,options) {
if(attributes) {
for(var a in attributes) {
var v = attributes[a];
if(typeof v === "object") {
var s = [];
for(var t in v) {
s.push(t + ":" + v[t] + ";");
if(v !== undefined) {
if(typeof v === "object") {
var s = [];
for(var t in v) {
s.push(t + ":" + v[t] + ";");
}
v = s.join("");
}
v = s.join("");
output.push(" ");
output.push(a);
output.push("='");
output.push(utils.htmlEncode(v));
output.push("'");
}
output.push(" ");
output.push(a);
output.push("='");
output.push(utils.htmlEncode(v));
output.push("'");
}
}
if(options.insertAfterAttributes) {

View File

@ -362,7 +362,7 @@ WikiStore.prototype.renderMacro = function(macroName,targetType,tiddler,params)
} else {
return null;
}
}
};
/*
Refresh a DOM node so that it reflects the current state of the store

34
js/macros/image.js Normal file
View File

@ -0,0 +1,34 @@
/*\
title: js/macros/image.js
\*/
(function(){
/*jslint node: true */
"use strict";
var utils = require("../Utils.js");
exports.macro = {
name: "image",
types: ["text/html","text/plain"],
params: {
src: {byName: "default", type: "tiddler", optional: false},
text: {byName: true, type: "text", optional: true}
},
handler: function(type,tiddler,store,params) {
if(type === "text/html") {
return utils.stitchElement("img",{
href: params.src,
alt: params.text,
title: params.text
},{
selfClosing: true
});
} else if (type === "text/plain") {
return params.text ? params.text : params.src;
}
}
};
})();

View File

@ -1,3 +1,5 @@
title: ThirdTiddler
An explicit link [[Fourth Tiddler]] and [[a pretty link|Fourth Tiddler]] and a transclusion <<tiddler [[Fourth Tiddler]] with:Stringy>>
An explicit link [[Fourth Tiddler]] and [[a pretty link|Fourth Tiddler]] and a transclusion <<tiddler [[Fourth Tiddler]] with:Stringy>>
[img[http://placehold.it/350x150]]

View File

@ -29,6 +29,7 @@ jsmodule: ../js/StoryNavigator.js
jsmodule: ../js/App.js
jsmodule: ../js/macros/echo.js
jsmodule: ../js/macros/image.js
jsmodule: ../js/macros/info.js
jsmodule: ../js/macros/link.js
jsmodule: ../js/macros/list.js