Browse Source

Fix bookoptions support

pull/184/head
Oliverpool 9 years ago
parent
commit
df5235d18e
  1. 4
      patacrep/build.py
  2. 8
      patacrep/data/templates/default_songbook.sb.yml
  3. 4
      patacrep/data/templates/songbook_schema.yml
  4. 3
      patacrep/data/templates/songs.tex
  5. 39
      patacrep/templates.py
  6. 4
      test/test_songbook/datadir.tex.control

4
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):

8
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

4
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

3
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 *)

39
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']

4
test/test_songbook/datadir.tex.control

@ -24,8 +24,10 @@
]{article}
\usepackage[
chorded,
chorded,
pictures,
repeatchords,
importantdiagramonly,
guitar,
]{patacrep}

Loading…
Cancel
Save