-
Notifications
You must be signed in to change notification settings - Fork 95
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
Nano gallery #115
base: master
Are you sure you want to change the base?
Nano gallery #115
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 @@ | ||
Nanogallery directive to display a gallery using http://nanogallery.brisbois.fr jQuery plugin | ||
|
||
# Usage | ||
|
||
``` | ||
.. nanogallery:: | ||
:theme: light | ||
:maxItemsPerLine: 2 | ||
|
||
0.jpg | ||
1.jpg | ||
2.jpg | ||
3.jpg | ||
4.jpg | ||
5.jpg | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Default options for nanogallery_directive plugin | ||
# To see all the options go to: http://nanogallery.brisbois.fr/ | ||
NANOGALLERY_OPTIONS = { | ||
'theme': 'clean', | ||
'maxitemsperline': 4, | ||
'thumbnailgutterwidth': 10, | ||
'thumbnailgutterheight': 10, | ||
'locationhash': False, | ||
'colorscheme': 'lightBackground', | ||
'thumbnailheight': 'auto', | ||
'thumbnailwidth': 250, | ||
'thumbnailhovereffect': 'imageScale150', | ||
'thumbnaillabel': {'display': 'false'}, | ||
} |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[Core] | ||
Name = nanogallery_directive | ||
Module = nanogallery_directive | ||
|
||
[Nikola] | ||
MinVersion = 7.6.3 | ||
|
||
[Documentation] | ||
Author = Manuel Kaufmann | ||
Version = 0.1 | ||
Website = http://plugins.getnikola.com/#nanogallery_directive | ||
Description = Nanogallery directive to display a gallery using http://nanogallery.brisbois.fr jQuery plugin |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
# -*- 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 collections import OrderedDict | ||
|
||
from docutils import nodes | ||
from docutils.parsers.rst import Directive, directives | ||
|
||
from nikola.plugin_categories import RestExtension | ||
|
||
from nikola.plugin_categories import LateTask | ||
from nikola.utils import copy_tree | ||
|
||
|
||
def flag_to_boolean(value): | ||
"""Function to parse directives.flag options""" | ||
return 'true' | ||
|
||
|
||
class Plugin(RestExtension, LateTask): | ||
|
||
name = "nanogallery_directive" | ||
|
||
def set_site(self, site): | ||
self.site = site | ||
site.template_hooks['extra_head'].append('<link href="/assets/css/nanogallery.min.css" rel="stylesheet" type="text/css">') | ||
site.template_hooks['body_end'].append('<script type="text/javascript" src="/assets/js/jquery.nanogallery.min.js"></script>') | ||
NanoGallery.site = site | ||
return super(Plugin, self).set_site(site) | ||
|
||
def gen_tasks(self): | ||
kw = { | ||
"output_folder": self.site.config['OUTPUT_FOLDER'], | ||
} | ||
|
||
# Copy all the assets to the right places | ||
asset_folder = os.path.join(os.path.dirname(__file__), "files") | ||
for task in copy_tree(asset_folder, kw["output_folder"]): | ||
task["basename"] = str(self.name) | ||
yield task | ||
|
||
|
||
class NanoGallery(Directive): | ||
""" Restructured text extension for inserting nanogallery galleries.""" | ||
|
||
# http://nanogallery.brisbois.fr/#docGeneralSettings | ||
option_spec = { | ||
'theme': directives.unchanged, | ||
'colorscheme': directives.unchanged, | ||
'rtl': flag_to_boolean, | ||
'maxitemsperline': directives.nonnegative_int, | ||
'maxwidth': directives.nonnegative_int, | ||
'paginationdots': flag_to_boolean, | ||
'paginationmaxlinesperpage': directives.nonnegative_int, | ||
'paginationswipe': flag_to_boolean, | ||
'locationhash': flag_to_boolean, | ||
'itemsselectable': flag_to_boolean, | ||
'showcheckboxes': flag_to_boolean, | ||
'checkboxstyle': directives.unchanged, | ||
'keepselection': flag_to_boolean, | ||
'i18n': directives.unchanged, | ||
'lazybuild': directives.unchanged, | ||
'lazybuildtreshold': directives.nonnegative_int, | ||
'openonstart': directives.unchanged, | ||
'breakpointsizesm': directives.nonnegative_int, | ||
'breakpointsizeme': directives.nonnegative_int, | ||
'breakpointsizela': directives.nonnegative_int, | ||
'breakpointsizexl': directives.nonnegative_int, | ||
'thumbnailheight': directives.nonnegative_int, | ||
'thumbnailwidth': directives.nonnegative_int, | ||
'thumbnailalignment': directives.unchanged, | ||
'thumbnailgutterwidth': directives.nonnegative_int, | ||
'thumbnailgutterheight': directives.nonnegative_int, | ||
'thumbnailopenimage': flag_to_boolean, | ||
'thumbnaillabel': directives.unchanged, | ||
'thumbnailhovereffect': directives.unchanged, | ||
'touchanimation': flag_to_boolean, | ||
'touchautoopendelay': directives.nonnegative_int, | ||
'thumbnaildisplayinterval': directives.nonnegative_int, | ||
'thumbnaildisplaytransition': flag_to_boolean, | ||
'thumbnaillazyload': flag_to_boolean, | ||
'thumbnaillazyloadtreshold': directives.nonnegative_int, | ||
'thumbnailadjustlastrowheight': flag_to_boolean, | ||
'thumbnailalbumdisplayimage': flag_to_boolean, | ||
} | ||
has_content = True | ||
|
||
def __init__(self, *args, **kwargs): | ||
super(NanoGallery, self).__init__(*args, **kwargs) | ||
self.state.document.settings.record_dependencies.add('####MAGIC####CONFIG:NANOGALLERY_OPTIONS') | ||
|
||
def _sanitize_options(self): | ||
THUMBNAIL_SIZE = self.site.config.get('THUMBNAIL_SIZE', 128) | ||
defaults = { | ||
'theme': 'clean', | ||
'maxitemsperline': 4, | ||
'thumbnailgutterwidth': 10, | ||
'thumbnailgutterheight': 10, | ||
'locationhash': 'false', | ||
'colorscheme': 'lightBackground', | ||
'thumbnailheight': 'auto', | ||
'thumbnailwidth': THUMBNAIL_SIZE, | ||
'thumbnailhovereffect': 'imageScale150', | ||
'thumbnaillabel': {'display': 'false'}, | ||
} | ||
user_defaults = self.site.config.get('NANOGALLERY_OPTIONS', {}) | ||
defaults.update(user_defaults) | ||
|
||
defaults.update(self.options) | ||
# TODO: validate options here and (maybe) display an error | ||
for option in defaults.keys(): | ||
assert option in self.option_spec | ||
|
||
# We need to convert all the lowercase options (rst make them | ||
# lowercase automatically) to the correct ones -supported by | ||
# nanoGALLERY Javascript function | ||
js_options = [ | ||
'theme', 'colorScheme', 'RTL', 'maxItemsPerLine', | ||
'maxWidth', 'paginationDots', 'paginationMaxLinesPerPage', | ||
'paginationSwipe', 'locationHash', 'itemsSelectable', | ||
'showCheckboxes', 'checkboxStyle', 'keepSelection', | ||
'i18n', 'lazyBuild', 'lazyBuildTreshold', 'openOnStart', | ||
'breakpointSizeSM', 'breakpointSizeME', 'breakpointSizeLA', | ||
'breakpointSizeXL', 'thumbnailHeight', 'thumbnailWidth', | ||
'thumbnailAlignment', 'thumbnailGutterWidth', | ||
'thumbnailGutterHeight', 'thumbnailOpenImage', | ||
'thumbnailLabel', 'thumbnailHoverEffect', | ||
'touchAnimation', 'touchAutoOpenDelay', | ||
'thumbnailDisplayInterval', 'thumbnailDisplayTransition', | ||
'thumbnailLazyLoad', 'thumbnailLazyLoadTreshold', | ||
'thumbnailAdjustLastRowHeight', 'thumbnailAlbumDisplayImage' | ||
] | ||
js_options = {o.lower(): o for o in js_options} | ||
|
||
options = {} | ||
for k in defaults: | ||
options[js_options[k]] = defaults[k] | ||
|
||
return options | ||
|
||
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({ | ||
'href': img, | ||
'data': { | ||
'ngthumb': thumb, | ||
}, | ||
}) | ||
|
||
output = self.site.template_system.render_template( | ||
'embedded-nanogallery.tmpl', | ||
None, | ||
{ | ||
'nanogallery_content': photo_array, | ||
'options': self._sanitize_options() | ||
} | ||
) | ||
return [nodes.raw('', output, format='html')] | ||
|
||
|
||
directives.register_directive('nanogallery', NanoGallery) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
## -*- coding: utf-8 -*- | ||
|
||
<div id="nanoGallery3"> | ||
% for image in nanogallery_content: | ||
<a href="${image['href']}" | ||
% for k, v in image['data'].iteritems(): | ||
data-${k}="${v}" | ||
% endfor | ||
> | ||
% if 'caption' in image: | ||
${image['caption']} | ||
% endif | ||
</a> | ||
% endfor | ||
</div> | ||
|
||
% if options['theme'] == 'clean': | ||
<link href="/assets/css/themes/clean/nanogallery_clean.min.css" rel="stylesheet" type="text/css"> | ||
% endif | ||
|
||
% if options['theme'] == 'light': | ||
<link href="/assets/css/themes/light/nanogallery_light.min.css" rel="stylesheet" type="text/css"> | ||
% endif | ||
|
||
<%def name="jsfy(x)"> | ||
<% | ||
import json | ||
return json.dumps(x) | ||
%> | ||
</%def> | ||
|
||
|
||
<script type="text/javascript"> | ||
// Some settings are configured by .nanoGallery() javascript method | ||
// We need window.onload here because jQuery is not loaded yet | ||
window.onload = function() { | ||
$("#nanoGallery3").nanoGallery({ | ||
% for k, v in options.iteritems(): | ||
% if isinstance(v, unicode): | ||
${k}: '${v}', | ||
% elif isinstance(v, dict): | ||
${k}: ${jsfy(v)}, | ||
% elif isinstance(v, bool): | ||
${k}: ${str(v).lower()}, | ||
% else: | ||
${k}: ${v}, | ||
% endif | ||
% endfor | ||
}); | ||
} | ||
</script> |
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.
write a Jinja version (the jinjify script could help you here, if you get it to work for one file)