With a few caveats, this code mostly works. Basically I take a stream of 
tiddlers sorted by the "created" field, and then insert a year/month label 
whenever the year/month changes.

!!! breaker test
<$macrocall $name=breaker variable="myvar" input="n/a" pos=6 reset="y" 
ending="" /> 
<$list filter="[tag[Journal]!is[system]has[created]sort[created]]">
<b><$macrocall $name=breaker variable="myvar" input={{!!created}} pos=6 
reset="N" ending="<br/>" /> </b>
<$view field="title"/><br/>
</$list>


So if you want the sub-lists to be sorted in a different order than the 
month data ... you're out of luck.

This is the only way I could find to do it without actually writing a 
widget that does it all. Widgets are messy to write -- at least at this 
point in my TW5 development. What I used instead was a javascript macro to 
break out labels. Code below. There are several parameters 
(variable,input,pos,ending,reset) that you need to pass to the macro. I can 
document them a little better if people find they are actually using the 
code. I figure this is more of a starter kit.

Something to be aware of is that the creation date field may not be the 
field you want. It apparently shows the UTC date of the actual moment the 
tiddler created, which may not be the same as the journal date. In fact, 
depending on where you live, it may be be on a different day than than the 
day in the tiddler title. When I created a journal tiddler at night, for 
instance, the creation date was already on the following day. For this 
reason, it might be better to alter the Journal template code to create and 
update a separate "journaldate" field that has the datestamp in a form that 
matches the journal title.

Javascript macros are tiddlers that have their type set to 
"javascript/application" and an addtional module-type field of "macro". Be 
absolutely sure to backup your data before trying this, because a single 
byte mistake can crash your TW, requiring you to manually edit the tw file 
with a text editor. 

The breaker macro gets called once before the listing begins to clear out a 
global variable and then called in a second way inside the listing.

By looking at the code, I think you can readily see how to change it if you 
want a different way of representing months/years. Here's the code for the 
breaker:

/*\
title: $:/MAS/breaker.js
type: application/javascript
author: MAS
module-type: macro
Break when first n characters of parameter change. User needs to reset.
\*/
(function(){
/*jslint node: true, browser: true */
/*
Information about this macro
*/
exports.name = "breaker";
exports.params = [{name:"variable",default:"masstuff"},{name:"input",default
:""},{name: "pos",default:0},{name:"ending",default:""},{name:"reset",
default:"n"}]; 
/*
Run the macro
*/
exports.run = function() {

var variable=arguments[0] ;
var input = arguments[1] ;
var pos = arguments[2] ;
var ending = arguments[3] ;
var reset = arguments[4] ;

/* For reset at start of loop */

if(reset==="y"  || reset==="Y") {
     $tw[variable]=input ;
     return "" ;
} 

var slc = input.slice(0,pos) ;
var twslc = $tw[variable] ;

if(slc==twslc) { return "" ; }
$tw[variable] = slc ;

var year = slc.slice(0,4) ;
var mo={"01":"January","02":"February","03":"March" ,"04":"April" ,"05":
"May" ,"06":"June","07":"July","08":"August","09":"September","10":"October"
,"11":"November","12":"December"}[slc.slice(4,6)] ;

return year+" "+mo+ending ;

};
})();

 



-- 
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 http://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/7c181960-4d85-4960-b287-194375f0ee57%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to