Skip to content

Commit

Permalink
Monkeypatched Image directive that supports class option
Browse files Browse the repository at this point in the history
  • Loading branch information
ralsina committed Apr 24, 2015
1 parent ab5ff35 commit ff854c8
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
10 changes: 10 additions & 0 deletions v7/classy-images/classy-images.plugin
@@ -0,0 +1,10 @@
[Core]
Name = classy_images
Module = classy_images

[Documentation]
Author = Roberto Alsina
Version = 0.1
Website = http://getnikola.com
Description = Image directive replacement supporting a class option

61 changes: 61 additions & 0 deletions v7/classy-images/classy_images.py
@@ -0,0 +1,61 @@
# -*- coding: utf-8 -*-

# Copyright © 2012-2015 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.

from __future__ import unicode_literals

import uuid

This comment has been minimized.

Copy link
@Kwpolska

Kwpolska Apr 24, 2015

Member

Does not seem to be used here.

This comment has been minimized.

Copy link
@ralsina

ralsina Apr 24, 2015

Author Member

There is a second commit that fixes that and a cople other things flake8 noticed.


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

from nikola.plugin_categories import RestExtension


class Plugin(RestExtension):

name = "classy_images"

def set_site(self, site):
self.site = site
directives.register_directive('image', ClassyImages)
ClassyImages.site = site
return super(Plugin, self).set_site(site)

classy_spec = directives.images.Image.option_spec
classy_spec['class'] = directives.unchanged

class ClassyImages(directives.images.Image):
""" Restructured text extension for inserting slideshows."""

option_spec = classy_spec

def run(self):
r = super(ClassyImages, self).run()
r[0]['classes'] = [r[0]['classes']]
return r


directives.register_directive('image', ClassyImages)

0 comments on commit ff854c8

Please sign in to comment.