From e7701d8af05a377674f65030e989d62b247d5cdb Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Sat, 7 Apr 2012 14:28:50 +0100 Subject: [PATCH] Fixed typo with `class` member of `linkInfo` And improved the docs --- js/macros/link.js | 14 ++++++++------ readme.md | 2 +- tiddlywiki5/store/CommandLineInterface.tid | 2 ++ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/js/macros/link.js b/js/macros/link.js index 76f09fa99..b81007e7d 100644 --- a/js/macros/link.js +++ b/js/macros/link.js @@ -21,10 +21,12 @@ as follows: The link massager is called with the `attributes` hashmap initialised as follows: { - classes: an array of strings representing the CSS classes to be applied to the link. The default classes are already applieda according to whether the heuristics decide the tiddler is external or missing + class: an array of strings representing the CSS classes to be applied to the link. The default classes are already applieda according to whether the heuristics decide the tiddler is external or missing href: the href to be used in the link (defaults to the unencoded value of the `to` parameter) } +Note that the member `class` cannot be referred to with JavaScript dot syntax: use `linkInfo.attributes["class"]` rather than `linkInfo.attributes.class`. + The linkMassager can modify the `classes` and `href` fields as required, and add additional HTML attributes, such as the `target` attribute. The linkMassager can cause the link to be suppressed by setting the `linkInfo.suppressLink` to `true`. The content of the link will still be displayed. @@ -78,15 +80,15 @@ exports.macro = { href: linkInfo.to }; // Generate the default classes for the link - linkInfo.attributes.classes = ["tw-tiddlylink"]; + linkInfo.attributes["class"] = ["tw-tiddlylink"]; if(linkInfo.isExternal) { - linkInfo.attributes.classes.push("tw-tiddlylink-external"); + linkInfo.attributes["class"].push("tw-tiddlylink-external"); } else { - linkInfo.attributes.classes.push("tw-tiddlylink-internal"); + linkInfo.attributes["class"].push("tw-tiddlylink-internal"); if(linkInfo.isMissing) { - linkInfo.attributes.classes.push("tw-tiddlylink-missing"); + linkInfo.attributes["class"].push("tw-tiddlylink-missing"); } else { - linkInfo.attributes.classes.push("tw-tiddlylink-resolves"); + linkInfo.attributes["class"].push("tw-tiddlylink-resolves"); } } // Invoke the link massager if defined diff --git a/readme.md b/readme.md index 5c43f9fdf..f55d8859a 100644 --- a/readme.md +++ b/readme.md @@ -6,7 +6,7 @@ node tiddlywiki.js --load mywiki.html --servewiki 127.0.0.1:8000 node tiddlywiki.js --recipe tiddlywiki.com/index.recipe --savewiki tmp/
This example ginsus a TiddlyWiki into its constituent tiddlers:
node tiddlywiki.js --load mywiki.html --savetiddlers tmp/tiddlers -

Notes

--servewiki and --servetiddlers are for different purposes and should not be used together. The former is for TiddlyWiki core developers who want to be able to edit the TiddlyWiki source files in a text editor and view the results in the browser by clicking refresh; it is slow because it reloads all the TiddlyWiki JavaScript files each time the page is loaded. The latter is for experimenting with the new wikification engine.

--wikitest looks for *.tid files in the specified folder. It then wikifies the tiddlers to both "text/plain" and "text/html" format and checks the results against the content of the *.html and *.txt files in the same directory.

--links controls the way that links are generated. Currently, the only option supported is:

none: Tiddler links are disabled



Testing

Test Scripts


Three test scripts are provided, each as a Mac OS X *.sh bash script and a Windows *.bat batch file. In each case they should be run with the current directory set to the directory in which they reside.


Architecture

Overview


The heart of TiddlyWiki can be seen as an extensible representation transformation engine. Given the text of a tiddler and its associated MIME type, the engine can produce a rendering of the tiddler in a new MIME type. Furthermore, it can efficiently selectively update the rendering to track any changes in the tiddler or its dependents.

The most important transformations are from text/x-tiddlywiki wikitext into text/html or text/plain but the engine is used throughout the system for other transformations, such as converting images for display in HTML, sanitising fragments of JavaScript, and processing CSS.

The key feature of wikitext is the ability to include one tiddler within another (usually referred to as transclusion). For example, one could have a tiddler called Disclaimer that contains the boilerplate of a legal disclaimer, and then include it within lots of different tiddlers with the macro call <<tiddler Disclaimer>>. This simple feature brings great power in terms of encapsulating and reusing content, and evolving a clean, usable implementation architecture to support it efficiently is a key objective of the TiddlyWiki5 design.

It turns out that the transclusion capability combined with the selective refreshing mechanism provides a good foundation for building TiddlyWiki's user interface itself. Consider, for example, the StoryMacro in its simplest form:
<<story story:MyStoryTiddler>>
+

Notes

The HTTP serving functionality built into TiddlyWiki5 is designed to support personal use scenarios. If you want to flexibly and robustly share tiddlers on the web for multiple users, you should use TiddlyWeb or TiddlySpace.

--servewiki and --servetiddlers are for different purposes and should not be used together. The former is for TiddlyWiki core developers who want to be able to edit the TiddlyWiki source files in a text editor and view the results in the browser by clicking refresh; it is slow because it reloads all the TiddlyWiki JavaScript files each time the page is loaded. The latter is for experimenting with the new wikification engine.

--wikitest looks for *.tid files in the specified folder. It then wikifies the tiddlers to both "text/plain" and "text/html" format and checks the results against the content of the *.html and *.txt files in the same directory.

--links controls the way that links are generated. Currently, the only option supported is:

none: Tiddler links are disabled



Testing

Test Scripts


Three test scripts are provided, each as a Mac OS X *.sh bash script and a Windows *.bat batch file. In each case they should be run with the current directory set to the directory in which they reside.


Architecture

Overview


The heart of TiddlyWiki can be seen as an extensible representation transformation engine. Given the text of a tiddler and its associated MIME type, the engine can produce a rendering of the tiddler in a new MIME type. Furthermore, it can efficiently selectively update the rendering to track any changes in the tiddler or its dependents.

The most important transformations are from text/x-tiddlywiki wikitext into text/html or text/plain but the engine is used throughout the system for other transformations, such as converting images for display in HTML, sanitising fragments of JavaScript, and processing CSS.

The key feature of wikitext is the ability to include one tiddler within another (usually referred to as transclusion). For example, one could have a tiddler called Disclaimer that contains the boilerplate of a legal disclaimer, and then include it within lots of different tiddlers with the macro call <<tiddler Disclaimer>>. This simple feature brings great power in terms of encapsulating and reusing content, and evolving a clean, usable implementation architecture to support it efficiently is a key objective of the TiddlyWiki5 design.

It turns out that the transclusion capability combined with the selective refreshing mechanism provides a good foundation for building TiddlyWiki's user interface itself. Consider, for example, the StoryMacro in its simplest form:
<<story story:MyStoryTiddler>>
 
The story macro looks for a list of tiddler titles in the tiddler MyStoryTiddler, and displays them in sequence. The subtle part is that subsequently, if MyStoryTiddler changes, the <<story>> macro is selectively re-rendered. So, to navigate to a new tiddler, code merely needs to add the name of the tiddler and a line break to the top of MyStoryTiddler:
var storyTiddler = store.getTiddler("MyStoryTiddler");
 store.addTiddler(new Tiddler(storyTiddler,{text: navigateTo + "\n" + storyTiddler.text}));
 
The mechanisms that allow all of this to work are fairly intricate. The sections below progressively build the key architectural concepts of TiddlyWiki5 in a way that should provide a good basis for exploring the code directly.

Tiddlers

Tiddlers are an immutable dictionary of name:value pairs called fields.

The only field that is required is the title field, but useful tiddlers also have a text field, and some or all of the standard fields modified, modifier, created, creator, tags and type.

Hardcoded in the system is the knowledge that the tags field is a string array, and that the modified and created fields are JavaScript Date objects. All other fields are strings.

The type field identifies the representation of the tiddler text with a MIME type.

WikiStore

Groups of uniquely titled tiddlers are contained in WikiStore objects.

The WikiStore also manages the plugin modules used for macros, and operations like serializing, deserializing, parsing and rendering tiddlers.

Each WikiStore is connected to another shadow store that is used to provide default content. Under usual circumstances, when an attempt is made to retrieve a tiddler that doesn't exist in the store, the search continues into its shadow store (and so on, if the shadow store itself has a shadow store).

WikiStore Events

Clients can register event handlers with the WikiStore object. Event handlers can be registered to be triggered for modifications to any tiddler in the store, or with a filter to only be invoked when a particular tiddler or set of tiddlers changes.

Whenever a change is made to a tiddler, the wikistore registers a nexttick handler (if it hasn't already done so). The nexttick handler looks back at all the tiddler changes, and dispatches any matching event handlers.

Parsing and Rendering

TiddlyWiki parses the content of tiddlers to build an internal tree representation that is used for several purposes:
The parse tree is built when needed, and then cached by the WikiStore until the tiddler changes.

TiddlyWiki5 uses multiple parsers:
Additional parsers are planned:
One global instance of each parser is instantiated in js/App.js and registered with the main WikiStore object.

The parsers are all used the same way:
var parseTree = parser.parse(type,text) // Parses the text and returns a parse tree object
diff --git a/tiddlywiki5/store/CommandLineInterface.tid b/tiddlywiki5/store/CommandLineInterface.tid
index d4b8b6673..c98746974 100644
--- a/tiddlywiki5/store/CommandLineInterface.tid
+++ b/tiddlywiki5/store/CommandLineInterface.tid
@@ -47,6 +47,8 @@ This example ginsus a TiddlyWiki into its constituent tiddlers:
 node tiddlywiki.js --load mywiki.html --savetiddlers tmp/tiddlers
 `
 !! Notes
+The HTTP serving functionality built into TiddlyWiki5 is designed to support personal use scenarios. If you want to flexibly and robustly share tiddlers on the web for multiple users, you should use TiddlyWeb or TiddlySpace.
+
 `--servewiki` and `--servetiddlers` are for different purposes and should not be used together. The former is for TiddlyWiki core developers who want to be able to edit the TiddlyWiki source files in a text editor and view the results in the browser by clicking refresh; it is slow because it reloads all the TiddlyWiki JavaScript files each time the page is loaded. The latter is for experimenting with the new wikification engine.
 
 `--wikitest` looks for `*.tid` files in the specified folder. It then wikifies the tiddlers to both "text/plain" and "text/html" format and checks the results against the content of the `*.html` and `*.txt` files in the same directory.