def setUp(self): TEST_SITE.make() TEST_SITE.parent.child_folder('sites/test_grouper').copy_contents_to( TEST_SITE) self.s = Site(TEST_SITE) 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: plugins description: Plugins """ self.s.config = Config(TEST_SITE, config_dict=yaml.load(cfg, Loader=yaml.FullLoader)) self.s.load() MetaPlugin(self.s).begin_site() SorterPlugin(self.s).begin_site() GrouperPlugin(self.s).begin_site() self.all = [ 'installation.html', 'overview.html', 'templating.html', 'plugins.html', 'tags.html' ] self.start = ['installation.html', 'overview.html', 'templating.html'] self.plugins = ['plugins.html', 'tags.html'] self.section = self.all
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)