:- ensure_loaded(common).
cvs_id('$Id: list_views.pl,v 1.1 2004/06/09 17:19:31 sandro Exp $').
/*

  Various list (collection) views.  

*/


%%  thing_list(?Q, +ListOfThings, -H)
%%
%%  Turn a list RDF Ids into some HTML with a comma-separated
%%  list of their +word views, with optional highlighting of some of them.

enword(Q, URI, [ +word(Q, URI) ]).

enword(Q, HighLight, URI, HTree) :-
	(   call(HighLight, URI)
	->  HTree = [ span(class=high, +word(Q, URI)) ]
	;   HTree = [ +word(Q, URI) ]
	).

thing_list(Q, Things, HTree) :-
	sort(Things, SortedThings),
	maplist(enword(Q), SortedThings, HTree2),
	commasep(HTree2, HTree).

thing_list(Q, Things, HighLight, HTree) :-
	sort(Things, SortedThings),
	maplist(enword(Q, HighLight), SortedThings, HTree2),
	commasep(HTree2, HTree).

commasep([], []).
commasep([X], [X]).
commasep([H|T], [H, ', '|TX]) :- commasep(T,TX).

