sphinxcontrib-plantuml-0.5/0000755000175000017500000000000012414205456016105 5ustar yuyayuya00000000000000sphinxcontrib-plantuml-0.5/sphinxcontrib_plantuml.egg-info/0000755000175000017500000000000012414205456024405 5ustar yuyayuya00000000000000sphinxcontrib-plantuml-0.5/sphinxcontrib_plantuml.egg-info/PKG-INFO0000644000175000017500000000573512414205455025513 0ustar yuyayuya00000000000000Metadata-Version: 1.1 Name: sphinxcontrib-plantuml Version: 0.5 Summary: Sphinx "plantuml" extension Home-page: https://bitbucket.org/birkenfeld/sphinx-contrib Author: Yuya Nishihara Author-email: yuya@tcha.org License: BSD Download-URL: https://pypi.python.org/pypi/sphinxcontrib-plantuml Description: PlantUML for Sphinx =================== Usage ----- Once you enable this extension, :: # Add any Sphinx extension module names here, as strings. They can be extensions # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. extensions = ['sphinxcontrib.plantuml'] you may need to specify plantuml command in your conf.py:: plantuml = 'java -jar /path/to/plantuml.jar' Instead, you can install a wrapper script in your PATH:: % cat < /usr/local/bin/plantuml #!/bin/sh -e java -jar /path/to/plantuml.jar "$@" EOT % chmod +x /usr/local/bin/plantuml Then, write PlantUML text under ``.. uml::`` directive:: .. uml:: Alice -> Bob: Hi! Alice <- Bob: How are you? You can specify ``height``, ``width`` or ``scale``:: .. uml:: :scale: 50 % Foo <|-- Bar You can specify a caption:: .. uml:: :caption: Caption with **bold** and *italic* :width: 50mm Foo <|-- Bar For details, please see PlantUML_ documentation. .. _PlantUML: http://plantuml.sourceforge.net/ Configuration ------------- plantuml Path to plantuml executable. (default: 'plantuml') plantuml_output_format Type of output image for HTML renderer. (default: 'png') :png: generate only .png :svg: generate .svg and .png as a fallback plantuml_latex_output_format Type of output image for LaTeX renderer. (default: 'png') :eps: generate .eps (not supported by `pdflatex`) :pdf: generate .eps and convert it to .pdf (requires `epstopdf`) :png: generate .png Because embedded png looks pretty bad, it is recommended to choose `pdf` for `pdflatex` or `eps` for `platex`. plantuml_epstopdf Path to epstopdf executable. (default: 'epstopdf') 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: Topic :: Documentation Classifier: Topic :: Utilities sphinxcontrib-plantuml-0.5/sphinxcontrib_plantuml.egg-info/dependency_links.txt0000644000175000017500000000000112414205455030452 0ustar yuyayuya00000000000000 sphinxcontrib-plantuml-0.5/sphinxcontrib_plantuml.egg-info/SOURCES.txt0000644000175000017500000000064612414205456026277 0ustar yuyayuya00000000000000MANIFEST.in README.rst setup.cfg setup.py sphinxcontrib/__init__.py sphinxcontrib/plantuml.py sphinxcontrib_plantuml.egg-info/PKG-INFO sphinxcontrib_plantuml.egg-info/SOURCES.txt sphinxcontrib_plantuml.egg-info/dependency_links.txt sphinxcontrib_plantuml.egg-info/namespace_packages.txt sphinxcontrib_plantuml.egg-info/not-zip-safe sphinxcontrib_plantuml.egg-info/requires.txt sphinxcontrib_plantuml.egg-info/top_level.txtsphinxcontrib-plantuml-0.5/sphinxcontrib_plantuml.egg-info/requires.txt0000644000175000017500000000001412414205455026777 0ustar yuyayuya00000000000000Sphinx>=1.0 sphinxcontrib-plantuml-0.5/sphinxcontrib_plantuml.egg-info/not-zip-safe0000644000175000017500000000000111543361427026636 0ustar yuyayuya00000000000000 sphinxcontrib-plantuml-0.5/sphinxcontrib_plantuml.egg-info/namespace_packages.txt0000644000175000017500000000001612414205455030734 0ustar yuyayuya00000000000000sphinxcontrib sphinxcontrib-plantuml-0.5/sphinxcontrib_plantuml.egg-info/top_level.txt0000644000175000017500000000001612414205455027133 0ustar yuyayuya00000000000000sphinxcontrib sphinxcontrib-plantuml-0.5/PKG-INFO0000644000175000017500000000573512414205456017214 0ustar yuyayuya00000000000000Metadata-Version: 1.1 Name: sphinxcontrib-plantuml Version: 0.5 Summary: Sphinx "plantuml" extension Home-page: https://bitbucket.org/birkenfeld/sphinx-contrib Author: Yuya Nishihara Author-email: yuya@tcha.org License: BSD Download-URL: https://pypi.python.org/pypi/sphinxcontrib-plantuml Description: PlantUML for Sphinx =================== Usage ----- Once you enable this extension, :: # Add any Sphinx extension module names here, as strings. They can be extensions # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. extensions = ['sphinxcontrib.plantuml'] you may need to specify plantuml command in your conf.py:: plantuml = 'java -jar /path/to/plantuml.jar' Instead, you can install a wrapper script in your PATH:: % cat < /usr/local/bin/plantuml #!/bin/sh -e java -jar /path/to/plantuml.jar "$@" EOT % chmod +x /usr/local/bin/plantuml Then, write PlantUML text under ``.. uml::`` directive:: .. uml:: Alice -> Bob: Hi! Alice <- Bob: How are you? You can specify ``height``, ``width`` or ``scale``:: .. uml:: :scale: 50 % Foo <|-- Bar You can specify a caption:: .. uml:: :caption: Caption with **bold** and *italic* :width: 50mm Foo <|-- Bar For details, please see PlantUML_ documentation. .. _PlantUML: http://plantuml.sourceforge.net/ Configuration ------------- plantuml Path to plantuml executable. (default: 'plantuml') plantuml_output_format Type of output image for HTML renderer. (default: 'png') :png: generate only .png :svg: generate .svg and .png as a fallback plantuml_latex_output_format Type of output image for LaTeX renderer. (default: 'png') :eps: generate .eps (not supported by `pdflatex`) :pdf: generate .eps and convert it to .pdf (requires `epstopdf`) :png: generate .png Because embedded png looks pretty bad, it is recommended to choose `pdf` for `pdflatex` or `eps` for `platex`. plantuml_epstopdf Path to epstopdf executable. (default: 'epstopdf') 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: Topic :: Documentation Classifier: Topic :: Utilities sphinxcontrib-plantuml-0.5/MANIFEST.in0000644000175000017500000000006111470775032017643 0ustar yuyayuya00000000000000include README include LICENSE include CHANGES.* sphinxcontrib-plantuml-0.5/README.rst0000644000175000017500000000332312414174335017576 0ustar yuyayuya00000000000000PlantUML for Sphinx =================== Usage ----- Once you enable this extension, :: # Add any Sphinx extension module names here, as strings. They can be extensions # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. extensions = ['sphinxcontrib.plantuml'] you may need to specify plantuml command in your conf.py:: plantuml = 'java -jar /path/to/plantuml.jar' Instead, you can install a wrapper script in your PATH:: % cat < /usr/local/bin/plantuml #!/bin/sh -e java -jar /path/to/plantuml.jar "$@" EOT % chmod +x /usr/local/bin/plantuml Then, write PlantUML text under ``.. uml::`` directive:: .. uml:: Alice -> Bob: Hi! Alice <- Bob: How are you? You can specify ``height``, ``width`` or ``scale``:: .. uml:: :scale: 50 % Foo <|-- Bar You can specify a caption:: .. uml:: :caption: Caption with **bold** and *italic* :width: 50mm Foo <|-- Bar For details, please see PlantUML_ documentation. .. _PlantUML: http://plantuml.sourceforge.net/ Configuration ------------- plantuml Path to plantuml executable. (default: 'plantuml') plantuml_output_format Type of output image for HTML renderer. (default: 'png') :png: generate only .png :svg: generate .svg and .png as a fallback plantuml_latex_output_format Type of output image for LaTeX renderer. (default: 'png') :eps: generate .eps (not supported by `pdflatex`) :pdf: generate .eps and convert it to .pdf (requires `epstopdf`) :png: generate .png Because embedded png looks pretty bad, it is recommended to choose `pdf` for `pdflatex` or `eps` for `platex`. plantuml_epstopdf Path to epstopdf executable. (default: 'epstopdf') sphinxcontrib-plantuml-0.5/setup.py0000644000175000017500000000206212414204165017613 0ustar yuyayuya00000000000000# -*- coding: utf-8 -*- from setuptools import setup, find_packages long_desc = open('README.rst').read() requires = ['Sphinx>=1.0'] setup( name='sphinxcontrib-plantuml', version='0.5', url='https://bitbucket.org/birkenfeld/sphinx-contrib', download_url='https://pypi.python.org/pypi/sphinxcontrib-plantuml', license='BSD', author='Yuya Nishihara', author_email='yuya@tcha.org', description='Sphinx "plantuml" 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'], use_2to3=True, ) sphinxcontrib-plantuml-0.5/sphinxcontrib/0000755000175000017500000000000012414205456020777 5ustar yuyayuya00000000000000sphinxcontrib-plantuml-0.5/sphinxcontrib/plantuml.py0000644000175000017500000002445112414204677023217 0ustar yuyayuya00000000000000# -*- coding: utf-8 -*- """ sphinxcontrib.plantuml ~~~~~~~~~~~~~~~~~~~~~~ Embed PlantUML diagrams on your documentation. :copyright: Copyright 2010 by Yuya Nishihara . :license: BSD, see LICENSE for details. """ import errno, os, re, shlex, subprocess try: from hashlib import sha1 except ImportError: # Python<2.5 from sha import sha as sha1 from docutils import nodes from docutils.parsers.rst import directives from sphinx.errors import SphinxError from sphinx.util.compat import Directive from sphinx.util.osutil import ensuredir, ENOENT try: from PIL import Image except ImportError: Image = None class PlantUmlError(SphinxError): pass class plantuml(nodes.General, nodes.Element): pass class UmlDirective(Directive): """Directive to insert PlantUML markup Example:: .. uml:: :alt: Alice and Bob Alice -> Bob: Hello Alice <- Bob: Hi """ has_content = True option_spec = {'alt': directives.unchanged, 'caption': directives.unchanged, 'height': directives.length_or_unitless, 'width': directives.length_or_percentage_or_unitless, 'scale': directives.percentage} def run(self): node = plantuml(self.block_text, **self.options) node['uml'] = '\n'.join(self.content) # if a caption is defined, insert a 'figure' with this node and # the caption if 'caption' in self.options: import docutils.statemachine cnode = nodes.Element() # anonymous container for parsing sl = docutils.statemachine.StringList([self.options['caption']], source='') self.state.nested_parse(sl, self.content_offset, cnode) caption = nodes.caption(self.options['caption'], '', *cnode) fig = nodes.figure('', node) fig += caption node = fig return [node] def generate_name(self, node, fileformat): key = sha1(node['uml'].encode('utf-8')).hexdigest() fname = 'plantuml-%s.%s' % (key, fileformat) imgpath = getattr(self.builder, 'imgpath', None) if imgpath: return ('/'.join((self.builder.imgpath, fname)), os.path.join(self.builder.outdir, '_images', fname)) else: return fname, os.path.join(self.builder.outdir, fname) _ARGS_BY_FILEFORMAT = { 'eps': '-teps'.split(), 'png': (), 'svg': '-tsvg'.split(), } def generate_plantuml_args(self, fileformat): if isinstance(self.builder.config.plantuml, basestring): args = shlex.split(self.builder.config.plantuml) else: args = list(self.builder.config.plantuml) args.extend('-pipe -charset utf-8'.split()) args.extend(_ARGS_BY_FILEFORMAT[fileformat]) return args def render_plantuml(self, node, fileformat): refname, outfname = generate_name(self, node, fileformat) if os.path.exists(outfname): return refname, outfname # don't regenerate ensuredir(os.path.dirname(outfname)) f = open(outfname, 'wb') try: try: p = subprocess.Popen(generate_plantuml_args(self, fileformat), stdout=f, stdin=subprocess.PIPE, stderr=subprocess.PIPE) except OSError, err: if err.errno != ENOENT: raise raise PlantUmlError('plantuml command %r cannot be run' % self.builder.config.plantuml) serr = p.communicate(node['uml'].encode('utf-8'))[1] if p.returncode != 0: raise PlantUmlError('error while running plantuml\n\n' + serr) return refname, outfname finally: f.close() def _get_png_tag(self, fnames, node): refname, _outfname = fnames['png'] alt = node.get('alt', node['uml']) # mimic StandaloneHTMLBuilder.post_process_images(). maybe we should # process images prior to html_vist. scale_keys = ('scale', 'width', 'height') if all(key not in node for key in scale_keys) or Image is None: return ('%s\n' % (self.encode(refname), self.encode(alt))) # Get sizes from the rendered image (defaults) im = Image.open(_outfname) im.load() (fw, fh) = im.size # Regex to get value and units vu = re.compile(r"(?P\d+)\s*(?P[a-zA-Z%]+)?") # Width if 'width' in node: m = vu.match(node['width']) if not m: raise PlantUmlError('Invalid width') else: m = m.groupdict() w = int(m['value']) wu = m['units'] if m['units'] else 'px' else: w = fw wu = 'px' # Height if 'height' in node: m = vu.match(node['height']) if not m: raise PlantUmlError('Invalid height') else: m = m.groupdict() h = int(m['value']) hu = m['units'] if m['units'] else 'px' else: h = fh hu = 'px' # Scale if 'scale' not in node: node['scale'] = 100 return ('%s' '\n' % (self.encode(refname), self.encode(refname), self.encode(alt), self.encode(w * node['scale'] / 100), self.encode(wu), self.encode(h * node['scale'] / 100), self.encode(hu))) def _get_svg_style(fname): f = open(fname) try: for l in f: m = re.search(r']+)', l) if m: attrs = m.group(1) break else: return finally: f.close() m = re.search(r'\bstyle=[\'"]([^\'"]+)', attrs) if not m: return return m.group(1) def _get_svg_tag(self, fnames, node): refname, outfname = fnames['svg'] return '\n'.join([ # copy width/height style from tag, so that area # has enough space. '' % ( self.encode(refname), _get_svg_style(outfname) or ''), _get_png_tag(self, fnames, node), '']) _KNOWN_HTML_FORMATS = { 'png': (('png',), _get_png_tag), 'svg': (('png', 'svg'), _get_svg_tag), } def html_visit_plantuml(self, node): try: format = self.builder.config.plantuml_output_format try: fileformats, gettag = _KNOWN_HTML_FORMATS[format] except KeyError: raise PlantUmlError( 'plantuml_output_format must be one of %s, but is %r' % (', '.join(map(repr, _KNOWN_HTML_FORMATS)), format)) # fnames: {fileformat: (refname, outfname), ...} fnames = dict((e, render_plantuml(self, node, e)) for e in fileformats) except PlantUmlError, err: self.builder.warn(str(err)) raise nodes.SkipNode self.body.append(self.starttag(node, 'p', CLASS='plantuml')) self.body.append(gettag(self, fnames, node)) self.body.append('

\n') raise nodes.SkipNode def _convert_eps_to_pdf(self, refname, fname): if isinstance(self.builder.config.plantuml_epstopdf, basestring): args = shlex.split(self.builder.config.plantuml_epstopdf) else: args = list(self.builder.config.plantuml_epstopdf) args.append(fname) try: try: p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) except OSError, err: # workaround for missing shebang of epstopdf script if err.errno != getattr(errno, 'ENOEXEC', 0): raise p = subprocess.Popen(['bash'] + args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) except OSError, err: if err.errno != ENOENT: raise raise PlantUmlError('epstopdf command %r cannot be run' % self.builder.config.plantuml_epstopdf) serr = p.communicate()[1] if p.returncode != 0: raise PlantUmlError('error while running epstopdf\n\n' + serr) return refname[:-4] + '.pdf', fname[:-4] + '.pdf' _KNOWN_LATEX_FORMATS = { 'eps': ('eps', lambda self, refname, fname: (refname, fname)), 'pdf': ('eps', _convert_eps_to_pdf), 'png': ('png', lambda self, refname, fname: (refname, fname)), } def latex_visit_plantuml(self, node): try: format = self.builder.config.plantuml_latex_output_format try: fileformat, postproc = _KNOWN_LATEX_FORMATS[format] except KeyError: raise PlantUmlError( 'plantuml_latex_output_format must be one of %s, but is %r' % (', '.join(map(repr, _KNOWN_LATEX_FORMATS)), format)) refname, outfname = render_plantuml(self, node, fileformat) refname, outfname = postproc(self, refname, outfname) except PlantUmlError, err: self.builder.warn(str(err)) raise nodes.SkipNode # put node representing rendered image img_node = nodes.image(uri=refname, **node.attributes) img_node.delattr('uml') if not img_node.hasattr('alt'): img_node['alt'] = node['uml'] node.append(img_node) def latex_depart_plantuml(self, node): pass def pdf_visit_plantuml(self, node): try: refname, outfname = render_plantuml(self, node, 'eps') refname, outfname = _convert_eps_to_pdf(self, refname, outfname) except PlantUmlError, err: self.builder.warn(str(err)) raise nodes.SkipNode rep = nodes.image(uri=outfname, alt=node.get('alt', node['uml'])) node.parent.replace(node, rep) def setup(app): app.add_node(plantuml, html=(html_visit_plantuml, None), latex=(latex_visit_plantuml, latex_depart_plantuml)) app.add_directive('uml', UmlDirective) app.add_config_value('plantuml', 'plantuml', 'html') app.add_config_value('plantuml_output_format', 'png', 'html') app.add_config_value('plantuml_epstopdf', 'epstopdf', '') app.add_config_value('plantuml_latex_output_format', 'png', '') # imitate what app.add_node() does if 'rst2pdf.pdfbuilder' in app.config.extensions: from rst2pdf.pdfbuilder import PDFTranslator as translator setattr(translator, 'visit_' + plantuml.__name__, pdf_visit_plantuml) �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������sphinxcontrib-plantuml-0.5/sphinxcontrib/__init__.py������������������������������������������������0000644�0001750�0001750�00000000556�11470775032�023121� 0����������������������������������������������������������������������������������������������������ustar �yuya����������������������������yuya����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������# -*- 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-plantuml-0.5/setup.cfg����������������������������������������������������������������0000644�0001750�0001750�00000000141�12414205456�017722� 0����������������������������������������������������������������������������������������������������ustar �yuya����������������������������yuya����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������[egg_info] tag_build = tag_date = 0 tag_svn_revision = 0 [aliases] release = egg_info -RDb '' �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������