Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions nikola/data/themes/base/templates/embedded-fotorama.tmpl
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 -->
Copy link
Member

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.


<link href="http://cdnjs.cloudflare.com/ajax/libs/fotorama/4.6.4/fotorama.css" rel="stylesheet"> <!-- 3 KB -->
Copy link
Member

Choose a reason for hiding this comment

The 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)

Copy link
Member

Choose a reason for hiding this comment

The 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
Sent from my Galaxy S3.
On 8 Jun 2015 12:23, "Roberto Alsina" [email protected] wrote:

In nikola/data/themes/base/templates/embedded-fotorama.tmpl
#1794 (comment):

@@ -0,0 +1,16 @@
+## -- coding: utf-8 --
+
+<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
+
+

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)


Reply to this email directly or view it on GitHub
https://github.com/getnikola/nikola/pull/1794/files#r31901731.

Copy link
Member

Choose a reason for hiding this comment

The 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 :-)

Copy link
Member

Choose a reason for hiding this comment

The 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():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not compatible with python 3, just use items(). Yes, it's slightly inefficient in python 2, but you won't have a million options :-)

data-${key}="${value}"
% endfor
>
% for image in fotorama_content:
<a href="${image['url']}"><img src="${image['url_thumb']}"></a>
% endfor
</div>
10 changes: 10 additions & 0 deletions nikola/plugins/compile/rest/fotorama.plugin
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

132 changes: 132 additions & 0 deletions nikola/plugins/compile/rest/fotorama.py
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,
Copy link
Member

Choose a reason for hiding this comment

The 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)