Code Snippets
Created pdexter 2024-05-29
Code Snippets are user defined "snippets" of code which one can insert into code windows (currently those based on the Ace Edit control).
This has been effected by a modification available as a Ruleset Include document, attached to the OnLoad rulesets of the respective editor templates.
Lists of code snippets are saved to the User Account document, so are distinct to each User.
Currently available in
- Ruleset Editors (vanilla and MSV)
- Ruleset Include Editors
Available as of Ruleset Editors v202405A
Future availability is planned for the component webservice editor also.
How to invoke Code Snippets
- Click into your code editor pane.
- Click Ctrl-Q
A dialog will appear similar to this:
- Click any of the grey button bars in the list of snippets to insert into code.
How to add new custom Snippets
- From the above dialog in How to invoke Code Snippets, click button "Add New"
A dialog will appear as below:
- Enter a name for the code snippet
- Enter the code you wish to have available to paste.
- Click Save
Editing your list of Code Snippets
Initially, the first three code snippets you see above will be automatically added to your available snippets, without saving.
Once you create your own snippets, they will all be saved to the User Account, under a property called "codeSnippets".
To change your Code Snippets, open your User Account, switch to a document script view (eg via Template/Document Editor), where you can modify, add or delete code snippets.
Using the "now" token
The code behind Code Snippets will render the current date time into the pasted text.
The token takes the form "{{now|format}}"
Eg the following
"snippet" : "// Updated by Samwise Gamgee on {{now|DD/MM/YY h:mm a}}"
will render as
// Updated by Samwise Gamgee on 29/05/24 4:33 pm
This can be entered either directly into the User Document json, or via the Add Code Snippet dialog above.