Exemplo n.º 1
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()
Exemplo n.º 2
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
Exemplo n.º 3
0
    def test_context(self):
        site = Site(TEST_SITE, Config(TEST_SITE, config_dict={
            "context": {
                "data": {
                    "abc": "def"
                }
            }
        }))
        text = """
{% extends "base.html" %}

{% block main %}
    abc = {{ abc }}
    Hi!

    I am a test template to make sure jinja2 generation works well with hyde.
    {{resource.name}}
{% endblock %}
"""
        site.load()
        resource = site.content.resource_from_path(TEST_SITE.child('content/about.html'))
        gen = Generator(site)
        resource.source_file.write(text)
        gen.generate_all()
        target = File(site.config.deploy_root_path.child(resource.name))
        assert "abc = def" in target.read_all()
Exemplo n.º 4
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()
Exemplo n.º 5
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'
Exemplo n.º 6
0
def test_resource_slug():
    s = Site(TEST_SITE_ROOT)
    s.load()
    path = 'blog/2010/december'
    node = s.content.node_from_relative_path(path)
    resource = node.get_resource('merry-christmas.html')
    assert resource.slug == 'merry-christmas'
Exemplo n.º 7
0
    def test_ignores_pattern_in_content(self):
        text = """
{% markdown %}

Heading 1
===

Heading 2
===

{% endmarkdown %}
"""
        about2 = File(TEST_SITE.child("content/about2.html"))
        about2.write(text)
        s = Site(TEST_SITE)
        s.load()
        res = s.content.resource_from_path(about2.path)
        assert res.is_processable

        s.config.plugins = ["hyde.ext.plugins.meta.MetaPlugin"]
        gen = Generator(s)
        gen.generate_all()
        target = File(Folder(s.config.deploy_root_path).child("about2.html"))
        text = target.read_all()
        q = PyQuery(text)
        assert q("h1").length == 2
        assert q("h1:eq(0)").text().strip() == "Heading 1"
        assert q("h1:eq(1)").text().strip() == "Heading 2"
Exemplo n.º 8
0
 def test_content_url_encoding_safe(self):
     s = Site(self.SITE_PATH, config=self.config)
     s.load()
     path = '".jpg/abc'
     print((s.content_url(path, "")))
     print(("/" + quote(path, "")))
     assert s.content_url(path, "") == "/" + quote(path, "")
Exemplo n.º 9
0
 def test_full_url_for_media(self):
     s = Site(self.SITE_PATH, config=self.config)
     s.load()
     path = 'media/css/site.css'
     assert s.is_media(path)
     full_url = s.full_url(path)
     assert full_url == "/" + path
Exemplo n.º 10
0
 def test_simple_copy_basic(self):
     self.setup_config(["about.html"])
     s = Site(self.SITE_PATH, config=self.config)
     s.load()
     res = s.content.resource_from_relative_path("about.html")
     assert res
     assert res.simple_copy
Exemplo n.º 11
0
def test_get_resource():
    s = Site(TEST_SITE_ROOT)
    s.load()
    path = 'blog/2010/december'
    node = s.content.node_from_relative_path(path)
    resource = node.get_resource('merry-christmas.html')
    assert resource == s.content.resource_from_relative_path(Folder(path).child('merry-christmas.html'))
Exemplo n.º 12
0
 def test_media_url_from_resource(self):
     s = Site(self.SITE_PATH, config=self.config)
     s.load()
     path = 'css/site.css'
     resource = s.content.resource_from_relative_path(
         Folder("media").child(path))
     assert resource
     assert resource.full_url == "/media/" + path
Exemplo n.º 13
0
 def test_generate_resource_from_path_with_is_processable_false(self):
     site = Site(TEST_SITE)
     site.load()
     resource = site.content.resource_from_path(TEST_SITE.child('content/about.html'))
     resource.is_processable = False
     gen = Generator(site)
     gen.generate_resource_at_path(TEST_SITE.child('content/about.html'))
     about = File(Folder(site.config.deploy_root_path).child('about.html'))
     assert not about.exists
Exemplo n.º 14
0
 def test_generate_resource_from_path(self):
     site = Site(TEST_SITE)
     site.load()
     gen = Generator(site)
     gen.generate_resource_at_path(TEST_SITE.child('content/about.html'))
     about = File(Folder(site.config.deploy_root_path).child('about.html'))
     assert about.exists
     text = about.read_all()
     q = PyQuery(text)
     assert about.name in q("div#main").text()
Exemplo n.º 15
0
def test_relative_deploy_path_override():
    s = Site(TEST_SITE_ROOT)
    s.load()
    res = s.content.resource_from_relative_path('blog/2010/december/merry-christmas.html')
    res.relative_deploy_path = 'blog/2010/december/happy-holidays.html'
    for page in s.content.walk_resources():
        if res.source_file == page.source_file:
            assert page.relative_deploy_path == 'blog/2010/december/happy-holidays.html'
        else:
            assert page.relative_deploy_path == Folder(page.relative_path)
Exemplo n.º 16
0
 def test_generate_resource_from_path_with_is_processable_false(self):
     site = Site(TEST_SITE)
     site.load()
     resource = site.content.resource_from_path(
         TEST_SITE.child('content/about.html'))
     resource.is_processable = False
     gen = Generator(site)
     gen.generate_resource_at_path(TEST_SITE.child('content/about.html'))
     about = File(Folder(site.config.deploy_root_path).child('about.html'))
     assert not about.exists
Exemplo n.º 17
0
 def test_simple_copy_directory(self):
     self.setup_config(["**/*.html"])
     s = Site(self.SITE_PATH, config=self.config)
     s.load()
     res = s.content.resource_from_relative_path("about.html")
     assert res
     assert not res.simple_copy
     res = s.content.resource_from_relative_path("blog/2010/december/merry-christmas.html")
     assert res
     assert res.simple_copy
Exemplo n.º 18
0
 def test_generate_resource_from_path(self):
     site = Site(TEST_SITE)
     site.load()
     gen = Generator(site)
     gen.generate_resource_at_path(TEST_SITE.child('content/about.html'))
     about = File(Folder(site.config.deploy_root_path).child('about.html'))
     assert about.exists
     text = about.read_all()
     q = PyQuery(text)
     assert about.name in q("div#main").text()
Exemplo n.º 19
0
    def test_context_providers_equivalence(self):
        import yaml
        events = """
    2011:
        -
            title: "one event"
            location: "a city"
        -
            title: "one event"
            location: "a city"

    2010:
        -
            title: "one event"
            location: "a city"
        -
            title: "one event"
            location: "a city"
"""
        events_dict = yaml.load(events)
        config_dict = dict(context=dict(
            data=dict(events1=events_dict),
            providers=dict(events2="events.yaml")
        ))
        text = """
{%% extends "base.html" %%}

{%% block main %%}
    <ul>
    {%% for year, eventlist in %s %%}
        <li>
            <h1>{{ year }}</h1>
            <ul>
                {%% for event in eventlist %%}
                <li>{{ event.title }}-{{ event.location }}</li>
                {%% endfor %%}
            </ul>
        </li>
    {%% endfor %%}
    </ul>
{%% endblock %%}
"""

        File(TEST_SITE.child('events.yaml')).write(events)
        f1 = File(TEST_SITE.child('content/text1.html'))
        f2 = File(TEST_SITE.child('content/text2.html'))
        f1.write(text % "events1")
        f2.write(text % "events2")
        site = Site(TEST_SITE, Config(TEST_SITE, config_dict=config_dict))
        site.load()
        gen = Generator(site)
        gen.generate_all()
        left = File(site.config.deploy_root_path.child(f1.name)).read_all()
        right = File(site.config.deploy_root_path.child(f2.name)).read_all()
        assert left == right
Exemplo n.º 20
0
    def test_context_providers_equivalence(self):
        import yaml
        events = """
    2011:
        -
            title: "one event"
            location: "a city"
        -
            title: "one event"
            location: "a city"

    2010:
        -
            title: "one event"
            location: "a city"
        -
            title: "one event"
            location: "a city"
"""
        events_dict = yaml.load(events, Loader=yaml.FullLoader)
        config_dict = dict(context=dict(
            data=dict(events1=events_dict),
            providers=dict(events2="events.yaml")
        ))
        text = """
{%% extends "base.html" %%}

{%% block main %%}
    <ul>
    {%% for year, eventlist in %s %%}
        <li>
            <h1>{{ year }}</h1>
            <ul>
                {%% for event in eventlist %%}
                <li>{{ event.title }}-{{ event.location }}</li>
                {%% endfor %%}
            </ul>
        </li>
    {%% endfor %%}
    </ul>
{%% endblock %%}
"""

        File(TEST_SITE.child('events.yaml')).write(events)
        f1 = File(TEST_SITE.child('content/text1.html'))
        f2 = File(TEST_SITE.child('content/text2.html'))
        f1.write(text % "events1")
        f2.write(text % "events2")
        site = Site(TEST_SITE, Config(TEST_SITE, config_dict=config_dict))
        site.load()
        gen = Generator(site)
        gen.generate_all()
        left = File(site.config.deploy_root_path.child(f1.name)).read_all()
        right = File(site.config.deploy_root_path.child(f2.name)).read_all()
        assert left == right
Exemplo n.º 21
0
 def test_config_ignore(self):
     s = Site(self.SITE_PATH, config=self.config)
     s.load()
     path = 'apple-touch-icon.png'
     resource = s.content.resource_from_relative_path(path)
     assert resource
     assert resource.full_url ==  "/" + path
     s = Site(self.SITE_PATH, config=self.config)
     s.config.ignore.append('*.png')
     resource = s.content.resource_from_relative_path(path)
     assert not resource
Exemplo n.º 22
0
def test_get_resource_from_relative_deploy_path():
    s = Site(TEST_SITE_ROOT)
    s.load()
    path = 'blog/2010/december'
    node = s.content.node_from_relative_path(path)
    resource = node.get_resource('merry-christmas.html')
    assert resource == s.content.resource_from_relative_deploy_path(
        Folder(path).child('merry-christmas.html'))
    resource.relative_deploy_path = Folder(path).child('merry-christmas.php')
    assert resource == s.content.resource_from_relative_deploy_path(
        Folder(path).child('merry-christmas.php'))
Exemplo n.º 23
0
def test_relative_deploy_path_override():
    s = Site(TEST_SITE_ROOT)
    s.load()
    res = s.content.resource_from_relative_path(
        'blog/2010/december/merry-christmas.html')
    res.relative_deploy_path = 'blog/2010/december/happy-holidays.html'
    for page in s.content.walk_resources():
        if res.source_file == page.source_file:
            assert page.relative_deploy_path == 'blog/2010/december/happy-holidays.html'
        else:
            assert page.relative_deploy_path == Folder(page.relative_path)
Exemplo n.º 24
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
Exemplo n.º 25
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
Exemplo n.º 26
0
 def test_simple_copy_directory(self):
     self.setup_config(['**/*.html'])
     s = Site(self.SITE_PATH, config=self.config)
     s.load()
     res = s.content.resource_from_relative_path('about.html')
     assert res
     assert not res.simple_copy
     res = s.content.resource_from_relative_path(
         'blog/2010/december/merry-christmas.html')
     assert res
     assert res.simple_copy
Exemplo n.º 27
0
 def test_load_with_config(self):
     s = Site(self.SITE_PATH, config=self.config)
     s.load()
     path = 'blog/2010/december'
     node = s.content.node_from_relative_path(path)
     assert node
     assert Folder(node.relative_path) == Folder(path)
     path += '/merry-christmas.html'
     resource = s.content.resource_from_relative_path(path)
     assert resource
     assert resource.relative_path == path
     assert not s.content.resource_from_relative_path('/happy-festivus.html')
Exemplo n.º 28
0
 def test_load_with_config(self):
     s = Site(self.SITE_PATH, config=self.config)
     s.load()
     path = 'blog/2010/december'
     node = s.content.node_from_relative_path(path)
     assert node
     assert Folder(node.relative_path) == Folder(path)
     path += '/merry-christmas.html'
     resource = s.content.resource_from_relative_path(path)
     assert resource
     assert resource.relative_path == path
     assert not s.content.resource_from_relative_path('/happy-festivus.html')
Exemplo n.º 29
0
def test_load():
    s = Site(TEST_SITE_ROOT)
    s.load()
    path = 'blog/2010/december'
    node = s.content.node_from_relative_path(path)
    assert node
    assert Folder(node.relative_path) == Folder(path)
    path += '/merry-christmas.html'
    resource = s.content.resource_from_relative_path(path)
    assert resource
    assert resource.relative_path == path
    assert not s.content.resource_from_relative_path('/happy-festivus.html')
Exemplo n.º 30
0
def test_load():
    s = Site(TEST_SITE_ROOT)
    s.load()
    path = 'blog/2010/december'
    node = s.content.node_from_relative_path(path)
    assert node
    assert Folder(node.relative_path) == Folder(path)
    path += '/merry-christmas.html'
    resource = s.content.resource_from_relative_path(path)
    assert resource
    assert resource.relative_path == path
    assert not s.content.resource_from_relative_path('/happy-festivus.html')
Exemplo n.º 31
0
 def test_generate_resource_from_path_with_uses_template_false(self):
     site = Site(TEST_SITE)
     site.load()
     resource = site.content.resource_from_path(TEST_SITE.child('content/about.html'))
     resource.uses_template = False
     gen = Generator(site)
     gen.generate_resource_at_path(TEST_SITE.child('content/about.html'))
     about = File(Folder(site.config.deploy_root_path).child('about.html'))
     assert about.exists
     text = about.read_all()
     expected = resource.source_file.read_all()
     assert text == expected
Exemplo n.º 32
0
def test_walk_resources():
    s = Site(TEST_SITE_ROOT)
    s.load()
    pages = [page.name for page in s.content.walk_resources()]
    expected = [
        "404.html", "about.html", "apple-touch-icon.png",
        "merry-christmas.html", "crossdomain.xml", "favicon.ico", "robots.txt",
        "site.css"
    ]
    pages.sort()
    expected.sort()
    assert pages == expected
Exemplo n.º 33
0
 def test_generate_resource_from_path_with_uses_template_false(self):
     site = Site(TEST_SITE)
     site.load()
     resource = site.content.resource_from_path(
         TEST_SITE.child('content/about.html'))
     resource.uses_template = False
     gen = Generator(site)
     gen.generate_resource_at_path(TEST_SITE.child('content/about.html'))
     about = File(Folder(site.config.deploy_root_path).child('about.html'))
     assert about.exists
     text = about.read_all()
     expected = resource.source_file.read_all()
     assert text == expected
Exemplo n.º 34
0
 def make_site(self, sitepath, config, deploy=None):
     """
     Creates a site object from the given sitepath and the config file.
     """
     config = Config(sitepath, config_file=config)
     config.deploy_root = deploy or Path(sitepath) / "deploy_gopher"
     site = Site(sitepath, config)
     site.context['site'] = site
     site.config.layout_root = getattr(
         site.config, "gopher_layout_root", "layout_gopher"
     )
     site.config.gopher_width = getattr(site.config, "gopher_width", 70)
     return site
Exemplo n.º 35
0
    def test_cant_find_depends_with_reference_tag_var(self):
        site = Site(TEST_SITE)
        JINJA2.copy_contents_to(site.content.source)
        inc = File(TEST_SITE.child('content/inc.md'))
        inc.write("{% set ind = 'index.html' %}{% refer to ind as index %}")
        site.load()
        gen = Generator(site)
        gen.load_template_if_needed()
        t = gen.template
        deps = list(t.get_dependencies('inc.md'))

        assert len(deps) == 1

        assert not deps[0]
Exemplo n.º 36
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>'
Exemplo n.º 37
0
    def test_cant_find_depends_with_reference_tag_var(self):
        site = Site(TEST_SITE)
        JINJA2.copy_contents_to(site.content.source)
        inc = File(TEST_SITE.child('content/inc.md'))
        inc.write("{% set ind = 'index.html' %}{% refer to ind as index %}")
        site.load()
        gen = Generator(site)
        gen.load_template_if_needed()
        t = gen.template
        deps = list(t.get_dependencies('inc.md'))

        assert len(deps) == 1

        assert not deps[0]
Exemplo n.º 38
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>'
Exemplo n.º 39
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
Exemplo n.º 40
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
Exemplo n.º 41
0
    def test_context_providers(self):
        site = Site(
            TEST_SITE,
            Config(TEST_SITE,
                   config_dict={
                       "context": {
                           "data": {
                               "abc": "def"
                           },
                           "providers": {
                               "nav": "nav.yaml"
                           }
                       }
                   }))
        nav = """
main:
    - home
    - articles
    - projects
"""
        text = """
{% extends "base.html" %}

{% block main %}
    {{nav}}
    {% for item in nav.main %}
    {{item}}
    {% endfor %}
    abc = {{ abc }}
    Hi!

    I am a test template to make sure jinja2 generation works well with hyde.
    {{resource.name}}
{% endblock %}
"""
        File(TEST_SITE.child('nav.yaml')).write(nav)
        site.load()
        resource = site.content.resource_from_path(
            TEST_SITE.child('content/about.html'))
        gen = Generator(site)
        resource.source_file.write(text)
        gen.generate_all()
        target = File(site.config.deploy_root_path.child(resource.name))
        out = target.read_all()
        assert "abc = def" in out
        assert "home" in out
        assert "articles" in out
        assert "projects" in out
Exemplo n.º 42
0
    def test_textlinks(self):
        d = {
            'objects': 'template/variables',
            'plugins': 'plugins/metadata',
            'sorter': 'plugins/sorter'
        }
        text = """
{%% markdown %%}
[[!!img/hyde-logo.png]]
*   [Rich object model][hyde objects] and
    [overridable hierarchical metadata]([[ %(plugins)s ]]) thats available
    for use in templates.
*   Configurable [sorting][], filtering and grouping support.

[hyde objects]: [[ %(objects)s ]]
[sorting]: [[%(sorter)s]]
{%% endmarkdown %%}
"""
        site = Site(TEST_SITE)
        site.config.plugins = ['hyde.ext.plugins.text.TextlinksPlugin']
        site.config.base_url = 'http://example.com/'
        site.config.media_url = '/media'
        tlink = File(site.content.source_folder.child('tlink.html'))
        tlink.write(text % d)
        print((tlink.read_all()))
        gen = Generator(site)
        gen.generate_all()
        f = File(site.config.deploy_root_path.child(tlink.name))
        assert f.exists
        html = f.read_all()
        assert html
        for name, path in list(d.items()):

            assert site.config.base_url + quote(path) in html
        assert '/media/img/hyde-logo.png' in html
Exemplo n.º 43
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
Exemplo n.º 44
0
    def test_depends_with_reference_tag(self):
        site = Site(TEST_SITE)
        JINJA2.copy_contents_to(site.content.source)
        inc = File(TEST_SITE.child('content/inc.md'))
        inc.write("{% refer to 'index.html' as index%}")
        site.load()
        gen = Generator(site)
        gen.load_template_if_needed()
        t = gen.template
        deps = list(t.get_dependencies('inc.md'))

        assert len(deps) == 3

        assert 'helpers.html' in deps
        assert 'layout.html' in deps
        assert 'index.html' in deps
Exemplo n.º 45
0
def test_walk_resources():
    s = Site(TEST_SITE_ROOT)
    s.load()
    pages = [page.name for page in s.content.walk_resources()]
    expected = ["404.html",
                "about.html",
                "apple-touch-icon.png",
                "merry-christmas.html",
                "crossdomain.xml",
                "favicon.ico",
                "robots.txt",
                "site.css"
                ]
    pages.sort()
    expected.sort()
    assert pages == expected
Exemplo n.º 46
0
 def test_simple_copy_multiple(self):
     self.setup_config([
         '**/*.html',
         'media/css/*.css'
     ])
     s = Site(self.SITE_PATH, config=self.config)
     s.load()
     res = s.content.resource_from_relative_path('about.html')
     assert res
     assert not res.simple_copy
     res = s.content.resource_from_relative_path('blog/2010/december/merry-christmas.html')
     assert res
     assert res.simple_copy
     res = s.content.resource_from_relative_path('media/css/site.css')
     assert res
     assert res.simple_copy
Exemplo n.º 47
0
    def test_depends(self):
        s = Site(TEST_SITE)
        s.config.plugins = [
            'hyde.ext.plugins.meta.MetaPlugin',
            'hyde.ext.plugins.depends.DependsPlugin'
        ]
        text = """
===
depends: index.html
===

"""
        inc = File(TEST_SITE.child('content/inc.md'))
        inc.write(text)
        gen = Generator(s)
        gen.load_site_if_needed()
        gen.load_template_if_needed()

        def dateformat(x):
            return x.strftime('%Y-%m-%d')

        gen.template.env.filters['dateformat'] = dateformat
        gen.generate_resource_at_path(inc.name)
        res = s.content.resource_from_relative_path(inc.name)
        assert len(res.depends) == 1
        assert 'index.html' in res.depends
        deps = list(gen.get_dependencies(res))
        assert len(deps) == 3

        assert 'helpers.html' in deps
        assert 'layout.html' in deps
        assert 'index.html' in deps
Exemplo n.º 48
0
    def test_plugins(self):

        text = """
---
title: Hey
author: Me
twitter: @me
---
{%% extends "base.html" %%}

{%% block main %%}
    Hi!

    I am a test template to make sure jinja2 generation works well with hyde.
    <span class="title">{{resource.meta.title}}</span>
    <span class="author">{{resource.meta.author}}</span>
    <span class="twitter">{{resource.meta.twitter}}</span>
{%% endblock %%}
"""
        index = File(self.SITE_PATH.child('content/blog/index.html'))
        index.write(text)
        self.setup_config(['**/*.html', 'media/css/*.css'])
        conf = {'plugins': ['hyde.ext.plugins.meta.MetaPlugin']}
        conf.update(self.config.to_dict())
        s = Site(self.SITE_PATH,
                 Config(sitepath=self.SITE_PATH, config_dict=conf))
        g = Generator(s)
        g.generate_all()
        source = s.content.resource_from_relative_path('blog/index.html')
        target = File(
            s.config.deploy_root_path.child(source.relative_deploy_path))
        left = source.source_file.read_all()
        right = target.read_all()
        assert left == right
Exemplo n.º 49
0
    def test_can_compress_with_stylus(self):
        s = Site(TEST_SITE)
        s.config.mode = "production"
        s.config.plugins = ['hyde.ext.plugins.stylus.StylusPlugin']
        paths = [
            '/usr/local/share/npm/bin/stylus', '~/local/bin/stylus',
            '~/bin/stylus'
        ]
        stylus = [path for path in paths if File(path).exists]
        if not stylus:
            assert False, "Cannot find the stylus executable"

        stylus = stylus[0]
        s.config.stylus = Expando(dict(app=stylus))
        source = TEST_SITE.child('content/media/css/site.styl')
        target = File(
            Folder(s.config.deploy_root_path).child('media/css/site.css'))
        gen = Generator(s)
        gen.generate_resource_at_path(source)

        assert target.exists
        text = target.read_all()
        expected_text = File(
            STYLUS_SOURCE.child('expected-site-compressed.css')).read_all()
        assert text.strip() == expected_text.strip()
Exemplo n.º 50
0
    def test_depends_with_reference_tag(self):
        site = Site(TEST_SITE)
        JINJA2.copy_contents_to(site.content.source)
        inc = File(TEST_SITE.child('content/inc.md'))
        inc.write("{% refer to 'index.html' as index%}")
        site.load()
        gen = Generator(site)
        gen.load_template_if_needed()
        t = gen.template
        deps = list(t.get_dependencies('inc.md'))

        assert len(deps) == 3

        assert 'helpers.html' in deps
        assert 'layout.html' in deps
        assert 'index.html' in deps
Exemplo n.º 51
0
 def setUp(self):
     TEST_SITE.make()
     TEST_SITE.parent.child_folder(
                 'sites/test_jinja').copy_contents_to(TEST_SITE)
     IMAGES = TEST_SITE.child_folder('content/media/img')
     IMAGES.make()
     IMAGE_SOURCE.copy_contents_to(IMAGES)
     self.site = Site(TEST_SITE)
Exemplo n.º 52
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
Exemplo n.º 53
0
 def make_site(self, sitepath, config, deploy=None):
     """
     Creates a site object from the given sitepath and the config file.
     """
     config = Config(sitepath, config_file=config)
     if deploy:
         config.deploy_root = deploy
     return Site(sitepath, config)
Exemplo n.º 54
0
def assert_markdown_typogrify_processed_well(include_text, includer_text):
    site = Site(TEST_SITE)
    site.config.plugins = ['hyde.ext.plugins.meta.MetaPlugin']
    inc = File(TEST_SITE.child('content/inc.md'))
    inc.write(include_text)
    site.load()
    gen = Generator(site)
    gen.load_template_if_needed()
    template = gen.template
    html = template.render(includer_text, {}).strip()
    assert html
    q = PyQuery(html)
    assert "is_processable" not in html
    assert "This is a" in q("h1").text()
    assert "heading" in q("h1").text()
    assert q(".amp").length == 1
    return html
Exemplo n.º 55
0
def test_node_module():
    s = Site(TEST_SITE_ROOT)
    r = RootNode(TEST_SITE_ROOT.child_folder('content'), s)
    assert not r.module
    n = r.add_node(TEST_SITE_ROOT.child_folder('content/blog'))
    assert n.module == n
    c = r.add_node(TEST_SITE_ROOT.child_folder('content/blog/2010/december'))
    assert c.module == n
Exemplo n.º 56
0
def assert_markdown_typogrify_processed_well(include_text, includer_text):
    site = Site(TEST_SITE)
    site.config.plugins = ['hyde.ext.plugins.meta.MetaPlugin']
    inc = File(TEST_SITE.child('content/inc.md'))
    inc.write(include_text)
    site.load()
    gen = Generator(site)
    gen.load_template_if_needed()
    template = gen.template
    html = template.render(includer_text, {}).strip()
    assert html
    q = PyQuery(html)
    assert "is_processable" not in html
    assert "This is a" in q("h1").text()
    assert "heading" in q("h1").text()
    assert q(".amp").length == 1
    return html
Exemplo n.º 57
0
def test_node_relative_path():
    s = Site(TEST_SITE_ROOT)
    r = RootNode(TEST_SITE_ROOT.child_folder('content'), s)
    assert not r.module
    n = r.add_node(TEST_SITE_ROOT.child_folder('content/blog'))
    assert n.relative_path == 'blog'
    c = r.add_node(TEST_SITE_ROOT.child_folder('content/blog/2010/december'))
    assert c.relative_path == 'blog/2010/december'
Exemplo n.º 58
0
    def test_multiple_levels(self):

        page_d = {'title': 'An even nicer title'}

        blog_d = {'author': 'Laks'}

        content_d = {'title': 'A nice title', 'author': 'Lakshmi Vyas'}

        site_d = {
            'author': 'Lakshmi',
            'twitter': 'lakshmivyas',
            'nodemeta': 'meta.yaml'
        }
        text = """
---
title: %(title)s
---
{%% extends "base.html" %%}

{%% block main %%}
    Hi!

    I am a test template to make sure jinja2 generation works well with hyde.
    <span class="title">{{resource.meta.title}}</span>
    <span class="author">{{resource.meta.author}}</span>
    <span class="twitter">{{resource.meta.twitter}}</span>
{%% endblock %%}
"""
        about2 = File(TEST_SITE.child('content/blog/about2.html'))
        about2.write(text % page_d)
        content_meta = File(TEST_SITE.child('content/nodemeta.yaml'))
        content_meta.write(yaml.dump(content_d))
        content_meta = File(TEST_SITE.child('content/blog/meta.yaml'))
        content_meta.write(yaml.dump(blog_d))
        s = Site(TEST_SITE)
        s.config.plugins = ['hyde.ext.plugins.meta.MetaPlugin']
        s.config.meta = site_d
        gen = Generator(s)
        gen.generate_all()
        expected = {}

        expected.update(site_d)
        expected.update(content_d)
        expected.update(blog_d)
        expected.update(page_d)

        res = s.content.resource_from_path(about2.path)
        assert hasattr(res, 'meta')
        for k, v in list(expected.items()):
            assert hasattr(res.meta, k)
            assert getattr(res.meta, k) == v
        target = File(
            Folder(s.config.deploy_root_path).child('blog/about2.html'))
        text = target.read_all()
        q = PyQuery(text)
        for k, v in list(expected.items()):
            if k != 'nodemeta':
                assert v in q("span." + k).text()