Commits

James Tocknell committed 4a3c9bc Merge

Fixed typos associated with songs

  • Participants
  • Parent commits 2f1f9e5, aa410f2

Comments (0)

Files changed (5)

File docs/primitives.rst

 Primitives
-~~~~~~~~~~
+==========
 
 .. module:: shinypress.render
 
-Got an image? Let’s render that for you:
+Images
+~~~~~~
 
 .. autofunction:: render_image
 
-Oh, you have some text instead? Well, let’s do that, then:
+Text
+~~~~
 
 .. autofunction:: render_text
 .. autoclass:: HAlignment
 .. autoclass:: VAlignment
 
-And there’s also a utility function useful for scaling content, used by those functions above.
+Utilities
+~~~~~~~~~
 
 .. autofunction:: scale
 .. autoclass:: ScalingMode

File shinypress/render.py

     """
     Horizontal alignment.
     Not an enum in the true sense, just some related constants.
+
+    :var LEFT:
+    :var CENTER:
+    :var RIGHT:
     """
     LEFT = 0.0
     CENTER = 0.5
     """
     Vertical alignment.
     Not an enum in the true sense, just some related constants.
+
+    :var TOP:
+    :var MIDDLE:
+    :var BOTTOM:
     """
     TOP = 0.0
     MIDDLE = 0.5

File shinypress/songs/__init__.py

     verses = {}
     ordering = {}
 
-
-
     templates = [
-            ("song-single",) # A single slide with a title, main text and info box
+            ("song-single",), # A single slide with a title, main text and info box
             (
                 "title-text", # Slide with title and main text
                 "text", # Slide with only main text
                 self.verses[verse]["markup"],
                 n_repeats
             ) for verse in uniqc(flatten(self.ordering[ordering_name])))))
+
+def old_to_new(old_song_file, new_json_file):
+    """
+    Converts a old song format file to new json format file.
+
+    :param old_song_file: file object in old song format
+    :param new_json_file: file object to write json to
+    """
+    new_json_file.write(Song().from_old_format(old_song_file).to_json())

File shinypress/songs/old_format.py

 from collections import namedtuple
 import re
 
-from utils import group_paragraphs
+try:
+    from cStringIO import StringIO
+except ImportError:
+    from StringIO import StringIO
+
+import itertools
 
 VERSE_REFERENCE = re.compile(r'^\((.*)\)(?: x([0-9]+))?$')
 VERSE_LABEL = re.compile(r'^(.*?[^:])(?: \((.*?)\))?:$')
 
     return '\n'.join(output)
 
+def group_paragraphs(lines):
+    """
+    Group an iterable by groups of non-empty lines.
+
+    Warning: the iterables this returns must be used in order,
+    otherwise badness will ensue.
+    """
+
+    # number of the current paragraph
+    i = [0]
+    up_to = lambda j: i[0] == j
+    finished = lambda: up_to(-1)
+    def next_paragraph():
+        i[0] += 1
+    def finish():
+        i[0] = -1
+
+    def make_iter(j):
+        while True:
+            if finished():
+                break
+
+            if not up_to(j):
+                raise ValueError, "iterators must be used in order"
+
+            try:
+                line = lines.next()
+            except StopIteration:
+                finish()
+                return
+
+            if not line:
+                break
+
+            yield line
+
+        next_paragraph()
+
+    for j in itertools.count():
+        yield make_iter(j)
+        if finished():
+            break

File shinypress/songs/utils.py

 # -*- coding: utf-8 -*-
 
-from shinypress.songs import Song
-
-def old_to_new(old_song_file, new_json_file):
-    """
-    Converts a old song format file to new json format file.
-
-    :param old_song_file: file object in old song format
-    :param new_json_file: file object to write json to
-    """
-    new_json_file.write(Song().from_old_format(old_song_file).to_json())
-
-
 def flatten(x):
     """
     From http://stackoverflow.com/a/2158522/1306020