Skip to content
Permalink
Browse files
Fix #2304 -- align options for youtube, soundcloud, vimeo directives
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Apr 29, 2016
1 parent b7b884b commit 78adaf3a5fe3d612f668d05b20ce6c5cfc6f061b
Showing 7 changed files with 51 additions and 11 deletions.
@@ -9,6 +9,8 @@ Features
Bugfixes
--------

* Add ``align`` options for ``youtube``, ``vimeo``, ``soundcloud``
reST directives (Issue #2304)
* Update ``FILE_METADATA_REGEXP`` example in docs (Issue #2296)
* Show “tags too similar” error instead of cryptic doit crash (Issue #2325)
* Fix crashes when tag appears multiple times in a post (Issue #2315)
@@ -1662,6 +1662,9 @@ Once you have that, all you need to do is:

.. youtube:: 8N_tupPBtWQ

Supported options: ``height``, ``width``, ``align`` (one of ``left``,
``center``, ``right``) — all are optional.

Vimeo
~~~~~

@@ -1684,6 +1687,9 @@ You can override this if you wish:
:height: 240
:width: 320

Supported options: ``height``, ``width``, ``align`` (one of ``left``,
``center``, ``right``) — all are optional.

Soundcloud
~~~~~~~~~~

@@ -1705,6 +1711,9 @@ You can also embed playlists, via the `soundcloud_playlist` directive which work

.. soundcloud_playlist:: 9411706

Supported options: ``height``, ``width``, ``align`` (one of ``left``,
``center``, ``right``) — all are optional.

Code
~~~~

@@ -191,7 +191,7 @@ img.align-center, .figure.align-center, object.align-center {
text-align: right }

/* reset inner alignment in figures */
div.align-right {
.figure.align-right {
text-align: inherit }

/* div.align-center * { */
@@ -36,6 +36,7 @@
import docutils.io
import docutils.readers.standalone
import docutils.writers.html4css1
import docutils.parsers.rst.directives

from nikola.plugin_categories import PageCompiler
from nikola.utils import unicode_str, get_logger, makedirs, write_metadata, STDERR_HANDLER
@@ -276,3 +277,10 @@ def rst2html(source, source_path=None, source_class=docutils.io.StringInput,
pub.publish(enable_exit_status=enable_exit_status)

return pub.writer.parts['docinfo'] + pub.writer.parts['fragment'], pub.document.reporter.max_level, pub.settings.record_dependencies

# Alignment helpers for extensions
_align_options_base = ('left', 'center', 'right')


def _align_choice(argument):
return docutils.parsers.rst.directives.choice(argument, _align_options_base + ("none", ""))
@@ -4,7 +4,7 @@

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

from nikola.plugins.compile.rest import _align_choice, _align_options_base

from nikola.plugin_categories import RestExtension

@@ -22,11 +22,13 @@ def set_site(self, site):
return super(Plugin, self).set_site(site)


CODE = ("""<iframe width="{width}" height="{height}"
CODE = """\
<div class="soundcloud-player{align}">
<iframe width="{width}" height="{height}"
scrolling="no" frameborder="no"
src="https://w.soundcloud.com/player/?url=http://api.soundcloud.com/{preslug}/"""
"""{sid}">
</iframe>""")
src="https://w.soundcloud.com/player/?url=http://api.soundcloud.com/{preslug}/{sid}">
</iframe>
</div>"""


class SoundCloud(Directive):
@@ -44,6 +46,7 @@ class SoundCloud(Directive):
option_spec = {
'width': directives.positive_int,
'height': directives.positive_int,
"align": _align_choice
}
preslug = "tracks"

@@ -57,6 +60,10 @@ def run(self):
'preslug': self.preslug,
}
options.update(self.options)
if self.options.get('align') in _align_options_base:
options['align'] = ' align-' + self.options['align']
else:
options['align'] = ''
return [nodes.raw('', CODE.format(**options), format='html')]

def check_content(self):
@@ -28,6 +28,7 @@

from docutils import nodes
from docutils.parsers.rst import Directive, directives
from nikola.plugins.compile.rest import _align_choice, _align_options_base

import requests
import json
@@ -48,10 +49,12 @@ def set_site(self, site):
return super(Plugin, self).set_site(site)


CODE = """<iframe src="https://player.vimeo.com/video/{vimeo_id}"
CODE = """<div class="vimeo-video{align}">
<iframe src="https://player.vimeo.com/video/{vimeo_id}"
width="{width}" height="{height}"
frameborder="0" webkitAllowFullScreen="webkitAllowFullScreen" mozallowfullscreen="mozallowfullscreen" allowFullScreen="allowFullScreen">
</iframe>
</div>
"""

VIDEO_DEFAULT_HEIGHT = 500
@@ -73,6 +76,7 @@ class Vimeo(Directive):
option_spec = {
"width": directives.positive_int,
"height": directives.positive_int,
"align": _align_choice
}

# set to False for not querying the vimeo api for size
@@ -92,6 +96,10 @@ def run(self):
return err
self.set_video_size()
options.update(self.options)
if self.options.get('align') in _align_options_base:
options['align'] = ' align-' + self.options['align']
else:
options['align'] = ''
return [nodes.raw('', CODE.format(**options), format='html')]

def check_modules(self):
@@ -28,7 +28,7 @@

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

from nikola.plugins.compile.rest import _align_choice, _align_options_base

from nikola.plugin_categories import RestExtension

@@ -46,10 +46,11 @@ def set_site(self, site):


CODE = """\
<iframe width="{width}"
height="{height}"
<div class="youtube-video{align}">
<iframe width="{width}" height="{height}"
src="https://www.youtube.com/embed/{yid}?rel=0&amp;hd=1&amp;wmode=transparent"
></iframe>"""
></iframe>
</div>"""


class Youtube(Directive):
@@ -67,6 +68,7 @@ class Youtube(Directive):
option_spec = {
"width": directives.positive_int,
"height": directives.positive_int,
"align": _align_choice
}

def run(self):
@@ -78,6 +80,10 @@ def run(self):
'height': 344,
}
options.update(self.options)
if self.options.get('align') in _align_options_base:
options['align'] = ' align-' + self.options['align']
else:
options['align'] = ''
return [nodes.raw('', CODE.format(**options), format='html')]

def check_content(self):

0 comments on commit 78adaf3

Please sign in to comment.