Start documenting rendering options in the HTML renderer

This commit is contained in:
Raoul Snyman 2021-08-01 22:06:02 -07:00
parent 80e74a77d4
commit 7222a5918b

View File

@ -1,3 +1,5 @@
import os
CHORD = '<td class="chord">{}</td>' CHORD = '<td class="chord">{}</td>'
SYLLB = '<td class="syllable">{}</td>' SYLLB = '<td class="syllable">{}</td>'
LINE = '<table class="line" border="0" cellpadding="0" cellspacing="0"><tr class="chords-line">{}</tr><tr ' \ LINE = '<table class="line" border="0" cellpadding="0" cellspacing="0"><tr class="chords-line">{}</tr><tr ' \
@ -29,6 +31,280 @@ STYLES = {
'verse_upper': '.verse-name { text-transform: uppercase; }', 'verse_upper': '.verse-name { text-transform: uppercase; }',
'chord_bold': '.chord { font-weight: bold; }' 'chord_bold': '.chord { font-weight: bold; }'
} }
HTML_OPTIONS = {
'default_font': {
'description': 'The default font to use.',
'type': str,
'default': None
},
'default_size': {
'description': 'The default size to use.',
'type': int,
'default': None
},
'title_font': {
'description': 'The font for the title',
'type': str,
'default': None
},
'title_size': {
'description': 'The size of the title in rem',
'type': int,
'default': None
},
'title_is_bold': {
'description': 'Set to True to make the title bold',
'type': bool,
'default': True
},
'title_is_upper': {
'description': 'Force the title to be uppercase',
'type': bool,
'default': None,
},
'composer_font': {
'description': 'The font for the composer',
'type': str,
'default': None
},
'composer_size': {
'description': 'The size of the composer in rem',
'type': int,
'default': None
},
'composer_is_bold': {
'description': 'Set to True to make the composer bold',
'type': bool,
'default': None
},
'composer_is_upper': {
'description': 'Force the composer to be uppercase',
'type': bool,
'default': None,
},
'copyright_font': {
'description': 'The font for the copyright',
'type': str,
'default': None
},
'copyright_size': {
'description': 'The size of the copyright in rem',
'type': int,
'default': None
},
'copyright_is_bold': {
'description': 'Set to True to make the copyright bold',
'type': bool,
'default': False,
},
'copyright_is_upper': {
'description': 'Force the copyright to be uppercase',
'type': bool,
'default': None,
},
'stanza_font': {
'description': 'The font for the stanzas',
'type': str,
'default': None
},
'stanza_size': {
'description': 'The size of the stanza in rem',
'type': int,
'default': None
},
'stanza_is_bold': {
'description': 'Set to True to make the stanza bold',
'type': bool,
'default': False
},
'stanza_indent': {
'description': 'How much to indent the stanza by, in rem',
'type': int,
'default': 2
},
'stanza_heading_font': {
'description': 'The font for the stanza headings',
'type': str,
'default': None
},
'stanza_heading_size': {
'description': 'The size of the stanza heading in rem',
'type': int,
'default': None
},
'stanza_heading_is_bold': {
'description': 'Set to True to make the stanza heading bold',
'type': bool,
'default': True
},
'stanza_heading_is_upper': {
'description': 'Force the stanza heading to be uppercase',
'type': bool,
'default': True,
},
'verse_font': {
'description': 'The font for the verses',
'type': str,
'default': None
},
'verse_size': {
'description': 'The size of the verse in rem',
'type': int,
'default': None
},
'verse_is_bold': {
'description': 'Set to True to make the verse bold',
'type': bool,
'default': None
},
'verse_indent': {
'description': 'How much to indent the verse by, in rem',
'type': int,
'default': None
},
'verse_heading_font': {
'description': 'The font for the verse headings',
'type': str,
'default': None
},
'verse_heading_size': {
'description': 'The size of the verse heading in rem',
'type': int,
'default': None
},
'verse_heading_is_bold': {
'description': 'Set to True to make the verse heading bold',
'type': bool,
'default': None
},
'verse_heading_is_upper': {
'description': 'Force the verse heading to be uppercase',
'type': bool,
'default': True,
},
'chorus_font': {
'description': 'The font for the choruses',
'type': str,
'default': None
},
'chorus_size': {
'description': 'The size of the chorus in rem',
'type': int,
'default': None
},
'chorus_is_bold': {
'description': 'Set to True to make the chorus bold',
'type': bool,
'default': None
},
'chorus_indent': {
'description': 'How much to indent the chorus by, in rem',
'type': int,
'default': None
},
'chorus_heading_font': {
'description': 'The font for the chorus headings',
'type': str,
'default': None
},
'chorus_heading_size': {
'description': 'The size of the chorus heading in rem',
'type': int,
'default': None
},
'chorus_heading_is_bold': {
'description': 'Set to True to make the chorus heading bold',
'type': bool,
'default': None
},
'chorus_heading_is_upper': {
'description': 'Force the chorus heading to be uppercase',
'type': bool,
'default': True,
},
'bridge_font': {
'description': 'The font for the bridge',
'type': str,
'default': None
},
'bridge_size': {
'description': 'The size of the bridge in rem',
'type': int,
'default': None
},
'bridge_is_bold': {
'description': 'Set to True to make the bridge bold',
'type': bool,
'default': None
},
'bridge_indent': {
'description': 'How much to indent the bridge by, in rem',
'type': int,
'default': None
},
'bridge_heading_font': {
'description': 'The font for the bridge headings',
'type': str,
'default': None
},
'bridge_heading_size': {
'description': 'The size of the bridge heading in rem',
'type': int,
'default': None
},
'bridge_heading_is_bold': {
'description': 'Set to True to make the bridge heading bold',
'type': bool,
'default': None
},
'bridge_heading_is_upper': {
'description': 'Force the bridge heading to be uppercase',
'type': bool,
'default': True,
},
'chord_font': {
'description': 'The font for the chord',
'type': str,
'default': None
},
'chord_size': {
'description': 'The size of the chord in rem',
'type': int,
'default': None
},
'chord_is_bold': {
'description': 'Set to True to make the chord bold',
'type': bool,
'default': True
},
'chord_is_centered': {
'description': 'Make chords centered over syllables',
'type': bool,
'default': True
}
}
def get_options():
"""Return the options supported by the HTML renderer"""
return HTML_OPTIONS
def make_style(name, font=None, size=None, is_bold=None, is_centered=None, is_upper=None):
"""Build a CSS style"""
styles = ['.{name} {{'.format(name=name)]
if font:
styles.append(' font-family: \'{font}\';'.format(font=font))
if size:
styles.append(' font-size: {size}rem;'.format(size=size))
if is_bold:
styles.append(' font-weight: bold !important;')
if is_centered:
styles.append(' text-align: center;')
if is_upper:
styles.append(' text-transform: uppercase;')
styles.append('}}')
return os.linesep.join(styles)
def render(song, verse_upper=False, verse_name_bold=False, chord_bold=False): def render(song, verse_upper=False, verse_name_bold=False, chord_bold=False):