From 1dd6e43a6f82bed847cd5c7830b6b204a5050844 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Thu, 29 Mar 2012 15:32:36 +0100 Subject: [PATCH] First version of the edit macro --- js/App.js | 1 + js/macros/edit.js | 47 +++++++++++++++++++ tiddlywiki5/shadows/StoryTiddlers.tid | 1 + tiddlywiki5/shadows/css/styles.css | 5 ++ .../shadows/templates/EditTemplate.tid | 7 +++ .../shadows/templates/SimpleTemplate.tid | 4 +- tiddlywiki5/tiddlers/DraftTiddler.tid | 4 ++ 7 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 js/macros/edit.js create mode 100644 tiddlywiki5/shadows/templates/EditTemplate.tid create mode 100644 tiddlywiki5/tiddlers/DraftTiddler.tid diff --git a/js/App.js b/js/App.js index 930acd42d..bbc466e4e 100644 --- a/js/App.js +++ b/js/App.js @@ -84,6 +84,7 @@ var App = function() { // Bit of a hack to set up the macros this.store.installMacro(require("./macros/chooser.js").macro); this.store.installMacro(require("./macros/echo.js").macro); + this.store.installMacro(require("./macros/edit.js").macro); this.store.installMacro(require("./macros/image.js").macro); this.store.installMacro(require("./macros/link.js").macro); this.store.installMacro(require("./macros/list.js").macro); diff --git a/js/macros/edit.js b/js/macros/edit.js new file mode 100644 index 000000000..b18e3fe49 --- /dev/null +++ b/js/macros/edit.js @@ -0,0 +1,47 @@ +/*\ +title: js/macros/edit.js + +\*/ +(function(){ + +/*jslint node: true */ +"use strict"; + +var Renderer = require("../Renderer.js").Renderer, + Dependencies = require("../Dependencies.js").Dependencies, + utils = require("../Utils.js"); + +exports.macro = { + name: "edit", + params: { + field: {byPos: 0, type: "text"} + }, + execute: function() { + var tiddler = this.store.getTiddler(this.tiddlerTitle), + field = this.hasParameter("field") ? this.params.field : "title", + value; + if(tiddler) { + value = tiddler[field]; + } else { + switch(field) { + case "text": + value = "Type the text for the tiddler '" + this.tiddlerTitle + "'"; + break; + case "title": + value = this.tiddlerTitle; + break; + default: + value = ""; + break; + } + } + var attributes = { + "contenteditable": true, + "class": ["tw-edit-field"] + } + return [Renderer.ElementNode("div",attributes,[Renderer.TextNode(value)])]; + } +}; + +})(); + diff --git a/tiddlywiki5/shadows/StoryTiddlers.tid b/tiddlywiki5/shadows/StoryTiddlers.tid index 09e17e160..968a773a3 100644 --- a/tiddlywiki5/shadows/StoryTiddlers.tid +++ b/tiddlywiki5/shadows/StoryTiddlers.tid @@ -3,6 +3,7 @@ type: application/json { "tiddlers": [ + {"title": "DraftTiddler", "template": "EditTemplate"}, {"title": "HelloThere", "template": "SimpleTemplate"}, {"title": "Introduction", "template": "SimpleTemplate"}, {"title": "NewWikiTextFeatures", "template": "SimpleTemplate"} diff --git a/tiddlywiki5/shadows/css/styles.css b/tiddlywiki5/shadows/css/styles.css index 741c1eeca..9b240813e 100644 --- a/tiddlywiki5/shadows/css/styles.css +++ b/tiddlywiki5/shadows/css/styles.css @@ -10,6 +10,11 @@ body { .tiddlerMissing .title { font-style: italic; + font-weight: normal; +} + +.tw-edit-field { + border: 1px dotted #888; } img { diff --git a/tiddlywiki5/shadows/templates/EditTemplate.tid b/tiddlywiki5/shadows/templates/EditTemplate.tid new file mode 100644 index 000000000..c429af4f8 --- /dev/null +++ b/tiddlywiki5/shadows/templates/EditTemplate.tid @@ -0,0 +1,7 @@ +title: EditTemplate +modifier: JeremyRuston + +{{title{ +<>}}} +{{body{ +<>}}} \ No newline at end of file diff --git a/tiddlywiki5/shadows/templates/SimpleTemplate.tid b/tiddlywiki5/shadows/templates/SimpleTemplate.tid index 6d9674fe0..1a8d25f2d 100644 --- a/tiddlywiki5/shadows/templates/SimpleTemplate.tid +++ b/tiddlywiki5/shadows/templates/SimpleTemplate.tid @@ -6,6 +6,4 @@ modifier: JeremyRuston {{small{ <> <>}}} {{body{ -<>}}} -<> -<> \ No newline at end of file +<>}}} \ No newline at end of file diff --git a/tiddlywiki5/tiddlers/DraftTiddler.tid b/tiddlywiki5/tiddlers/DraftTiddler.tid new file mode 100644 index 000000000..8f6db4a7d --- /dev/null +++ b/tiddlywiki5/tiddlers/DraftTiddler.tid @@ -0,0 +1,4 @@ +title: DraftTiddler +draft.title: New Tiddler + +This is a sample draft tiddler. It is a draft of the tiddler titled in the `draft.title` field, in this case <>.