mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-01-24 16:06:58 +00:00
Update JavaScript Macro docs
This commit is contained in:
parent
1e54b1bcc9
commit
f31369035b
@ -1,11 +1,13 @@
|
|||||||
created: 20131211222303769
|
created: 20131211222303769
|
||||||
modified: 20131211225411570
|
modified: 20140120130146763
|
||||||
tags: dev
|
tags: dev
|
||||||
title: JavaScript Macros
|
title: JavaScript Macros
|
||||||
type: text/vnd.tiddlywiki
|
type: text/vnd.tiddlywiki
|
||||||
|
|
||||||
Macros can be implemented as JavaScript modules as well as via the [[wikitext syntax|Macros in WikiText]].
|
Macros can be implemented as JavaScript modules as well as via the [[wikitext syntax|Macros in WikiText]].
|
||||||
|
|
||||||
|
! Overview
|
||||||
|
|
||||||
JavaScript macros are modules with their ''module-type'' field set to ''macro''. They must export these three properties:
|
JavaScript macros are modules with their ''module-type'' field set to ''macro''. They must export these three properties:
|
||||||
|
|
||||||
* ''name'': A string giving the name used to invoke the macro
|
* ''name'': A string giving the name used to invoke the macro
|
||||||
@ -15,3 +17,11 @@ JavaScript macros are modules with their ''module-type'' field set to ''macro''.
|
|||||||
* ''run'': Function called when the macro requires evaluation. The parameters are pulled from the macro call and arranged according to the ''params'' array. The ''run'' function should return the string value of the macro. When invoked, `this` points to the widget node invoking the macro.
|
* ''run'': Function called when the macro requires evaluation. The parameters are pulled from the macro call and arranged according to the ''params'' array. The ''run'' function should return the string value of the macro. When invoked, `this` points to the widget node invoking the macro.
|
||||||
|
|
||||||
Note that if the ''params'' array is missing or blank, then all the supplied parameters are passed to the `run()` method.
|
Note that if the ''params'' array is missing or blank, then all the supplied parameters are passed to the `run()` method.
|
||||||
|
|
||||||
|
! Writing JavaScript macros
|
||||||
|
|
||||||
|
There are several JavaScript macros built into the core which can serve as a jumping off point for your own macros:
|
||||||
|
|
||||||
|
https://github.com/Jermolene/TiddlyWiki5/tree/master/core/modules/macros
|
||||||
|
|
||||||
|
Note that JavaScript macros work on both the client and the server, and so do not have access to the browser DOM.
|
||||||
|
Loading…
Reference in New Issue
Block a user