1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-09-15 00:39:42 +00:00
TiddlyWiki5/tiddlywiki5/tiddlers/MacroInternals.tid

59 lines
2.6 KiB
Plaintext
Raw Normal View History

2012-01-15 11:46:20 +00:00
title: MacroInternals
2012-02-10 11:12:20 +00:00
! Macro Fields
2012-02-11 17:11:23 +00:00
Macros are implemented as conventional JavaScript modules that export a single variable called `macro` that contains these fields:
2012-01-15 11:46:20 +00:00
|!Field Name |!Description |
|`name` |The name of the macro |
|`types` |An array of the MIME types that the macro can render |
|`params` |A hashmap of the parameters accepted by the macro (see below) |
2012-02-10 11:12:20 +00:00
|`events` |An optional hashmap of event handling functions (see below) |
|`render` |The macro rendering function (see below) |
|`rerender` |The optional macro rerendering function (see below) |
|`dependentAll` |True if the macro needs access to all available tiddlers |
2012-01-15 11:46:20 +00:00
2012-02-10 11:12:20 +00:00
! Macro Parameters
2012-01-15 11:46:20 +00:00
The `params` hashmap provides the following fields about each parameter:
|!Param Field Name |!Description |
2012-02-10 11:12:20 +00:00
|`byName` |Provided if the parameter should be referenced by name. The value can be `true` or `"default"` to indicate that anonymous parameters are acceptable |
|`type` |The type of the parameter, either `text` or `tiddler` (used for dependency tracking) |
|`rel` |The relationship for parameters of type tiddler - either "link" or "include" |
2012-01-15 11:46:20 +00:00
|`optional` |`true` if the parameter is optional |
2012-02-10 11:12:20 +00:00
! Macro Rendering
The `render` function should return the new text representation of the macro output. It is called with the following parameters:
|!Param Name |!Description |
|`type` |The target MIME type for rendering the macro |
|`tiddler` |The tiddler in whose context the macro is being rendered |
|`store` |The `WikiStore` object to be used |
|`params` |The macro parameters as a hashmap |
|`content` |The rendered text of the children of the macro |
!Macro Rerendering
The `rerender` function is called with the following parameters:
2012-01-15 11:46:20 +00:00
|!Param Name |!Description |
2012-02-10 11:12:20 +00:00
|`node` |The DOM node containing the existing rendering of the macro |
|`changes` |Hashmap of `{title: "created|modified|deleted"}` |
2012-01-15 11:46:20 +00:00
|`type` |The target MIME type for rendering the macro |
|`tiddler` |The tiddler in whose context the macro is being rendered |
|`store` |The `WikiStore` object to be used |
|`params` |The macro parameters as a hashmap |
2012-01-17 15:05:22 +00:00
|`content` |The rendered text of the children of the macro |
2012-02-10 11:12:20 +00:00
!Macro Event Handlers
Event handlers are called with the following parameters:
|!Param Name |!Description |
|`event` |The DOM node containing the existing rendering of the macro |
|`node` |Hashmap of `{title: "created|modified|deleted"}` |
|`tiddler` |The tiddler in whose context the macro is being rendered |
|`store` |The `WikiStore` object to be used |
|`params` |The macro parameters as a hashmap |
Event handlers should return `false` if they handle the event (and generally should also call `event.preventDefault()`), and `true` if they do not.