Using the ForEachTiddlerPlugin[1], you would use something like the
following for each individual tab:
---------------
<<forEachTiddler
where 'store.getValue(tiddler, "author") &&
store.getValue(tiddler, "author").substr(0, 1).toLowerCase() == "a"'
write '"* [[" + tiddler.title + "]]\n"'
>>
---------------
(The .toLowerCase() method for case-insensitive comparison is optional.)
In order to automatically generate that list for each letter of the
basic Latin alphabet, I've used the InlineTabsPlugin[2] and came up with
the following script (requires InlineJavascriptPlugin[3]):
---------------
<script>
var FETScriptPre = '<<forEachTiddler\n'
+ 'where [[store.getValue(tiddler, "author") && '
+ 'store.getValue(tiddler, "author").substr(0, 1).toLowerCase() == "'
var FETScriptPost = '"]]\n'
+ 'write \'"* [[" + tiddler.title + "]]\\n"\'\n'
+ '>>\n'
var c;
var output = "<tabs authorsIndex>\n";
for(var i = 0; i < 26; i++) {
c = String.fromCharCode(i + 97);
output += "<tab " + c + ">\n";
output += FETScriptPre + c + FETScriptPost;
output += "</tab>\n";
}
output += "</tabs>";
wikify(output, place);
</script>
---------------
It's not pretty (mostly due to the nested quotes of the FET macro call),
but it seems to work.
HTH.
-- F.
[1] http://tiddlywiki.abego-software.de/#ForEachTiddlerPlugin
[2] http://tw.lewcid.org/sandbox/#InlineTabsPlugin
[3] http://www.tiddlytools.com/#InlineJavascriptPlugin
I'm not entirely sure why the tabs don't simply wrap by default (as far
as I can tell, they're just inline elements - so basically not much
different from regular text).
Nevertheless, try adding this to your StyleSheet:
.tabset {
overflow: auto;
}
.tab {
display: block;
float: left;
}
You could also have a vertical tab bar with the contents on the right:
.tabset {
float: left;
padding: 0;
}
.tabContents {
overflow: auto;
}
.tab {
display: block;
}
Neither of these things is heavily tested, so let me know if you run
into problems.
-- F.
Glad I could help.
> Thanks for this beautiful (in my eyes) little piece of code!
It's not beautiful code at all to me.
For example, instead of embedding the FET macro calls, we could have
directly used the forEachTiddler() core function (since we're using
custom code, it's not suitable for non-tech-savvy users anyway).
In fact, that would probably have been much easier - why didn't I think
of that before?!
Well, maybe another time...
-- F.
I'm not sure I understand that scenario, but the difference between
Timeline/All and these tabs is simply the amount of data that's being
rendered.
In fact, that's also the reason why embedded the FET macro call is
indeed required after all; the macro is only executed when it's being
rendered (i.e. when the respective tab is selected), so the tabs reduce
the processing effort to 1/26th (on average).
Of course I could say now that this fact had temporarily slipped my mind
when I was criticizing myself before - but that performance advantage is
really more of a conceptual accident; the reason I had used the FET
macro in the first place was because I hadn't yet thought about
automatically generating those tabs.
-- F.
Use the FET macro's sortBy command:
---------------
<<forEachTiddler
where 'store.getValue(tiddler, "author") &&
store.getValue(tiddler, "author").substr(0, 1).toLowerCase() == "a"'
sortBy 'tiddler.fields["author"]'
write '"* " + tiddler.fields["author"] + " – "
+ "[[" + tiddler.title + "]]\n"'
>>
---------------
Note that instead of using store.getValue(), I've used tiddler.fields[]
for the sortBy and write arguments - that means that only the current
iteration's tiddler object is accessed there, instead of processing the
entire store again (another potential performance enhancement).
Our script should look like this then:
---------------
<script>
var FETScriptPre = '<<forEachTiddler\n'
+ 'where [[store.getValue(tiddler, "author") && '
+ 'store.getValue(tiddler, "author").substr(0, 1).toLowerCase() == "'
var FETScriptPost = '"]]\n'
+ 'sortBy \'tiddler.fields["author"]\'\n'
+ 'write \'"* " + tiddler.fields["author"] + " – " '
+ '+ "[[" + tiddler.title + "]]\\n"\'\n'
+ '>>\n'
var c;
var output = "<tabs authorsIndex>\n";
for(var i = 0; i < 26; i++) {
c = String.fromCharCode(i + 97);
output += "<tab " + c + ">\n";
output += FETScriptPre + c + FETScriptPost;
output += "</tab>\n";
}
output += "</tabs>";
wikify(output, place);
</script>
---------------
(All those nested quotes are driving me $#@%!)*
> ... the ugly duckling is actually a swan!
It's still an ugly duckling, but one with quick feet.
(Sort of the equivalent of Steffi Graf, I guess... )*
-- F.
* Yes, that's my Christmas mood at work right there...
Sure - just change the following lines (old/new adjacency pairs)
+ 'store.getValue(tiddler, "author").substr(0, 1).toLowerCase() == "'
+ 'store.getValue(tiddler, "author").substr(0, 1).toUpperCase() == "'
c = String.fromCharCode(i + 97);
c = String.fromCharCode(i + 65);
This then results in the following script:
---------------
<script>
var FETScriptPre = '<<forEachTiddler\n'
+ 'where [[store.getValue(tiddler, "author") && '
+ 'store.getValue(tiddler, "author").substr(0, 1).toUpperCase() == "'
var FETScriptPost = '"]]\n'
+ 'sortBy \'tiddler.fields["author"]\'\n'
+ 'write \'"* " + tiddler.fields["author"] + " – " '
+ '+ "[[" + tiddler.title + "]]\\n"\'\n'
+ '>>\n'
var c;
var output = "<tabs authorsIndex>\n";
for(var i = 0; i < 26; i++) {
c = String.fromCharCode(i + 65);
output += "<tab " + c + ">\n";
output += FETScriptPre + c + FETScriptPost;
output += "</tab>\n";
}
output += "</tabs>";
wikify(output, place);
</script>
---------------
HTH.
-- F.
For this you could use the OpenTiddlersMacro*, you could try the following:
---------------
<<openTiddlers
text:"click"
tiddlers:{{
var letter = "S";
var tiddlers = store.getTiddlers().map(function(t) {
return t.title;
});
var t = "";
for(var i = 0; i < tiddlers.length; i++) {
if(tiddlers[i].indexOf(letter) == 0)
t += "[[" + tiddlers[i] + "]] ";
}
t;
}}
>>
---------------
Of course this macro call could also be embedded into a script that
automatically generates this macro for each letter of the alphabet
(similar to what we did for Mark before), but that's gonna take some
more effort...
-- F.
* http://tinyurl.com/3xgg26
(http://tw.lewcid.org/svn/plugins/OpenTiddlersMacro/OpenTiddlersMacro.js)
Clever solution, Wolfgang - I'd actually prefer that over a convoluted
FET macro call!
(quoting myself: "Duh! *facepalm* Why didn't I think of that... ")
-- F.