Browse Source

Use the new methods to search for a file related to a song

pull/98/head
Oliverpool 9 years ago
parent
commit
eab22ad862
  1. 11
      patacrep/songs/__init__.py
  2. 8
      patacrep/songs/chordpro/__init__.py
  3. 2
      patacrep/songs/chordpro/data/latex/content_image
  4. 2
      patacrep/songs/chordpro/data/latex/content_partition
  5. 2
      patacrep/songs/chordpro/data/latex/song

11
patacrep/songs/__init__.py

@ -252,6 +252,17 @@ class Song:
return fullpath
return None
def search_image(self, filename):
"""Search for an image file"""
datadir_img = self.get_datadirs('img')
filepath = self.search_file(filename, ['', '.jpg', '.png'], datadir_img)
return filepath if filepath else filename
def search_partition(self, filename):
"""Search for a lilypond file"""
filepath = self.search_file(filename, ['', '.ly'])
return filepath if filepath else filename
def unprefixed_title(title, prefixes):
"""Remove the first prefix of the list in the beginning of title (if any).
"""

8
patacrep/songs/chordpro/__init__.py

@ -5,7 +5,7 @@ import pkg_resources
import os
from patacrep import encoding, files
from patacrep.songs import Song, search_image
from patacrep.songs import Song
from patacrep.songs.chordpro.syntax import parse_song
from patacrep.templates import Renderer
@ -42,7 +42,11 @@ class ChordproSong(Song):
os.path.abspath(pkg_resources.resource_filename(__name__, 'data')),
output_format,
)))
self.jinjaenv.filters['search_image'] = search_image
self.jinjaenv.filters['search_image'] = self.search_image
self.jinjaenv.filters['search_partition'] = self.search_partition
return self._render_ast(
context,
self.cached['song'].content,

2
patacrep/songs/chordpro/data/latex/content_image

@ -1 +1 @@
\image{(( content.argument|search_image(path, config) ))}
\image{(( content.argument|search_image ))}

2
patacrep/songs/chordpro/data/latex/content_partition

@ -1 +1 @@
\lilypond{ ((- content.argument|search_image(path, config) -)) }
\lilypond{ ((- content.argument|search_partition -)) }

2
patacrep/songs/chordpro/data/latex/song

@ -28,7 +28,7 @@
(* endif *)
(* endfor *)
(* if 'cov' in metadata *)
cov={(( metadata["cov"].argument|search_image(path, config) ))},
cov={(( metadata["cov"].argument|search_image ))},
(* endif *)
(* for key in metadata.keys *)
(( key.keyword ))={(( key.argument ))},

Loading…
Cancel
Save