1. Georg Brandl
  2. sphinx-contrib

Commits

Takeshi Komiya  committed ee7b9ad

Add new extension: sphinxcontrib-slide

  • Participants
  • Parent commits 462aaf8
  • Branches default
  • Tags slide-0.1.0

Comments (0)

Files changed (9)

File AUTHORS

View file
  • Ignore whitespace
 nicovideo:
    Takeshi KOMIYA <i.tkomiya@gmail.com>
 
+slide:
+   Takeshi KOMIYA <i.tkomiya@gmail.com>
+
 requirements:
    Andrey Mikhaylenko <neithere@gmail.com>
 

File README

View file
  • Ignore whitespace
 - sdedit: an extension inserting sequence diagram by using Quick Sequence.
   Diagram Editor (sdedit_)
 - seqdiag: embed sequence diagrams by using seqdiag_
+- slide: embed presentation slides on slideshare_ and other sites.
 - sword: an extension inserting Bible verses from Sword_.
 - traclinks: create TracLinks_ to a Trac_ instance from within Sphinx
 - youtube: embed videos from YouTube_
 
 .. _Zope interfaces: http://docs.zope.org/zope.interface/README.html
 
+.. _slideshare: http://www.slideshare.net/
+
 For contributors
 ================
 

File slide/MANIFEST.in

View file
  • Ignore whitespace
+include README
+include LICENSE
+include CHANGES.*

File slide/README

View file
  • Ignore whitespace
+slide extension README
+=======================
+
+This is a sphinx extension for embedding your presentation slides.
+
+This extension enable you to embed your slides on slideshare_ and other sites.
+Following code is sample::
+
+   .. slide:: http://www.slideshare.net/TakeshiKomiya/blockdiag-a-simple-diagram-generator
+
+
+.. _slideshare: http://www.slideshare.net/
+
+
+Setting
+=======
+
+.. You can see available package at `PyPI <http://pypi.python.org/pypi/sphinxcontrib-slide>`_.
+
+You can get archive file at http://bitbucket.org/birkenfeld/sphinx-contrib/
+
+Install
+-------
+
+.. code-block:: bash
+
+   > easy_install sphinxcontrib-slide
+
+
+Configure Sphinx
+----------------
+
+To enable this extension, add ``sphinxcontrib.slide`` module to extensions 
+option at :file:`conf.py`. 
+
+.. code-block:: python
+
+   import os, sys
+
+   # Path to the folder where blockdiag.py is
+   # NOTE: not needed if the package is installed in traditional way
+   # using setup.py or easy_install
+   sys.path.append(os.path.abspath('/path/to/sphinxcontrib.slide'))
+
+   # Enabled extensions
+   extensions = ['sphinxcontrib.slide']
+
+
+Directive
+=========
+
+.. describe:: .. slide:: [URL]
+
+   This directive insert slide interface into the generated document.
+   sphinxcontrib-slide supports presentations on slideshare and googledocs. 
+
+   Examples::
+
+      .. slide:: http://www.slideshare.net/TakeshiKomiya/blockdiag-a-simple-diagram-generator

File slide/setup.cfg

View file
  • Ignore whitespace
+[egg_info]
+;tag_build = dev
+;tag_date = true
+
+[aliases]
+release = egg_info -RDb ''

File slide/setup.py

View file
  • Ignore whitespace
+# -*- coding: utf-8 -*-
+
+from setuptools import setup, find_packages
+
+long_desc = '''
+This package contains the slide Sphinx extension.
+
+This extension enable you to embed your slides on slideshare_ and other sites.
+Following code is sample::
+
+   .. slide:: http://www.slideshare.net/TakeshiKomiya/blockdiag-a-simple-diagram-generator
+
+
+.. _slideshare: http://www.slideshare.net/
+'''
+
+requires = ['Sphinx>=0.6']
+
+setup(
+    name='sphinxcontrib-slide',
+    version='0.1.0',
+    url='http://bitbucket.org/birkenfeld/sphinx-contrib',
+    download_url='http://pypi.python.org/pypi/sphinxcontrib-slide',
+    license='BSD',
+    author='Takeshi KOMIYA',
+    author_email='i.tkomiya@gmail.com',
+    description='Sphinx "slide" extension',
+    long_description=long_desc,
+    zip_safe=False,
+    classifiers=[
+        'Development Status :: 4 - Beta',
+        'Environment :: Console',
+        'Environment :: Web Environment',
+        'Intended Audience :: Developers',
+        'License :: OSI Approved :: BSD License',
+        'Operating System :: OS Independent',
+        'Programming Language :: Python',
+        'Topic :: Documentation',
+        'Topic :: Utilities',
+    ],
+    platforms='any',
+    packages=find_packages(),
+    include_package_data=True,
+    install_requires=requires,
+    namespace_packages=['sphinxcontrib'],
+)

File slide/sphinxcontrib/__init__.py

View file
  • Ignore whitespace
+# -*- coding: utf-8 -*-
+"""
+    sphinxcontrib
+    ~~~~~~~~~~~~~
+
+    This package is a namespace package that contains all extensions
+    distributed in the ``sphinx-contrib`` distribution.
+
+    :copyright: Copyright 2007-2009 by the Sphinx team, see AUTHORS.
+    :license: BSD, see LICENSE for details.
+"""
+
+__import__('pkg_resources').declare_namespace(__name__)
+

File slide/sphinxcontrib/slide.py

View file
  • Ignore whitespace
+# -*- coding: utf-8 -*-
+"""
+    sphinxcontrib.slide
+    ~~~~~~~~~~~~~~~~~~~
+
+    :copyright: Copyright 2012 by Takeshi KOMIYA
+    :license: BSD, see LICENSE for details.
+"""
+
+import os
+import re
+import urllib2
+
+from docutils import nodes, utils
+from docutils.parsers.rst import directives
+
+from sphinx.util.compat import Directive
+
+
+class slide(nodes.General, nodes.Element):
+    pass
+
+
+class SlideDirective(Directive):
+    """Directive for embedding slide"""
+
+    has_content = False
+    required_arguments = 1
+    optional_arguments = 0
+    final_argument_whitespace = True
+    option_spec = {
+    }
+
+    def run(self):
+        try:
+            node = slide()
+            node['url'] = self.arguments[0]
+            node['slide_options'] = get_slide_options(self.arguments[0])
+
+            return [node]
+        except Exception, e:
+            reporter = self.state.document.reporter
+            return [reporter.warning(str(e), line=self.lineno)]
+
+
+def get_slide_options(url):
+    if re.match('https://docs.google.com/presentation/pub', url):
+        return get_slide_options_for_googledocs(url)
+    elif re.match('http://www.slideshare.net/', url):
+        return get_slide_options_for_slideshare(url)
+    else:
+        msg = 'unknown slide URL: %s' % url
+        raise Exception(msg)
+
+
+def get_slide_options_for_googledocs(url):
+    options = {}
+    options['type'] = 'googledocs'
+    options['embed_url'] = re.sub('/pub\?', '/embed?', url)
+
+    content = urllib2.urlopen(url).read()
+    matched = re.search('<title>(.*?)</title>', content)
+    if matched:
+        options['title'] = matched.group(1).decode('utf-8')
+
+    return options
+
+
+def get_slide_options_for_slideshare(url):
+    options = {}
+    options['type'] = 'slideshare'
+
+    content = urllib2.urlopen(url).read()
+    matched = re.search('http://www.slideshare.net/slideshow/embed_code/\d+', content)
+    if matched:
+        options['embed_url'] = matched.group(0)
+
+    matched = re.search('<title>(.*?)</title>', content)
+    if matched:
+        options['title'] = matched.group(1).decode('utf-8')
+
+    matched = re.search('<meta name="slideshow_author".*? content="(.*?)" />', content)
+    if matched:
+        options['author_url'] = matched.group(1)
+
+    matched = re.search('<img class="h-author-image".*? alt="(.*?)" width="50" />', content)
+    if matched:
+        options['author_name'] = matched.group(1).decode('utf-8')
+
+    return options
+
+
+def html_visit_slide_node(self, node):
+    options = node['slide_options']
+
+    if options['type'] == 'googledocs':
+        template = """<iframe src="%s" frameborder="0" width="480" height="375" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true"></iframe>"""
+        self.body.append(template % options.get('embed_url'))
+    elif options['type'] == 'slideshare':
+        template = """<iframe src="%s" width="427" height="356" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" style="border:1px solid #CCC;border-width:1px 1px 0;margin-bottom:5px" allowfullscreen> </iframe> <div style="margin-bottom:5px"> <strong> <a href="%s" title="%s" target="_blank">%s</a> </strong> from <strong><a href="%s" target="_blank">%s</a></strong> </div>"""
+        self.body.append(template % (options.get('embed_url'),
+                                     node.get('url'),
+                                     options.get('title', ""),
+                                     options.get('title', ""),
+                                     options.get('author_url'),
+                                     options.get('author_name', "")))
+
+
+def latex_visit_slide_node(self, node):
+    title = node['slide_options'].get('title')
+
+    if title:
+        self.body.append("\\href{%s}{%s}" % (self.encode_uri(node['url']), self.encode(title)))
+    else:
+        self.body.append("\\url{%s}" % self.encode_uri(node['url']))
+
+
+def depart_slide_node(self, node):
+    pass
+
+
+def setup(app):
+    app.add_node(slide,
+                 html=(html_visit_slide_node, depart_slide_node),
+                 latex=(latex_visit_slide_node, depart_slide_node))
+    app.add_directive('slide', SlideDirective)

File slide/tox.ini

View file
  • Ignore whitespace
+## configuration for tox <http://codespeak.net/tox/>
+
+## tox automates running certain tasks within virtualenvs.  The following
+## tox configuration outlines a basic setup for running unit tests and
+## building sphinx docs in separate virtual environments.  Give it a try!
+
+[tox]
+envlist=python,doc
+
+# test running
+[testenv:python]
+deps=
+    ## if you use nose for test running
+    # nose
+    ## if you use py.test for test running
+    # pytest
+commands=
+    ## run tests with py.test
+    # py.test []
+    ## run tests with nose
+    # nose
+
+[testenv:doc]
+deps=
+    sphinx
+    # add all Sphinx extensions and other dependencies required to build your docs
+commands=
+    ## test links
+    # sphinx-build -W -b linkcheck -d {envtmpdir}/doctrees doc {envtmpdir}/linkcheck
+    ## test html output
+    # sphinx-build -W -b html -d {envtmpdir}/doctrees doc {envtmpdir}/html
+