|
@ -3,6 +3,7 @@ |
|
|
|
|
|
|
|
|
import glob |
|
|
import glob |
|
|
import importlib |
|
|
import importlib |
|
|
|
|
|
import jinja2 |
|
|
import logging |
|
|
import logging |
|
|
import os |
|
|
import os |
|
|
|
|
|
|
|
@ -14,7 +15,7 @@ EOL = '\n' |
|
|
class Content: |
|
|
class Content: |
|
|
"""Content item of type 'example'.""" |
|
|
"""Content item of type 'example'.""" |
|
|
|
|
|
|
|
|
def render(self): |
|
|
def render(self, context): |
|
|
"""Render this content item. |
|
|
"""Render this content item. |
|
|
|
|
|
|
|
|
Returns a string, to be placed verbatim in the generated .tex file. |
|
|
Returns a string, to be placed verbatim in the generated .tex file. |
|
@ -23,12 +24,13 @@ class Content: |
|
|
|
|
|
|
|
|
# Block management |
|
|
# Block management |
|
|
|
|
|
|
|
|
def begin_new_block(self, previous): |
|
|
def begin_new_block(self, previous, context): |
|
|
"""Return a boolean stating if a new block is to be created. |
|
|
"""Return a boolean stating if a new block is to be created. |
|
|
|
|
|
|
|
|
# Arguments |
|
|
# Arguments |
|
|
|
|
|
|
|
|
- previous: the songbook.content.Content object of the previous item. |
|
|
- previous: the songbook.content.Content object of the previous item. |
|
|
|
|
|
- context: TODO |
|
|
|
|
|
|
|
|
# Return |
|
|
# Return |
|
|
|
|
|
|
|
@ -37,11 +39,11 @@ class Content: |
|
|
""" |
|
|
""" |
|
|
return True |
|
|
return True |
|
|
|
|
|
|
|
|
def begin_block(self): |
|
|
def begin_block(self, context): |
|
|
"""Return the string to begin a block.""" |
|
|
"""Return the string to begin a block.""" |
|
|
return "" |
|
|
return "" |
|
|
|
|
|
|
|
|
def end_block(self): |
|
|
def end_block(self, context): |
|
|
"""Return the string to end a block.""" |
|
|
"""Return the string to end a block.""" |
|
|
return "" |
|
|
return "" |
|
|
|
|
|
|
|
@ -73,7 +75,8 @@ def load_plugins(): |
|
|
plugins[key] = value |
|
|
plugins[key] = value |
|
|
return plugins |
|
|
return plugins |
|
|
|
|
|
|
|
|
def render_content(content): |
|
|
@jinja2.contextfunction |
|
|
|
|
|
def render_content(context, content): |
|
|
rendered = "" |
|
|
rendered = "" |
|
|
previous = None |
|
|
previous = None |
|
|
last = None |
|
|
last = None |
|
@ -83,15 +86,15 @@ def render_content(content): |
|
|
continue |
|
|
continue |
|
|
|
|
|
|
|
|
last = elem |
|
|
last = elem |
|
|
if elem.begin_new_block(previous): |
|
|
if elem.begin_new_block(previous, context): |
|
|
if previous: |
|
|
if previous: |
|
|
rendered += previous.end_block() + EOL |
|
|
rendered += previous.end_block(context) + EOL |
|
|
rendered += elem.begin_block() + EOL |
|
|
rendered += elem.begin_block(context) + EOL |
|
|
rendered += elem.render() + EOL |
|
|
rendered += elem.render(context) + EOL |
|
|
previous = elem |
|
|
previous = elem |
|
|
|
|
|
|
|
|
if isinstance(last, Content): |
|
|
if isinstance(last, Content): |
|
|
rendered += last.end_block() + EOL |
|
|
rendered += last.end_block(context) + EOL |
|
|
|
|
|
|
|
|
return rendered |
|
|
return rendered |
|
|
|
|
|
|
|
|