Browse Source

Clarified signature of `patacrep.songs.ChordproSong.render()`

pull/103/head
Louis 9 years ago
parent
commit
b73027c865
  1. 6
      patacrep/songs/__init__.py
  2. 6
      patacrep/songs/chordpro/__init__.py
  3. 2
      patacrep/songs/latex/__init__.py
  4. 1
      test/test_chordpro/test_parser.py

6
patacrep/songs/__init__.py

@ -165,16 +165,16 @@ class Song:
def __repr__(self):
return repr((self.titles, self.data, self.fullpath))
def render(self, output, output_format):
def render(self, output_format, output=None, *args, **kwargs):
"""Return the code rendering this song.
Arguments:
- output: Name of the output file.
- output_format: Format of the output file (latex, chordpro...)
- output: Name of the output file, or `None` if irrelevant.
"""
method = "render_{}".format(output_format)
if hasattr(self, method):
return getattr(self, method)(output)
return getattr(self, method)(output, *args, **kwargs)
raise NotImplementedError()
def _parse(self, config): # pylint: disable=no-self-use

6
patacrep/songs/chordpro/__init__.py

@ -36,9 +36,7 @@ class ChordproSong(Song):
'song': song,
}
def render(self, output, output_format, content=None, template="song"): # pylint: disable=arguments-differ
if content is None:
content = self.cached['song'].content
def render(self, output_format, output=None, template="song"):
context = {
'language': self.languages[0],
"titles": self.titles,
@ -46,7 +44,7 @@ class ChordproSong(Song):
"metadata": self.data,
"render": self._render_ast,
"config": self.config,
"content": content,
"content": self.cached['song'].content,
}
jinjaenv = Environment(loader=FileSystemLoader(

2
patacrep/songs/latex/__init__.py

@ -30,6 +30,8 @@ class LatexSong(Song):
def render_latex(self, output):
"""Return the code rendering the song."""
if output is None:
raise ValueError(output)
path = files.path2posix(files.relpath(
self.fullpath,
os.path.dirname(output)

1
test/test_chordpro/test_parser.py

@ -48,7 +48,6 @@ class TestParsingRendering(unittest.TestCase):
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().strip(),

Loading…
Cancel
Save