Пример #1
0
 def test_attribute_checker_with_meta(self):
     s = Site(TEST_SITE)
     s.load()
     MetaPlugin(s).begin_site()
     from hyde.ext.plugins.meta import attributes_checker
     have_index = [
         "angry-post.html", "another-sad-post.html", "happy-post.html"
     ]
     for r in s.content.walk_resources():
         expected = r.name in have_index
         assert attributes_checker(r, ['meta.index']) == expected
Пример #2
0
    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
Пример #3
0
    def test_walk_resources_sorted_by_index(self):
        s = Site(TEST_SITE)
        s.load()
        config = {"index": {"attr": ['meta.index', 'name']}}
        s.config.sorter = Expando(config)
        MetaPlugin(s).begin_site()
        SorterPlugin(s).begin_site()

        assert hasattr(s.content, 'walk_resources_sorted_by_index')
        expected = [
            "angry-post.html", "another-sad-post.html", "happy-post.html"
        ]

        pages = [
            page.name for page in s.content.walk_resources_sorted_by_index()
        ]

        assert pages == sorted(expected, key=lambda f: (File(f).kind, f))
Пример #4
0
    def test_nav_with_grouper_sorted(self):

        cfg = """
        nodemeta: meta.yaml
        plugins:
          - hyde.ext.plugins.meta.MetaPlugin
          - hyde.ext.plugins.sorter.SorterPlugin
          - hyde.ext.plugins.grouper.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)