Browse Source

Silent changes to `seach_*()` methods; using `search_*()` filters in templates

pull/103/head
Louis 9 years ago
parent
commit
becea663ea
  1. 25
      patacrep/songs/__init__.py
  2. 2
      patacrep/songs/chordpro/data/chordpro/content_image
  3. 2
      patacrep/songs/chordpro/data/chordpro/content_partition
  4. 5
      patacrep/songs/chordpro/data/chordpro/song_header

25
patacrep/songs/__init__.py

@ -206,16 +206,20 @@ class Song:
"""Search for a file name.
:param str filename: The name, as provided in the chordpro file (with or without extension).
:param list extensions: Possible extensions (with '.')
:param list extensions: Possible extensions (with '.'). Default is no extension.
:param iterator directories: Other directories where to search for the file
The directory where the Song file is stored is added to the list.
Returns None if nothing found.
This function can also be used as a preprocessor for a renderer: for
instance, it can compile a file, place it in a temporary folder, and
return the path to the compiled file.
"""
if extensions is None:
extensions = ['']
if directories is None:
directories = []
directories = self.config['datadir']
songdir = os.path.dirname(self.fullpath)
@ -228,8 +232,16 @@ class Song:
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)
filepath = self.search_file(
filename,
['', '.jpg', '.png'],
self.get_datadirs('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
@property
@ -241,11 +253,6 @@ class Song:
datadir_img = self.get_datadirs('img')
return self.search_file(filename, ['', '.jpg', '.png'], datadir_img)
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).
"""

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

@ -1 +1 @@
{image: (( content.argument ))}
{image: (( content.argument|search_image ))}

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

@ -1 +1 @@
{partition: ((content.argument))}
{partition: ((content.argument|search_partition))}

5
patacrep/songs/chordpro/data/chordpro/song_header

@ -16,11 +16,14 @@
{artist: (( author[1] ))(( author[0] ))}
(* endfor *)
(*- for key in ['album', 'copyright', 'cov', 'tag'] *)
(*- for key in ['album', 'copyright', 'tag'] *)
(* if key in metadata -*)
{(( key )): (( metadata[key] ))}
(* endif *)
(* endfor *)
(* if 'cov' in metadata -*)
{(( 'cov' )): (( metadata['cov'].argument|search_image ))}
(* endif *)
(*- for key in metadata.keys -*)
{key: (( key.keyword )): (( key.argument ))}

Loading…
Cancel
Save