예제 #1
0
    def test_prev_next(self):
        s = Site(TEST_SITE)
        cfg = """
        plugins:
            - hyde.ext.meta.SorterPlugin
        sorter:
            kind2:
                filters:
                    source_file.kind: html
                attr:
                    - name
        """
        s.config = Config(TEST_SITE, config_dict=yaml.load(cfg))
        s.load()
        SorterPlugin(s).begin_site()

        p_404 = s.content.resource_from_relative_path('404.html')
        p_about = s.content.resource_from_relative_path('about.html')
        p_mc = s.content.resource_from_relative_path(
            'blog/2010/december/merry-christmas.html')

        assert hasattr(p_404, 'prev_by_kind2')
        assert not p_404.prev_by_kind2
        assert hasattr(p_404, 'next_by_kind2')
        assert p_404.next_by_kind2 == p_about

        assert hasattr(p_about, 'prev_by_kind2')
        assert p_about.prev_by_kind2 == p_404
        assert hasattr(p_about, 'next_by_kind2')
        assert p_about.next_by_kind2 == p_mc

        assert hasattr(p_mc, 'prev_by_kind2')
        assert p_mc.prev_by_kind2 == p_about
        assert hasattr(p_mc, 'next_by_kind2')
        assert not p_mc.next_by_kind2
예제 #2
0
    def test_walk_resources_sorted_no_default_is_processable(self):
        s = Site(TEST_SITE)
        cfg = """
        plugins:
            - hyde.ext.meta.SorterPlugin
        sorter:
            kind2:
                filters:
                    source_file.kind: html
                attr:
                    - name
        """
        s.config = Config(TEST_SITE, config_dict=yaml.load(cfg))
        s.load()
        p_404 = s.content.resource_from_relative_path('404.html')
        p_404.is_processable = False
        SorterPlugin(s).begin_site()

        assert hasattr(s.content, 'walk_resources_sorted_by_kind2')
        expected = ["404.html", "about.html", "merry-christmas.html"]

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

        assert pages == sorted(expected)
예제 #3
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
예제 #4
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))
예제 #5
0
    def test_walk_resources_sorted(self):
        s = Site(TEST_SITE)
        s.load()
        s.config.plugins = ['hyde.ext.meta.SorterPlugin']
        s.config.sorter = Expando(
            dict(kind=dict(attr=['source_file.kind', 'name'])))

        SorterPlugin(s).begin_site()

        assert hasattr(s.content, 'walk_resources_sorted_by_kind')
        expected = [
            "404.html", "about.html", "apple-touch-icon.png",
            "merry-christmas.html", "crossdomain.xml", "favicon.ico",
            "robots.txt", "site.css"
        ]

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

        assert pages == sorted(expected, key=lambda f: (File(f).kind, f))
예제 #6
0
    def test_walk_resources_sorted_with_filters(self):
        s = Site(TEST_SITE)
        cfg = """
        plugins:
            - hyde.ext.meta.SorterPlugin
        sorter:
            kind2:
                filters:
                    source_file.kind: html
        """
        s.config = Config(TEST_SITE, config_dict=yaml.load(cfg))
        s.load()
        SorterPlugin(s).begin_site()

        assert hasattr(s.content, 'walk_resources_sorted_by_kind2')
        expected = ["404.html", "about.html", "merry-christmas.html"]

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

        assert pages == sorted(expected)
예제 #7
0
    def test_walk_resources_sorted_with_multiple_attributes(self):
        s = Site(TEST_SITE)
        cfg = """
        plugins:
            - hyde.ext.meta.SorterPlugin
        sorter:
            multi:
                attr:
                    - source_file.kind
                    - node.name
                    - name

        """
        s.config = Config(TEST_SITE, config_dict=yaml.load(cfg))
        s.load()
        SorterPlugin(s).begin_site()

        assert hasattr(s.content, 'walk_resources_sorted_by_multi')
        expected = [
            "content/404.html", "content/about.html",
            "content/apple-touch-icon.png",
            "content/blog/2010/december/merry-christmas.html",
            "content/crossdomain.xml", "content/favicon.ico",
            "content/robots.txt", "content/site.css"
        ]

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

        expected_sorted = [
            File(page).name for page in sorted(
                expected,
                key=lambda p: tuple([File(p).kind,
                                     File(p).parent.name, p]))
        ]
        assert pages == expected_sorted
예제 #8
0
    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)