Browse Source

Merge pull request #220 from patacrep/metacrep

Allow the definition of custom directives
pull/224/head
oliverpool 9 years ago
parent
commit
1228f164bf
  1. 1
      patacrep/data/templates/songs/chordpro/chordpro/content_meta
  2. 1
      patacrep/data/templates/songs/chordpro/latex/content_meta
  3. 10
      patacrep/data/templates/styles/patacrep.sty
  4. 3
      patacrep/songs/chordpro/ast.py
  5. 31
      test/test_book/syntax.tex.control
  6. 9
      test/test_book/syntax_datadir/songs/metacrep.csg
  7. 16
      test/test_song/metacrep.csg
  8. 11
      test/test_song/metacrep.csg.source
  9. 30
      test/test_song/metacrep.tsg

1
patacrep/data/templates/songs/chordpro/chordpro/content_meta

@ -0,0 +1 @@
{meta: (( content.argument[0] )):(( content.argument[2] ))}

1
patacrep/data/templates/songs/chordpro/latex/content_meta

@ -0,0 +1 @@
\metacrep{((- content.argument[0] -))}{((- content.argument[2] -))}

10
patacrep/data/templates/styles/patacrep.sty

@ -473,4 +473,14 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Handle metacrep key (skip if the \metacrep<keyname> command is not defined)
\newcommand{\metacrep}[2]{%
\ifcsname metacrep#1\endcsname%
\csname metacrep#1\endcsname{#2}%
\fi%
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\endinput

3
patacrep/songs/chordpro/ast.py

@ -43,6 +43,7 @@ INLINE_DIRECTIVES = {
"guitar_comment",
"image",
"newline",
"meta",
}
#: Some directive have alternative names. For instance `{title: Foo}` and `{t:
@ -355,6 +356,8 @@ class Directive(AST):
def __init__(self, keyword, argument=None):
super().__init__()
self.keyword = directive_name(keyword.strip())
if keyword == 'meta':
argument = argument.partition(':')
self.argument = argument
@property

31
test/test_book/syntax.tex.control

@ -32,6 +32,7 @@ guitar,
\usepackage{lmodern}
\PassOptionsToPackage{ngerman}{babel}
\PassOptionsToPackage{english}{babel}
\usepackage[english]{babel}
\lang{english}
@ -150,6 +151,36 @@ guitar,
\image[width=2cm]{img/image.png}
\endsong
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% songs/./metacrep.csg
\selectlanguage{ngerman}
\beginsong{Der kleine Troll}[
by={
},
]
\metacrep{liederbock}{ 292}
\begin{verse}
Let's sing and test a
\end{verse}
\metacrep{undefined}{ whatever}
\begin{verse}
directive between verses
\end{verse}
\endsong
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

9
test/test_book/syntax_datadir/songs/metacrep.csg

@ -0,0 +1,9 @@
{lang: de}
{title: Der kleine Troll}
{meta: liederbock: 292}
Let's sing and test a
{meta: undefined: whatever}
directive between verses

16
test/test_song/metacrep.csg

@ -0,0 +1,16 @@
{lang: de}
{title: Der kleine Troll}
{meta: liederbock: 292}
Let's sing and test a
{meta: emptyarg:}
directive between verses
{meta: and: with: more: arguments}

11
test/test_song/metacrep.csg.source

@ -0,0 +1,11 @@
{lang: de}
{title: Der kleine Troll}
{meta: liederbock: 292}
Let's sing and test a
{meta: emptyarg}
directive between verses
{meta: and: with: more: arguments}

30
test/test_song/metacrep.tsg

@ -0,0 +1,30 @@
\selectlanguage{ngerman}
\beginsong{Der kleine Troll}[
by={
},
]
\metacrep{liederbock}{ 292}
\begin{verse}
Let's sing and test a
\end{verse}
\metacrep{emptyarg}{}
\begin{verse}
directive between verses
\end{verse}
\metacrep{and}{ with: more: arguments}
\endsong
Loading…
Cancel
Save