Conversion: Insert metadata: Allow hiding entries in the jacket template when they are not present in the metadata.

This commit is contained in:
Kovid Goyal 2021-01-20 19:35:07 +05:30
parent eeb609f983
commit 3f8403ca84
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 31 additions and 17 deletions

View File

@ -49,7 +49,9 @@
label #genre, you can add it to this template with _genre_label and
_genre. Note that the # is replaced by an underscore. For example
<div><b>{_genre_label}:</b> {_genre}</div>
<div style="display: display._genre"><b>{_genre_label}:</b> {_genre}</div>
If #genre is not set, then the entire <div> element will be hidden.
-->
<div class="cbj_comments">{comments}</div>

View File

@ -229,6 +229,12 @@ def postprocess_jacket(root, output_profile, has_data):
extract_class('cbj_kindle_banner_hr')
class Attributes:
def __getattr__(self, name):
return 'none'
def render_jacket(mi, output_profile,
alt_title=_('Unknown'), alt_tags=[], alt_comments='',
alt_publisher='', rescale_fonts=False, alt_authors=None):
@ -282,6 +288,7 @@ def render_jacket(mi, output_profile,
has_data = {}
def generate_html(comments):
display = Attributes()
args = dict(xmlns=XHTML_NS,
title_str=title_str,
css=css,
@ -294,6 +301,7 @@ def render_jacket(mi, output_profile,
tags_label=_('Tags'), tags=tags,
comments=comments,
footer='',
display=display,
searchable_tags=' '.join(escape(t)+'ttt' for t in tags.tags_list),
)
for key in mi.custom_field_keys():
@ -322,6 +330,7 @@ def render_jacket(mi, output_profile,
else:
args[dkey] = escape(val)
args[dkey+'_label'] = escape(display_name)
setattr(display, dkey, 'none' if mi.is_null(key) else 'initial')
except Exception:
# if the val (custom column contents) is None, don't add to args
pass
@ -336,13 +345,16 @@ def render_jacket(mi, output_profile,
# Don't change this unless you also change it in template.xhtml
args['_genre_label'] = args.get('_genre_label', '{_genre_label}')
args['_genre'] = args.get('_genre', '{_genre}')
formatter = SafeFormatter()
generated_html = formatter.format(template, **args)
has_data['series'] = bool(series)
has_data['tags'] = bool(tags)
has_data['rating'] = bool(rating)
has_data['pubdate'] = bool(pubdate)
for k, v in has_data.items():
setattr(display, k, 'initial' if v else 'none')
display.title = 'initial'
formatter = SafeFormatter()
generated_html = formatter.format(template, **args)
return strip_encoding_declarations(generated_html)