sphinxcontrib-actdiag-0.6.0/0000755000175000017500000000000012224001723017206 5ustar katsuwokatsuwo00000000000000sphinxcontrib-actdiag-0.6.0/PKG-INFO0000644000175000017500000000274612224001723020314 0ustar katsuwokatsuwo00000000000000Metadata-Version: 1.1 Name: sphinxcontrib-actdiag Version: 0.6.0 Summary: Sphinx "actdiag" extension Home-page: http://bitbucket.org/birkenfeld/sphinx-contrib Author: Takeshi Komiya Author-email: i.tkomiya@gmail.com License: BSD Download-URL: http://pypi.python.org/pypi/sphinxcontrib-actdiag Description: This package contains the actdiag Sphinx extension. .. _Sphinx: http://sphinx.pocoo.org/ .. _actdiag: http://blockdiag.com/en/actdiag/ This extension enable you to insert activity diagrams in your Sphinx document. Following code is sample:: .. actdiag:: diagram { A -> B -> C -> D; lane { A; B; } lane { C; D; } } This module needs actdiag_. Platform: any Classifier: Development Status :: 4 - Beta Classifier: Environment :: Console Classifier: Environment :: Web Environment Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3.2 Classifier: Programming Language :: Python :: 3.3 Classifier: Topic :: Documentation Classifier: Topic :: Utilities sphinxcontrib-actdiag-0.6.0/setup.py0000644000175000017500000000323412224001617020724 0ustar katsuwokatsuwo00000000000000# -*- coding: utf-8 -*- from setuptools import setup, find_packages long_desc = ''' This package contains the actdiag Sphinx extension. .. _Sphinx: http://sphinx.pocoo.org/ .. _actdiag: http://blockdiag.com/en/actdiag/ This extension enable you to insert activity diagrams in your Sphinx document. Following code is sample:: .. actdiag:: diagram { A -> B -> C -> D; lane { A; B; } lane { C; D; } } This module needs actdiag_. ''' requires = ['actdiag>=0.5.0', 'Sphinx>=0.6', 'setuptools'] setup( name='sphinxcontrib-actdiag', version='0.6.0', url='http://bitbucket.org/birkenfeld/sphinx-contrib', download_url='http://pypi.python.org/pypi/sphinxcontrib-actdiag', license='BSD', author='Takeshi Komiya', author_email='i.tkomiya@gmail.com', description='Sphinx "actdiag" 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', 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3.2', 'Programming Language :: Python :: 3.3', 'Topic :: Documentation', 'Topic :: Utilities', ], platforms='any', packages=find_packages(), include_package_data=True, install_requires=requires, namespace_packages=['sphinxcontrib'], ) sphinxcontrib-actdiag-0.6.0/setup.cfg0000644000175000017500000000014112224001723021023 0ustar katsuwokatsuwo00000000000000[egg_info] tag_build = tag_date = 0 tag_svn_revision = 0 [aliases] release = egg_info -RDb '' sphinxcontrib-actdiag-0.6.0/sphinxcontrib/0000755000175000017500000000000012224001723022100 5ustar katsuwokatsuwo00000000000000sphinxcontrib-actdiag-0.6.0/sphinxcontrib/__init__.py0000644000175000017500000000055612223754371024234 0ustar katsuwokatsuwo00000000000000# -*- 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__) sphinxcontrib-actdiag-0.6.0/sphinxcontrib/actdiag.py0000644000175000017500000002562012223755012024061 0ustar katsuwokatsuwo00000000000000# -*- coding: utf-8 -*- """ actdiag.sphinx_ext ~~~~~~~~~~~~~~~~~~~~ Allow actdiag-formatted diagrams to be included in Sphinx-generated documents inline. :copyright: Copyright 2010 by Takeshi Komiya. :license: BSDL. """ import io import os import re import posixpath import traceback from collections import namedtuple try: from hashlib import sha1 as sha except ImportError: from sha import sha from docutils import nodes from sphinx.errors import SphinxError from sphinx.util.osutil import ensuredir import actdiag_sphinxhelper as actdiag u = actdiag.utils.compat.u class ActdiagError(SphinxError): category = 'Actdiag error' class Actdiag(actdiag.utils.rst.directives.ActdiagDirective): def run(self): try: return super(Actdiag, self).run() except actdiag.core.parser.ParseException as e: if self.content: msg = '[%s] ParseError: %s\n%s' % (self.name, e, "\n".join(self.content)) else: msg = '[%s] ParseError: %s\n%r' % (self.name, e, self.arguments[0]) reporter = self.state.document.reporter return [reporter.warning(msg, line=self.lineno)] def node2image(self, node, diagram): return node def get_image_filename(self, code, format, options, prefix='actdiag'): """ Get path of output file. """ if format.upper() not in ('PNG', 'PDF', 'SVG'): raise ActdiagError('actdiag error:\nunknown format: %s\n' % format) if format.upper() == 'PDF': try: import reportlab except ImportError: msg = 'actdiag error:\n' + \ 'colud not output PDF format; Install reportlab\n' raise ActdiagError(msg) hashkey = (code + str(options)).encode('utf-8') fname = '%s-%s.%s' % (prefix, sha(hashkey).hexdigest(), format.lower()) if hasattr(self.builder, 'imgpath'): # HTML relfn = posixpath.join(self.builder.imgpath, fname) outfn = os.path.join(self.builder.outdir, '_images', fname) else: # LaTeX relfn = fname outfn = os.path.join(self.builder.outdir, fname) if os.path.isfile(outfn): return relfn, outfn ensuredir(os.path.dirname(outfn)) return relfn, outfn def get_fontmap(self): FontMap = actdiag.utils.fontmap.FontMap try: fontmappath = self.builder.config.actdiag_fontmap fontmap = FontMap(fontmappath) except: attrname = '_actdiag_fontmap_warned' if not hasattr(self.builder, attrname): msg = ('actdiag cannot load "%s" as fontmap file, ' 'check the actdiag_fontmap setting' % fontmappath) self.builder.warn(msg) setattr(self.builder, attrname, True) fontmap = FontMap(None) try: fontpath = self.builder.config.actdiag_fontpath if isinstance(fontpath, actdiag.utils.compat.string_types): fontpath = [fontpath] if fontpath: config = namedtuple('Config', 'font')(fontpath) _fontpath = actdiag.utils.bootstrap.detectfont(config) fontmap.set_default_font(_fontpath) except: attrname = '_actdiag_fontpath_warned' if not hasattr(self.builder, attrname): msg = ('actdiag cannot load "%s" as truetype font, ' 'check the actdiag_fontpath setting' % fontpath) self.builder.warn(msg) setattr(self.builder, attrname, True) return fontmap def get_anchor(self, refid, fromdocname): for docname in self.builder.env.found_docs: doctree = self.builder.env.get_doctree(docname) for target in doctree.traverse(nodes.Targetable): if target.attributes.get('refid') == refid: targetfile = self.builder.get_relative_uri(fromdocname, docname) return targetfile + "#" + refid def resolve_reference(self, href, options): if href is None: return pattern = re.compile(u("^:ref:`(.+?)`"), re.UNICODE) matched = pattern.search(href) if matched: return get_anchor(self, matched.group(1), options['current_docname']) else: return href def create_actdiag(self, code, format, filename, options, prefix='actdiag'): """ Render actdiag code into a PNG output file. """ draw = None fontmap = get_fontmap(self) try: tree = actdiag.core.parser.parse_string(code) diagram = actdiag.core.builder.ScreenNodeBuilder.build(tree) for lane in diagram.lanes: if lane.href: lane.href = resolve_reference(self, lane.href, options) for node in diagram.traverse_nodes(): if node.href: node.href = resolve_reference(self, node.href, options) antialias = self.builder.config.actdiag_antialias draw = actdiag.core.drawer.DiagramDraw(format, diagram, filename, fontmap=fontmap, antialias=antialias) except Exception as e: if self.builder.config.actdiag_debug: traceback.print_exc() raise ActdiagError('actdiag error:\n%s\n' % e) return draw def make_svgtag(self, image, relfn, trelfn, outfn, alt, thumb_size, image_size): svgtag_format = """%s """ code = io.open(outfn, 'r', encoding='utf-8-sig').read() return (svgtag_format % (alt, image_size[0], image_size[1], code)) def make_imgtag(self, image, relfn, trelfn, outfn, alt, thumb_size, image_size): result = "" clickable_map = [] for l in image.diagram.lanes: if l.href: cell = image.metrics.lane_headerbox(l) clickable_map.append((cell, l.href)) for n in image.nodes: if n.href: cell = image.metrics.cell(n) clickable_map.append((cell, n.href)) if clickable_map: imgtag_format = '%s' % relfn) result += (imgtag_format % (trelfn, alt, thumb_size[0], thumb_size[1])) result += ('') else: result += (imgtag_format % (relfn, alt, image_size[0], image_size[1])) if clickable_map: result += ('' % id(image)) rect_format = '' for m in clickable_map: x1 = m[0][0] y1 = m[0][1] x2 = m[0][2] y2 = m[0][3] result += (rect_format % (x1, y1, x2, y2, m[1])) result += ('') return result def render_dot_html(self, node, code, options, prefix='actdiag', imgcls=None, alt=None): trelfn = None thumb_size = None try: format = self.builder.config.actdiag_html_image_format relfn, outfn = get_image_filename(self, code, format, options, prefix) options['current_docname'] = self.builder.current_docname image = create_actdiag(self, code, format, outfn, options, prefix) if not os.path.isfile(outfn): image.draw() image.save() # generate thumbnails image_size = image.pagesize() if 'maxwidth' in options and options['maxwidth'] < image_size[0]: thumb_prefix = prefix + '_thumb' trelfn, toutfn = get_image_filename(self, code, format, options, thumb_prefix) ratio = float(options['maxwidth']) / image_size[0] thumb_size = (options['maxwidth'], image_size[1] * ratio) if not os.path.isfile(toutfn): image.filename = toutfn image.save(thumb_size) except UnicodeEncodeError: msg = ("actdiag error: UnicodeEncodeError caught " "(check your font settings)") self.builder.warn(msg) raise nodes.SkipNode except ActdiagError as exc: self.builder.warn('dot code %r: ' % code + str(exc)) raise nodes.SkipNode self.body.append(self.starttag(node, 'p', CLASS='actdiag')) if relfn is None: self.body.append(self.encode(code)) else: if alt is None: alt = node.get('alt', self.encode(code).strip()) if format.upper() == 'SVG': tagfunc = make_svgtag else: tagfunc = make_imgtag self.body.append(tagfunc(self, image, relfn, trelfn, outfn, alt, thumb_size, image_size)) self.body.append('

\n') raise nodes.SkipNode def html_visit_actdiag(self, node): render_dot_html(self, node, node['code'], node['options']) def render_dot_latex(self, node, code, options, prefix='actdiag'): try: format = self.builder.config.actdiag_tex_image_format fname, outfn = get_image_filename(self, code, format, options, prefix) image = create_actdiag(self, code, format, outfn, options, prefix) if not os.path.isfile(outfn): image.draw() image.save() except ActdiagError as exc: self.builder.warn('dot code %r: ' % code + str(exc)) raise nodes.SkipNode if fname is not None: self.body.append('\\par\\includegraphics{%s}\\par' % fname) raise nodes.SkipNode def latex_visit_actdiag(self, node): render_dot_latex(self, node, node['code'], node['options']) def on_doctree_resolved(self, doctree, docname): if self.builder.name in ('gettext', 'singlehtml', 'html', 'latex', 'epub'): return for node in doctree.traverse(actdiag.utils.rst.nodes.actdiag): code = node['code'] prefix = 'actdiag' format = 'PNG' options = node['options'] relfn, outfn = get_image_filename(self, code, format, options, prefix) image = create_actdiag(self, code, format, outfn, options, prefix) if not os.path.isfile(outfn): image.draw() image.save() candidates = {'image/png': outfn} image = nodes.image(uri=outfn, candidates=candidates) node.parent.replace(node, image) def setup(app): app.add_node(actdiag.utils.rst.nodes.actdiag, html=(html_visit_actdiag, None), latex=(latex_visit_actdiag, None)) app.add_directive('actdiag', Actdiag) app.add_config_value('actdiag_fontpath', None, 'html') app.add_config_value('actdiag_fontmap', None, 'html') app.add_config_value('actdiag_antialias', False, 'html') app.add_config_value('actdiag_debug', False, 'html') app.add_config_value('actdiag_html_image_format', 'PNG', 'html') app.add_config_value('actdiag_tex_image_format', 'PNG', 'html') app.connect("doctree-resolved", on_doctree_resolved) sphinxcontrib-actdiag-0.6.0/sphinxcontrib_actdiag.egg-info/0000755000175000017500000000000012224001723025246 5ustar katsuwokatsuwo00000000000000sphinxcontrib-actdiag-0.6.0/sphinxcontrib_actdiag.egg-info/PKG-INFO0000644000175000017500000000274612224001723026354 0ustar katsuwokatsuwo00000000000000Metadata-Version: 1.1 Name: sphinxcontrib-actdiag Version: 0.6.0 Summary: Sphinx "actdiag" extension Home-page: http://bitbucket.org/birkenfeld/sphinx-contrib Author: Takeshi Komiya Author-email: i.tkomiya@gmail.com License: BSD Download-URL: http://pypi.python.org/pypi/sphinxcontrib-actdiag Description: This package contains the actdiag Sphinx extension. .. _Sphinx: http://sphinx.pocoo.org/ .. _actdiag: http://blockdiag.com/en/actdiag/ This extension enable you to insert activity diagrams in your Sphinx document. Following code is sample:: .. actdiag:: diagram { A -> B -> C -> D; lane { A; B; } lane { C; D; } } This module needs actdiag_. Platform: any Classifier: Development Status :: 4 - Beta Classifier: Environment :: Console Classifier: Environment :: Web Environment Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3.2 Classifier: Programming Language :: Python :: 3.3 Classifier: Topic :: Documentation Classifier: Topic :: Utilities sphinxcontrib-actdiag-0.6.0/sphinxcontrib_actdiag.egg-info/dependency_links.txt0000644000175000017500000000000112224001723031314 0ustar katsuwokatsuwo00000000000000 sphinxcontrib-actdiag-0.6.0/sphinxcontrib_actdiag.egg-info/top_level.txt0000644000175000017500000000001612224001723027775 0ustar katsuwokatsuwo00000000000000sphinxcontrib sphinxcontrib-actdiag-0.6.0/sphinxcontrib_actdiag.egg-info/not-zip-safe0000644000175000017500000000000111606004647027507 0ustar katsuwokatsuwo00000000000000 sphinxcontrib-actdiag-0.6.0/sphinxcontrib_actdiag.egg-info/requires.txt0000644000175000017500000000004512224001723027645 0ustar katsuwokatsuwo00000000000000actdiag>=0.5.0 Sphinx>=0.6 setuptoolssphinxcontrib-actdiag-0.6.0/sphinxcontrib_actdiag.egg-info/SOURCES.txt0000644000175000017500000000065612224001723027141 0ustar katsuwokatsuwo00000000000000AUTHORS LICENSE MANIFEST.in README.rst setup.cfg setup.py sphinxcontrib/__init__.py sphinxcontrib/actdiag.py sphinxcontrib_actdiag.egg-info/PKG-INFO sphinxcontrib_actdiag.egg-info/SOURCES.txt sphinxcontrib_actdiag.egg-info/dependency_links.txt sphinxcontrib_actdiag.egg-info/namespace_packages.txt sphinxcontrib_actdiag.egg-info/not-zip-safe sphinxcontrib_actdiag.egg-info/requires.txt sphinxcontrib_actdiag.egg-info/top_level.txtsphinxcontrib-actdiag-0.6.0/sphinxcontrib_actdiag.egg-info/namespace_packages.txt0000644000175000017500000000001612224001723031576 0ustar katsuwokatsuwo00000000000000sphinxcontrib sphinxcontrib-actdiag-0.6.0/MANIFEST.in0000644000175000017500000000010111571600560020744 0ustar katsuwokatsuwo00000000000000include AUTHORS include LICENSE include README include CHANGES.* sphinxcontrib-actdiag-0.6.0/README.rst0000644000175000017500000000415612223716543020717 0ustar katsuwokatsuwo00000000000000actdiag extension README ======================== This is a sphinx extension which render block diagrams by using `actdiag `_ . rendered: .. actdiag:: diagram { A -> B -> C -> D; lane { A; B; } lane { C; D; } } source: .. code-block:: text .. actdiag:: diagram { A -> B -> C -> D; lane { A; B; } lane { C; D; } } Setting ======= .. You can see available package at `PyPI `_. You can get archive file at http://bitbucket.org/birkenfeld/sphinx-contrib/ Required components ------------------- * `actdiag `_ . Install ------- .. code-block:: bash > easy_install sphinxcontrib-actdiag Configure Sphinx ---------------- To enable this extension, add ``sphinxcontrib.actdiag`` module to extensions option at :file:`conf.py`. .. code-block:: python import os, sys # Path to the folder where actdiag.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.actdiag')) # Enabled extensions extensions = ['sphinxcontrib.actdiag'] Directive ========= .. describe:: .. actdiag:: [filename] This directive insert a block diagram into the generated document. If filename is specified, sphinx reads external file as source script of blockfile. In another case, actdiag directive takes code block as source script. Examples:: .. actdiag:: foobar.diag .. actdiag:: diagram { // some diagrams are here. } Configuration File Options ========================== .. confval:: actdiag_fontpath This is a path for renderring fonts. You can use truetype font (.ttf) file path. .. confval:: actdiag_antialias If :confval:`actdiag_antialias: is True, actdiag generates images with anti-alias filter. Repository ========== This code is hosted by Bitbucket. http://bitbucket.org/birkenfeld/sphinx-contrib/ sphinxcontrib-actdiag-0.6.0/AUTHORS0000644000175000017500000000004511571600560020265 0ustar katsuwokatsuwo00000000000000Takeshi KOMIYA sphinxcontrib-actdiag-0.6.0/LICENSE0000644000175000017500000000261211571600560020224 0ustar katsuwokatsuwo00000000000000If not otherwise noted, the extensions in this package are licensed under the following license. Copyright (c) 2009 by the contributors (see AUTHORS file). All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.