Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 10-21-2011, 04:35 PM   #1
uli
Zealot
uli can program the VCR without an owner's manual.uli can program the VCR without an owner's manual.uli can program the VCR without an owner's manual.uli can program the VCR without an owner's manual.uli can program the VCR without an owner's manual.uli can program the VCR without an owner's manual.uli can program the VCR without an owner's manual.uli can program the VCR without an owner's manual.uli can program the VCR without an owner's manual.uli can program the VCR without an owner's manual.uli can program the VCR without an owner's manual.
 
Posts: 106
Karma: 194274
Join Date: Jun 2011
Location: Montreal
Device: Kobo, Calibre
Lightbulb Plugboard: Series Contains Star Wars formatting

I'd like the plugboard to use a different formatting when the series is Star Wars or Star Trek. So I created the following, everything works except if the title contains a comma or a parenthesis.

The calibre template guide mentions you need to escape these. How can I escape a field value?

Code:
{series:contains(Star Wars|Star Trek, {title}, {series}{series_index:0>2s| - | - }{title})}

Bad Solution:
Spoiler:

Created a custom column to escape the offending commas
Code:
#clean_title
{title:re(\,,\\,)}
Code:
{series:contains(Star Wars|Star Trek, {#clean_title}, {series}{series_index:0>2s| - | - }{#clean_title})}


The solution is to use program mode in the plugboard mentioned bellow.

Last edited by uli; 10-22-2011 at 12:52 PM. Reason: solution
uli is offline   Reply With Quote
Old 10-22-2011, 01:55 AM   #2
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,734
Karma: 6690881
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by uli View Post
I'd like the plugboard to use a different formatting when the series is Star Wars or Star Trek. So I created the following, everything works except if the title contains a comma or a parenthesis.

The calibre template guide mentions you need to escape these. How can I escape a field value?

Code:
{series:contains(Star Wars|Star Trek, {title}, {series}{series_index:0>2s| - | - }{title})}
Using template expressions inside template expressions has lots of problems. I consider it a bug that it works at all, but if I 'fixed' it I would annoy too many people. To be precise, the templates act as macros, inserting the text from the sub-evaluation then evaluating the enclosing phrase. If the sub-evaluation results in characters that are significant, then evaluating the enclosing phrase will fail.

What you should use is general program mode (see the manual) so you have control over what is evaluated, in what context. This mode permits embedding arbitrary templates as function values. For example, the above template would be written
Code:
program: contains(field('series'), 'Star Wars|Star Trek', field('title'), template('{series}{series_index:0>2s| - | - }{title}'))
This expression says that if the series field matches the regexp 'Star Wars|Star Trek' then return the title field, otherwise return the results of evaluating the template '{series}{series_index:0>2s| - | - }{title}'.
chaley is offline   Reply With Quote
Advert
Old 10-22-2011, 01:03 PM   #3
uli
Zealot
uli can program the VCR without an owner's manual.uli can program the VCR without an owner's manual.uli can program the VCR without an owner's manual.uli can program the VCR without an owner's manual.uli can program the VCR without an owner's manual.uli can program the VCR without an owner's manual.uli can program the VCR without an owner's manual.uli can program the VCR without an owner's manual.uli can program the VCR without an owner's manual.uli can program the VCR without an owner's manual.uli can program the VCR without an owner's manual.
 
Posts: 106
Karma: 194274
Join Date: Jun 2011
Location: Montreal
Device: Kobo, Calibre
Thanks, works perfectly! Now those extra long Star Wars series are readable!

Here is the final code.

Shows series as initials for Star Wars and Star Trek
Shows full series name for everything else.
ex: 'Star Wars: The New Jedi Order...' = SWTNJO - 11 - Rebel Dream
ex: Culture - 01 - Consider Phlebas

Code:
program: contains(field('series'), 'Star Wars|Star Trek', template('{series:re(([^\s])[^\s]+(\s|$),\1)}{series_index:0>2s| - | - }{title}'), template('{series}{series_index:0>2s| - | - }{title}'))
uli is offline   Reply With Quote
Reply

Tags
plugboard, template


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Star Wars geeks NormHart Deals and Resources (No Self-Promotion or Affiliate Links) 1 04-08-2009 12:08 AM
Star Trek vs. Star Wars daffy4u Lounge 48 12-04-2008 10:06 AM
Star Wars Episode III Laurens Lounge 14 05-24-2005 10:44 AM
Star Wars Episode 3 in photos ignatz Lounge 9 02-24-2005 03:41 PM


All times are GMT -4. The time now is 12:03 AM.


MobileRead.com is a privately owned, operated and funded community.