mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Permit empty keys in templates. Simplifies using functions that don't require a value
This commit is contained in:
parent
52da86dbb6
commit
67d570de1c
@ -42,6 +42,8 @@ field_metadata = FieldMetadata()
|
||||
class SafeFormat(TemplateFormatter):
|
||||
|
||||
def get_value(self, orig_key, args, kwargs):
|
||||
if not orig_key:
|
||||
return ''
|
||||
key = orig_key.lower()
|
||||
if key != 'title_sort' and key not in TOP_LEVEL_IDENTIFIERS:
|
||||
key = field_metadata.search_term_to_field_key(key)
|
||||
|
@ -134,6 +134,8 @@ class SafeFormat(TemplateFormatter):
|
||||
'''
|
||||
|
||||
def get_value(self, key, args, kwargs):
|
||||
if key == '':
|
||||
return ''
|
||||
try:
|
||||
key = key.lower()
|
||||
try:
|
||||
|
@ -342,6 +342,8 @@ class EvalFormatter(TemplateFormatter):
|
||||
A template formatter that uses a simple dict instead of an mi instance
|
||||
'''
|
||||
def get_value(self, key, args, kwargs):
|
||||
if key == '':
|
||||
return ''
|
||||
key = key.lower()
|
||||
return kwargs.get(key, _('No such variable ') + key)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user