Browse Source

Merge pull request #148 from patacrep/directive_tag

Ajout d'une directive `{tag: FOO}`
pull/152/head
Louis 9 years ago
parent
commit
8f295e1887
  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 from jinja2 import Environment, FileSystemLoader, contextfunction, ChoiceLoader
import jinja2 import jinja2
import logging import logging
import operator
import os import os
from pkg_resources import resource_filename from pkg_resources import resource_filename
@ -14,6 +15,10 @@ from patacrep.latex import lang2babel
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
def sort_directive_argument(directives):
"""Sort directives by their argument."""
return sorted(directives, key=operator.attrgetter("argument"))
class ChordproSong(Song): class ChordproSong(Song):
"""Chordpro song parser""" """Chordpro song parser"""
# pylint: disable=abstract-method # pylint: disable=abstract-method
@ -54,6 +59,7 @@ class ChordproSong(Song):
jinjaenv.filters['search_image'] = self.search_image jinjaenv.filters['search_image'] = self.search_image
jinjaenv.filters['search_partition'] = self.search_partition jinjaenv.filters['search_partition'] = self.search_partition
jinjaenv.filters['lang2babel'] = lang2babel jinjaenv.filters['lang2babel'] = lang2babel
jinjaenv.filters['sortargs'] = sort_directive_argument
try: try:
return Renderer( return Renderer(

1
patacrep/songs/chordpro/ast.py

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

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

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

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

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