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 import authors, content, errors, encoding, files, utils
from patacrep.index import process_sxd 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 from patacrep.songs import DataSubpath, DEFAULT_CONFIG
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
@ -109,6 +109,8 @@ class Songbook(object):
) )
config['filename'] = output.name[:-4] config['filename'] = output.name[:-4]
config['bookoptions'] = iter_bookoptions(config)
renderer.render_tex(output, config) renderer.render_tex(output, config)
def requires_lilypond(self): def requires_lilypond(self):

8
patacrep/data/templates/default_songbook.sb.yml

@ -3,14 +3,16 @@ book:
encoding: utf-8 encoding: utf-8
pictures: yes pictures: yes
template: default.tex template: default.tex
onesongperpage: no
chords: # Options relatives aux accords chords: # Options relatives aux accords
show: yes show: yes
diagramreminder: all diagramreminder: important
diagrampage: yes diagrampage: yes
repeatchords: yes repeatchords: yes
lilypond: yes lilypond: no
instruments: guitar tablatures: no
instrument: guitar
notation: alphascale notation: alphascale
authors: # Comment sont analysés les auteurs authors: # Comment sont analysés les auteurs

4
patacrep/data/templates/songbook_schema.yml

@ -13,6 +13,7 @@ required:
lang: //str lang: //str
pictures: //bool pictures: //bool
template: //str template: //str
onesongperpage: //bool
chords: chords:
type: //rec type: //rec
required: required:
@ -20,6 +21,7 @@ required:
diagrampage: //bool diagrampage: //bool
repeatchords: //bool repeatchords: //bool
lilypond: //bool lilypond: //bool
tablatures: //bool
diagramreminder: diagramreminder:
type: //any type: //any
of: of:
@ -29,7 +31,7 @@ required:
value: "important" value: "important"
- type: //str - type: //str
value: "all" value: "all"
instruments: instrument:
type: //any type: //any
of: of:
- type: //str - type: //str

3
patacrep/data/templates/songs.tex

@ -69,11 +69,8 @@
(* block songbookpackages *) (* block songbookpackages *)
\usepackage[ \usepackage[
((booktype)),
(* for option in bookoptions *)((option)), (* for option in bookoptions *)((option)),
(* endfor *) (* endfor *)
(* for instrument in instruments *)((instrument)),
(* endfor *)
]{patacrep} ]{patacrep}
(* endblock *) (* endblock *)

39
patacrep/templates.py

@ -238,3 +238,42 @@ class TexBookRenderer(Renderer):
''' '''
output.write(self.template.render(context)) 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} ]{article}
\usepackage[ \usepackage[
chorded, chorded,
pictures, pictures,
repeatchords,
importantdiagramonly,
guitar, guitar,
]{patacrep} ]{patacrep}

Loading…
Cancel
Save