-
Notifications
You must be signed in to change notification settings - Fork 466
fotorama directive for rst #1794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
## -*- coding: utf-8 -*- | ||
|
||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <!-- 33 KB --> | ||
|
||
<link href="http://cdnjs.cloudflare.com/ajax/libs/fotorama/4.6.4/fotorama.css" rel="stylesheet"> <!-- 3 KB --> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can't drop CSS link elements in the middle of the HTML, it's not standards compliant (see Notes here: https://developer.mozilla.org/en/docs/Web/HTML/Element/link ). I'm afraid that means to support this you need to add that link element in your conf.py (EXTRA_HEAD is the option, IIRC) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could also use the template hooks for that. Chris Warrick https://chriswarrick.com
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indeed an example on how to do that via template hooks would be awesome :-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
<script src="http://cdnjs.cloudflare.com/ajax/libs/fotorama/4.6.4/fotorama.js"></script> <!-- 16 KB --> | ||
|
||
<div class="fotorama" | ||
% for key, value in options.iteritems(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not compatible with python 3, just use |
||
data-${key}="${value}" | ||
% endfor | ||
> | ||
% for image in fotorama_content: | ||
<a href="${image['url']}"><img src="${image['url_thumb']}"></a> | ||
% endfor | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[Core] | ||
Name = rest_fotorama | ||
Module = fotorama | ||
|
||
[Documentation] | ||
Author = Manuel Kaufmann | ||
Version = 0.1 | ||
Website = http://getnikola.com | ||
Description = Fotorama directive to display a gallery using http://fotorama.io jQuery plugin | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright © 2015 Manuel Kaufmann | ||
|
||
# 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. | ||
|
||
from __future__ import unicode_literals | ||
|
||
import os | ||
|
||
from docutils import nodes | ||
from docutils.parsers.rst import Directive, directives | ||
|
||
from nikola.plugin_categories import RestExtension | ||
|
||
|
||
class Plugin(RestExtension): | ||
|
||
name = "rest_fotorama" | ||
|
||
def set_site(self, site): | ||
self.site = site | ||
directives.register_directive('fotorama', Fotorama) | ||
Fotorama.site = site | ||
return super(Plugin, self).set_site(site) | ||
|
||
|
||
class Fotorama(Directive): | ||
""" Restructured text extension for inserting fotorama galleries.""" | ||
|
||
# http://fotorama.io/customize/options/ | ||
option_spec = { | ||
'width': directives.unchanged, | ||
'minwidth': directives.unchanged, | ||
'maxwidth': directives.unchanged, | ||
'height': directives.unchanged, | ||
'minheight': directives.unchanged, | ||
'maxheight': directives.unchanged, | ||
'ratio': directives.unchanged, | ||
'margin': directives.nonnegative_int, | ||
'glimpse': directives.unchanged, | ||
'nav': lambda arg: directives.choice(arg, ('dots', 'thumbs', 'false')), | ||
'navposition': lambda arg: directives.choice(arg, ('bottom', 'top')), | ||
'navwidth': directives.unchanged, | ||
'thumbwidth': directives.nonnegative_int, | ||
'thumbheight': directives.nonnegative_int, | ||
'thumbborderwidth': directives.nonnegative_int, | ||
'allowfullscreen': lambda arg: directives.choice(arg, ('false', 'true', 'native')), | ||
'fit': lambda arg: directives.choice(arg, ('contain', 'cover', 'scaledown', 'none')), | ||
'thumbfit': directives.unchanged, | ||
'transition': lambda arg: directives.choice(arg, ('slide', 'crossfade', 'disolve')), | ||
'clicktransition': directives.unchanged, | ||
'transitionduration': directives.nonnegative_int, | ||
'captions': directives.flag, | ||
'hash': directives.flag, | ||
'startindex': directives.unchanged, | ||
'loop': directives.flag, | ||
'autoplay': directives.unchanged, | ||
'stopautoplayontouch': directives.unchanged, | ||
'keyboard': directives.unchanged, | ||
'arrows': lambda arg: directives.choice(arg, ('true', 'false', 'always')), | ||
'click': directives.flag, | ||
'swipe': directives.flag, | ||
'trackpad': directives.flag, | ||
'shuffle': directives.flag, | ||
'direction': lambda arg: directives.choice(arg, ('ltr', 'rtl')), | ||
'spinner': directives.unchanged, | ||
'shadows': directives.flag, | ||
} | ||
has_content = True | ||
|
||
def _sanitize_options(self): | ||
defaults = { | ||
'nav': 'thumbs', | ||
'ratio': '16/9', | ||
'keyboard': 'true', | ||
'thumb-width': 128, | ||
'thumb-height': 128, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we already have a thumbnails size setting in conf.py it would be great if you could respect it. |
||
'allowfullscreen': 'native' | ||
} | ||
defaults = self.site.config.get('FOTORAMA_OPTIONS', defaults) | ||
|
||
# TODO: validate options here and (maybe) display an error | ||
defaults.update(self.options) | ||
return defaults | ||
|
||
def run(self): | ||
if len(self.content) == 0: | ||
return | ||
|
||
image_list = [t for t in self.content] | ||
thumbs = ['.thumbnail'.join(os.path.splitext(p)) for p in image_list] | ||
|
||
photo_array = [] | ||
for img, thumb in zip(image_list, thumbs): | ||
photo_array.append({ | ||
'url': img, | ||
'url_thumb': thumb, | ||
}) | ||
|
||
output = self.site.template_system.render_template( | ||
'embedded-fotorama.tmpl', | ||
None, | ||
{ | ||
'fotorama_content': photo_array, | ||
'options': self._sanitize_options() | ||
} | ||
) | ||
return [nodes.raw('', output, format='html')] | ||
|
||
|
||
directives.register_directive('fotorama', Fotorama) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most themes already load jquery, but they do so at the end of the body.