...
The block object has the following structure:
Property | Type | Required? | Description |
---|---|---|---|
| String | Required | Location of the Groovy function which the block calls. |
| String | Required | Name of the function in the element specified by the |
| List | Optional | List of parameter objects specifying the inputs of the block. Each parameter object has the following properties:
|
| String | Required | Label rendered on the block. It can contain parameter placeholders like If no placeholders are specified, the parameters will be all added at the end of the block. |
| Integer or String | Optional | Color of the block. It can be either an integer value (0 to 360) representing HSV hue value, or a #rrggbb String representing a web color. If no color is specified, the block will have the default color of the Functions toolbox category. |
| String | Optional | Tooltip of the block which is displayed when the user hovers the pointer over the block. If empty, no tooltip will be displayed. |
| String | Optional | By default,
|
| String, either number or string | Required | Return type of the block. It should correspond with the type of the return value from the function defined by the |
Examples of Custom Blocks
...
Create the Meta element and return a list with a single block configuration object from it, like this:
Code Block language groovy return [ [ "element" : "Math", "function": "markupPct", "label" : "{1} x (1 + {2})", "params" : [ ["name": "base", "type": "number", "label": "label_base"], ["name": "markup", "type": "number", "label": "label_markup", "default": 0] ], "inlineParams": true, "returns" : "number" ] ]
Notice the label containing the placeholders that make the inputs render at the correct places.
Create a Math element and in it create a function called markupPct with two parameters, like this:
Code Block language groovy BigDecimal markupPct(BigDecimal base, BigDecimal markup) { if (base == null) { throw new Error("The base cannot be empty"); } if (markup == null) { return base; } return base * (1 + markup) }
You can name the element and function whatever you want as long as it is the same name as specified in the
element
andfunction
properties in the block configuration object.
...