diff --git a/patacrep/build.py b/patacrep/build.py index 00bc8e07..71d8742f 100644 --- a/patacrep/build.py +++ b/patacrep/build.py @@ -12,7 +12,7 @@ import yaml from patacrep import authors, content, errors, encoding, files, utils from patacrep.index import process_sxd -from patacrep.templates import TexBookRenderer +from patacrep.templates import TexBookRenderer, iter_bookoptions from patacrep.songs import DataSubpath, DEFAULT_CONFIG LOGGER = logging.getLogger(__name__) @@ -109,6 +109,8 @@ class Songbook(object): ) config['filename'] = output.name[:-4] + config['bookoptions'] = iter_bookoptions(config) + renderer.render_tex(output, config) def requires_lilypond(self): diff --git a/patacrep/data/templates/default_songbook.sb.yml b/patacrep/data/templates/default_songbook.sb.yml index b2bf3edb..fc8ccd10 100644 --- a/patacrep/data/templates/default_songbook.sb.yml +++ b/patacrep/data/templates/default_songbook.sb.yml @@ -3,14 +3,16 @@ book: encoding: utf-8 pictures: yes template: default.tex + onesongperpage: no chords: # Options relatives aux accords show: yes - diagramreminder: all + diagramreminder: important diagrampage: yes repeatchords: yes - lilypond: yes - instruments: guitar + lilypond: no + tablatures: no + instrument: guitar notation: alphascale authors: # Comment sont analysés les auteurs diff --git a/patacrep/data/templates/songbook_schema.yml b/patacrep/data/templates/songbook_schema.yml index 8db2b584..cd6dc66d 100644 --- a/patacrep/data/templates/songbook_schema.yml +++ b/patacrep/data/templates/songbook_schema.yml @@ -13,6 +13,7 @@ required: lang: //str pictures: //bool template: //str + onesongperpage: //bool chords: type: //rec required: @@ -20,6 +21,7 @@ required: diagrampage: //bool repeatchords: //bool lilypond: //bool + tablatures: //bool diagramreminder: type: //any of: @@ -29,7 +31,7 @@ required: value: "important" - type: //str value: "all" - instruments: + instrument: type: //any of: - type: //str diff --git a/patacrep/data/templates/songs.tex b/patacrep/data/templates/songs.tex index 6b8f01e2..b2f71e6a 100644 --- a/patacrep/data/templates/songs.tex +++ b/patacrep/data/templates/songs.tex @@ -69,11 +69,8 @@ (* block songbookpackages *) \usepackage[ - ((booktype)), (* for option in bookoptions *)((option)), (* endfor *) - (* for instrument in instruments *)((instrument)), - (* endfor *) ]{patacrep} (* endblock *) diff --git a/patacrep/templates.py b/patacrep/templates.py index 8e4e32fd..fc24c91a 100644 --- a/patacrep/templates.py +++ b/patacrep/templates.py @@ -238,3 +238,42 @@ class TexBookRenderer(Renderer): ''' output.write(self.template.render(context)) + + +def transform_options(config, equivalents): + """ + Get the equivalent name of the checked options + """ + for option in config: + if config[option] and option in equivalents: + yield equivalents[option] + +def iter_bookoptions(config): + """ + Extract the bookoptions from the config structure + """ + if config['chords']['show']: + yield 'chorded' + else: + yield 'lyrics' + + book_equivalents = { + 'pictures': 'pictures', + 'onesongperpage': 'onesongperpage', + } + yield from transform_options(config['book'], book_equivalents) + + chords_equivalents = { + 'lilypond': 'lilypond', + 'tablatures': 'tabs', + 'repeatchords': 'repeatchords', + } + yield from transform_options(config['chords'], chords_equivalents) + + if config['chords']['show']: + if config['chords']['diagramreminder'] == "important": + yield 'importantdiagramonly' + elif config['chords']['diagramreminder'] == "all": + yield 'diagram' + + yield config['chords']['instrument'] diff --git a/test/test_songbook/datadir.tex.control b/test/test_songbook/datadir.tex.control index afc99160..ecb85055 100644 --- a/test/test_songbook/datadir.tex.control +++ b/test/test_songbook/datadir.tex.control @@ -24,8 +24,10 @@ ]{article} \usepackage[ - chorded, +chorded, pictures, +repeatchords, +importantdiagramonly, guitar, ]{patacrep}