def setUpClass(cls): """ Create the markdown parser using the configuration file. """ super(MarkdownTestCase, cls).setUpClass() # Setup logging cls._stream = StringIO.StringIO() cls._formatter = init_logging(stream=cls._stream) # Define the local directory cls._path = os.path.abspath(os.path.dirname(inspect.getfile(cls))) # Read the YAML configurations config = MooseMarkdown.getDefaultExtensions() config.update( MooseDocs.load_config( os.path.join(MooseDocs.MOOSE_DIR, 'docs', cls.CONFIG))) # Update extension list if cls.EXTENSIONS: for key in config: if key not in cls.EXTENSIONS: config.pop(key) cls.updateExtensions(config) cls.parser = MooseMarkdown(config, default=False)
def check(config_file=None, generate=None, update=None, dump=None, template=None, groups=None, **template_args): """ Performs checks and optionally generates stub pages for missing documentation. """ # Create the markdown parser and get the AppSyntaxExtension config = MooseDocs.load_config(config_file, template=template, template_args=template_args) parser = MooseMarkdown(config) ext = parser.getExtension(AppSyntaxExtension) syntax = ext.getMooseAppSyntax() # Dump the complete syntax tree if desired if dump: print syntax # Check all nodes for documentation for node in syntax.findall(): node.check(ext.getConfig('install'), generate=generate, groups=groups, update=update) return 0
def testNodeFinder(self): config = dict() config['framework'] = dict(base='docs/content', include=['docs/content/documentation/systems*']) root = common.moose_docs_file_tree(config) node0 = MooseMarkdown.find(root, 'systems/index.md')[0] node1 = MooseMarkdown.find(root, 'systems/Adaptivity/index.md')[0] path = os.path.relpath(node1.destination, os.path.dirname(node0.destination)) self.assertEqual(path, 'Adaptivity/index.html')
def setUpClass(cls): """ Create the markdown parser using the configuration file. """ super(MarkdownTestCase, cls).setUpClass() # Setup logging cls._stream = StringIO.StringIO() cls._formatter = init_logging(stream=cls._stream) # Define the local directory cls._path = os.path.abspath(os.path.dirname(inspect.getfile(cls))) # Read the YAML configurations config = MooseMarkdown.getDefaultExtensions() config.update(MooseDocs.load_config(os.path.join(MooseDocs.MOOSE_DIR, 'docs', cls.CONFIG))) # Update extension list if cls.EXTENSIONS: for key in config: if key not in cls.EXTENSIONS: config.pop(key) cls.updateExtensions(config) cls.parser = MooseMarkdown(config, default=False)
def latex(config_file=None, output=None, md_file=None, template=None, **template_args): """ Command for converting markdown file to latex. """ LOG.warning( "The latex command is experimental and requires additional development to be " "complete, please be patient as this develops.\nIf you would like to aid in " "improving this feature please contact the MOOSE mailing list: " "[email protected].") # The markdown file is provided via the command line, thus it is provided relative to the # current working directory. The internals of MooseDocs are setup to always work from the # repository root directory (i.e., MooseDocs.ROOT_DIR), thus the path of this file must be # converted to be relative to MooseDocs.ROOT_DIR. md_file = os.path.relpath(os.path.abspath(md_file), MooseDocs.ROOT_DIR) # Create the markdown parser config = MooseDocs.load_config(config_file, template=template, template_args=template_args) parser = MooseMarkdown(config) # Build the html builder = LatexBuilder(md_file=md_file, output=output, parser=parser) builder.init() builder.build(num_threads=1) return 0
def presentation(config_file=None, md_file=None, serve=None, port=None, host=None, template=None, **template_args): """ MOOSE markdown presentation blaster. """ # The markdown file is provided via the command line, thus it is provided relative to the # current working directory. The internals of MooseDocs are setup to always work from the # repository root directory (i.e., MooseDocs.ROOT_DIR), thus the path of this file must be # converted to be relative to MooseDocs.ROOT_DIR. md_file = os.path.relpath(os.path.abspath(md_file), MooseDocs.ROOT_DIR) # Create the markdown parser config = MooseDocs.load_config(config_file, template=template, template_args=template_args) parser = MooseMarkdown(config) # Build the html builder = PresentationBuilder(md_file=md_file, parser=parser) builder.init() builder.build(num_threads=1) if serve: server = livereload.Server() server.watch(os.path.join(MooseDocs.ROOT_DIR, md_file), lambda: builder.build(num_threads=1)) server.serve(root=builder.rootDirectory(), host=host, port=port, restart_delay=0) return 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)
def build(config_file=None, site_dir=None, num_threads=None, no_livereload=False, content=None, dump=False, clean=False, serve=False, host=None, port=None, template=None, **template_args): """ The main build command. """ if serve: clean = True site_dir = os.path.abspath(os.path.join(MooseDocs.TEMP_DIR, 'site')) # Clean/create site directory if clean and os.path.exists(site_dir): LOG.info('Cleaning build directory: %s', site_dir) shutil.rmtree(site_dir) # Create the "temp" directory if not os.path.exists(site_dir): os.makedirs(site_dir) # Create the markdown parser config = MooseDocs.load_config(config_file, template=template, template_args=template_args) parser = MooseMarkdown(config) # Create the builder object and build the pages builder = WebsiteBuilder(parser=parser, site_dir=site_dir, content=content) builder.init() if dump: print builder return None builder.build(num_threads=num_threads) # Serve if serve: if not no_livereload: server = livereload.Server( watcher=MooseDocsWatcher(builder, num_threads)) else: server = livereload.Server() server.serve(root=site_dir, host=host, port=port, restart_delay=0) return 0
def build(config_file=None, site_dir=None, num_threads=None, no_livereload=False, content=None, dump=False, clean=False, serve=False, host=None, port=None, template=None, init=False, **template_args): """ The main build command. """ if serve: clean = True site_dir = os.path.abspath(os.path.join(MooseDocs.TEMP_DIR, 'site')) # Clean/create site directory if clean and os.path.exists(site_dir): LOG.info('Cleaning build directory: %s', site_dir) shutil.rmtree(site_dir) # Create the "temp" directory if not os.path.exists(site_dir): os.makedirs(site_dir) # Check submodule for large_media if MooseDocs.ROOT_DIR == MooseDocs.MOOSE_DIR: status = common.submodule_status() if status['docs/content/media/large_media'] == '-': if init: subprocess.call([ 'git', 'submodule', 'update', '--init', 'docs/content/media/large_media' ], cwd=MooseDocs.MOOSE_DIR) else: LOG.warning( "The 'large_media' submodule for storing images above 1MB is not " "initialized, thus some images will not be visible within the " "generated website. Run the build command with the --init flag to " "initialize the submodule.") # Check media files size if MooseDocs.ROOT_DIR == MooseDocs.MOOSE_DIR: media = os.path.join(MooseDocs.MOOSE_DIR, 'docs', 'content', 'media') ignore = set() for base, _, files in os.walk(os.path.join(media, 'large_media')): for name in files: ignore.add(os.path.join(base, name)) large = mooseutils.check_file_size(base=media, ignore=ignore) if large: msg = "Media files above the limit of 1 MB detected, these files should be stored in " \ "large media repository (docs/content/media/large_media):" for name, size in large: msg += '\n{}{} ({:.2f} MB)'.format(' ' * 4, name, size) LOG.error(msg) # Create the markdown parser config = MooseDocs.load_config(config_file, template=template, template_args=template_args) parser = MooseMarkdown(config) # Create the builder object and build the pages builder = WebsiteBuilder(parser=parser, site_dir=site_dir, content=content) builder.init() if dump: print builder return None builder.build(num_threads=num_threads) # Serve if serve: if not no_livereload: server = livereload.Server( watcher=MooseDocsWatcher(builder, num_threads)) else: server = livereload.Server() server.serve(root=site_dir, host=host, port=port, restart_delay=0) return 0