Browse Source

Merge pull request #118 from patacrep/one_language

Only one language per song (the latest defined)
pull/126/head
Louis 9 years ago
parent
commit
436fc28157
  1. 1
      examples/example-all.sb
  2. 2
      patacrep/content/song.py
  3. 6
      patacrep/latex/ast.py
  4. 6
      patacrep/songs/__init__.py
  5. 4
      patacrep/songs/chordpro/__init__.py
  6. 1
      patacrep/songs/chordpro/ast.py
  7. 4
      patacrep/songs/latex/__init__.py
  8. 2
      test/test_chordpro/metadata.source

1
examples/example-all.sb

@ -6,6 +6,7 @@
"pictures"
],
"booktype" : "chorded",
"datadir": ["datadir2"],
"template" : "patacrep.tex",
"lang" : "french",
"encoding": "utf8",

2
patacrep/content/song.py

@ -92,7 +92,7 @@ def parse(keyword, argument, contentlist, config):
datadir=songdir.datadir,
))
songlist.append(renderer)
config["_languages"].update(renderer.song.languages)
config["_languages"].add(renderer.song.language)
if len(songlist) > before:
break
if len(songlist) == before:

6
patacrep/latex/ast.py

@ -2,6 +2,8 @@
# pylint: disable=too-few-public-methods
DEFAULT_LANGUAGE = "english"
class AST:
"""Base class for the tree."""
# pylint: disable=no-init
@ -16,7 +18,7 @@ class AST:
parsing.
"""
cls.metadata = {
'@languages': set(),
'@language': DEFAULT_LANGUAGE,
}
class Expression(AST):
@ -44,7 +46,7 @@ class Command(AST):
self.optional = optional
if name == r'\selectlanguage':
self.metadata['@languages'] |= set(self.mandatory)
self.metadata['@language'] = self.mandatory[0]
def __str__(self):
if self.name in [r'\emph']:

6
patacrep/songs/__init__.py

@ -89,7 +89,7 @@ class Song:
"cached",
"data",
"subpath",
"languages",
"language",
"authors",
"_filehash",
"_version",
@ -186,8 +186,8 @@ class Song:
- titles: the list of (raw) titles. This list will be processed to
remove prefixes.
- languages: the list of languages used in the song, as languages
recognized by the LaTeX babel package.
- language: the main language of the song, as language recognized by
the LaTeX babel package.
- authors: the list of (raw) authors. This list will be processed to
'clean' it (see function :func:`patacrep.authors.processauthors`).
- data: song metadata. Used (among others) to sort the songs.

4
patacrep/songs/chordpro/__init__.py

@ -35,7 +35,7 @@ class ChordproSong(Song):
song = parse_song(song.read(), self.fullpath)
self.authors = song.authors
self.titles = song.titles
self.languages = song.get_data_argument('language', [self.config['lang']])
self.language = song.get_data_argument('language', self.config['lang'])
self.data = song.meta
self.cached = {
'song': song,
@ -46,7 +46,7 @@ class ChordproSong(Song):
templatedirs = []
context = {
'language': self.languages[0],
'language': self.language,
"titles": self.titles,
"authors": self.authors,
"metadata": self.data,

1
patacrep/songs/chordpro/ast.py

@ -193,7 +193,6 @@ class Song(AST):
"artist": "add_author",
"key": "add_key",
"define": "add_cumulative",
"language": "add_cumulative",
}
def __init__(self, filename):

4
patacrep/songs/latex/__init__.py

@ -20,8 +20,8 @@ class LatexSong(Song):
self.data = parse_song(song.read(), self.fullpath)
self.titles = self.data['@titles']
del self.data['@titles']
self.languages = self.data['@languages']
del self.data['@languages']
self.language = self.data['@language']
del self.data['@language']
if "by" in self.data:
self.authors = [self.data['by']]
del self.data['by']

2
test/test_chordpro/metadata.source

@ -4,8 +4,8 @@
{subtitle: Subtitle4}
{t: Subtitle2}
{st: Subtitle5}
{language: french}
{language: english}
{language: french}
{by: Author1}
{artist: Author2}
{album: Album}

Loading…
Cancel
Save