mirror of https://github.com/patacrep/patacrep.git
Louis
9 years ago
17 changed files with 155 additions and 40 deletions
@ -0,0 +1,36 @@ |
|||||
|
"""Change base directory before importing songs.""" |
||||
|
|
||||
|
from patacrep.content import process_content, validate_parser_argument |
||||
|
|
||||
|
#pylint: disable=unused-argument |
||||
|
@validate_parser_argument(""" |
||||
|
type: //rec |
||||
|
required: |
||||
|
path: //str |
||||
|
optional: |
||||
|
content: //any |
||||
|
""") |
||||
|
def parse(keyword, config, argument): |
||||
|
"""Return a list of songs, whith a different base path. |
||||
|
|
||||
|
Arguments: |
||||
|
- keyword: unused; |
||||
|
- config: the current songbook configuration dictionary; |
||||
|
- argument: a dict containing: |
||||
|
path: string specifying the path to append to current songdirs; |
||||
|
content: songbook content, that is parsed by |
||||
|
patacrep.content.process_content(). |
||||
|
|
||||
|
The 'path' is added as a relative path to every path already present |
||||
|
in config['songdir'] (which are 'songs' dir inside the datadirs). |
||||
|
""" |
||||
|
subpath = argument['path'] |
||||
|
old_songdir = config['_songdir'] |
||||
|
|
||||
|
config['_songdir'] = [path.clone().join(subpath) for path in config['_songdir']] |
||||
|
|
||||
|
processed_content = process_content(argument.get('content'), config) |
||||
|
config['_songdir'] = old_songdir |
||||
|
return processed_content |
||||
|
|
||||
|
CONTENT_PLUGINS = {'cd': parse} |
@ -0,0 +1,48 @@ |
|||||
|
"""Allows to set an arbitrary value to any LaTeX counter (like `songnum`).""" |
||||
|
|
||||
|
from patacrep.content import ContentItem, ContentList, validate_parser_argument |
||||
|
|
||||
|
class CounterSetter(ContentItem): |
||||
|
"""Set a counter.""" |
||||
|
# pylint: disable=too-few-public-methods |
||||
|
|
||||
|
def __init__(self, name, value): |
||||
|
self.name = name |
||||
|
self.value = value |
||||
|
|
||||
|
def render(self, __context): |
||||
|
"""Set the value of the counter.""" |
||||
|
return r'\setcounter{{{}}}{{{}}}'.format(self.name, self.value) |
||||
|
|
||||
|
#pylint: disable=unused-argument |
||||
|
@validate_parser_argument(""" |
||||
|
type: //any |
||||
|
of: |
||||
|
- //nil |
||||
|
- //int |
||||
|
- type: //rec |
||||
|
optional: |
||||
|
name: //str |
||||
|
value: //int |
||||
|
""") |
||||
|
def parse(keyword, argument, config): |
||||
|
"""Parse the counter setter. |
||||
|
|
||||
|
Arguments: |
||||
|
- nothing |
||||
|
reset the "songnum" counter to 1 |
||||
|
- an int |
||||
|
reset the "songnum" counter to this value |
||||
|
- a dict: |
||||
|
- name ("songnum"): the counter to set; |
||||
|
- value: value to set the counter to; |
||||
|
""" |
||||
|
if argument is None: |
||||
|
argument = {} |
||||
|
if isinstance(argument, int): |
||||
|
argument = {'value': argument} |
||||
|
name = argument.get('name', 'songnum') |
||||
|
value = argument.get('value', 1) |
||||
|
return ContentList([CounterSetter(name, value)]) |
||||
|
|
||||
|
CONTENT_PLUGINS = {'setcounter': parse} |
@ -1,3 +1,3 @@ |
|||||
- cwd: |
- cd: |
||||
path: subdir |
path: subdir |
||||
content: |
content: |
@ -0,0 +1,4 @@ |
|||||
|
- setcounter{songnum}{101} |
||||
|
- setcounter{songnum}{1} |
||||
|
- setcounter{songnum}{5} |
||||
|
- setcounter{counter_name}{-1} |
@ -0,0 +1,7 @@ |
|||||
|
- setcounter: |
||||
|
value: 101 |
||||
|
- setcounter: |
||||
|
- setcounter: 5 |
||||
|
- setcounter: |
||||
|
name: counter_name |
||||
|
value: -1 |
Loading…
Reference in new issue