diff --git a/patacrep/content/song.py b/patacrep/content/song.py index 4f8cd8f4..9a1b4635 100755 --- a/patacrep/content/song.py +++ b/patacrep/content/song.py @@ -4,6 +4,7 @@ import glob import jinja2 import logging import os +import textwrap from patacrep.content import process_content, ContentError, Content from patacrep import files, errors @@ -34,7 +35,16 @@ class SongRenderer(Content): def render(self, context): """Return the string that will render the song.""" - return self.song.render(output=context['filename'], output_format="latex") + return textwrap.dedent("""\ + {separator} + %% {path} + + {song} + """).format( + separator="%"*80, + path=self.song.subpath, + song=self.song.render(output=context['filename'], output_format="latex"), + ) #pylint: disable=unused-argument def parse(keyword, argument, contentlist, config): diff --git a/patacrep/songs/chordpro/data/latex/song b/patacrep/songs/chordpro/data/latex/song index a4f4d9ca..4664d52f 100644 --- a/patacrep/songs/chordpro/data/latex/song +++ b/patacrep/songs/chordpro/data/latex/song @@ -1,12 +1,10 @@ - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% ((path)) - (* if language is defined -*) \selectlanguage{((language))} (* endif *) + +(*- if metadata.columns is defined *) \songcolumns{(( metadata.columns ))} +(* endif *) \beginsong{ (*- for title in titles -*) @@ -33,9 +31,9 @@ (* if (metadata.cov is defined) or (metadata.vcov is defined) *) \cover -(* endif -*) +(* endif *) -(* for chord in metadata['define'] *) +(*- for chord in metadata['define'] *) (( render(chord) )) (* endfor *) @@ -44,5 +42,3 @@ (* endfor *) \endsong -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - diff --git a/patacrep/songs/chordpro/test/02.sgc.tex b/patacrep/songs/chordpro/test/02.sgc.tex new file mode 100644 index 00000000..b3ec6f17 --- /dev/null +++ b/patacrep/songs/chordpro/test/02.sgc.tex @@ -0,0 +1,10 @@ +\selectlanguage{english} + +\beginsong{A directive}[ + by={ + }, +] + + + +\endsong diff --git a/patacrep/songs/chordpro/test/test_parser.py b/patacrep/songs/chordpro/test/test_parser.py index 394e9966..32216d47 100644 --- a/patacrep/songs/chordpro/test/test_parser.py +++ b/patacrep/songs/chordpro/test/test_parser.py @@ -10,6 +10,10 @@ from patacrep.build import DEFAULT_CONFIG from patacrep.songs.chordpro import ChordproSong from patacrep.test import disable_logging +LANGUAGES = { + 'tex': 'latex', + 'sgc': 'chordpro', +} class TestParsingRendering(unittest.TestCase): """Test parsing and rendering""" @@ -26,17 +30,21 @@ class TestParsingRendering(unittest.TestCase): '*.source', ))): base = source[:-len(".source")] - with open("{}.sgc".format(base), 'r', encoding='utf8') as expectfile: - chordproname = "{}.source".format(base) - with disable_logging(): - with self.subTest(base=os.path.basename(base)): - self.assertMultiLineEqual( - ChordproSong(None, chordproname, config).render( - output=chordproname, - output_format="chordpro", - ).strip(), - expectfile.read().replace( - "DIRNAME", - os.path.dirname(base), - ).strip(), - ) + for dest in LANGUAGES: + destname = "{}.{}".format(base, dest) + if not os.path.exists(destname): + continue + with open(destname, 'r', encoding='utf8') as expectfile: + chordproname = "{}.source".format(base) + with disable_logging(): + with self.subTest(base=os.path.basename(base), format=dest): + self.assertMultiLineEqual( + ChordproSong(None, chordproname, config).render( + output=chordproname, + output_format=LANGUAGES[dest], + ).strip(), + expectfile.read().replace( + "DIRNAME", + os.path.dirname(base), + ).strip(), + )