def test_flat(self):
     doc_tree, _ = read_doc_tree(
         self.dir, ['index.md', 'a.md'], _empty)
     self.assertSequenceEqual(doc_tree.entries, [
         DocSubtree(self.dir / "index.md", ("index",), []),
         DocSubtree(self.dir / "a.md", ('a',), []),
     ])
 def test_nested(self):
     doc_tree, _ = read_doc_tree(
         self.dir, [{'index.md': ['a.md']}], _empty)
     self.assertSequenceEqual(doc_tree.entries, [
         DocSubtree(self.dir / "index.md", ("index",), [
             DocSubtree(self.dir / "a.md", ('a',), []),
         ]),
     ])
 def test_nested_glob(self):
     doc_tree, _ = read_doc_tree(self.dir, ['**/*.md'], _empty)
     self.assertSequenceEqual(doc_tree.entries, [
         DocSubtree(self.dir / "index.md", ("index",), []),
         DocSubtree(self.dir / "a.md", ('a',), []),
         DocSubtree(self.dir / "x" / "b.md", ("x", "b"), []),
         DocSubtree(self.dir / "y" / "index.md", ("y", "index"), []),
         DocSubtree(self.dir / "y" / "c.md", ("y", "c"), []),
         DocSubtree(self.dir / "y" / "yy" / "index.md", ("y", "yy", "index"), []),
         DocSubtree(self.dir / "y" / "yy" / "page2.md", ("y", "yy", "page2"), []),
         DocSubtree(self.dir / "y" / "yy" / "yyy" / "page3.md", ("y", "yy", "yyy", "page3"), []),
         DocSubtree(self.dir / "z" / "zz" / "blah.md", ("z", "zz", "blah"), []),
     ])
Exemple #4
0
def run():
    p = argparse.ArgumentParser()
    p.add_argument('--conf', default="conf.json", type=argparse.FileType('r'))
    p.add_argument('--debug', default=False, action='store_true')
    p.add_argument('--writer', default='html', action='store')
    args = p.parse_args()

    config_json = json.load(args.conf)
    plugin_names = DEFAULT_CONFIG['plugins'] + config_json.get('plugins', [])
    plugins = list(_get_plugins(plugin_names))
    more_defaults = [
        {plugin.CONFIG_NAMESPACE: plugin.get_default_config()}
        for plugin in plugins
        if plugin.CONFIG_NAMESPACE is not None
    ]

    config = dict(
        DictCascade(*([DEFAULT_CONFIG] + more_defaults + [config_json])))

    files_root = pathlib.Path(args.conf.name).parent.resolve()
    config['root_dir'] = files_root
    output_root = pathlib.Path(files_root) / pathlib.Path(config['output_dir'])
    if not output_root.exists():
        output_root.mkdir()

    for plugin in plugins:
        plugin.postprocess_config(config)

    for plugin in plugins:
        plugin.add_processors(stdlib)

    doc_tree, document_nodes = read_doc_tree(
        files_root, config['file_hierarchy'], _get_cfm_reader(stdlib))
    tree = CWTree(CWRootNode(document_nodes), {
        'doc_tree': doc_tree,
        'output_dir': output_root,
        'config': config
    })
    if args.debug:
        print(tree.root.get_string_for_test_comparison())
    tree.apply_library(stdlib)

    writers = {
        plugin.WRITER_NAME: plugin
        for plugin in plugins
        if plugin.WRITER_NAME is not None
    }
    writers[args.writer].write(config, files_root, output_root, stdlib, tree)
 def test_single_glob(self):
     doc_tree, _ = read_doc_tree(self.dir, ['x/*.md'], _empty)
     self.assertSequenceEqual(doc_tree.entries, [
         DocSubtree(self.dir / "x" / "b.md", ("x", "b"), []),
     ])