From 1d0eed695718ac94cff01d5df49cbeb48dac3712 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Fri, 1 Nov 2013 15:00:17 +0000 Subject: [PATCH] Docs updates --- .../tiddlers/mechanisms/ParsingMechanism.tid | 41 ++++++++++ .../mechanisms/RenderingMechanism.tid | 2 + .../moduletypes/SyncAdaptorModules.tid | 4 +- .../tiddlers/moduletypes/WidgetModules.tid | 79 +++++++++++++++++++ .../tiddlers/moduletypes/WikiRuleModules.tid | 2 +- .../tiddlers/widgets/CheckboxWidget.tid | 2 +- .../tiddlers/widgets/EditBitmapWidget.tid | 2 +- .../tiddlers/widgets/EditTextWidget.tid | 2 +- .../tw5.com/tiddlers/widgets/EditWidget.tid | 2 +- .../tiddlers/widgets/FieldManglerWidget.tid | 2 +- .../tw5.com/tiddlers/widgets/FieldsWidget.tid | 2 +- .../tw5.com/tiddlers/widgets/LinkWidget.tid | 2 +- .../tiddlers/widgets/SetVariableWidget.tid | 2 +- .../tw5.com/tiddlers/widgets/ViewWidget.tid | 2 +- 14 files changed, 134 insertions(+), 12 deletions(-) diff --git a/editions/tw5.com/tiddlers/mechanisms/ParsingMechanism.tid b/editions/tw5.com/tiddlers/mechanisms/ParsingMechanism.tid index d2664a20a..0708fda6b 100644 --- a/editions/tw5.com/tiddlers/mechanisms/ParsingMechanism.tid +++ b/editions/tw5.com/tiddlers/mechanisms/ParsingMechanism.tid @@ -1,4 +1,45 @@ title: ParsingMechanism tags: mechanism +created: 201311011307 +modified: 201311011307 +! Introduction +The parsing mechanism analyses the text of a tiddler against a set of parsing rules, producing a tree representing the structure of the text. The RenderingMechanism is used to transform parse trees into render trees of widget nodes. + +TiddlyWiki5 includes ParserModules for several types of tiddler: + +* WikiText +* Raw HTML +* Plain text +* Images (bitmap, SVG and PDF) + +The WikiText parser is the most complex, comprising separate individual WikiRuleModules encapsulating each parsing rule. + +! Parse Trees + +The output of parsing a tiddler is an object containing a tree of parse nodes corresponding to the original text. For example: + +``` +> JSON.stringify($tw.wiki.parseText("text/vnd.tiddlywiki","Some //italics// and a {{Transclusion}}.").tree) + +[ + {type: "element", tag: "p", children: [ + {type: "text", text: "Some "}, + {type: "element", tag: "em", children: [ + {type: "text", text: "italics"} + ]}, + {type: "text", text: " and a "}, + {type: "tiddler", attributes:{ + tiddler: {type: "string", value: "Transclusion"} + }, children:[ + {type: "transclude", attributes:{ + tiddler: {type: "string", value: "Transclusion"} + }} + ]}, + {type: "text", text: "."} + ]} +] +``` + +Parse tree nodes are plain JavaScript objects, and do not have a prototype. diff --git a/editions/tw5.com/tiddlers/mechanisms/RenderingMechanism.tid b/editions/tw5.com/tiddlers/mechanisms/RenderingMechanism.tid index 3fc2bd72e..23e2b6ae9 100644 --- a/editions/tw5.com/tiddlers/mechanisms/RenderingMechanism.tid +++ b/editions/tw5.com/tiddlers/mechanisms/RenderingMechanism.tid @@ -1,3 +1,5 @@ title: RenderingMechanism tags: mechanism +created: 201311011307 +modified: 201311011307 diff --git a/editions/tw5.com/tiddlers/moduletypes/SyncAdaptorModules.tid b/editions/tw5.com/tiddlers/moduletypes/SyncAdaptorModules.tid index 7d3eb0223..868f9dd93 100644 --- a/editions/tw5.com/tiddlers/moduletypes/SyncAdaptorModules.tid +++ b/editions/tw5.com/tiddlers/moduletypes/SyncAdaptorModules.tid @@ -1,8 +1,8 @@ created: 201308251621 creator: JeremyRuston -modified: 201308251621 +modified: 201311011307 modifier: JeremyRuston -tags: dev +tags: dev moduletypes title: SyncAdaptorModules ! Introduction diff --git a/editions/tw5.com/tiddlers/moduletypes/WidgetModules.tid b/editions/tw5.com/tiddlers/moduletypes/WidgetModules.tid index 6dd65109d..2dd3a836b 100644 --- a/editions/tw5.com/tiddlers/moduletypes/WidgetModules.tid +++ b/editions/tw5.com/tiddlers/moduletypes/WidgetModules.tid @@ -1,2 +1,81 @@ title: WidgetModules +tags: dev moduletypes +created: 201311011307 +modified: 201311011307 +! Introduction + +Widget modules are used as part of the RenderingMechanism to implement each type of renderable entity. As well as the widgets that are familiar to end users, the following primitives are also implemented as widgets: + +* HTML text nodes +* HTML element nodes +* HTML entities + +All widgets inherit from a base widget class that is defined in [[$:/core/modules/new_widgets/widget.js]]. + +! Widget Properties + +The following widget properties are defined by the core. The lifecycle of a widget object is largely a matter of maintaining the consistency of these internal properties in the face of external state changes. Individual widgets usually add their own additional properties too. + +|!Name |!Description | +|''parseTreeNode'' |Reference to the parse tree node corresponding to this widget | +|''wiki'' |Reference to the [[Wiki]] object associated with this widget | +|''variables'' |Hashmap of information about each [[widget variable|WidgetVariables]] (see below) | +|''parentWidget'' |Reference to the parent widget | +|''document'' |Reference to the document object associated with this widget. Usually either the browser global `document` variable or a reference to the FakeDomMechanism's `$tw.document` | +|''attributes'' |Hashmap of information about each attribute attached to this widget (see below) | +|''children'' |Array of child widgets | +|''domNodes'' |For widgets that directly generate DOM nodes, an array of the generated nodes | +|''eventListeners'' |Array of event listener definitions | + +!! Widget Variables + +The widget variables defined on a widget are stored in a hashmap of the variable name. The hashmap contains: + +* `name`: name of variable +* `params`: array of parameters for macro definitions, each `{name: "", default: ""}` +* `value`: string value of variable + +!! Widget Attributes + +The widget attributes associated with a widget are stored in a hashmap of the attribute name. The hashmap contains an object that describes the attribute value. Currently three attribute value types are supported: + +* Strings: `{type: "string", value: ""}` +* Tiddler text reference indirection: `{type: "indirect", textReference: ""}` +* Macro invocation: `{type: "macro", value: {name: "", params: [{name: "", value: ""}, ... ]}` + +!! Widget Event Listeners + +The event listeners attached to a widget are stored as a hashmap by event type. Each value is a handler function that accepts a single `event` parameter. + +! Widget methods + +The individual methods defined by the widget object are documented in the source code of [[$:/core/modules/new_widgets/widget.js]]. Here we give an overview of the overall lifecycle, and how the methods fit together + +!! Widget `initialise` method +!! Widget `widgetClasses` method +!! Widget `render` method +!! Widget `execute` method +!! Widget `getVariable` method +!! Widget `substituteVariableParameters` method +!! Widget `substituteVariableReferences` method +!! Widget `evaluateMacroModule` method +!! Widget `setVariable` method +!! Widget `hasVariable` method +!! Widget `getStateQualifier` method +!! Widget `computeAttributes` method +!! Widget `hasAttribute` method +!! Widget `getAttribute` method +!! Widget `assignAttributes` method +!! Widget `makeChildWidgets` method +!! Widget `makeChildWidget` method +!! Widget `renderChildren` method +!! Widget `addEventListeners` method +!! Widget `addEventListener` method +!! Widget `dispatchEvent` method +!! Widget `refresh` method +!! Widget `refreshSelf` method +!! Widget `refreshChildren` method +!! Widget `findNextSiblingDomNode` method +!! Widget `findFirstDomNode` method +!! Widget `removeChildDomNodes` method diff --git a/editions/tw5.com/tiddlers/moduletypes/WikiRuleModules.tid b/editions/tw5.com/tiddlers/moduletypes/WikiRuleModules.tid index f80aef5d7..615c757ad 100644 --- a/editions/tw5.com/tiddlers/moduletypes/WikiRuleModules.tid +++ b/editions/tw5.com/tiddlers/moduletypes/WikiRuleModules.tid @@ -1,6 +1,6 @@ created: 201308252147 creator: JeremyRuston -modified: 201308252147 +modified: 201311011307 modifier: JeremyRuston tags: dev moduletypes title: WikiRuleModules diff --git a/editions/tw5.com/tiddlers/widgets/CheckboxWidget.tid b/editions/tw5.com/tiddlers/widgets/CheckboxWidget.tid index 836f35a53..02ea77b45 100644 --- a/editions/tw5.com/tiddlers/widgets/CheckboxWidget.tid +++ b/editions/tw5.com/tiddlers/widgets/CheckboxWidget.tid @@ -14,5 +14,5 @@ The checkbox widget displays an HTML `` element that is d The content of the `<$checkbox>` widget is displayed within an HTML `