Example #1
0
    def testErrors(self):
        MooseDocs.LOG_LEVEL = logging.DEBUG
        root = page.DirectoryNode(source='docs')
        page.FileNode(root, source='docs/index.md')
        page.FileNode(root, source='docs/core.md')
        sub = page.DirectoryNode(root, source='docs/sub')
        page.FileNode(sub, source='docs/sub/core.md')

        with self.assertRaises(exceptions.MooseDocsException) as e:
            root.findall('foo', maxcount=2.2)
        self.assertIn("The argument 'maxcount' must be", str(e.exception))

        with self.assertRaises(exceptions.MooseDocsException) as e:
            root.findall('foo', mincount=2.2)
        self.assertIn("The argument 'mincount' must be", str(e.exception))
Example #2
0
    def examine(self):
        """
        Investigate directories for new files and add them to the tree if found.

        TODO: Remove nodes if page is deleted.
        TODO: Handle !include (see extensions.include.py for more information).
        """
        for node in anytree.PreOrderIter(self._translator.root):

            # Only perform check on valid directories
            if not isinstance(node, page.DirectoryNode) or not os.path.exists(node.source):
                continue

            # Build map of child pages for the directory
            children = {child.name:child for child in node.children \
                        if isinstance(child, page.FileNode)}

            # Compare the list of files in the directory with those tracked by MooseDocs
            for filename in os.listdir(node.source):  #pylint: disable=no-member
                if filename.endswith(MooseDocs.FILE_EXT) and not filename.startswith('.'):
                    if filename not in children:
                        source = os.path.join(node.source, filename)
                        if filename.endswith('.md'):
                            new = page.MarkdownNode(node, source=source)
                        else:
                            new = page.FileNode(node, source=source) #pylint: disable=redefined-variable-type
                        new.base = self._options.destination
                        self.watch(new.source, new.build, delay=2) #pylint: disable=no-member
                        new.init(self._translator)
                        new.build()

        return super(MooseDocsWatcher, self).examine()
Example #3
0
    def testBasic(self):
        root = page.DirectoryNode(None, source='docs')
        page.FileNode(root, source='docs/index.md')
        page.FileNode(root, source='docs/core.md')
        sub = page.DirectoryNode(root, source='docs/sub')
        page.FileNode(sub, source='docs/sub/core.md')
        page.FileNode(sub, source='docs/sub/full_core.md')

        nodes = root.findall('core.md', maxcount=None)
        self.assertEqual(len(nodes), 3)

        nodes = root.findall('/core.md', maxcount=None)
        self.assertEqual(len(nodes), 2)

        nodes = root.findall('docs/core.md', maxcount=None)
        self.assertEqual(len(nodes), 1)
Example #4
0
def create_file_node(parent, name, filename):
    """
    Create the correct node object for the given extension.
    """
    _, ext = os.path.splitext(filename)
    if ext == '.md':
        return page.MarkdownNode(parent, name=name, source=filename)
    else:
        return page.FileNode(parent, name=name, source=filename)
Example #5
0
 def testFileNode(self):
     source = os.path.join(ROOT_DIR, 'docs', 'content', 'utilities',
                           'MooseDocs', 'index.md')
     node = page.FileNode(source=source)
     self.assertEqual(node.source, source)