Example #1
0
    def run(self):
        import docutils
        from docutils.writers import html4css1

        from nagare.doc import code_block

        class Writer(html4css1.Writer):
            def interpolation_dict(self):
                d = html4css1.Writer.interpolation_dict(self)
                d["stylesheet"] += '\n<link rel="stylesheet" href="print.css" type="text/css" media="print" />'
                d["body_prefix"] = '<img id="logo" src="img/logo.png">' + d["body_prefix"]
                return d

        if not self.args:
            raise distutils.errors.DistutilsOptionError("No file to convert")

        code_block.register_role(self.trac)
        code_block.register_directive()

        docPath = os.path.abspath(self.path)
        print "Documentation directory:", docPath

        for filename in self.args:
            if not os.path.isfile(filename):
                raise distutils.errors.DistutilsOptionError("The path '%s' is not a file" % filename)

            print "Processing:", filename

            out_filename = os.path.splitext(os.path.basename(filename))[0] + ".html"
            out_filename = os.path.join(docPath, out_filename)

            docutils.core.publish_file(
                source_path=filename, destination_path=out_filename, writer=Writer(), settings_overrides=settings
            )
Example #2
0
    def run(self):
        if self.dry_run:
            return

        import docutils
        from nagare.doc import code_block
        from rstdoc.rstlib.astdoc import documentPackages, documentFile

        code_block.register_directive()

        docPath = os.path.abspath(self.path)
        if self.no_status:
            output = None
        else:
            output = sys.stderr

        if not self.args:
            docDirs = sorted(find_packages())

            documentPackages(
                docPath=docPath,
                packages=docDirs,
                writer_name="html",
                output=output,
                title=self.title,
                settings=settings,
            )
        else:
            print "Documentation directory:", docPath

            for filename in self.args:
                if not os.path.isfile(filename):
                    raise distutils.errors.DistutilsOptionError("The path '%s' is not a file" % filename)

                print "Processing:", filename

                tree = documentFile(filename).docTree()

                out_filename = os.path.splitext(filename.replace(os.sep, "-"))[0] + ".html"
                out_filename = os.path.join(docPath, out_filename)

                with open(out_filename, "w") as f:
                    f.write(docutils.core.publish_from_doctree(tree, writer_name="html", settings_overrides=settings))