Ejemplo n.º 1
0
def render_site(site):
    """Renders every content object in the site."""

    renderer = Renderer(site.settings)
    dest = site.settings["site"]
    os.makedirs(dest, exist_ok=True)

    for page in site.pages:
        print(page.name)
        out = os.path.join(dest, page.url)
        args = {"page": page, "site": site, "settings": site.settings}
        renderer.render(out, page.templates, args)

    for category in site.categories:
        print(category.name)
        out = os.path.join(dest, category.url)
        args = {
            "category": category,
            "site": site,
            "settings": site.settings,
        }
        renderer.render(out, category.templates, args)

        for item in category.items:
            print(item.value)
            out = os.path.join(dest, item.url)
            args = {"item": item, "site": site, "settings": site.settings}
            renderer.render(out, item.templates, args)
Ejemplo n.º 2
0
    def test_canonify_media_img(self):
        img = '<img src="/relative/link/image.png"/>'
        string = "{{ img|canonify_media('https://www.example.org') }}"
        text = Renderer.render_from_string(string, {"img": img})
        expected = '<img src="https://www.example.org/relative/link/image.png"/>'

        assert text == expected
Ejemplo n.º 3
0
    def test_canonify_media_vid(self):
        vid = '<video src="/relative/link/video.webm"></video>'
        string = "{{ vid|canonify_media('https://www.example.org') }}"
        text = Renderer.render_from_string(string, {"vid": vid})
        expected = (
            '<video src="https://www.example.org/relative/link/video.webm"></video>'
        )

        assert text == expected
Ejemplo n.º 4
0
    def url(self):
        """Return the page URL.

        Page URLs can be overridden in the site config by specifying a
        URL override template for the section.

        """

        if self.section.override:
            template = self.section.override
        else:
            template = "{{ page.section.rel }}/{{ page|slug }}"

        args = {"page": self}
        return Renderer.render_from_string(template, args)
Ejemplo n.º 5
0
    def url(self):
        """Return the category item URL."""

        template = "{{ item.category.name }}/{{ item.value }}"
        args = {"item": self}
        return Renderer.render_from_string(template, args)
Ejemplo n.º 6
0
    def url(self):
        """Return the category URL."""

        template = "{{ category.name }}/index.html"
        args = {"category": self}
        return Renderer.render_from_string(template, args)
Ejemplo n.º 7
0
def renderer(shared_datadir):
    settings = {"templates": f"{shared_datadir}/templates"}

    return Renderer(settings)
Ejemplo n.º 8
0
    def test_render_from_string(self, page):
        string = "{{ page.name }}"
        text = Renderer.render_from_string(string, args={"page": page})

        assert text == "top_level_page"
Ejemplo n.º 9
0
    def test_canonify_already_canonical(self):
        url = "https://www.website.com/relative/link/image.png"
        string = "{{ url|canonify('https://www.example.org') }}"
        text = Renderer.render_from_string(string, {"url": url})

        assert text == url
Ejemplo n.º 10
0
    def test_canonify(self):
        url = "/relative/link/image.png"
        string = "{{ url|canonify('https://www.example.org') }}"
        text = Renderer.render_from_string(string, {"url": url})

        assert text == "https://www.example.org/relative/link/image.png"
Ejemplo n.º 11
0
    def test_date(self, page):
        string = "{{ page|date('%Y--%m--%d') }}"
        text = Renderer.render_from_string(string, {"page": page})

        assert text == "2013--04--15"
Ejemplo n.º 12
0
    def test_slug(self, page):
        string = "{{ page|slug }}"
        text = Renderer.render_from_string(string, {"page": page})

        assert text == "top"
Ejemplo n.º 13
0
    def test_isoformat(self):
        string = "{{ '2010/01/01'|datetime|isoformat }}"
        text = Renderer.render_from_string(string)

        assert text == "2010-01-01T00:00:00"
Ejemplo n.º 14
0
    def test_datetime(self):
        string = "{{ '2010/01/01'|datetime }}"
        text = Renderer.render_from_string(string)

        assert text == "2010-01-01 00:00:00"