SliceCalculatorPlugin

5 views
Skip to first unread message

Kashgarinn

unread,
Mar 5, 2008, 2:01:39 PM3/5/08
to TiddlyWiki
Hi there.

I just made my first plugin where I don't overly ask/beg for help on
the tiddlywiki forums, very proud of that.

http://www.pc.is/#SliceCalculatorPlugin

Of course, I used another plugin as a starter, took the
columncalculator plugin Eric Schulman did, and deleted everything out
of it to have the barebone look and feel I'm comfortable with (and to
inspire me a bit).

The basic premise is stupidly simple really, take 2 slices and do
basic mathematics with them.

I'm thinking of a few things I could do to extend it, 1) make it so
that you can optionally replace the macro code in the tiddler with the
result itself and 2) make it so that you could optionally specify a
slice name, and a tag, and all the slices in tiddlers which match the
tag would be added together.

Hope I'll have the stamina and will to see that through.

Like Eric would say, enjoy :P

K.

Dave Parker

unread,
Mar 7, 2008, 10:47:21 AM3/7/08
to TiddlyWiki
Thanks for sharing that - I think it could be very useful! (I've been
trying to learn about variables (I think one could think of slices as
a "sort of" variable) in five minute increments and I hadn't gotten
around to doing math with them yet, so this helps...

Eric Shulman

unread,
Mar 7, 2008, 2:55:15 PM3/7/08
to TiddlyWiki
> http://www.pc.is/#SliceCalculatorPlugin
> The basic premise is stupidly simple really, take 2 slices and do
> basic mathematics with them.

hmmm... math from slices... very interesting...

I've got another take on how to do this, using
http://www.TiddlyTools.com/#WikifyPlugin

I've just added a minor tweak (only two lines) to the existing plugin
code, it can now assemble a javascript expression from slice values
(automatically retrieved by the core's macro handler) and then also
'eval' that expression to compute a new value before it is output as
wiki-formatted content.

For example, you could write:

The ratio of Vegetables to Hamburgers is:
<<wikiCalc "%0/%1" [[MyFood::Vegetables]] [[MyFood::Hamburgers]]>>
Your diet is <<wikiCalc
"(%0/%1)<1?'unhealthy... eat more vegetables!':'healthy... keep it
up!'"
[[MyFood::Vegetables]] [MyFood::Hamburgers]]>>

Note the second use includes a javascript "conditional expression"
that determines which text is ultimately displayed, based on the ratio
of vegetables to hamburgers.

enjoy,
-e
Reply all
Reply to author
Forward
0 new messages