View Single Post
Old 04-19-2022, 10:34 AM   #1
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,336
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
[Kobo] Collections: using a template

@davidfor: last we talked about this I was playing with using a template to optionally rewrite collection names. You felt that a better approach would be to use a template to generate the names, not rewrite the names. After a month or so of using my original system I came to agree with you.

I have an implementation that permits one to add "template" to the list of collection attributes. It can be the only attribute if you wish. The driver invokes the template when looping through the collection attributes. The template returns a list of collection names separated by '#@#' (the same separator used in template searches).

Here is the template I am now using. It supports both my wife's and my Libra 2s. All the hard work is done in the generate_values() function. For my Libra 2 the template generates two sets of collection names, one set for my personal tags all prefixed with "CBHTags: ", and another set of the author's name's first letter prefixed by 'Authors: '. For my wife's it generates one set of names from her personal tags.
Code:
program:
	globals(serial_number='N4181B1027108');

	def generate_values(previous, col_val, sep, prefix, letters):
		res = '';
		for f in col_val separator sep:
			f = re(f, '^\s*(.*)\s*$', '\1');
			if f then
				if letters then f = substr(f, 0, letters) fi;
				res = ':@:' & prefix & f
			fi
		rof;
		return previous & res
	fed;

	if serial_number == 'N4181B1027108' then
		res = generate_values('', $authors, '&', 'Authors: ', 1);
		res = generate_values(res, $#cbhtags, ',', 'CBHTags: ', '');
		return res
	fi;
	if serial_number == 'N4181B5019336' then
		return generate_values('', $#dthtags, ',', 'DTH_Tags: ', '')
	fi
Here is a screenshot of the configuration tab.
Click image for larger version

Name:	Clipboard01.jpg
Views:	467
Size:	69.8 KB
ID:	193339

There are two reasons I chose to add "template" as a collections attribute instead of making it either attributes or template but not both:
  • It doesn't interfere with metadata management because in get_collections it acts like a column. This is important when dealing with device_collections.
  • It permits generating collections from columns in addition to the template.
chaley is offline   Reply With Quote