Exemplo n.º 1
0
def serve(config_file='moosedocs.yml',
          host='127.0.0.1',
          port='8000',
          num_threads=multiprocessing.cpu_count()):
    """
    Create live server
    """

    # Location of serve site
    tempdir = os.path.abspath(
        os.path.join(os.getenv('HOME'), '.local', 'share', 'moose', 'site'))

    # Clean the "temp" directory (if desired)
    if os.path.exists(tempdir):
        log.info('Cleaning build directory: {}'.format(tempdir))
        shutil.rmtree(tempdir)

    # Create the "temp" directory
    if not os.path.exists(tempdir):
        os.makedirs(tempdir)

    # Perform the initial build
    log.info("Building documentation...")

    # Wrapper for building complete website
    def build_complete():
        return build.build_site(config_file=config_file,
                                site_dir=tempdir,
                                num_threads=num_threads)

    config, parser, builder = build_complete()

    # Start the live server
    server = livereload.Server()

    # Watch markdown files
    for page in builder:
        server.watch(page.source(), page.build)

    # Watch support directories
    server.watch(os.path.join(os.getcwd(), 'media'), builder.copyFiles)
    server.watch(os.path.join(os.getcwd(), 'css'), builder.copyFiles)
    server.watch(os.path.join(os.getcwd(), 'js'), builder.copyFiles)
    server.watch(os.path.join(os.getcwd(), 'fonts'), builder.copyFiles)

    # Watch the files and directories that require complete rebuild
    moose_extension = MooseDocs.get_moose_markdown_extension(parser)
    if moose_extension:
        server.watch(
            os.path.join(os.getcwd(), moose_extension.getConfig('executable')),
            build_complete)
    server.watch(config['navigation'], build_complete)
    server.watch(config_file, build_complete)
    server.watch('templates')

    # Start the server
    server.serve(root=config['site_dir'],
                 host=host,
                 port=port,
                 restart_delay=0)
Exemplo n.º 2
0
    def __init__(self,
                 md_file=None,
                 syntax=None,
                 parser=None,
                 navigation=None,
                 template=None,
                 template_args=dict(),
                 **kwargs):
        super(MooseDocsMarkdownNode, self).__init__(**kwargs)

        if (not md_file) or (not os.path.exists(md_file)):
            raise Exception(
                'The supplied markdown file must exists: {}'.format(md_file))

        # Extract the MooseLinkDatabase for creating source and doxygen links
        ext = MooseDocs.get_moose_markdown_extension(parser)
        self.__syntax = ext.syntax if ext else dict()

        self.__parser = parser
        self.__navigation = navigation
        self.__template = template
        self.__template_args = template_args
        self.__html = None
        self.__md_file = md_file