View Single Post
Old 01-04-2011, 06:57 AM   #122
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: 11,789
Karma: 7029971
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by stevehaley View Post
Many thanks to all who have lead the way on this - I thought I would add my two-pennyworth and findings.

My problem was the normal kindle/series/collection title format problem but I wasnt happy that any one derived format fixed the problem as I could see having collections with one series where just the series number would be ok and others with more than one where I would want to show the series name or a shortened version of this as well.
Nice job. Two small points:
1: The line
Code:
str_title5 = template('{title}');
would be better written
Code:
str_title5 = field('title');
Although they produce the same result, the second will have much better performance because it avoids all the kerfuffle of setting up a recursive template evaluation.

2: Instead of
Code:
str_input = lowercase(field('#kindle_title_fmt'));
switch(str_input,
You might consider using
Code:
switch(lowercase(field('#kindle_title_fmt')),
Reason: performance and (matter of taste) readability. The template language is double-interpreted (an interpreter written in python) and not in byte code, making reducing the amount of executed code a worthwhile endeavor. The assignment requires execution of an 'assign' function that stores the value in the variable table, while using the lowercase function directly in the switch does avoids that work.

Another option that has even better performance takes advantage of the fact that the match-value parameters in switch are really regexps. This lets you use case-insensitive matching by writing the switch as:
Code:
switch(field('#kindle_title_fmt'),
           '(?i)series and num',str_title1,
           '(?i)alt and num',str_title2,
           '(?i)short and num',str_title3,
           '(?i)num only',str_title4,
           '(?i)no series info',str_title5,
           str_default);
The matter of taste can be ignored.
Quote:
3) Was easiest to just put any old text into the 3rd column when creating it then use the f2 edit later to put the actual code in.
I have considered changing the creation dialog to use the same multi-line editor that F2 uses. This would make entering complex templates during creation much easier, at the expense of making entering simple templates take another click or two. Opinions?
chaley is offline   Reply With Quote