new pluging, updated some imported files
This commit is contained in:
parent
2be26e1008
commit
3fb5ec341a
5 changed files with 168 additions and 0 deletions
17
plugins/slides/README.md
Normal file
17
plugins/slides/README.md
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
Slides for reStructuredText.
|
||||||
|
|
||||||
|
This was previously part of Nikola core, but has been downgraded to optional plugin.
|
||||||
|
|
||||||
|
Compatible with Nikola v7 and v8, Bootstrap 4. (The v7 version is Bootstrap 3.)
|
||||||
|
|
||||||
|
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
|
||||||
|
```
|
||||||
14
plugins/slides/slides.plugin
Normal file
14
plugins/slides/slides.plugin
Normal file
|
|
@ -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
|
||||||
|
|
||||||
77
plugins/slides/slides.py
Normal file
77
plugins/slides/slides.py
Normal file
|
|
@ -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)
|
||||||
30
plugins/slides/templates/jinja2/slides.tmpl
Normal file
30
plugins/slides/templates/jinja2/slides.tmpl
Normal file
|
|
@ -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 %}
|
||||||
30
plugins/slides/templates/mako/slides.tmpl
Normal file
30
plugins/slides/templates/mako/slides.tmpl
Normal file
|
|
@ -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>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue