Browse Source

[WIP] Error works, and chordpro to chordpro image conversion works

[CI SKIP]
pull/218/head
Louis 8 years ago
parent
commit
6c29053a61
  1. 2
      patacrep/data/templates/songs/chordpro/chordpro/content_image
  2. 13
      patacrep/songs/chordpro/__init__.py
  3. 3
      patacrep/songs/chordpro/ast.py
  4. 4
      patacrep/songs/chordpro/syntax.py
  5. 0
      test/test_song/image with spaces.png
  6. 38
      test/test_song/image.csg
  7. 33
      test/test_song/image.csg.source
  8. 0
      test/test_song/image.png

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

@ -1 +1 @@
{image: (( content.argument|search_image ))}
{image: "(( content.filename|search_image ))" ((content.size|render_size))}

13
patacrep/songs/chordpro/__init__.py

@ -60,6 +60,7 @@ class ChordproSong(Song):
'search_partition': self.search_partition,
'escape_specials': self._escape_specials,
'escape_url': self._escape_url,
'render_size': self._render_size,
})
return filters
@ -94,6 +95,18 @@ class ChordproSong(Song):
context.vars['content'] = content
return context.environment.get_template(content.template()).render(context)
@staticmethod
def _render_size(size):
if size == (None, None):
return ""
text = "size="
if size[0] != (None, None):
text += "".join(size[0])
text += "x"
if size[1] != (None, None):
text += "".join(size[1])
return text
def _escape_specials(self, content, chars=None, *, translation_map=None):
if translation_map is None:
translation_map = self._translation_map

3
patacrep/songs/chordpro/ast.py

@ -422,9 +422,6 @@ class Image(Directive):
self.size = size
super().__init__("image", None)
def __str__(self):
raise NotImplementedError("TODO4")
class Tab(AST):
"""Tablature"""

4
patacrep/songs/chordpro/syntax.py

@ -191,7 +191,7 @@ class ChordproParser(Parser):
if match is None:
self.error(
line=symbols.lexer.lineno,
message="TODO1",
message="Cannot parse image size '{}'.".format(splitted[1]),
)
symbols[0] = ast.Error()
else:
@ -206,7 +206,7 @@ class ChordproParser(Parser):
else:
self.error(
line=symbols.lexer.lineno,
message="TODO3",
message="Too many arguments to 'image' directive.",
)
symbols[0] = ast.Error()
else:

0
test/test_song/image with spaces.png

38
test/test_song/image.csg

@ -1,22 +1,34 @@
{image: dices.png}
{image: "image with spaces.png"}
{image: image.png }
{image: "image with spaces.png" }
{image: dices.png size=20%x}
{image: "image with spaces.png" size=x20%}
{image: dices.png size=20%x10%}
{image: dices.png size=20%x}
{image: image.png size=20%x}
{image: "image with spaces.png" size=x20%}
{image: dices.png size=20%x10%}
{image: image.png size=20%x10%}
{image: dices.png size=2cmx}
{image: image.png size=2cmx}
{image: "image with spaces.png" size=x2cm}
{image: dices.png size=2cmx1cm}
{image: image.png size=2cmx1cm}
{image: dices.png size=2emx}
{image: image.png size=2emx}
{image: "image with spaces.png" size=x2em}
{image: dices.png size=2emx1em}
{image: image.png size=2emx1em}
{image: dices.png size=50ptx}
{image: image.png size=50ptx}
{image: "image with spaces.png" size=x50pt}
{image: dices.png size=50ptx100pt}
{image: image.png size=50ptx100pt}
{image: image.png size=2.5cmx}
{image: "image with spaces.png" size=x2.5cm}
{image: image.png size=2.5cmx1.5cm}
{image: image.png size=3cmx10%}
{image: "image with spaces.png" size=10%x3cm}
{image: image.png size=x}

33
test/test_song/image.csg.source

@ -1,30 +1,31 @@
{image: dices.png}
{image: image.png}
{image: "image with spaces.png"}
{image: dices.png size=20%x }
{image: image.png size=20%x }
{image: "image with spaces.png" size=x20%}
{image: dices.png size=20%x10%}
{image: image.png size=20%x10%}
{image: dices.png size=2cmx}
{image: image.png size=2cmx}
{image: "image with spaces.png" size=x2cm}
{image: dices.png size=2cmx1cm}
{image: image.png size=2cmx1cm}
{image: dices.png size=2emx}
{image: image.png size=2emx}
{image: "image with spaces.png" size=x2em}
{image: dices.png size=2emx1em}
{image: image.png size=2emx1em}
{image: dices.png size=50ptx}
{image: image.png size=50ptx}
{image: "image with spaces.png" size=x50pt}
{image: dices.png size=50ptx100pt}
{image: image.png size=50ptx100pt}
{image: dices.png size=2.5cmx}
{image: image.png size=2.5cmx}
{image: "image with spaces.png" size=x2.5cm}
{image: dices.png size=2.5cmx1.5cm}
{image: image.png size=2.5cmx1.5cm}
{image: dices.png size=3cmx10%}
{image: image.png size=3cmx10%}
{image: "image with spaces.png" size=10%x3cm}
{image: dices.png size=x}
{image: image.png size=x}
{image: dices.png error=foo}
{image: "image with spaces.png" dices.png}
{image: dices.png size=2exx3km}
{image: image.png error=foo}
{image: "image with spaces.png" image.png}
{image: "image with spaces.png" image.png image.png}
{image: image.png size=2exx3km}

0
test/test_song/image.png

Loading…
Cancel
Save