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): def __repr__(self):
return repr((self.titles, self.data, self.fullpath)) 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. """Return the code rendering this song.
Arguments: Arguments:
- output: Name of the output file.
- output_format: Format of the output file (latex, chordpro...) - output_format: Format of the output file (latex, chordpro...)
- output: Name of the output file, or `None` if irrelevant.
""" """
method = "render_{}".format(output_format) method = "render_{}".format(output_format)
if hasattr(self, method): if hasattr(self, method):
return getattr(self, method)(output) return getattr(self, method)(output, *args, **kwargs)
raise NotImplementedError() raise NotImplementedError()
def _parse(self, config): # pylint: disable=no-self-use def _parse(self, config): # pylint: disable=no-self-use

6
patacrep/songs/chordpro/__init__.py

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

2
patacrep/songs/latex/__init__.py

@ -30,6 +30,8 @@ class LatexSong(Song):
def render_latex(self, output): def render_latex(self, output):
"""Return the code rendering the song.""" """Return the code rendering the song."""
if output is None:
raise ValueError(output)
path = files.path2posix(files.relpath( path = files.path2posix(files.relpath(
self.fullpath, self.fullpath,
os.path.dirname(output) 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): with self.subTest(base=os.path.basename(base), format=dest):
self.assertMultiLineEqual( self.assertMultiLineEqual(
ChordproSong(None, chordproname, config).render( ChordproSong(None, chordproname, config).render(
output=chordproname,
output_format=LANGUAGES[dest], output_format=LANGUAGES[dest],
).strip(), ).strip(),
expectfile.read().strip(), expectfile.read().strip(),

Loading…
Cancel
Save