def generate_catalog(self, pages): logger.info("Generate catalog page.") catalog_generator = CatalogGenerator(self.config, self.target_path, pages) html = catalog_generator.generate_catalog_html() ofile = os.path.join(self.target_path, self.config["destination"], "index.html") write_file(ofile, html)
class TestCatalogGenerator(unittest.TestCase): def setUp(self): self.default_config = get_default_config() self.wiki_path = os.path.join(test_path, "mywiki_for_generator") os.chdir(self.wiki_path) self.config_file = os.path.join(base_path, "simiki", "conf_templates", "_config.yml.in") self.config = parse_config(self.config_file) s_themes_path = os.path.join(base_path, "simiki", self.default_config["themes_dir"]) self.d_themes_path = os.path.join("./", self.default_config["themes_dir"]) if os.path.exists(self.d_themes_path): shutil.rmtree(self.d_themes_path) copytree(s_themes_path, self.d_themes_path) self.pages = { "content/other/page1.md": { "content": "", "collection": "mycoll", "date": "2016-06-02 00:00", "layout": "page", "title": "Page 1", }, "content/other/page2.md": {"content": "", "date": "2016-06-02 00:00", "layout": "page", "title": "Page 2"}, "content/other/page3.md": { "content": "", "collection": "mycoll", "date": "2016-06-02 00:00", "layout": "page", "title": "Page 3", }, } self.generator = CatalogGenerator(self.config, self.wiki_path, self.pages) def test_get_template_vars(self): tpl_vars = self.generator.get_template_vars() with open(os.path.join(self.wiki_path, "expected_pages.json"), "r") as fd: expected_pages = json.load(fd) assert tpl_vars["pages"] == expected_pages with open(os.path.join(self.wiki_path, "expected_structure.json"), "r") as fd: expected_structure = json.load(fd) assert tpl_vars["site"]["structure"] == expected_structure def test_to_catalog(self): catalog_html = self.generator.generate_catalog_html() # trip site generated paragraph catalog_html = re.sub("(?m)^\s*<p>Site Generated .*?<\/p>$\n", "", catalog_html) fd = open(os.path.join(self.wiki_path, "expected_catalog.html"), "rb") year = datetime.date.today().year expected_html = unicode(fd.read(), "utf-8") % year assert catalog_html == expected_html
def generate_catalog(self, pages): logger.info("Generate catalog page.") catalog_generator = CatalogGenerator(self.config, self.target_path, pages) html = catalog_generator.generate_catalog_html() ofile = os.path.join( self.target_path, self.config["destination"], "index.html" ) write_file(ofile, html)
def setUp(self): self.default_config = get_default_config() self.wiki_path = os.path.join(test_path, 'mywiki_for_generator') os.chdir(self.wiki_path) self.config_file = os.path.join(base_path, 'simiki', 'conf_templates', '_config.yml.in') self.config = parse_config(self.config_file) s_themes_path = os.path.join(base_path, 'simiki', self.default_config['themes_dir']) self.d_themes_path = os.path.join('./', self.default_config['themes_dir']) if os.path.exists(self.d_themes_path): shutil.rmtree(self.d_themes_path) copytree(s_themes_path, self.d_themes_path) self.pages = { 'content/other/page1.md': { 'content': '', 'collection': 'mycoll', 'date': '2016-06-02 00:00', 'layout': 'page', 'title': 'Page 1' }, 'content/other/page2.md': { 'content': '', 'date': '2016-06-02 00:00', 'layout': 'page', 'title': 'Page 2' }, 'content/other/page3.md': { 'content': '', 'collection': 'mycoll', 'date': '2016-06-02 00:00', 'layout': 'page', 'title': 'Page 3' }, } self.generator = CatalogGenerator(self.config, self.wiki_path, self.pages)
def generate_catalog(self, pages): logger.info("Generate catalog page.") if self.configs["index"]: cgen = CustomCatalogGenerator(self.configs, os.getcwd(), None) else: cgen = CatalogGenerator(self.configs, os.getcwd(), pages) html = cgen.generate_catalog_html() ofile = osp.join(os.getcwd(), self.configs["destination"], "index.html") write_file(html, ofile, "index")
def generate_catalog(self, pages): logger.info("Generate catalog page.") if self.configs["index"]: cgen = CustomCatalogGenerator(self.configs, self.target_path) else: cgen = CatalogGenerator(self.configs, self.target_path, pages) html = cgen.generate_catalog_html() ofile = os.path.join(self.target_path, self.configs["destination"], "index.html") write_file(html, ofile, "index")
def generate_catalog(): pg = PageGenerator(_site_config, _base_path) pages = {} for root, dirs, files in os.walk(_site_config["source"]): files = [f for f in files if not f.startswith(".")] dirs[:] = [d for d in dirs if not d.startswith(".")] for filename in files: if not filename.endswith(_site_config["default_ext"]): continue md_file = os.path.join(root, filename) pg.src_file = md_file meta, _ = pg.get_meta_and_content(do_render=False) pages[md_file] = meta cg = CatalogGenerator(_site_config, _base_path, pages) html = cg.generate_catalog_html() ofile = os.path.join(_base_path, _site_config['destination'], "index.html") write_file(ofile, html) logging.debug('Regenerating catalog')
def generate_catalog(): pg = PageGenerator(_site_config, _base_path) pages = {} for root, dirs, files in os.walk(_site_config["source"]): files = [f for f in files if not f.startswith(".")] dirs[:] = [d for d in dirs if not d.startswith(".")] for filename in files: if not filename.endswith(_site_config["default_ext"]): continue md_file = os.path.join(root, filename) pg.src_file = md_file meta, _ = pg.get_meta_and_content(do_render=False) pages[md_file] = meta cg = CatalogGenerator(_site_config, _base_path, pages) html = cg.generate_catalog_html() ofile = os.path.join( _base_path, _site_config['destination'], "index.html" ) write_file(ofile, html) logging.debug('Regenerating catalog')
def setUp(self): self.default_config = get_default_config() self.wiki_path = os.path.join(test_path, 'mywiki_for_generator') os.chdir(self.wiki_path) self.config_file = os.path.join(base_path, 'simiki', 'conf_templates', '_config.yml.in') self.config = parse_config(self.config_file) s_themes_path = os.path.join(base_path, 'simiki', self.default_config['themes_dir']) self.d_themes_path = os.path.join('./', self.default_config['themes_dir']) if os.path.exists(self.d_themes_path): shutil.rmtree(self.d_themes_path) copytree(s_themes_path, self.d_themes_path) self.pages = { 'content/other/page1.md': {'content': '', 'collection': 'mycoll', 'date': '2016-06-02 00:00', 'layout': 'page', 'title': 'Page 1'}, 'content/other/page2.md': {'content': '', 'date': '2016-06-02 00:00', 'layout': 'page', 'title': 'Page 2'}, 'content/other/page3.md': {'content': '', 'collection': 'mycoll', 'date': '2016-06-02 00:00', 'layout': 'page', 'title': 'Page 3'}, } self.generator = CatalogGenerator(self.config, self.wiki_path, self.pages)
def setUp(self): self.default_config = get_default_config() self.wiki_path = os.path.join(test_path, "mywiki_for_generator") os.chdir(self.wiki_path) self.config_file = os.path.join(base_path, "simiki", "conf_templates", "_config.yml.in") self.config = parse_config(self.config_file) s_themes_path = os.path.join(base_path, "simiki", self.default_config["themes_dir"]) self.d_themes_path = os.path.join("./", self.default_config["themes_dir"]) if os.path.exists(self.d_themes_path): shutil.rmtree(self.d_themes_path) copytree(s_themes_path, self.d_themes_path) self.pages = { "content/other/page1.md": { "content": "", "collection": "mycoll", "date": "2016-06-02 00:00", "layout": "page", "title": "Page 1", }, "content/other/page2.md": {"content": "", "date": "2016-06-02 00:00", "layout": "page", "title": "Page 2"}, "content/other/page3.md": { "content": "", "collection": "mycoll", "date": "2016-06-02 00:00", "layout": "page", "title": "Page 3", }, } self.generator = CatalogGenerator(self.config, self.wiki_path, self.pages)
def generate_catalog(self): logger.info("Generate catalog page.") cgen = CatalogGenerator(self.configs) cgen.update_catalog_page()
class TestCatalogGenerator(unittest.TestCase): def setUp(self): self.default_config = get_default_config() self.wiki_path = os.path.join(test_path, 'mywiki_for_generator') os.chdir(self.wiki_path) self.config_file = os.path.join(base_path, 'simiki', 'conf_templates', '_config.yml.in') self.config = parse_config(self.config_file) s_themes_path = os.path.join(base_path, 'simiki', self.default_config['themes_dir']) self.d_themes_path = os.path.join('./', self.default_config['themes_dir']) if os.path.exists(self.d_themes_path): shutil.rmtree(self.d_themes_path) copytree(s_themes_path, self.d_themes_path) self.pages = { 'content/other/page1.md': { 'content': '', 'collection': 'mycoll', 'date': '2016-06-02 00:00', 'layout': 'page', 'title': 'Page 1' }, 'content/other/page2.md': { 'content': '', 'date': '2016-06-02 00:00', 'layout': 'page', 'title': 'Page 2' }, 'content/other/page3.md': { 'content': '', 'collection': 'mycoll', 'date': '2016-06-02 00:00', 'layout': 'page', 'title': 'Page 3' }, } self.generator = CatalogGenerator(self.config, self.wiki_path, self.pages) def test_get_template_vars(self): tpl_vars = self.generator.get_template_vars() with open(os.path.join(self.wiki_path, 'expected_pages.json'), 'r') \ as fd: expected_pages = json.load(fd) assert (tpl_vars['pages'] == expected_pages) with open(os.path.join(self.wiki_path, 'expected_structure.json'), 'r') \ as fd: expected_structure = json.load(fd) assert (tpl_vars['site']['structure'] == expected_structure) def test_to_catalog(self): catalog_html = self.generator.generate_catalog_html() # trip site generated paragraph catalog_html = re.sub('(?m)^\s*<p>Site Generated .*?<\/p>$\n', '', catalog_html) fd = open(os.path.join(self.wiki_path, 'expected_catalog.html'), "rb") year = datetime.date.today().year expected_html = unicode(fd.read(), "utf-8") % year assert catalog_html == expected_html
class TestCatalogGenerator(unittest.TestCase): def setUp(self): self.default_config = get_default_config() self.wiki_path = os.path.join(test_path, 'mywiki_for_generator') os.chdir(self.wiki_path) self.config_file = os.path.join(base_path, 'simiki', 'conf_templates', '_config.yml.in') self.config = parse_config(self.config_file) s_themes_path = os.path.join(base_path, 'simiki', self.default_config['themes_dir']) self.d_themes_path = os.path.join('./', self.default_config['themes_dir']) if os.path.exists(self.d_themes_path): shutil.rmtree(self.d_themes_path) copytree(s_themes_path, self.d_themes_path) self.pages = { 'content/other/page1.md': {'content': '', 'collection': 'mycoll', 'date': '2016-06-02 00:00', 'layout': 'page', 'title': 'Page 1'}, 'content/other/page2.md': {'content': '', 'date': '2016-06-02 00:00', 'layout': 'page', 'title': 'Page 2'}, 'content/other/page3.md': {'content': '', 'collection': 'mycoll', 'date': '2016-06-02 00:00', 'layout': 'page', 'title': 'Page 3'}, } self.generator = CatalogGenerator(self.config, self.wiki_path, self.pages) def test_get_template_vars(self): tpl_vars = self.generator.get_template_vars() with open(os.path.join(self.wiki_path, 'expected_pages.json'), 'r') \ as fd: expected_pages = json.load(fd) assert(tpl_vars['pages'] == expected_pages) with open(os.path.join(self.wiki_path, 'expected_structure.json'), 'r') \ as fd: expected_structure = json.load(fd) assert(tpl_vars['site']['structure'] == expected_structure) def test_to_catalog(self): catalog_html = self.generator.generate_catalog_html() # trip site generated paragraph catalog_html = re.sub('(?m)^\s*<p>Site Generated .*?<\/p>$\n', '', catalog_html) fd = open(os.path.join(self.wiki_path, 'expected_catalog.html'), "rb") year = datetime.date.today().year expected_html = unicode(fd.read(), "utf-8") % year assert catalog_html.rstrip() == expected_html.rstrip()