Browse Source

[songs.chordpro] Add a new directive `{tag: ...}`

pull/148/head
Louis 9 years ago
parent
commit
9950debe9c
  1. 6
      patacrep/songs/chordpro/__init__.py
  2. 1
      patacrep/songs/chordpro/ast.py
  3. 10
      patacrep/songs/chordpro/data/chordpro/song_header
  4. 2
      patacrep/songs/chordpro/data/latex/song
  5. 5
      test/test_chordpro/tags.sgc
  6. 4
      test/test_chordpro/tags.source
  7. 10
      test/test_chordpro/tags.tex

6
patacrep/songs/chordpro/__init__.py

@ -3,6 +3,7 @@
from jinja2 import Environment, FileSystemLoader, contextfunction, ChoiceLoader
import jinja2
import logging
import operator
import os
from pkg_resources import resource_filename
@ -14,6 +15,10 @@ from patacrep.latex import lang2babel
LOGGER = logging.getLogger(__name__)
def sort_directive_argument(directives):
"""Sort directives by their argument."""
return sorted(directives, key=operator.attrgetter("argument"))
class ChordproSong(Song):
"""Chordpro song parser"""
# pylint: disable=abstract-method
@ -54,6 +59,7 @@ class ChordproSong(Song):
jinjaenv.filters['search_image'] = self.search_image
jinjaenv.filters['search_partition'] = self.search_partition
jinjaenv.filters['lang2babel'] = lang2babel
jinjaenv.filters['sortargs'] = sort_directive_argument
try:
return Renderer(

1
patacrep/songs/chordpro/ast.py

@ -194,6 +194,7 @@ class Song(AST):
"artist": "add_author",
"key": "add_key",
"define": "add_cumulative",
"tag": "add_cumulative",
}
def __init__(self, filename):

10
patacrep/songs/chordpro/data/chordpro/song_header

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

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

@ -22,7 +22,7 @@
(* endif *)
(* endfor *)
},
(* for key in ['album', 'copyright', 'tag'] *)
(* for key in ['album', 'copyright'] *)
(* if key in metadata *)
(( key ))={(( metadata[key] ))},
(* endif *)

5
test/test_chordpro/tags.sgc

@ -0,0 +1,5 @@
{lang: en}
{title: Tag test}
{tag: a third tag}
{tag: another}
{tag: one tag}

4
test/test_chordpro/tags.source

@ -0,0 +1,4 @@
{title: Tag test}
{tag: one tag}
{tag: another}
{tag: a third tag}

10
test/test_chordpro/tags.tex

@ -0,0 +1,10 @@
\selectlanguage{english}
\beginsong{Tag test}[
by={
},
]
\endsong
Loading…
Cancel
Save