Esempio n. 1
0
    def test_get_target(self):
        # Test basic case
        site = cli.Site('.')
        page = cli.Page("./content/this/file/does/not/exist.html", site)
        page.parse_metadata("")
        assert page.get_target() == "this/file/does/not/exist/index.html"
        assert page.url == "/this/file/does/not/exist/"

        # Test not html / markdown case
        page = cli.Page("./content/this/file/does/not/exist.css", site)
        page.parse_metadata("")
        assert page.get_target() == "this/file/does/not/exist.css"
        assert page.url == "/this/file/does/not/exist.css"

        # Test index case
        page = cli.Page("./content/this/file/does/not/index.md", site)
        page.parse_metadata("")
        assert page.get_target() == "this/file/does/not/index.html"
        assert page.url == "/this/file/does/not/"

        # Test customized slug case
        meta = """
slug = some-title
        """
        page = cli.Page("./content/this/file/does/not/exist.md", site)
        page.parse_metadata(meta)
        assert page._get_folder() == "this/file/does/not"
        assert page.get_target() == "this/file/does/not/some-title/index.html"
        assert page.url == "/this/file/does/not/some-title/"
Esempio n. 2
0
 def test_init(self):
     site = cli.Site('.')
     page = cli.Page("./content/this/file/does/not/exist.html", site)
     assert page.slug == "exist"
     assert page.folder == "this/file/does/not"
     assert page.ext == ".html"
     assert page.url == "/this/file/does/not/exist/"
Esempio n. 3
0
    def test_render(self):
        site = cli.Site(".")
        site.renderer = jinja2.Environment(loader=jinja2.DictLoader({
            "markdown.html": "MARKDOWN{{title}}{{content}}",
            "basic.html": "HTML{{content}}",
            "just.html": "Waka"
        }))

        page = cli.Page("filename.md", site)
        page.parse_metadata("title=My Title")
        page.body = "#This is awesome!"
        assert page.render() == "MARKDOWNMy Title<h1>This is awesome!</h1>"

        page.template = "basic.html"
        assert page.render() == "HTML<h1>This is awesome!</h1>"

        # This case is a bit odd. We don't actually use the page content we
        # parsed, we just let Jinja find the template on disk and render it
        # as-is. This is inconsistent from the markdown case, but works. There
        # may be some opportunity to clean up the API here and remove body or
        # content since only one is actually used.
        page = cli.Page("content/just.html", site)
        assert page.render() == "Waka"
Esempio n. 4
0
    def test_parse_metadata(self):
        meta = """
title = Some title
date = 2013-01-02
tags = pie cake chocolate
slug = some-title
template = myfile.html
        """

        site = cli.Site('.')
        page = cli.Page("./content/this/file/does/not/exist.html", site)
        page.parse_metadata(meta)

        assert page.title == "Some title"
        assert page.date == "2013-01-02"
        assert page.tags == ['pie', 'cake', 'chocolate']
        assert page.slug == "some-title"
        assert page.template == "myfile.html"
        assert page.url == "/this/file/does/not/some-title/"
Esempio n. 5
0
 def test_parse_checker(self):
     site = cli.Site('.')
     with pytest.raises(RuntimeError):
         page = cli.Page("./content/this/file/does/not/exist.html", site)
         page.get_target()