Skip to content
Permalink
Browse files
slides: Bootstrap 4 compatibility (in v8 branch)
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Sep 5, 2018
1 parent 6b8f4e1 commit 2234cc6e1c7c62c37b6ac5934444e7d50218ef1c
Showing 5 changed files with 166 additions and 0 deletions.
@@ -0,0 +1,15 @@
Slides for reStructuredText.

This was previously part of Nikola core, but has been downgraded to optional plugin.

Example:

```
.. slides::
/galleries/demo/tesla_conducts_lg.jpg
/galleries/demo/tesla_lightning2_lg.jpg
/galleries/demo/tesla4_lg.jpg
/galleries/demo/tesla_lightning1_lg.jpg
/galleries/demo/tesla_tower1_lg.jpg
```
@@ -0,0 +1,14 @@
[Core]
name = rest_slides
module = slides

[Nikola]
compiler = rest
PluginCategory = CompilerExtension

[Documentation]
author = Roberto Alsina
version = 0.1
website = https://plugins.getnikola.com/slides
description = Slides directive

@@ -0,0 +1,77 @@
# -*- coding: utf-8 -*-

# Copyright © 2012-2018 Roberto Alsina and others.

# Permission is hereby granted, free of charge, to any
# person obtaining a copy of this software and associated
# documentation files (the "Software"), to deal in the
# Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the
# Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice
# shall be included in all copies or substantial portions of
# the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
# OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

"""Slides directive for reStructuredText."""


import uuid

from docutils import nodes
from docutils.parsers.rst import Directive, directives

from nikola.plugin_categories import RestExtension


class Plugin(RestExtension):
"""Plugin for reST slides directive."""

name = "rest_slides"

def set_site(self, site):
"""Set Nikola site."""
self.site = site
directives.register_directive('slides', Slides)
Slides.site = site
return super(Plugin, self).set_site(site)


class Slides(Directive):
"""reST extension for inserting slideshows."""

has_content = True

def run(self):
"""Run the slides directive."""
if len(self.content) == 0: # pragma: no cover
return

if self.site.invariant: # for testing purposes
carousel_id = 'slides_' + 'fixedvaluethatisnotauuid'
else:
carousel_id = 'slides_' + uuid.uuid4().hex

output = self.site.template_system.render_template(
'slides.tmpl',
None,
{
'slides_content': self.content,
'carousel_id': carousel_id,
}
)
return [nodes.raw('', output, format='html')]


directives.register_directive('slides', Slides)
@@ -0,0 +1,30 @@
{% block content %}
<div id="{{ carousel_id }}" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
{% for i in range(slides_content|length) %}
{% if i == 0 %}
<li data-target="#{{ carousel_id }}" data-slide-to="{{ i }}" class="active"></li>
{% else %}
<li data-target="#{{ carousel_id }}" data-slide-to="{{ i }}"></li>
{% endif %}
{% endfor %}
</ol>
<div class="carousel-inner">
{% for image in slides_content %}
{% if loop.index0 == 0 %}
<div class="carousel-item active"><img class="d-block w-100" src="{{ image }}" alt=""></div>
{% else %}
<div class="carousel-item"><img class="d-block w-100" src="{{ image }}" alt=""></div>
{% endif %}
{% endfor %}
</div>
<a class="carousel-control-prev" href="#{{ carousel_id }}" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#{{ carousel_id }}" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
{% endblock %}
@@ -0,0 +1,30 @@
<%block name="content">
<div id="${carousel_id}" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
% for i in range(len(slides_content)):
% if i == 0:
<li data-target="#${carousel_id}" data-slide-to="${i}" class="active"></li>
% else:
<li data-target="#${carousel_id}" data-slide-to="${i}"></li>
% endif
% endfor
</ol>
<div class="carousel-inner">
% for image in slides_content:
% if loop.index == 0:
<div class="carousel-item active"><img class="d-block w-100" src="${image}" alt=""></div>
% else:
<div class="carousel-item"><img class="d-block w-100" src="${image}" alt=""></div>
% endif
% endfor
</div>
<a class="carousel-control-prev" href="#${carousel_id}" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#${carousel_id}" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</%block>

0 comments on commit 2234cc6

Please sign in to comment.