Browse Source

Error "Invalid songbook language" is now gathered into list songbook errors.

pull/176/head
Louis 9 years ago
parent
commit
d639cdc375
  1. 1
      patacrep/build.py
  2. 16
      patacrep/templates.py

1
patacrep/build.py

@ -114,6 +114,7 @@ class Songbook:
self._config['filename'] = output.name[:-4] self._config['filename'] = output.name[:-4]
renderer.render_tex(output, self._config) renderer.render_tex(output, self._config)
self._errors.extend(renderer.errors)
def has_errors(self): def has_errors(self):
"""Return `True` iff errors have been encountered in the book. """Return `True` iff errors have been encountered in the book.

16
patacrep/templates.py

@ -9,7 +9,7 @@ from jinja2.ext import Extension
from jinja2.meta import find_referenced_templates as find_templates from jinja2.meta import find_referenced_templates as find_templates
from patacrep import errors, files from patacrep import errors, files
from patacrep.latex import lang2babel from patacrep.latex import lang2babel, UnknownLanguage
import patacrep.encoding import patacrep.encoding
_LATEX_SUBS = ( _LATEX_SUBS = (
@ -72,6 +72,7 @@ class Renderer:
# pylint: disable=too-few-public-methods # pylint: disable=too-few-public-methods
def __init__(self, template, jinjaenv, encoding=None): def __init__(self, template, jinjaenv, encoding=None):
self.errors = []
self.encoding = encoding self.encoding = encoding
self.jinjaenv = jinjaenv self.jinjaenv = jinjaenv
self.jinjaenv.block_start_string = '(*' self.jinjaenv.block_start_string = '(*'
@ -92,11 +93,22 @@ class Renderer:
for key, value in [ for key, value in [
("path2posix", files.path2posix), ("path2posix", files.path2posix),
("iter_datadirs", files.iter_datadirs), ("iter_datadirs", files.iter_datadirs),
("lang2babel", lang2babel), ("lang2babel", self.lang2babel),
]: ]:
if key not in self.jinjaenv.filters: if key not in self.jinjaenv.filters:
self.jinjaenv.filters[key] = value self.jinjaenv.filters[key] = value
def lang2babel(self, lang):
"""Return the LaTeX babel code corresponding to `lang`.
Add an error to the list of errors if argument is invalid.
"""
try:
return lang2babel(lang, raise_unknown=True)
except UnknownLanguage as error:
error.message = "Songbook: {}".format(error.message)
self.errors.append(error)
return error.babel
class TexBookRenderer(Renderer): class TexBookRenderer(Renderer):
"""Tex renderer for the whole songbook""" """Tex renderer for the whole songbook"""

Loading…
Cancel
Save