regebro / hovercraft

Make dynamic impressive presentations from text files!
https://hovercraft.readthedocs.org
MIT License
1.48k stars 209 forks source link

Update main function to simplify in-process execution of hovercraft #179

Closed tonysyu closed 5 years ago

tonysyu commented 5 years ago

This alters hovercraft's main function to support input arguments passed to the command-line parser. The main use case for this is to simplify the creation of custom directives that will be recognized by hovercraft. Custom directives need to be registered in the same process that starts up the hovercraft server, so using hovercraft through the cli entry point makes this difficult.

Allowing users to pass arguments to the main function simplifies use of custom directives. For example

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

import hovercraft

class HelloWorld(Directive):
    def run(self):
        para = nodes.paragraph(text='Hello World')
        return [para]

directives.register_directive('hello-world', HelloWorld)

if __name__ == "__main__":
    cmd = ['--skip-help', '--template', 'templates/impress1.0.0', 'slides.rst']
    hovercraft.main(cmd)

Marking as a work-in-progress for now, since I'd like to add a bit of documentation if this goes forward.

regebro commented 5 years ago

That seems reasonable.

tonysyu commented 5 years ago

@regebro: Added documentation and removed WIP from title.

regebro commented 5 years ago

Cool. I didn't actually know there was useful custom directives out there.