diff --git a/songbook_core/build.py b/songbook_core/build.py index 264d1e16..bc257aa7 100755 --- a/songbook_core/build.py +++ b/songbook_core/build.py @@ -62,23 +62,6 @@ class Songbook(object): self._parse_raw(raw_songbook) - - - - def __TODO(self): - Song.authwords['after'] = [ - re.compile(r"^.*%s\b(.*)" % after) - for after - in config['authwords']["after"] - ] - Song.authwords['ignore'] = config['authwords']['ignore'] - Song.authwords['sep'] = [ - re.compile(r"^(.*)%s (.*)$" % sep) - for sep in ([ - " %s" % sep for sep in config['authwords']["sep"] - ] + [',']) - ] - def _parse_raw(self, raw_songbook): """Parse raw_songbook. @@ -87,12 +70,26 @@ class Songbook(object): """ self.config.update(raw_songbook) self._set_datadir() + self._set_authwords() + - # TODO This should be moved elsewhere + def _set_authwords(self): # Ensure self.config['authwords'] contains all entries for (key, value) in DEFAULT_AUTHWORDS.items(): if key not in self.config['authwords']: self.config['authwords'][key] = value + # Convert strings to regular expressions + self.config["authwords"]['after'] = [ + re.compile(r"^.*%s\b(.*)" % after) + for after + in self.config['authwords']["after"] + ] + self.config["authwords"]['sep'] = [ + re.compile(r"^(.*)%s (.*)$" % sep) + for sep in ([ + " %s" % sep for sep in self.config['authwords']["sep"] + ] + [',']) + ] def _set_datadir(self): """Set the default values for datadir""" diff --git a/songbook_core/data/templates/default.tex b/songbook_core/data/templates/default.tex index 802d8806..6c756fad 100644 --- a/songbook_core/data/templates/default.tex +++ b/songbook_core/data/templates/default.tex @@ -98,11 +98,11 @@ (* endfor*) (* for key in titleprefixkeys *) (* for word in authwords.key *) - (* if key=="after" *) - \authbyword{((word))} - (* else *) - \auth((key))word{((word))} - (* endif *) + (* if key=="after" *) + \authbyword{((word))} + (* else *) + \auth((key))word{((word))} + (* endif *) (* endfor *) (* endfor*) diff --git a/songbook_core/songs.py b/songbook_core/songs.py index e2222b85..a3909d1c 100644 --- a/songbook_core/songs.py +++ b/songbook_core/songs.py @@ -14,9 +14,6 @@ from songbook_core.plastex import parsetex class Song(object): """Song management""" - #: Dictionnaire des options pour le traitement des auteurs - authwords = {"after": [], "ignore": [], "sep": []} - def __init__(self, filename, config): # Data extraction from the song with plastex data = parsetex(filename) @@ -38,7 +35,7 @@ class Song(object): self.normalized_authors = [ locale.strxfrm(author) for author - in processauthors(self.args["by"], **self.authwords) + in processauthors(self.args["by"], **config["authwords"]) ] else: self.normalized_authors = []