Пример #1
0
def generate(config_file='moosedocs.yml', pages='pages.yml', stubs=False, pages_stubs=False, **kwargs):
  """
  Generates MOOSE system and object markdown files from the source code.

  Args:
    config_file[str]: (Default: 'moosedocs.yml') The MooseMkDocs project configuration file.
  """

  # Configuration file
  if not os.path.exists(config_file):
    raise IOError("The supplied configuration file was not found: {}".format(config_file))

  # Read the configuration
  config = MooseDocs.yaml_load(config_file)
  config = config['markdown_extensions'][-1]['MooseDocs.extensions.MooseMarkdown']

  # Run the executable
  exe = config['executable']
  if not os.path.exists(exe):
    log.error('The executable does not exist: {}'.format(exe))
  else:
    log.debug("Executing {} to extract syntax.".format(exe))
    raw = utils.runExe(exe, '--yaml')
    yaml = utils.MooseYaml(raw)

  # Populate the syntax
  for key, value in config['locations'].iteritems():
    if 'hide' in value:
      value['hide'] += config.get('hide', [])
    else:
      value['hide'] = config.get('hide', [])
    syntax = MooseDocs.MooseApplicationSyntax(yaml, name=key, stubs=stubs,  pages_stubs=pages_stubs, pages=pages, **value)
    log.info("Checking documentation for '{}'.".format(key))
    syntax.check()
Пример #2
0
def generate_html(input, config_file):
    """
  Generates html from Moose flavored markdown.

  Args:
    input[str]: The *.md file to convert.
    config_file[str]: The *.yml configuration file.
  """
    # Load the config to extract MooseMarkdown settings
    #TODO: Make this more robust
    config = MooseDocs.yaml_load(config_file)
    md_config = config['markdown_extensions'][-1][
        'MooseDocs.extensions.MooseMarkdown']
    md_config['dot_ext'] = 'svg'

    # Convert markdown
    with open(input, 'r') as fid:
        md = fid.read()

    # Extract Jinja2 blocks
    settings = dict()

    def sub(match):
        settings[match.group(1).strip()] = eval(match.group(2))
        return ''

    md = re.sub(r'@\+\s*set\s+(.*?)=(.*?)\+@', sub, md)

    moose = MooseDocs.extensions.MooseMarkdown(**md_config)
    parser = markdown.Markdown(extensions=[
        moose, 'markdown_include.include', 'admonition', 'mdx_math', 'toc',
        'extra'
    ])
    return parser.convert(md), settings
Пример #3
0
def generate_html(input, config_file):
  """
  Generates html from Moose flavored markdown.

  Args:
    input[str]: The *.md file to convert.
    config_file[str]: The *.yml configuration file.
  """
  # Load the config to extract MooseMarkdown settings
  #TODO: Make this more robust
  config = MooseDocs.yaml_load(config_file)
  md_config = config['markdown_extensions'][-1]['MooseDocs.extensions.MooseMarkdown']
  md_config['dot_ext'] = 'svg'

  # Convert markdown
  with open(input, 'r') as fid:
    md = fid.read()

  # Extract Jinja2 blocks
  settings = dict()
  def sub(match):
    settings[match.group(1).strip()] = eval(match.group(2))
    return ''
  md = re.sub(r'@\+\s*set\s+(.*?)=(.*?)\+@', sub, md)

  moose = MooseDocs.extensions.MooseMarkdown(**md_config)
  parser = markdown.Markdown(extensions=[moose, 'markdown_include.include', 'admonition', 'mdx_math', 'toc', 'extra'])
  return parser.convert(md), settings
Пример #4
0
    def __init__(self, markdown_instance=None, **kwargs):
        MooseCommonExtension.__init__(self, **kwargs)
        Pattern.__init__(self, self.RE, markdown_instance)

        # Load the yaml data containing package information
        self.package = MooseDocs.yaml_load("packages.yml")

        # The default settings
        self._settings = {'arch': None, 'return': None}
Пример #5
0
def build(config_file='mkdocs.yml', pages='pages.yml', **kwargs):
    """
    Build the documentation using mkdocs build command.

    Args:
        config_file[str]: (Default: 'mkdocs.yml') The configure file to pass to mkdocs.
    """
    pages = MooseDocs.yaml_load(pages)
    config = mkdocs.config.load_config(config_file, pages=pages, **kwargs)
    mkdocs.commands.build.build(config)
Пример #6
0
    def __init__(self, markdown_instance=None, **kwargs):
        MooseMarkdownCommon.__init__(self, **kwargs)
        Preprocessor.__init__(self, markdown_instance)

        # Import the directly defined globals
        self._globals = kwargs.pop('globals', dict())

        # Add the defined globals from the supplied file(s)
        for filename in kwargs.pop('import'):
            self._globals.update(MooseDocs.yaml_load(os.path.join(MooseDocs.ROOT_DIR, filename)))
Пример #7
0
  def __init__(self, markdown_instance=None, **kwargs):
    MooseCommonExtension.__init__(self, **kwargs)
    Pattern.__init__(self, self.RE, markdown_instance)

    # Load the yaml data containing package information
    self.package = MooseDocs.yaml_load("packages.yml")

    # The default settings
    self._settings = {'arch' : None,
             'return' : None}
Пример #8
0
def build(config_file='moosedocs.yml', disable_threads=False, **kwargs):
    """
  The main build command.
  """

    # Load the YAML configuration file
    config = MooseDocs.yaml_load(config_file)
    config.update(kwargs)

    # Set the default arguments
    config.setdefault('docs_dir', os.getcwd())
    config.setdefault('site_dir', os.path.join('..', 'site'))
    config.setdefault('pages', 'pages.yml')
    config.setdefault('template', 'materialize.html')
    config.setdefault('template_arguments', dict())
    config.setdefault('extra_pages', [])

    # Load the site map
    sitemap = MooseDocs.yaml_load(config['pages'])

    # Create the markdown parser
    extensions, extension_configs = get_markdown_extensions(config)
    parser = markdown.Markdown(extensions=extensions,
                               extension_configs=extension_configs)

    # Create object for storing pages to be generated
    builder = Builder(sitemap, parser, config['site_dir'], config['template'],
                      **config['template_arguments'])

    # Build "extra" pages (i.e., the home page)
    if 'extra_pages' in config:
        for extra in config['extra_pages']:
            for name, kwargs in extra.iteritems():
                kwargs.setdefault('template_arguments', dict())
                builder.add(kwargs.pop('filename'),
                            kwargs['template'],
                            name=name,
                            **kwargs['template_arguments'])

    # Create the html
    builder.build(use_threads=not disable_threads)
    return config, parser, builder
Пример #9
0
    def __init__(self, content=None, **kwargs):
        super(WebsiteBuilder, self).__init__(**kwargs)
        if (content is None) or (not os.path.isfile(content)):
            LOG.info("Using default content directory configuration "
                     "(i.e., --content does not include a valid filename).")
            content = dict(default=dict(base=os.path.join(os.getcwd(), 'content'),
                                        include=[os.path.join(os.getcwd(), 'content', '*')]))
        else:
            content = MooseDocs.yaml_load(content)

        self._content = content
Пример #10
0
    def _configure(self):
        """
        Build the configuration options for included sub-directories.
        """

        # Read the moosedocs yml configuration file
        yml = MooseDocs.yaml_load(self._config_file)

        # Default settings
        defaults = yml.get('defaults', dict())
        defaults.setdefault('details', os.path.join(os.getcwd(), 'details'))
        defaults.setdefault('source', None)
        defaults.setdefault('include', None)
        defaults.setdefault('install', os.path.join(os.getcwd(), 'content'))
        defaults.setdefault('repo', None)
        defaults.setdefault('doxygen', None)
        defaults.setdefault('hide', list())
        defaults.setdefault('links', dict())

        def update_config(config):
            """
            Helper for updating/creating local configuration dict.
            """

            # Apply defaults
            for key, value in defaults.iteritems():
                config.setdefault(key, value)

            # Append the hide data
            config['hide'] = set(config.get('hide', list()) + list(defaults['hide']))

            return config

        # Extract executable
        if 'app' not in yml:
            self._exe = utils.find_moose_executable(self._root)
        else:
            app = yml['app']
            if os.path.isdir(app):
                self._exe = utils.find_moose_executable(app)
            else:
                self._exe = app

        # Error if the executable is not found
        if not os.path.exists(self._exe):
            print 'Unable to locate a working executable: {}'.format(self._exe)
            os.exit()

        configs = []
        if 'include' in yml:
            for key, value in yml['include'].iteritems():
                log.debug('Configuring settings for including {}'.format(key))
                configs.append(update_config(value))
        return configs
Пример #11
0
    def __init__(self, markdown_instance=None, **kwargs):
        MooseMarkdownCommon.__init__(self, **kwargs)
        Preprocessor.__init__(self, markdown_instance)

        # Import the directly defined globals
        self._globals = kwargs.pop('globals', dict())

        # Add the defined globals from the supplied file(s)
        for filename in kwargs.pop('import'):
            self._globals.update(
                MooseDocs.yaml_load(os.path.join(MooseDocs.ROOT_DIR,
                                                 filename)))
Пример #12
0
    def arguments(self, template_args, text): #pylint: disable=no-self-use
        """
        Method for modifying the template arguments to be applied to the jinja2 templates engine.

        Args:
            template_args[dict]: Template arguments to be applied to jinja2 template.
            text[str]: Convert markdown to be applied via the 'content' template argument.
        """
        template_args['content'] = text

        if 'navigation' in template_args:
            template_args['navigation'] = \
                MooseDocs.yaml_load(MooseDocs.abspath(template_args['navigation']))
Пример #13
0
  def setUpClass(cls):
    """
    Create the markdown parser using the 'moosedocs.yml' configuration file.
    """

    cwd = os.getcwd()
    os.chdir(os.path.join(MooseDocs.MOOSE_DIR, 'docs'))

    config = MooseDocs.yaml_load('moosedocs.yml')

    extensions, extension_configs = MooseDocs.commands.get_markdown_extensions(config)
    cls.parser = markdown.Markdown(extensions=extensions, extension_configs=extension_configs)
    os.chdir(cwd)
Пример #14
0
    def arguments(self, template_args, text):  #pylint: disable=no-self-use
        """
        Method for modifying the template arguments to be applied to the jinja2 templates engine.

        Args:
            template_args[dict]: Template arguments to be applied to jinja2 template.
            text[str]: Convert markdown to be applied via the 'content' template argument.
        """
        template_args['content'] = text

        if 'navigation' in template_args:
            template_args['navigation'] = \
                MooseDocs.yaml_load(MooseDocs.abspath(template_args['navigation']))
Пример #15
0
def build(config_file='mkdocs.yml', pages='pages.yml', **kwargs):
    """
    Build the documentation using mkdocs build command.

    Args:
        config_file[str]: (Default: 'mkdocs.yml') The configure file to pass to mkdocs.
    """
    pages = MooseDocs.yaml_load(pages)
    config = mkdocs.config.load_config(config_file, pages=pages, **kwargs)
    update_extra()
    mkdocs.commands.build.build(config)
    mkdocs.utils.copy_media_files(config['docs_dir'], config['site_dir'])
    return config
Пример #16
0
    def setUpClass(cls):
        """
    Create the markdown parser using the 'moosedocs.yml' configuration file.
    """

        cwd = os.getcwd()
        os.chdir(os.path.join(MooseDocs.MOOSE_DIR, "docs"))

        config = MooseDocs.yaml_load("moosedocs.yml")

        extensions, extension_configs = MooseDocs.commands.get_markdown_extensions(config)
        cls.parser = markdown.Markdown(extensions=extensions, extension_configs=extension_configs)
        os.chdir(cwd)
Пример #17
0
def build(config_file='moosedocs.yml', disable_threads=False, **kwargs):
  """
  The main build command.
  """

  # Load the YAML configuration file
  config = MooseDocs.yaml_load(config_file)
  config.update(kwargs)

  # Set the default arguments
  config.setdefault('docs_dir', os.getcwd())
  config.setdefault('site_dir', os.path.join('..', 'site'))
  config.setdefault('pages', 'pages.yml')
  config.setdefault('template', 'materialize.html')
  config.setdefault('template_arguments', dict())
  config.setdefault('extra_pages', [])

  # Load the site map
  sitemap = MooseDocs.yaml_load(config['pages'])

  # Create the markdown parser
  extensions, extension_configs = get_markdown_extensions(config)
  parser = markdown.Markdown(extensions=extensions, extension_configs=extension_configs)

  # Create object for storing pages to be generated
  builder = Builder(sitemap, parser, config['site_dir'], config['template'], **config['template_arguments'])

  # Build "extra" pages (i.e., the home page)
  if 'extra_pages' in config:
    for extra in config['extra_pages']:
      for name, kwargs in extra.iteritems():
        kwargs.setdefault('template_arguments', dict())
        builder.add(kwargs.pop('filename'), kwargs['template'], name=name, **kwargs['template_arguments'])

  # Create the html
  builder.build(use_threads=not disable_threads)
  return config, parser, builder
Пример #18
0
    def _configure(self):
        """
        Build the configuration options for included sub-directories.
        """

        # Read the moosedocs yml configuration file
        yml = MooseDocs.yaml_load(self._config_file)

        # Default settings
        defaults = yml.get('defaults', dict())
        defaults.setdefault('details', os.path.join(os.getcwd(), 'details'))
        defaults.setdefault('source', None)
        defaults.setdefault('install', os.path.join(os.getcwd(), 'content'))
        defaults.setdefault('repo', None)
        defaults.setdefault('doxygen', None)
        defaults.setdefault('hide', list())
        defaults.setdefault('links', dict())

        def update_config(config):
            """
            Helper for updating/creating local configuration dict.
            """

            # Apply defaults
            for key, value in defaults.iteritems():
                config.setdefault(key, value)

            # Append the hide data
            config['hide'] = set(config.get('hide', list()) + list(defaults['hide']))

            return config

        # Extract executable
        if 'app' not in yml:
            self._exe = utils.find_moose_executable(self._root)
        else:
            app = yml['app']
            if os.path.isdir(app):
                self._exe = utils.find_moose_executable(app)
            else:
                self._exe = app

        configs = []
        if 'include' in yml:
            for key, value in yml['include'].iteritems():
                log.debug('Configuring settings for including {}'.format(key))
                configs.append(update_config(value))
        return configs
Пример #19
0
    def testContentFile(self):
        config = MooseDocs.yaml_load(os.path.join(MooseDocs.ROOT_DIR, 'docs', 'content.yml'))
        root = common.moose_docs_file_tree(config)

        node = self.finder(root, 'media/gitlab-logo.png')[0]
        self.assertEqual(node.filename, os.path.join(MooseDocs.ROOT_DIR, 'docs', 'content', 'media',
                                                     'gitlab-logo.png'))

        node0 = MooseMarkdown.find(root, 'utilities/moose_docs/index.md')[0]
        self.assertIsNotNone(node0)

        node1 = MooseMarkdown.find(root, 'utilities/moose_docs/moose_markdown/index.md')
        self.assertIsNotNone(node1)

        node2 = MooseMarkdown.find(root,
                                   'utilities/moose_docs/moose_markdown/extensions/include.md')
        self.assertIsNotNone(node2)
Пример #20
0
    def testContentFile(self):
        config = MooseDocs.yaml_load(os.path.join(MooseDocs.ROOT_DIR, 'docs', 'content.yml'))
        root = common.moose_docs_file_tree(config)

        node = self.finder(root, 'media/gitlab-logo.png')[0]
        self.assertEqual(node.filename, os.path.join(MooseDocs.ROOT_DIR, 'docs', 'content', 'media',
                                                     'gitlab-logo.png'))

        node0 = MooseMarkdown.find(root, 'utilities/moose_docs/index.md')[0]
        self.assertIsNotNone(node0)

        node1 = MooseMarkdown.find(root, 'utilities/moose_docs/moose_markdown/index.md')
        self.assertIsNotNone(node1)

        node2 = MooseMarkdown.find(root,
                                   'utilities/moose_docs/moose_markdown/extensions/include.md')
        self.assertIsNotNone(node2)
Пример #21
0
def serve(config_file='mkdocs.yml',
          strict=None,
          livereload='dirtyreload',
          clean=True,
          pages='pages.yml',
          **kwargs):
    """
    Mimics mkdocs serve command.
    """

    # 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 clean and 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)

    # Read the pages file
    pages = MooseDocs.yaml_load(pages)

    def builder(**kwargs):
        dirty = kwargs.pop('dirty', livereload == 'dirtyreload')
        live_server = livereload in ['dirtyreload', 'livereload']
        config = build.build(live_server=live_server,
                             dirty=dirty,
                             site_dir=tempdir)
        return config

    # Perform the initial build
    log.info("Building documentation...")
    config = builder(dirty=not clean, **kwargs)
    host, port = config['dev_addr'].split(':', 1)

    try:
        if livereload in ['livereload', 'dirtyreload']:
            _livereload(host, port, config, builder, tempdir)
        else:
            mkdocs.commands.serve._static_server(host, port, tempdir)
    finally:
        log.info("Finished serving local site.")
Пример #22
0
def generate(config_file='moosedocs.yml',
             pages='pages.yml',
             stubs=False,
             pages_stubs=False,
             **kwargs):
    """
  Generates MOOSE system and object markdown files from the source code.

  Args:
    config_file[str]: (Default: 'moosedocs.yml') The MooseMkDocs project configuration file.
  """

    # Configuration file
    if not os.path.exists(config_file):
        raise IOError(
            "The supplied configuration file was not found: {}".format(
                config_file))

    # Read the configuration
    config = MooseDocs.yaml_load(config_file)
    config = config['markdown_extensions'][-1][
        'MooseDocs.extensions.MooseMarkdown']

    # Run the executable
    exe = config['executable']
    if not os.path.exists(exe):
        log.error('The executable does not exist: {}'.format(exe))
    else:
        log.debug("Executing {} to extract syntax.".format(exe))
        raw = utils.runExe(exe, '--yaml')
        yaml = utils.MooseYaml(raw)

    # Populate the syntax
    for key, value in config['locations'].iteritems():
        if 'hide' in value:
            value['hide'] += config['hide']
        else:
            value['hide'] = config['hide']
        syntax = MooseDocs.MooseApplicationSyntax(yaml,
                                                  name=key,
                                                  stubs=stubs,
                                                  pages_stubs=pages_stubs,
                                                  pages=pages,
                                                  **value)
        log.info("Checking documentation for '{}'.".format(key))
        syntax.check()
Пример #23
0
    def __init__(self, parser, site_dir, template, template_args, navigation):

        self._site_dir = site_dir

        content_dir = os.path.join(os.getcwd(), 'content')
        kwargs = {
            'parser': parser,
            'site_dir': self._site_dir,
            'navigation': MooseDocs.yaml_load(navigation),
            'template': template,
            'template_args': template_args
        }
        self._root = MooseDocsMarkdownNode(name='',
                                           md_file=os.path.join(
                                               content_dir, 'index.md'),
                                           **kwargs)
        make_tree(content_dir, self._root, **kwargs)
        self._pages = [self._root] + list(flat(self._root))
Пример #24
0
def serve(config_file='mkdocs.yml', strict=None, livereload='dirtyreload', clean=True, pages='pages.yml', **kwargs):
    """
    Mimics mkdocs serve command.

    @TODO: When the mkdocs plugin system allows for custom Watcher this should be removed.
    """

    # Location of serve site
    tempdir = os.path.abspath('.moosedocs')

    # Clean the "temp" directory (if desired)
    if clean and 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.mkdir(tempdir)

    # Read the pages file
    pages = MooseDocs.yaml_load(pages)

    def builder(**kwargs):
        dirty = kwargs.pop('dirty', livereload == 'dirtyreload')
        config = mkdocs.config.load_config(config_file=config_file, strict=strict, pages=pages, **kwargs)
        config['site_dir'] = tempdir
        live_server = livereload in ['dirtyreload', 'livereload']
        mkdocs.commands.build.build(config, live_server=live_server, dirty=dirty)
        return config

    # Perform the initial build
    log.info("Building documentation...")
    config = builder(dirty=not clean, **kwargs)
    host, port = config['dev_addr'].split(':', 1)

    try:
        if livereload in ['livereload', 'dirtyreload']:
            _livereload(host, port, config, builder, tempdir)
        else:
            mkdocs.commands.serve._static_server(host, port, tempdir)
    finally:
        log.info("Finished serving local site.")
Пример #25
0
    def _generate(self):
        """
        Generate the documentation.
        """

        # Setup the location
        log.info('Generating Documentation: {}'.format(self._config_file))

        # Parse the configuration file for the desired paths
        configs = self._configure()

        # Locate and run the MOOSE executable
        raw = utils.runExe(self._exe, '--yaml')
        ydata = utils.MooseYaml(raw)

        for config in configs:
            generator = MooseSubApplicationDocGenerator(ydata, config)
            generator.write()

        # Create the mkdocs.yml file
        # TODO: When mkdocs plugins API is up and running this should go away.

        def dumptree(node, level=0):
            for item in node:
                for key, value in item.iteritems():
                    if isinstance(value, list):
                        yield '{}- {}:'.format(' '*4*level, key)
                        for f in dumptree(value, level+1):
                            yield f
                    else:
                        yield '{}- {}: {}'.format(' '*4*(level), key, value)

        pages = MooseDocs.yaml_load('pages.yml')
        output = ['pages:']
        output += dumptree(pages, 1)
        shutil.copyfile('mkdocs.template.yml', 'mkdocs.yml')
        with open('mkdocs.yml', 'a') as fid:
            fid.write('\n'.join(output))
Пример #26
0
 def __init__(self, pages):
   self.pages = MooseDocs.yaml_load(pages)
   self.raw = yaml.dump(self.pages, default_flow_style=False)
Пример #27
0
    def extendMarkdown(self, md, md_globals):
        """
        Builds the extensions for MOOSE flavored markdown.
        """

        # Strip description from config
        config = self.getConfigs()

        # Generate YAML data from application
        global cache
        exe = config['executable']
        if exe != cache['exe']:
            if not os.path.exists(exe):
                log.error('The executable does not exist: {}'.format(exe))
            else:
                log.debug("Executing {} to extract syntax.".format(exe))
                raw = utils.runExe(exe, '--yaml')
                cache['exe'] = exe
                cache['yaml'] = utils.MooseYaml(raw)

        # Populate the database for input file and children objects
        if not cache['input_files']:
            log.info('Building input and inheritance databases...')
            for key, path in config['links'].iteritems():
                cache['input_files'][key] =  MooseDocs.database.Database('.i', path, MooseDocs.database.items.InputFileItem, repo=config['repo'])
                cache['child_objects'][key] = MooseDocs.database.Database('.h', path, MooseDocs.database.items.ChildClassItem, repo=config['repo'])

        # Populate the syntax
        if not cache['syntax']:
            for key, value in config['locations'].iteritems():
                cache['syntax'][key] = MooseDocs.MooseApplicationSyntax(cache['yaml'], **value)

        # Populate the pages yaml
        if not cache['pages']:
            yml = MooseDocs.yaml_load(config['pages'])
            for match in re.finditer(r':(.*?\.md)', yaml.dump(yml, default_flow_style=False)):
                cache['pages'].append(match.group(1).strip())

        # Preprocessors
        md.preprocessors.add('moose_bibtex', MooseBibtex(markdown_instance=md, root=config['root']), '_end')
        md.preprocessors.add('moose_auto_link', MooseMarkdownLinkPreprocessor(markdown_instance=md, pages=cache['pages']), '_begin')
        if config['slides']:
            md.preprocessors.add('moose_slides', MooseSlidePreprocessor(markdown_instance=md), '_end')

        # Block processors
        md.parser.blockprocessors.add('diagrams', MooseDiagram(md.parser, graphviz=config['graphviz']), '_begin')
        md.parser.blockprocessors.add('slideshow', MooseCarousel(md.parser, root=config['root']), '_begin')
        md.parser.blockprocessors.add('css', MooseCSS(md.parser, root=config['root']), '_begin')

        # Inline Patterns
        object_markdown = MooseObjectSyntax(markdown_instance=md,
                                            yaml=cache['yaml'],
                                            syntax=cache['syntax'],
                                            input_files=cache['input_files'],
                                            child_objects=cache['child_objects'],
                                            repo=config['repo'],
                                            root=config['root'])
        system_markdown = MooseSystemSyntax(markdown_instance=md,
                                            yaml=cache['yaml'],
                                            syntax=cache['syntax'])
        md.inlinePatterns.add('moose_object_syntax', object_markdown, '_begin')
        md.inlinePatterns.add('moose_system_syntax', system_markdown, '_begin')

        md.inlinePatterns.add('moose_input_block', MooseInputBlock(markdown_instance=md, repo=config['repo'], root=config['root']), '<image_link')
        md.inlinePatterns.add('moose_cpp_method', MooseCppMethod(markdown_instance=md, make=config['make'], repo=config['repo'], root=config['root']), '<image_link')
        md.inlinePatterns.add('moose_text', MooseTextFile(markdown_instance=md, repo=config['repo'], root=config['root']), '<image_link')
        md.inlinePatterns.add('moose_image', MooseImageFile(markdown_instance=md, root=config['root']), '<image_link')
        md.inlinePatterns.add('moose_build_status', MooseBuildStatus(markdown_instance=md), '_begin')

        if config['package']:
            md.inlinePatterns.add('moose_package_parser', MoosePackageParser(markdown_instance=md), '_end')
Пример #28
0
    def __init__(self, markdown_instance=None, **kwargs):
        MooseMarkdownCommon.__init__(self, **kwargs)
        Pattern.__init__(self, self.RE, markdown_instance)

        # Load the yaml data containing package information
        self.package = MooseDocs.yaml_load(kwargs.pop('package_file'))
Пример #29
0
    def extendMarkdown(self, md, md_globals):
        """
    Builds the extensions for MOOSE flavored markdown.
    """

        # Strip description from config
        config = self.getConfigs()

        # Generate YAML data from application
        global cache
        exe = config['executable']
        if exe != cache['exe']:
            if not os.path.exists(exe):
                log.error('The executable does not exist: {}'.format(exe))
            else:
                log.debug("Executing {} to extract syntax.".format(exe))
                raw = utils.runExe(exe, '--yaml')
                cache['exe'] = exe
                cache['yaml'] = utils.MooseYaml(raw)

        # Populate the database for input file and children objects
        if not cache['input_files']:
            log.info('Building input and inheritance databases...')
            for key, path in config['links'].iteritems():
                cache['input_files'][key] = MooseDocs.database.Database(
                    '.i',
                    path,
                    MooseDocs.database.items.InputFileItem,
                    repo=config['repo'])
                cache['child_objects'][key] = MooseDocs.database.Database(
                    '.h',
                    path,
                    MooseDocs.database.items.ChildClassItem,
                    repo=config['repo'])

        # Populate the syntax
        if not cache['syntax']:
            for key, value in config['locations'].iteritems():
                if 'hide' in value:
                    value['hide'] += config['hide']
                else:
                    value['hide'] = config['hide']
                cache['syntax'][key] = MooseDocs.MooseApplicationSyntax(
                    cache['yaml'], **value)

        # Populate the pages yaml
        if not cache['pages']:
            yml = MooseDocs.yaml_load(config['pages'])
            for match in re.finditer(r':(.*?\.md)',
                                     yaml.dump(yml, default_flow_style=False)):
                cache['pages'].append(match.group(1).strip())

        # Preprocessors
        bibtex = MooseBibtex(markdown_instance=md, root=config['root'])
        md.preprocessors.add('moose_bibtex', bibtex, '_end')

        links = MooseMarkdownLinkPreprocessor(markdown_instance=md,
                                              pages=cache['pages'])
        md.preprocessors.add('moose_auto_link', links, '_begin')

        if config['slides']:
            slides = MooseSlidePreprocessor(markdown_instance=md)
            md.preprocessors.add('moose_slides', slides, '_end')

        # Block processors
        diagrams = MooseDiagram(md.parser,
                                root=config['root'],
                                docs_dir=config['docs_dir'],
                                graphviz=config['graphviz'],
                                ext=config['dot_ext'])
        md.parser.blockprocessors.add('diagrams', diagrams, '_begin')

        carousel = MooseCarousel(md.parser,
                                 root=config['root'],
                                 docs_dir=config['docs_dir'])
        md.parser.blockprocessors.add('slideshow', carousel, '_begin')

        css = MooseCSS(md.parser,
                       root=config['root'],
                       docs_dir=config['docs_dir'])
        md.parser.blockprocessors.add('css', css, '_begin')

        # Inline Patterns
        object_markdown = MooseObjectSyntax(
            markdown_instance=md,
            yaml=cache['yaml'],
            syntax=cache['syntax'],
            input_files=cache['input_files'],
            child_objects=cache['child_objects'],
            repo=config['repo'],
            root=config['root'],
            docs_dir=config['docs_dir'])
        md.inlinePatterns.add('moose_object_syntax', object_markdown, '_begin')

        system_markdown = MooseSystemSyntax(markdown_instance=md,
                                            yaml=cache['yaml'],
                                            syntax=cache['syntax'],
                                            root=config['root'],
                                            docs_dir=config['docs_dir'])
        md.inlinePatterns.add('moose_system_syntax', system_markdown, '_begin')

        moose_input = MooseInputBlock(markdown_instance=md,
                                      root=config['root'],
                                      docs_dir=config['docs_dir'],
                                      repo=config['repo'])
        md.inlinePatterns.add('moose_input_block', moose_input, '<image_link')

        moose_cpp = MooseCppMethod(markdown_instance=md,
                                   root=config['root'],
                                   docs_dir=config['docs_dir'],
                                   make=config['make'],
                                   repo=config['repo'])
        md.inlinePatterns.add('moose_cpp_method', moose_cpp, '<image_link')

        moose_text = MooseTextFile(markdown_instance=md,
                                   root=config['root'],
                                   docs_dir=config['docs_dir'],
                                   repo=config['repo'])
        md.inlinePatterns.add('moose_text', moose_text, '<image_link')

        moose_image = MooseImageFile(markdown_instance=md,
                                     root=config['root'],
                                     docs_dir=config['docs_dir'])
        md.inlinePatterns.add('moose_image', moose_image, '<image_link')

        moose_status = MooseBuildStatus(markdown_instance=md,
                                        root=config['root'],
                                        docs_dir=config['docs_dir'])
        md.inlinePatterns.add('moose_build_status', moose_status, '_begin')

        if config['package']:
            package = MoosePackageParser(markdown_instance=md,
                                         root=config['root'],
                                         docs_dir=config['docs_dir'])
            md.inlinePatterns.add('moose_package_parser', package, '_end')
Пример #30
0
 def __init__(self, pages):
     self.pages = MooseDocs.yaml_load(pages)
     self.raw = yaml.dump(self.pages, default_flow_style=False)
Пример #31
0
    def __init__(self, markdown_instance=None, **kwargs):
        MooseMarkdownCommon.__init__(self, **kwargs)
        Pattern.__init__(self, self.RE, markdown_instance)

        # Load the yaml data containing package information
        self.package = MooseDocs.yaml_load(kwargs.pop('package_file'))