def test_nav_with_grouper(self): text = """ {% for group, resources in site.content.walk_section_groups() %} <ul> <li> <h2>{{ group.name|title }}</h2> <h3>{{ group.description }}</h3> <ul class="links"> {% for resource in resources %} <li>{{resource.name}}</li> {% endfor %} </ul> </li> </ul> {% endfor %} """ expected = """ <ul> <li> <h2>Section</h2> <h3>Sections in the site</h3> <ul class="links"></ul> </li> </ul> <ul> <li> <h2>Start</h2> <h3>Getting Started</h3> <ul class="links"> <li>installation.html</li> <li>overview.html</li> <li>templating.html</li> </ul> </li> </ul> <ul> <li> <h2>Plugins</h2> <h3>Plugins</h3> <ul class="links"> <li>plugins.html</li> <li>tags.html</li> </ul> </li> </ul> """ gen = Generator(self.s) gen.load_site_if_needed() gen.load_template_if_needed() out = gen.template.render(text, {'site': self.s}) assert_html_equals(out, expected)
def assert_valid_restructuredtext(self, actual_html_resource): expected_text = File( TEST_ROOT.child("dst_test_restructuredtext.html")).read_all() self.generator.process(actual_html_resource) # Ensure source file is not changed # The source should be copied to tmp and then # the processor should do its thing. original_source = File( TEST_ROOT.child("src_test_restructuredtext.html")).read_all() source_text = actual_html_resource.file.read_all() assert original_source == source_text actual_text = actual_html_resource.temp_file.read_all() assert_html_equals(expected_text, actual_text)
def test_recent_posts(self): site = SiteInfo(settings, TEST_SITE.path) site.refresh() self.generator = Generator(TEST_SITE.path) self.generator.build_siteinfo() self.generator.pre_process(site) actual_resource = site.find_resource(File(site.content_folder.child('recent_posts.html'))) self.generator.process(actual_resource) expected_text = File( TEST_ROOT.child("recent_posts_dest.html")).read_all() actual_text = actual_resource.temp_file.read_all() if ORIGINAL_PRE_PROCESSORS: settings.SITE_PRE_PROCESSORS = ORIGINAL_PRE_PROCESSORS assert_html_equals(expected_text, actual_text)
def test_recent_posts(self): site = SiteInfo(settings, TEST_SITE.path) site.refresh() self.generator = Generator(TEST_SITE.path) self.generator.build_siteinfo() self.generator.pre_process(site) actual_resource = site.find_resource( File(site.content_folder.child('recent_posts.html'))) self.generator.process(actual_resource) expected_text = File( TEST_ROOT.child("recent_posts_dest.html")).read_all() actual_text = actual_resource.temp_file.read_all() if ORIGINAL_PRE_PROCESSORS: settings.SITE_PRE_PROCESSORS = ORIGINAL_PRE_PROCESSORS assert_html_equals(expected_text, actual_text)
def test_render_direct(self): render_folder = TEST_SITE.child_folder('content/render'); render_folder.make() template_folder = TEST_SITE.child_folder('layout'); template_folder.make() File(TEST_ROOT.child("render_tag/template.html") ).copy_to(template_folder.child('render.html')) source = File(TEST_ROOT.child("render_tag/source.html")).copy_to(render_folder) site = SiteInfo(settings, TEST_SITE.path) site.refresh() self.generator = Generator(TEST_SITE.path) self.generator.build_siteinfo() self.generator.pre_process(site) actual_resource = site.find_resource(source) self.generator.process(actual_resource) expected_text = File(TEST_ROOT.child("render_tag/dest.html")).read_all() actual_text = actual_resource.temp_file.read_all() if ORIGINAL_PRE_PROCESSORS: settings.SITE_PRE_PROCESSORS = ORIGINAL_PRE_PROCESSORS assert_html_equals(expected_text, actual_text)
def test_render_direct(self): render_folder = TEST_SITE.child_folder('content/render') render_folder.make() template_folder = TEST_SITE.child_folder('layout') template_folder.make() File(TEST_ROOT.child("render_tag/template.html")).copy_to( template_folder.child('render.html')) source = File( TEST_ROOT.child("render_tag/source.html")).copy_to(render_folder) site = SiteInfo(settings, TEST_SITE.path) site.refresh() self.generator = Generator(TEST_SITE.path) self.generator.build_siteinfo() self.generator.pre_process(site) actual_resource = site.find_resource(source) self.generator.process(actual_resource) expected_text = File( TEST_ROOT.child("render_tag/dest.html")).read_all() actual_text = actual_resource.temp_file.read_all() if ORIGINAL_PRE_PROCESSORS: settings.SITE_PRE_PROCESSORS = ORIGINAL_PRE_PROCESSORS assert_html_equals(expected_text, actual_text)
def test_nav_with_grouper_sorted(self): cfg = """ nodemeta: meta.yaml plugins: - hyde.ext.plugins.meta.MetaPlugin - hyde.ext.plugins.meta.SorterPlugin - hyde.ext.plugins.meta.GrouperPlugin sorter: kind: attr: - source_file.kind filters: is_processable: True grouper: section: description: Sections in the site sorter: kind groups: - name: start description: Getting Started - name: awesome description: Awesome - name: plugins description: Plugins """ self.s.config = Config(TEST_SITE, config_dict=yaml.load(cfg)) self.s.load() MetaPlugin(self.s).begin_site() SorterPlugin(self.s).begin_site() GrouperPlugin(self.s).begin_site() text = """ {% set sorted = site.grouper['section'].groups|sort(attribute='name') %} {% for group in sorted %} <ul> <li> <h2>{{ group.name|title }}</h2> <h3>{{ group.description }}</h3> <ul class="links"> {% for resource in group.walk_resources_in_node(site.content) %} <li>{{resource.name}}</li> {% endfor %} </ul> </li> </ul> {% endfor %} """ expected = """ <ul> <li> <h2>Awesome</h2> <h3>Awesome</h3> <ul class="links"> </ul> </li> </ul> <ul> <li> <h2>Plugins</h2> <h3>Plugins</h3> <ul class="links"> <li>plugins.html</li> <li>tags.html</li> </ul> </li> </ul> <ul> <li> <h2>Start</h2> <h3>Getting Started</h3> <ul class="links"> <li>installation.html</li> <li>overview.html</li> <li>templating.html</li> </ul> </li> </ul> """ self.s.config.grouper.section.groups.append( Expando({"name": "awesome", "description": "Aweesoome"})) gen = Generator(self.s) gen.load_site_if_needed() gen.load_template_if_needed() out = gen.template.render(text, {'site': self.s}) assert_html_equals(out, expected)
def test_nav_with_grouper_sorted(self): cfg = """ nodemeta: meta.yaml plugins: - hyde.ext.plugins.meta.MetaPlugin - hyde.ext.plugins.meta.SorterPlugin - hyde.ext.plugins.meta.GrouperPlugin sorter: kind: attr: - source_file.kind filters: is_processable: True grouper: section: description: Sections in the site sorter: kind groups: - name: start description: Getting Started - name: awesome description: Awesome - name: plugins description: Plugins """ self.s.config = Config(TEST_SITE, config_dict=yaml.load(cfg)) self.s.load() MetaPlugin(self.s).begin_site() SorterPlugin(self.s).begin_site() GrouperPlugin(self.s).begin_site() text = """ {% set sorted = site.grouper['section'].groups|sort(attribute='name') %} {% for group in sorted %} <ul> <li> <h2>{{ group.name|title }}</h2> <h3>{{ group.description }}</h3> <ul class="links"> {% for resource in group.walk_resources_in_node(site.content) %} <li>{{resource.name}}</li> {% endfor %} </ul> </li> </ul> {% endfor %} """ expected = """ <ul> <li> <h2>Awesome</h2> <h3>Awesome</h3> <ul class="links"> </ul> </li> </ul> <ul> <li> <h2>Plugins</h2> <h3>Plugins</h3> <ul class="links"> <li>plugins.html</li> <li>tags.html</li> </ul> </li> </ul> <ul> <li> <h2>Start</h2> <h3>Getting Started</h3> <ul class="links"> <li>installation.html</li> <li>overview.html</li> <li>templating.html</li> </ul> </li> </ul> """ self.s.config.grouper.section.groups.append( Expando({ "name": "awesome", "description": "Aweesoome" })) gen = Generator(self.s) gen.load_site_if_needed() gen.load_template_if_needed() out = gen.template.render(text, {'site': self.s}) assert_html_equals(out, expected)