Folks,

Fancy yourself a tiddlywiki wizard (or wannabee)?, are you up to the 
challenge?, think the solution is obvious?, like to learn through trying?

This is an *optional* coding challenge to provide a better solution, more 
concise code, if you are interested.

   - I am in the middle of creating a solution, the solution contains a 
   configuration tiddler $:/config/name
   - I have long sought to automate configuration settings and have done so 
   with the code below.
   - I would like to see if it can be simplified further.
   - I thought I would open this as a coding challenge for anyone 
   interested, basically since each select statement differs only on value 
   pairs
   eg yes no / show hide, there may be a way to simplify, or shorten the 
   macro.

*The solution*

   - You call this macro with a tiddlername (defaults to current tiddler) 
   and fieldname, default field is "fieldname", (because text could be 
   dangerous)
   - Based on the value it finds there, it allows you to select the value 
   to its natural alternative, eg Yes you can toggle to no, true to false 
   etc...
   - If no value is found the first select widget, allows you to select one 
   from all the available values "yes no show hide true false left right top 
   bottom"
   - However there is a select widget for each of the common pairs of 
   values and they differ only by the two filter used.

*The challenge;*

   - See if you can write the same code in much shorter yet easier to 
   configure/customisation form. For example add the additional options 
   enable/disable.

*Extended challenges *(for the foolhardily)

   - Once a config value pair is selected, set the config-values field in 
   the config tiddler to those two values eg config-values="true false"
   - Allow the order to be set so the first value in config-values is 
   considered the default.
   - Create a view template that detects tiddlers containing one of these 
   values and show the config value select macro on those tiddlers

*I will do this eventually myself but do not yet have the required 
inspiration as to how, so I thought I would open it to the community as a 
challenge.*

The tiddler is also attached for your convenience, works on empty.html, 
tiddlywiki.com or my playground 
<https://anthonymuscio.github.io/playground.html>. The macro is both 
defined and called in this tiddler.

\define smart-configure(tiddlername fieldname:"fieldname")
<$set name=tiddlername value="$tiddlername$" emptyValue=<<currentTiddler>> >
<$set name=currentValue value={{{ [<tiddlername>get[$fieldname$]] }}}>
tiddlername=<<tiddlername>>, fieldname=$fieldname$, currentValue=<<
currentValue>><br>

<$list filter="[<currentValue>is[blank]]" variable=nul>
Select initial value: 
<$select tiddler=<<tiddlername>> field="$fieldname$" default=<<currentValue
>> >
  <$list filter='yes no show hide true false left right top bottom'>
     <option value=<<currentTiddler>>><$view field='title'/></option>
  </$list>
</$select>
</$list>

<$list filter="yes no +[match<currentValue>]" variable=nul>
<$select tiddler=<<tiddlername>> field="$fieldname$" 
default=<<currentValue>> >
  <$list filter='yes no'>
     <option value=<<currentTiddler>>><$view field='title'/></option>
  </$list>
</$select>
</$list>

<$list filter="show hide +[match<currentValue>]" variable=nul>
<$select tiddler=<<tiddlername>> field="$fieldname$" 
default=<<currentValue>> >
  <$list filter='show hide'>
     <option value=<<currentTiddler>>><$view field='title'/></option>
  </$list>
</$select>
</$list>

<$list filter="true false +[match<currentValue>]" variable=nul>
<$select tiddler=<<tiddlername>> field="$fieldname$" 
default=<<currentValue>> >
  <$list filter='true false'>
     <option value=<<currentTiddler>>><$view field='title'/></option>
  </$list>
</$select>
</$list>

<$list filter="left right +[match<currentValue>]" variable=nul>
<$select tiddler=<<tiddlername>> field="$fieldname$" 
default=<<currentValue>> >
  <$list filter='left right'>
     <option value=<<currentTiddler>>><$view field='title'/></option>
  </$list>
</$select>
</$list>

<$list filter="top bottom +[match<currentValue>]" variable=nul>
<$select tiddler=<<tiddlername>> field="$fieldname$" 
default=<<currentValue>> >
  <$list filter='top bottom'>
     <option value=<<currentTiddler>>><$view field='title'/></option>
  </$list>
</$select>
</$list>
</$set></$set>
\end

<<smart-configure "$:/config/Tiddlers/TitleLinks" text>>

*In closing*

   - Do you like the idea of such challenges, 
   - shall I release more? 
   - Is there one you would like to raise?
   - Or a challenge you would like me to post?
   - Let me know here or privately.

Regards
TW Tones

 

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/8bdd0936-16e7-48c8-a6f1-9d6cb587784fo%40googlegroups.com.

Attachment: Select Challenge.json
Description: application/json

Reply via email to