Skip to content

Commit

Permalink
Merge branch 'release/0.7.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
Hayley van Waas committed Jan 18, 2018
2 parents c434800 + b43c586 commit 1ff1295
Show file tree
Hide file tree
Showing 33 changed files with 386 additions and 90 deletions.
5 changes: 5 additions & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
#######################################

0.7.3
=======================================

- Modified :doc:`processors/interactive` processor to change interactive template depending on the type of file path given for the thumbnail image of whole page interactives (external or internal) as well as changed the default path for the thumbnail.

0.7.2
=======================================

Expand Down
22 changes: 9 additions & 13 deletions docs/source/processors/interactive.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Required Tag Parameters
on a separate page). The link shows a thumbnail of the interactive with
text (the text is set using the ``text`` parameter).
By default, the thumbnail should be a ``thumbnail.png`` file found
within the interactive folder.
within the interactive's img folder.
- ``iframe`` - The interactive is included in the page by embedding using
an iframe. This is used if the interactive is included multiple times on
the page to avoid conflicts in JavaScript/CSS.
Expand All @@ -52,23 +52,23 @@ Optional Tag Parameters
the ``?`` at the start, as this is already included in the output.
- ``thumbnail`` (optional - used with ``whole-page`` value) - Displays an
alternative thumbnail for the interactive. When not provided, it defaults to
the ``thumbnail.png`` image within the interactive's folder.
``interactives/interactive-name/img/thumbnail.png``, where ``interactive-name`` is the
value given for the ``name`` tag parameter (see above).

- If the ``thumbnail`` value provided is an relative link (a link that
- If the ``thumbnail`` value provided is a relative link (a link that
doesn't start with ``http:``), the link will be rendered with a Django
static command. For example, the link:

.. code-block:: none
binary-cards/thumbnail-2.png
thumbnail-2.png
would be rendered as:

.. code-block:: none
{% static 'binary-cards/thumbnail-2.png' %}
{% static 'thumbnail-2.png' %}
This can be overriden, see the override section below.
- Each ``thumbnail`` provided is added to the ``images`` set in required
files stored by Verto.
The set of filepaths can be accessed after conversion,
Expand Down Expand Up @@ -128,13 +128,8 @@ When overriding the HTML for interactives, the following Jinja2 placeholders are
- ``{{ text }}`` - The text to to display to a link to a ``whole-page``
interactive.
- ``{{ parameters }}`` - GET parameters to append to the interactive link.
- ``{{ file_path }}`` - The location for the path to the thumbnail image.

If the ``file_path`` provided is an relative link, the link is passed through the ``relative-image-link.html`` template.
The default HTML for relative images is:

.. literalinclude:: ../../../verto/html-templates/relative-file-link.html
:language: css+jinja
- ``{{ thumbnail_file_path }}`` - The location for the path to the thumbnail image.
- ``{{ thumbnail_file_relative }}`` - If the ``thumbnail_file_path`` is a relative link, this is the boolean value ``True``, otherwise ``False``.

**Example**

Expand All @@ -156,6 +151,7 @@ would result in:
.. literalinclude:: ../../../verto/tests/assets/interactive/doc_example_override_html_expected.html
:language: html


.. _Computer Science Field Guide: https://github.com/uccser/cs-field-guide
.. _animations comparing sorting algorithms: http://www.csfieldguide.org.nz/en/interactives/sorting-algorithm-comparison/index.html
.. _viewing pixels of an image: http://www.csfieldguide.org.nz/en/interactives/pixel-viewer/index.html
2 changes: 1 addition & 1 deletion verto/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# flake8: noqa
from .Verto import Verto

__version__ = '0.7.2'
__version__ = '0.7.3'
9 changes: 8 additions & 1 deletion verto/html-templates/interactive.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@
<a
href="{{ "{% url 'interactive' name='" }}{{ name }}{{ "' %}" }}{% if parameters %}?{{ parameters }}{% endif %}"
class="btn btn-interactive-link">
<img class="btn-interactive-link-image" src="{{ file_path }}"/>
<img class="btn-interactive-link-image"
{% if thumbnail_file_relative %}
{% autoescape false -%}
src="{{ "{% static '" }}{{ thumbnail_file_path }}{{ "' %}" }}"
{%- endautoescape %}
{% else %}
src="{{ thumbnail_file_path }}"
{% endif %}/>
<div class="btn-interactive-whole-page-text">
{% if text -%}
{{ text }}
Expand Down
20 changes: 20 additions & 0 deletions verto/processor-info.json
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,26 @@
"required": false,
"dependencies": []
}
},
"template_parameters": {
"type": {
"argument": "type"
},
"name": {
"argument": "name"
},
"text": {
"argument": "text"
},
"parameters": {
"argument": "parameters"
},
"thumbnail_file_path": {
"argument": "thumbnail_file_path"
},
"thumbnail_file_relative": {
"argument": "thumbnail_file_relative"
}
}
},
"panel": {
Expand Down
6 changes: 4 additions & 2 deletions verto/processors/ImageContainerBlockProcessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ def custom_parsing(self, content_blocks, argument_values):
Extracts the caption of an image block and creates file path based on whether internal or external image.
Args:
content_blocks: List of strings to either be parsed or inserted as caption in template.
content_blocks (list): List of strings to either be parsed or inserted as caption in template.
argument_values (dict): Dictionary of arguments and values provided in tag block.
Returns:
Tuple containing blocks and extra_args to update the content_blocks list and argument_values dict.
Tuple containing blocks (list) and extra_args (dict) to update the content_blocks list and
agument_values dict.
Raises:
ImageCaptionContainsImageError: If the first line of an image block is another image block.
ImageMissingCaptionError: If no caption can be found in the image block.
Expand Down
10 changes: 6 additions & 4 deletions verto/processors/ImageTagBlockProcessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ def custom_parsing(self, argument_values):
Extracts the caption of an image block and creates file path based on whether internal or external image.
Args:
content_blocks: List of strings to either be parsed or inserted as caption in template.
argument_values (dict): Dictionary of arguments and values provided in tag block.
Returns:
extra_args: dictionary to update the argument_values dict.
extra_args (dict): dictionary to update the agument_values dict.
'''
extra_args = {}

Expand All @@ -48,9 +49,10 @@ def custom_parsing(self, argument_values):
if caption_value:
del argument_values[argument] # delete from dictionary so as to not be included in template

# check if internal or external image
file_path = argument_values['file-path']
del(argument_values['file-path'])
del argument_values['file-path']

# check if internal or external image
external_path_match = re.search(r'^http', file_path)
if external_path_match is None: # internal image
self.required.add(file_path)
Expand Down
85 changes: 26 additions & 59 deletions verto/processors/InteractiveBlockProcessor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from verto.processors.GenericTagBlockProcessor import GenericTagBlockProcessor
from verto.processors.utils import parse_arguments
from verto.utils.HtmlParser import HtmlParser
import re


Expand All @@ -15,77 +13,46 @@ def __init__(self, ext, *args, **kwargs):
Args:
ext: An instance of the Verto Extension.
'''
super().__init__('interactive', ext, *args, **kwargs)
self.relative_file_template = ext.jinja_templates['relative-file-link']
self.processor = 'interactive'
super().__init__(self.processor, ext, *args, **kwargs)
self.scripts = ext.required_files['page_scripts']
self.required = ext.required_files['interactives']
self.required_interactives = ext.required_files['interactives']
self.required_images = ext.required_files['images']

def test(self, parent, block):
''' Tests a block to see if the run method should be applied.
def custom_parsing(self, argument_values):
'''Determines the file path to use for an interactive's thumbnail.
Args:
parent: The parent node of the element tree that children
will reside in.
block: The block to be tested.
argument_values (dict): Dictionary of arguments and values provided in tag block.
Returns:
True if the block matches the pattern regex of a HeadingBlock.
extra_args (dict): dictionary to update the agument_values dict.
'''
return self.pattern.match(block) is not None

def run(self, parent, blocks):
''' Processes the block matching the heading and adding to the
html tree and the verto heading tree.
Args:
parent: The parent node of the element tree that children
will reside in.
blocks: A list of strings of the document, where the
first block tests true.
'''
block = blocks.pop(0)

match = self.pattern.match(block)
before = block[:match.start()]
after = block[match.end():]

if before.strip() != '':
self.parser.parseChunk(parent, before)
if after.strip() != '':
blocks.insert(0, after)

arguments = match.group('args')
argument_values = parse_arguments(self.processor, arguments, self.arguments)

name = argument_values['name']
extra_args = {}
interactive_type = argument_values['type']
text = argument_values.get('text', None)
parameters = argument_values.get('parameters', None)
name = argument_values['name']

# add to list of interactives
self.required.add(name)
self.required_interactives.add(name)

if interactive_type == 'in-page':
self.scripts.add('interactive/{}/scripts.html'.format(name))
elif interactive_type == 'whole-page':
argument = 'thumbnail'
thumbnail_file_path = argument_values.get(argument, None)

context = dict()
context['type'] = interactive_type
context['name'] = name
context['text'] = text
context['parameters'] = parameters

if interactive_type == 'whole-page':
file_path = argument_values.get('thumbnail', None)
if file_path is None:
file_path = '{}/thumbnail.png'.format(name)
if thumbnail_file_path is not None:
del argument_values[argument]
else:
thumbnail_file_path = 'interactives/{}/img/thumbnail.png'.format(name)

external_path_match = re.search(r'^http', file_path)
external_path_match = re.search(r'^http', thumbnail_file_path)
if external_path_match is None: # internal image
self.required_images.add(file_path)
file_path = self.relative_file_template.render({'file_path': file_path})
context['file_path'] = file_path
thumbnail_file_relative = True
self.required_images.add(thumbnail_file_path)
else:
thumbnail_file_relative = False

extra_args['thumbnail_file_path'] = thumbnail_file_path
extra_args['thumbnail_file_relative'] = thumbnail_file_relative

html_string = self.template.render(context)
parser = HtmlParser()
parser.feed(html_string).close()
parent.append(parser.get_root())
return extra_args
Loading

0 comments on commit 1ff1295

Please sign in to comment.