Your own utility script library

From Freeplane - free mind mapping and knowledge management software
Revision as of 01:48, 14 March 2013 by Boercher (talk | contribs) (Created page with 'Starting with Freeplane 1.3.2 all .groovy files in the script classpath directories are automatically compiled when Freeplane starts. Note that no .class files are generated - it...')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Starting with Freeplane 1.3.2 all .groovy files in the script classpath directories are automatically compiled when Freeplane starts. Note that no .class files are generated - it all happens inside of Freeplane.

Extract often used functionality

This feature allows to keep your scripts and formulas more concise since you can define functionality that you often use in your scripts in a utility script/class. Let's assume that you want to create a map with a lot of formulas that compute sums over child nodes: <groovy> =node.children.sum(0){ it['total'].num0 } </groovy> and that 50 times in a map. Put that into a utility script named FP.groovy and put it into the scripts classpath (see below): <groovy name="FP.groovy"> def static attribSum(parentNode, attributeName) {

   parentNode.children.sum(0){ it[attributeName].num0 }

} </groovy>

Then your formula will look nicer: <groovy> =attribSum(node, 'total') </groovy>

Note that for utility functions you should think twice to find good names for functions to make it easier to remember what they do.

Make yourself at home

Let's assume you don't like the groovy way to sum over child node attribute. Let's also assume that you like functions with UPPERCASE LETTERS.

TODO

You can also define constants that you often use. If you define them in one place it will be easier to change them if you like. <groovy name="Const.groovy"> final String company = 'Scripting Geeks Inc.' final String stdDateFormat = 'yyyy/MM/dd_hhmm' </groovy>

Use it like this: <groovy> node['started'] = format(new Date(), stdDateFormat) </groovy>