Пример #1
0
    def test_prev_next(self):
        s = Site(TEST_SITE)
        cfg = """
        plugins:
            - hyde.ext.sorter.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_url_cleaner(self):
        s = Site(TEST_SITE)
        cfg = """
           plugins:
                - hyde.ext.plugins.urls.UrlCleanerPlugin
           urlcleaner:
                index_file_names:
                    - about.html
                strip_extensions:
                    - html
                append_slash: true
           """
        s.config = Config(TEST_SITE, config_dict=yaml.load(cfg, Loader=yaml.FullLoader))
        text = """
   {% extends "base.html" %}

   {% block main %}
   <a id="index" href="{{ content_url('about.html') }}"></a>
   <a id="blog" href=
       "{{ content_url('blog/2010/december/merry-christmas.html') }}"></a>
   {% endblock %}
   """

        about2 = File(TEST_SITE.child('content/test.html'))
        about2.write(text)
        gen = Generator(s)
        gen.generate_all()

        from pyquery import PyQuery
        target = File(Folder(s.config.deploy_root_path).child('test.html'))
        text = target.read_all()
        q = PyQuery(text)
        assert q('a#index').attr("href") == '/'
        assert q('a#blog').attr(
            "href") == '/blog/2010/december/merry-christmas'
Пример #3
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
Пример #4
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)
Пример #5
0
def test_markdown_with_sourcecode():
    source = """
{%markdown%}
# Code

    :::python
    def add(a, b):
        return a + b

See [Example][]
[Example]: example.html

{%endmarkdown%}
"""

    expected = """
    <h1>Code</h1>
<div class="codehilite"><pre><span class="k">def</span> <span class="nf">add</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">):</span>
    <span class="k">return</span> <span class="n">a</span> <span class="o">+</span> <span class="n">b</span>
</pre></div>


<p>See <a href="example.html">Example</a></p>
    """
    t = Jinja2Template(JINJA2.path)
    s = Site(JINJA2.path)
    c = Config(JINJA2.path, config_dict=dict(
                    markdown=dict(extensions=['codehilite'])))
    s.config = c
    t.configure(s)
    html = t.render(source, {}).strip()
    assert html.strip() == expected.strip()
Пример #6
0
def test_restructuredtext_with_sourcecode():
    source = """
{% restructuredtext %}
Code
====
.. sourcecode:: python

    def add(a, b):
        return a + b

See `Example`_

.. _Example: example.html

{% endrestructuredtext %}
"""

    expected = """
<div class="document" id="code">
<h1 class="title">Code</h1>
<div class="highlight"><pre><span class="k">def</span> <span class="nf">add</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">):</span>
    <span class="k">return</span> <span class="n">a</span> <span class="o">+</span> <span class="n">b</span>
</pre></div>
<p>See <a class="reference external" href="example.html">Example</a></p>
</div>
"""
    t = Jinja2Template(JINJA2.path)
    s = Site(JINJA2.path)
    c = Config(JINJA2.path, config_dict=dict(
                    restructuredtext=dict(highlight_source=True)))
    s.config = c
    t.configure(s)
    html = t.render(source, {}).strip()
    assert html.strip() == expected.strip()
Пример #7
0
    def test_url_cleaner(self):
           s = Site(TEST_SITE)
           cfg = """
           plugins:
                - hyde.ext.plugins.urls.UrlCleanerPlugin
           urlcleaner:
                index_file_names:
                    - about.html
                strip_extensions:
                    - html
                append_slash: true
           """
           s.config = Config(TEST_SITE, config_dict=yaml.load(cfg))
           text = """
   {% extends "base.html" %}

   {% block main %}
   <a id="index" href="{{ content_url('about.html') }}"></a>
   <a id="blog" href="{{ content_url('blog/2010/december/merry-christmas.html') }}"></a>
   {% endblock %}
   """

           about2 = File(TEST_SITE.child('content/test.html'))
           about2.write(text)
           gen = Generator(s)
           gen.generate_all()

           from pyquery import PyQuery
           target = File(Folder(s.config.deploy_root_path).child('test.html'))
           text = target.read_all()
           q = PyQuery(text)
           assert q('a#index').attr("href") == '/'
           assert q('a#blog').attr("href") == '/blog/2010/december/merry-christmas'
Пример #8
0
def test_line_statements():
    source = """
    $$$ markdown
    ### Heading 3

    $$$ endmarkdown
    """
    t = Jinja2Template(JINJA2.path)
    s = Site(JINJA2.path)
    c = Config(JINJA2.path, config_dict=dict(markdown=dict(extensions=['headerid'])))
    s.config = c
    t.configure(s)
    html = t.render(source, {}).strip()
    assert html == u'<h3 id="heading_3">Heading 3</h3>'
Пример #9
0
def test_markdown_with_extensions():
    source = """
    {%markdown%}
    ### Heading 3

    {%endmarkdown%}
    """
    t = Jinja2Template(JINJA2.path)
    s = Site(JINJA2.path)
    c = Config(JINJA2.path, config_dict=dict(markdown=dict(extensions=['headerid'])))
    s.config = c
    t.configure(s)
    html = t.render(source, {}).strip()
    assert html == u'<h3 id="heading_3">Heading 3</h3>'
Пример #10
0
 def test_drafts_are_published_in_development(self):
     s = Site(TEST_SITE)
     cfg = """
     mode: development
     plugins:
         - hyde.ext.plugins.meta.MetaPlugin
         - hyde.ext.plugins.blog.DraftsPlugin
     """
     import yaml
     s.config = Config(TEST_SITE, config_dict=yaml.load(cfg))
     s.load()
     gen = Generator(s)
     gen.generate_all()
     assert s.config.deploy_root_path.child_file(
         'blog/2013/may/draft-post.html').exists
Пример #11
0
 def test_drafts_are_published_in_development(self):
     s = Site(TEST_SITE)
     cfg = """
     mode: development
     plugins:
         - hyde.ext.plugins.meta.MetaPlugin
         - hyde.ext.plugins.blog.DraftsPlugin
     """
     import yaml
     s.config = Config(TEST_SITE, config_dict=yaml.load(cfg))
     s.load()
     gen = Generator(s)
     gen.generate_all()
     assert s.config.deploy_root_path.child_file(
         'blog/2013/may/draft-post.html').exists
Пример #12
0
 def test_drafts_are_skipped_in_production(self):
     s = Site(TEST_SITE)
     cfg = """
     mode: production
     plugins:
         - hyde.ext.plugins.meta.MetaPlugin
         - hyde.ext.plugins.blog.DraftsPlugin
     """
     import yaml
     s.config = Config(TEST_SITE,
                       config_dict=yaml.load(cfg, Loader=yaml.FullLoader))
     s.load()
     gen = Generator(s)
     gen.generate_all()
     assert not s.config.deploy_root_path.child_file(
         'blog/2013/may/draft-post.html').exists
Пример #13
0
    def test_can_flatten(self):
        s = Site(TEST_SITE)
        cfg = """
        plugins:
            - hyde.ext.plugins.folders.FlattenerPlugin
        flattener:
            items:
                -
                    source: blog
                    target: ''
        """
        import yaml
        s.config = Config(TEST_SITE, config_dict=yaml.load(cfg))
        s.load()
        gen = Generator(s)
        gen.generate_all()

        assert not s.config.deploy_root_path.child_folder('blog').exists
        assert File(s.config.deploy_root_path.child('merry-christmas.html')).exists
Пример #14
0
    def test_flattener_fixes_nodes(self):
        s = Site(TEST_SITE)
        cfg = """
        plugins:
            - hyde.ext.plugins.structure.FlattenerPlugin
        flattener:
            items:
                -
                    source: blog
                    target: ''
        """
        import yaml
        s.config = Config(TEST_SITE, config_dict=yaml.load(cfg))
        s.load()
        gen = Generator(s)
        gen.generate_all()
        blog_node = s.content.node_from_relative_path('blog')

        assert blog_node
        assert blog_node.url == '/'
Пример #15
0
def test_line_statements_with_config():
    source = """
    %% markdown
    ### Heading 3

    %% endmarkdown
    """
    config = """
    markdown:
        extensions:
            - headerid
    jinja2:
        line_statement_prefix: '%%'

    """
    t = Jinja2Template(JINJA2.path)
    s = Site(JINJA2.path)
    s.config = Config(JINJA2.path, config_dict=yaml.load(config))
    t.configure(s)
    html = t.render(source, {}).strip()
    assert html == u'<h3 id="heading_3">Heading 3</h3>'
Пример #16
0
    def test_walk_resources_sorted_using_generator(self):
           s = Site(TEST_SITE)
           cfg = """
           meta:
               time: !!timestamp 2010-10-23
               title: NahNahNah
           plugins:
               - hyde.ext.plugins.meta.MetaPlugin
               - hyde.ext.plugins.meta.SorterPlugin
           sorter:
               time:
                   attr: meta.time
                   filters:
                       source_file.kind: html
           """
           s.config = Config(TEST_SITE, config_dict=yaml.load(cfg))
           text = """
   ---
    time: !!timestamp 2010-12-31
    title: YayYayYay
   ---
   {% extends "base.html" %}

   {% block main %}
       {% set latest = site.content.walk_resources_sorted_by_time()|reverse|first %}
       <span class="latest">{{ latest.meta.title }}</span>
   {% endblock %}
   """

           about2 = File(TEST_SITE.child('content/about2.html'))
           about2.write(text)
           gen = Generator(s)
           gen.generate_all()

           from pyquery import PyQuery
           target = File(Folder(s.config.deploy_root_path).child('about2.html'))
           text = target.read_all()
           q = PyQuery(text)

           assert q('span.latest').text() == 'YayYayYay'
Пример #17
0
    def test_walk_resources_sorted_using_generator(self):
           s = Site(TEST_SITE)
           cfg = """
           meta:
               time: !!timestamp 2010-10-23
               title: NahNahNah
           plugins:
               - hyde.ext.plugins.meta.MetaPlugin
               - hyde.ext.plugins.sorter.SorterPlugin
           sorter:
               time:
                   attr: meta.time
                   filters:
                       source_file.kind: html
           """
           s.config = Config(TEST_SITE, config_dict=yaml.load(cfg))
           text = """
   ---
    time: !!timestamp 2010-12-31
    title: YayYayYay
   ---
   {% extends "base.html" %}

   {% block main %}
       {% set latest = site.content.walk_resources_sorted_by_time()|reverse|first %}
       <span class="latest">{{ latest.meta.title }}</span>
   {% endblock %}
   """

           about2 = File(TEST_SITE.child('content/about2.html'))
           about2.write(text)
           gen = Generator(s)
           gen.generate_all()

           from pyquery import PyQuery
           target = File(Folder(s.config.deploy_root_path).child('about2.html'))
           text = target.read_all()
           q = PyQuery(text)

           assert q('span.latest').text() == 'YayYayYay'
Пример #18
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)
Пример #19
0
    def test_walk_resources_sorted_no_default_is_processable(self):
        s = Site(TEST_SITE)
        cfg = """
        plugins:
            - hyde.ext.sorter.SorterPlugin
        sorter:
            kind2:
                filters:
                    source_file.kind: html
        """
        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)
Пример #20
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)
Пример #21
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
Пример #22
0
    def test_walk_resources_sorted_with_multiple_attributes(self):
        s = Site(TEST_SITE)
        cfg = """
        plugins:
            - hyde.ext.sorter.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