Hi Tobias, I'm looking for an answer to the same question as *Mr. Mal* 
above is. Here's my use case.

I have tiddlers tagged  Phone Number , which contain the fields: *countrycode, 
areacode, exchangecode, phonenumber, type, purpose, owner*. The first four 
of those contain numeric values only. The *type** field contains values 
such as *Landline, Mobile, Freephone*. I have a ViewTemplate which formats 
and displays the fields as a proper phone number, such as:

+<$view field="countrycode"/>-<$view field="areacode"/>-<$view 
field="exchangecode"/>-<$view field="phonenumber"/>

The problem is, I recycle the same fields regardless of whether a Phone 
Number is a landline, mobile, or freephone number, all of which have 
slightly different formats, particularly the freephone ones. I want to be 
able to somehow evaluate the value of the *type* field, and format the 
output accordingly. For instance, a freephone number should be formatted as:

0-800-<$view field="exchangecode"/>-<$view field="phonenumber"/>

Is there some way of doing this using your *eval[ ]* filter plugin, or any 
other way of doing it?

* Yes, I know that *type* is a reserved fieldname in TiddlyWiki. I'm still 
coming up with a replacement field name. Any suggestions gratefully 
accepted. This is for my *{{DesignWrite}}* 
<https://dl.dropboxusercontent.com/s/tk91wqty552z6z1/designwrite.html> semester 
project 
<https://dl.dropboxusercontent.com/s/tk91wqty552z6z1/designwrite.html#SemesterProject>,
 
TiddlyCRM 
<https://groups.google.com/forum/#!searchin/tiddlywiki/CRM/tiddlywiki/9PSw_3OsyyE/qsq9prjaHgAJ>
.

Hegart.


On Thursday, 3 March 2016 22:31:24 UTC+13, Mr. Mal wrote:
>
> Hi Tobias.
>
> Is It possible to using this plugin to make conditional statement like if 
> {{!!foo}} >80 then print A. I am try to make gradebook using TW5. Thank you.
>
> On Monday, December 7, 2015 at 8:00:44 AM UTC+8, Tobias Beer wrote:
>>
>> Hi everyone,
>>
>> I hereby release the new eval 
>> <http://tobibeer.github.io/tw5-plugins/#eval> plugin (or tobibeer/eval 
>> <http://tobibeer.github.io/tw5-plugins/#eval>) which provides an *eval* 
>> filter and an *eval* widget ...the latter working similar to the *calc* 
>> widget in mklauber/math.js <http://mklauber.github.io/tiddly-mathjs/>, 
>> however leveraging a "plug-and-play" library model (and then some).
>>
>> The *eval* plugin was born out of my desire (and Jeremy's suggestion) to 
>> overcome the constraints of let filter 
>> <http://let.tiddlyspot.com/#GettingStarted>, (henceforth abandoned,) 
>> which started out with similar aspirations, allowing to compute and compare 
>> with tidbits, however, somewhat at the wrong end of the stick.
>>
>> If you prefer to learn by example, take a look at the examples 
>> <http://tobibeer.github.io/tw5-plugins/#eval-Examples>.
>>
>> The repo and the commented, non-minified source code is at:
>> https://github.com/tobibeer/tw5-eval
>>
>> Although quite neatly designed, thoroughly tested and refactored, I have 
>> flagged this release as *BETA* so as to invite you to test it, and also 
>> to indicate that — architecturally speaking — things might nevertheless 
>> still change, perhaps. With or without further modifications, I intend to 
>> take it out of BETA in, say, a couple of weeks.
>>
>> Eval is capable of evaluating expressions leveraging different libraries, 
>> for now supporting:
>>
>>    - *math.js*
>>       - you need to separately install tobibeer/math.js 
>>       <http://tobibeer.github.io/tw5-plugins/#math.js> which contains 
>>       nothing but math.js <http://mathjs.org/> itself
>>          - and avails it at *$:/lib/math.js*
>>       - should you already use mklauber/math.js 
>>       <http://mklauber.github.io/tiddly-mathjs/>, *eval* will load the 
>>       *math.js* version it ships with
>>          - so there's no need to install *tobibeer/math.js*
>>       - *js*
>>       - allows to evaluate native javascript
>>       - needs to be specifically enabled, see configuration 
>>       <http://tobibeer.github.io/tw5-plugins/#eval-Configure>
>>       - in other words, you don't even need any *math.js* if...
>>          - you are confident to do your math in nothing but js
>>          - wish to trim those resource requirements
>>       
>> The eval filter provides the following capabilities:
>>
>>    - a *main* expression to be evaluated, obviously ...being the operand
>>       - you can specify more expressions, predefined or custom 
>>       variables, and options, all in the operand
>>          - separate different operand declarations via backslash (*\*), 
>>          defined as *name:value* e.g...
>>       - an *init* value — initializing the *value* before taking off to 
>>    evaluate the main expression against each input title
>>    - a *final* expression — a final computation after the *main *expression 
>>    had been evaluated against the last input title
>>    - the *value* and *title* run-time variables — automatically set for 
>>    each input title, for use in the *main* or *final* expression
>>    - a *format* option — to have math.js nicely format your output value
>>    - a *lib* option — to specify for each filter instance which library 
>>    to use in order to evaluate the given expression(s)
>>    - custom *variables — *any name that is not a predefined variable or 
>>    option
>>       - to help make your *main* or *final* expression more readable
>>    - the suffix — to define what to return
>>       - *no suffix:* returns just the final *value*
>>       - *output mode* suffixes, prefixed *$*, use one at a time, 
>>       returning...
>>          - *$* — those input titles where value is truthy
>>          - *$all* — all input titles if the value is truthy for any 
>>          input title
>>          - *$val* — a list of values, one for each input title
>>          - *$expr* — a list of expressions, one for each input title
>>          - *$eq* — a list of equations, one for each input title => 
>>          great for debugging
>>       
>> Both *text references* as well as *wikitext-variables* can be used 
>> freely in the operand and are substituted in any expression or variable. 
>> (*Note*: custom variables are only evaluated on init, not during 
>> iterations. They shall also not reference each other).
>>
>> Ok, so... hope to see you give it a test-ride and let me know what you 
>> think, what things may not work (as expected) but also which work just 
>> about right. ;-)
>>
>> ~
>>
>> For loading libraries, the *eval* plugin does some neat dependency 
>> resolving, the gist of which I hope will eventually find its way into the 
>> core, in one form or another. That way, we don't ship and install things 
>> like *vis* or *math.js* or any other library with any plugins that build 
>> on them. Nor does plugin A require plugin B, just to not duplicate a given 
>> library. For math.js, for example, there barely any needs for a plugin to 
>> depend on a given version of math.js. But even that can be catered for with 
>> some minor amends as to version handling / dedicated library versions 
>> resolved in just about the same way as *eval* does right now.
>>
>> Best wishes,
>>
>> Tobias.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/facdd9e6-b738-4d37-b889-b6cc49c48da5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to