Thinking about this a bit more, I think that the best solution is
Code:
program:
contains(approximate_formats(), 'EPUB|MOBI|PDF', 'red', '')
Why better? Because:
- As I said abive, GPM templates are compiled so the custom column doesn't have that advantage.
- There is no list manipulation in this template.
- It is general enough to return different values for yes and no.
Note that this template suffers from the same problem as the function example I gave. It will return true if a format string contains one of the values. For example, it will match ORIGINAL_EPUB as well as EPUB. If you don't want this then you could use the following:
Code:
program:
list_re(approximate_formats(), ',', '^(EPUB|MOBI|PDF)$', 'red');
but this is significantly slower.
Alternatively you could do the same thing as a custom template function, which will be faster because it isn't as general as list_re.
Code:
def evaluate(self, formatter, kwargs, mi, locals, color):
import re
fmt_data = mi._proxy_metadata.db_approx_formats
for f in fmt_data:
if re.search('^(EPUB|MOBI|PDF)$', f):
return color
return ''