[TW5] New plugin / update: tobibeer/make

340 views
Skip to first unread message

Tobias Beer

unread,
Dec 19, 2015, 1:48:02 PM12/19/15
to tiddl...@googlegroups.com
Hi folks,

As created, discussed and announced in the context of this thread,
I made a new filter plugin called tobibeer/make to be found at:


It provides the make filter which allows to
batch create new titles (or modify input titles)
using flexible patterns including:
  • date-stamps
  • random strings (incl. uuid)
  • count, increment, max
  • variables and text-references
  • and always that mechanism to ensure a created title is indeed unique
For those already following its development,
for the last release 0.5.5, I added these options:
  • now handles input titles as well
  • added options septiddlerunique
  • added placeholders %title%%tiddler%
  • added test-suite
If you use it to generate random strings,
I recommend you combine it with tobibeer/setvars (announcement),
for the simple reason that it will not refresh a computed random string at every click (details).

Best wishes,

Tobias.

Felix Küppers

unread,
Dec 19, 2015, 4:03:05 PM12/19/15
to tiddl...@googlegroups.com
Hi Tobias,

Very(!!) nice filter you created! Quite revolutionary, I have to say.

It is more than just a very handy swiss army knife (uuid creation, concatinations, placeholders, for loops with the use of count, step and max directives, how cool!) – it opens the gate for a whole lot of possibilies! Great stuff.

A proposal:

With your plugin, it is now possible for the first time to mix titles with other content on the fly in a sophisticated way using tw-filters.
However your plugin would even become more powerful if you included a macro that allows de-serialization afterwards.

What this means: In the filter expressions users can combine/merge/mix titles with other stuff and could use delimiters e.g. "---". Your plugin at the moment does a great job at serializing the data into one string that can be accessed later on.

So in addition, it would be nice if you added a deserilzer function e.g. named "splitAndSelect" (as a global macro).

<$list filter="a b c +[make[%count%---%title%---%oddeven%]]">

<!-- returns the full serialized compound e.g. "1---a---odd" -->
{{!!title}}

<!-- returns only the counter -->
<
<splitAndSelect separator:"---" index:"1" >>
<!-- returns only the title -->
<
<splitAndSelect "---" "2" >>
<!-- returns "odd" or "even" depending on division of count by 2; could you implement that by the way ;) -->
<
<splitAndSelect "---" "3" >>
<!-- returns and empty string as the 4th slot doesn't exist in the array -->
<
<splitAndSelect "---" "4" >>

<$list>

As you certainly guessed it, splitAndSelect is just a wrapper for a JS split and a subsequent array access operation (see code below).
You could copy the code of the splitAndSelect "macro" from TiddlyMap (I use it there for deserialization of lists in my own scenarios).      

var str = this.getVariable("currentTiddler");
var result = str.split(arguments[1])[arguments[2]];
     
return (result != null ? result : str);

In TiddlyMap I use it e.g. like this:

<$select>
<$list filter="[[|Do not display a neighbourhood]]
               [[1|1 steps away]]
               [[2|2 steps away]]
               [[3|3 steps away]]
               [[*|No limit]]">

  <option value=<
<tmap "splitAndSelect" "|" "0">>><<tmap "splitAndSelect" "|" "1">>

</$list>
</$select>

Which produces

<select>
 
<option value="">Do not display a neighbourhood</option>
 
<option value="1">1 steps away</option>
 
<option value="2">2 steps away</option>
 
<option value="3">3 steps away</option>
 
<option value="*">No limit</option>
</select>

Minor suggestion:
As you noticed in the example above, I added a suggestion for an automatic variable %evenodd% that outputs "even" or odd" depending on the division by 2. I guess that might come handy in the future?! On the other hand users could also write a macro for that task, so I am not sure if it really makes sense to include it as part of your plugin…

In summary: great job and I hope you can add the splitAndSelect thingy as a global macro which would be great for deserialization.

-Felix

P.S. Which github repo url to use for further discussing this plugin?

Alex Hough

unread,
Dec 19, 2015, 5:39:59 PM12/19/15
to TiddlyWiki
Very thought provoking Tobias

I also like the way the view template displays the title of tiddlers with the prefix "make-" ... very easy to navigate



Alex

On 19 December 2015 at 21:03, Felix Küppers <felixk...@hotmail.de> wrote:
Hi Tobias,

Very(!!) nice filter you created! Quite revolutionary, I have to say.

It is more than just a very handy swiss army knife (uuid creation, concatinations, placeholders, for loops with the use of count, step and max directives, how cool!) – it opens the gate for a whole lot of possibilies! Great stuff.

A proposal:

With your plugin, it is now possible for the first time to mix titles with other content on the fly in a sophisticated way using tw-filters.
However your plugin would even become more powerful if you included a macro that allows de-serialization afterwards.

What this means: In the filter expressions users can combine/merge/mix titles with other stuff and could use delimiters e.g. "---". Your plugin at the moment does a great job at serializing the data into one string that can be accessed later on.

So in addition, it would be nice if you added a deserilzer function e.g. named "splitAndSelect" (as a global macro).

<$list filter="a b c +[make[%count%---%title%---%oddeven%%]]">

<!-- returns the counter -->

<
<splitAndSelect separator:"---" index:"1" >>
<!-- returns the title -->
<
<splitAndSelect "---" "2" >>
<!-- returns the "odd" or "even" depending on division of count by 2; could you implement that by the way ;) -->
<
<splitAndSelect "---" "3" >>
<!-- returns and empty string as the 4th slot doesn't exist -->
<
<splitAndSelect "---" "4" >>

<$list>

As you certainly guessed it, splitAndSelect is just a wrapper for a JS split and a subsequent array access operation (see code below).
You could copy the code of the splitAndSelect "macro" from TiddlyMap (I use it there for deserialization of lists in my own scenarios).      

var str = this.getVariable("currentTiddler");
var result = str.split(arguments[1])[arguments[2]];
     
return (result != null ? result : str);

In TiddlyMap I use it e.g. like this:

<$list filter="[[|Do not display a neighbourhood]]
               [[1|1 steps away]]
               [[2|2 steps away]]
               [[3|3 steps away]]
               [[*|No limit]]">
<$select>
<option value=<
<tmap "splitAndSelect" "|" "0">>><<tmap "splitAndSelect" "|" "1">>
</$select>

</$list>

Which produces

<select>
 
<option value="">Do not display a neighbourhood</option>
 
<option value="1">1 steps away</option>
 
<option value="2">2 steps away</option>
 
<option value="3">3 steps away</option>
 
<option value="*">No limit</option>
</select>

Minor suggestion:
As you noticed in the example above, I added a suggestion for an automatic variable %evenodd% that outputs "even" or odd" depending on the division by 2. I guess that might come handy in the future?! On the other hand users could also write a macro for that task, so I am not sure if it really makes sense to include it as part of your plugin…

In summary: great job and I hope you can add the splitAndSelect thingy as a global macro which would be great for deserialization.

-Felix

P.S. Which github repo url to use for further discussing this plugin?

--
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 tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
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/57ea88a9-cd86-4d06-86ec-8daf66ed375c%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Tobias Beer

unread,
Dec 19, 2015, 6:00:16 PM12/19/15
to TiddlyWiki
Hi Felix,

Glad you like this little swiss-knife. :)

Before we further discuss your proposals,
I believe you can already do these things somewhat differently, but quite easily, I think.
Now, it wouldn't work like your splitAndSelect macro, but what you could do instead is use...
  • tobibeer/setvars
    • a widget to create a bunch of variables in one go (capable of evaluating filters)
      • the crucial bit is that it is also capable of addressing and selecting values from a list!
    • and...
  • tobibeer/split
    • you guessed it, a simple filter to split stuff
      • by whichever separator you want
      • or at whichever position you want
I hope it's not too much to ask (today it's a little too late for me anyway)... but,
can you perhaps consider the above two alongside tobibeer/make
and see if that won't achieve the same thing you have in mind, however,
first creating variables you wrap your template / list-contents with?

Best wishes,

Tobias.

Felix Küppers

unread,
Dec 22, 2015, 10:00:37 AM12/22/15
to TiddlyWiki
Hi Tobias,

the setvars plugin is quite clever and it can select values from a list, yes, but it does not give me the option to split a string (deserialize it) based on a specified delimiter (e.g. ";;") and access the array indeces later on.

However: The split filter is what I was looking for (in combination with nth() filter)

<$list filter="a b c +[make[%count%;;%title%;;%max%]]" variable="s">

<div style="background: #ffffcc; padding: 3px; margin: 10px;">

''Serialized string:'' <
<s>>

''Deserialized string:''

|!Index |!First Element |!Second Element |
|{{{ [
<s>split[;;]nth[1]] }}}| {{{ [<s>split[;;]nth[2]] }}}| {{{ [<s>split[;;]nth[3]] }}}|

</div>

</$list>




































The combination of make, split and nth will definitely open doors for people who want to do wikitext "for loops" in a way that is resembles iterations over nested 2-dim-arrays:
  1. People can dynamically create nested arrays in wikitext on the fly using the make filter in combination with a delimiter, e.g.";;".
  2. Then they can iterate over the serialized sub-arrays and access the array elements by index using split and nth

I always wished this was possible in TW ;) Hope my description helps others who are also interested in advanced loops.


@Tobias there seems to be a bug though: do you notice the missing value in the third iteration?


-Felix


Big compliment on your documentation of your plugins by the way.

Tobias Beer

unread,
Dec 22, 2015, 4:34:32 PM12/22/15
to tiddl...@googlegroups.com
Hi Felix,
 
However: The split filter is what I was looking for (in combination with nth() filter)

Haven't yet noticed there was an nth filter. :D
That is, I never considered using it yet.
 

@Tobias there seems to be a bug though: do you notice the missing value in the third iteration?


It's not quite a bug, it's what they call a feature.
Most TiddlyWiki filters treat titles as sets and so does (even) split.
However, I can see how that is confusing, to say the least.

Will think about it and probably change its behavior to not produce sets,
unless explicitly told to do so.

Best wishes,

Tobias.

Felix Küppers

unread,
Dec 22, 2015, 5:29:20 PM12/22/15
to TiddlyWiki
Most TiddlyWiki filters treat titles as sets and so does (even) split.
 
Ahhhh, that's what's happening here :D

Usually, this makes sense but I think as the split filter is more directed at string operations it makes more sense to allow dublicates and have its result be an array (like the result of js split).

Will think about it and probably change it's behavior to not produce sets,

Yes, that would be great as default behavior. please do so! I think it makes more sense here as default mode. E.g. if I split elements of a tuple list separated by colon e.g. soccer results of matches (1:2) I expect the split outcome to be two values but with the current behavior matches that ended e.g. 1:1 or 2:2 would not have their data correctly displayed in the table based on split.

-Felix

Steven Schneider

unread,
Dec 22, 2015, 6:04:35 PM12/22/15
to TiddlyWiki
Hi Tobias, this looks very interesting.

For those of us less experienced, where would I find copy/paste code as examples?

When I copy/paste code from http://tobibeer.github.io/tw5-plugins/#make-Examples, for example:

!
! Simple


// Creates a new unique title based on the current tiddler: //


<<` """{{{ [[]make[]] }}}""">>


I don't get anything; probably not a surprise to you!

Thanks!

//steve.

Tobias Beer

unread,
Dec 23, 2015, 6:14:20 PM12/23/15
to tiddl...@googlegroups.com
Hi Steve,
 
For those of us less experienced, where would I find copy/paste code as examples?
 
You may not have noticed, but you're "playing" with a plugin, not a core feature.
In other words, you need to install it first to see any results.
On the other hand, maybe you just forgot to save/reload after dnd'ing make to your wiki?

Best wishes,

Tobias.

Tobias Beer

unread,
Dec 31, 2015, 9:57:55 AM12/31/15
to tiddl...@googlegroups.com
Hi everyone,

As suggested by Felix, I added the ability to zero-pad the count

Get the update from:


Check out the corresponding examples or operand syntax.

pad:max — zero-pad count to length of max
pad:5 — zero-pad count to 5 digits: 00001

Best wishes,

Tobias.
Reply all
Reply to author
Forward
0 new messages