Exemplo n.º 1
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.º 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))
           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.º 3
0
    def __generate_resource__(self, resource):
        if not resource.is_processable:
            logger.debug("Skipping [%s]", resource)
            return
        logger.debug("Processing [%s]", resource)
        with self.context_for_resource(resource) as context:
            if resource.source_file.is_text:
                text = resource.source_file.read_all()
                text = self.events.begin_text_resource(resource, text) or text
                if resource.uses_template:
                    logger.debug("Rendering [%s]", resource)
                    try:
                        text = self.template.render(text, context)
                    except Exception:
                        logger.error("Error occurred when"
                            " processing template:[%s]" % resource)
                        raise

                text = self.events.text_resource_complete(
                                        resource, text) or text
                target = File(self.site.config.deploy_root_path.child(
                                    resource.relative_deploy_path))
                target.parent.make()
                target.write(text)
            else:
                logger.debug("Copying binary file [%s]", resource)
                self.events.begin_binary_resource(resource)
                target = File(self.site.config.deploy_root_path.child(
                                    resource.relative_deploy_path))
                target.parent.make()
                resource.source_file.copy_to(target)
                self.events.binary_resource_complete(resource)
Exemplo n.º 4
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.º 5
0
    def test_textlinks(self):
        d = {
            'objects': 'template/variables',
            'plugins': 'plugins/metadata',
            'sorter': 'plugins/sorter'
        }
        text = u"""
{%% 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.textlinks.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)
        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 d.items():
            assert quote(site.config.base_url + path) in html
        assert '/media/img/hyde-logo.png' in html
Exemplo n.º 6
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.º 7
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.º 8
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.º 9
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.º 10
0
    def _generate_site_with_meta(self, meta):
        self.site.config.mode = "production"
        self.site.config.plugins = ['hyde.ext.plugins.meta.MetaPlugin', 'hyde.ext.plugins.images.ImageThumbnailsPlugin']

        mlink = File(self.image_folder.child('meta.yaml'))
        meta_text = yaml.dump(meta, default_flow_style=False)
        mlink.write(meta_text)
        gen = Generator(self.site)
        gen.generate_all()
Exemplo n.º 11
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.º 12
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.º 13
0
 def _generic_test_image(self, text):
     self.site.config.mode = "production"
     self.site.config.plugins = ['hyde.ext.plugins.images.ImageSizerPlugin']
     tlink = File(self.site.content.source_folder.child('timg.html'))
     tlink.write(text)
     gen = Generator(self.site)
     gen.generate_all()
     f = File(self.site.config.deploy_root_path.child(tlink.name))
     assert f.exists
     html = f.read_all()
     assert html
     return html
Exemplo n.º 14
0
 def _generic_test_image(self, text):
     self.site.config.mode = "production"
     self.site.config.plugins = ['hyde.ext.plugins.images.ImageSizerPlugin']
     tlink = File(self.site.content.source_folder.child('timg.html'))
     tlink.write(text)
     gen = Generator(self.site)
     gen.generate_all()
     f = File(self.site.config.deploy_root_path.child(tlink.name))
     assert f.exists
     html = f.read_all()
     assert html
     return html
Exemplo n.º 15
0
 def assert_extended(self, s, txt, templ):
     content = (templ.strip() % txt).strip()
     bd = File(TEST_SITE.child('content/auto_extend.html'))
     bd.write(content)
     gen = Generator(s)
     gen.generate_resource_at_path(bd.path)
     res = s.content.resource_from_path(bd.path)
     target = File(s.config.deploy_root_path.child(
         res.relative_deploy_path))
     assert target.exists
     text = target.read_all()
     q = PyQuery(text)
     assert q('title').text().strip() == txt.strip()
Exemplo n.º 16
0
def test_can_remove_file():
    f = FS(__file__).parent
    c =  f.child_folder('__test__')
    c.make()
    assert c.exists
    txt = "abc"
    abc = File(c.child('abc.txt'))
    abc.write(txt)
    assert abc.exists
    abc.delete()
    assert not abc.exists
    abc.delete()
    assert True # No Exception
    c.delete()
Exemplo n.º 17
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.º 18
0
def test_can_remove_file():
    f = FS(__file__).parent
    c = f.child_folder('__test__')
    c.make()
    assert c.exists
    txt = "abc"
    abc = File(c.child('abc.txt'))
    abc.write(txt)
    assert abc.exists
    abc.delete()
    assert not abc.exists
    abc.delete()
    assert True  # No Exception
    c.delete()
Exemplo n.º 19
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.º 20
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.º 21
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.º 22
0
    def _create_tag_archive(self, config):
        """
        Generates archives for each tag based on the given configuration.
        """
        if not 'template' in config:
            raise self.template.exception_class(
                "No Template specified in tagger configuration.")
        content = self.site.content.source_folder
        source = Folder(config.get('source', ''))
        target = content.child_folder(config.get('target', 'tags'))
        if not target.exists:
            target.make()

        # Write meta data for the configuration
        meta = config.get('meta', {})
        meta_text = u''
        if meta:
            import yaml
            meta_text = yaml.dump(meta, default_flow_style=False)

        extension = config.get('extension', 'html')
        template = config['template']

        archive_text = u"""
---
extends: false
%(meta)s
---

{%% set tag = site.tagger.tags['%(tag)s'] %%}
{%% set source = site.content.node_from_relative_path('%(node)s') %%}
{%% set walker = source['walk_resources_tagged_with_%(tag_nospace)s'] %%}
{%% extends "%(template)s" %%}
"""
        for tagname, tag in self.site.tagger.tags.to_dict().iteritems():
            tag_data = {
                "tag": tagname,
                "tag_nospace": tagname.replace(' ','_'),
                "node": source.name,
                "template": template,
                "meta": meta_text
            }
            text = archive_text % tag_data
            archive_file = File(target.child("%s.%s" % (tagname, extension)))
            archive_file.delete()
            archive_file.write(text.strip())
            self.site.content.add_resource(archive_file)
Exemplo n.º 23
0
    def site_complete(self):
        """
        Generate archives.
        """

        content = self.site.content
        archive_config = None

        try:
            archive_config = attrgetter("tagger.archives")(self.site.config)
        except AttributeError:
            return

        self.logger.debug("Generating archives for tags")

        for name, config in archive_config.to_dict().iteritems():

            if not 'template' in config:
                raise self.template.exception_class(
                    "No Template sepecified in tagger configuration.")
            source = content.node_from_relative_path(config.get('source', ''))
            target = self.site.config.deploy_root_path.child_folder(
                            config.get('target', 'tags'))
            extension = config.get('extension', 'html')

            if not target.exists:
                target.make()

            template = config['template']
            text = "{%% extends \"%s\" %%}" % template

            for tagname, tag in self.site.tagger.tags.to_dict().iteritems():
                context = {}
                context.update(self.site.context)
                context.update(dict(
                                    time_now=datetime.now(),
                                    site=self.site,
                                    node=source,
                                    tag=tag,
                                    walker=getattr(source,
                                        "walk_resources_tagged_with_%s" % tagname)
                                ))
                archive_text = self.template.render(text, context)
                archive_file = File(target.child("%s.%s" % (tagname, extension)
                    if extension is not None else tagname))
                archive_file.write(archive_text)
Exemplo n.º 24
0
    def __generate_resource__(self, resource, incremental=False):
        self.refresh_config()
        if not resource.is_processable:
            logger.debug("Skipping [%s]", resource)
            return
        if incremental and not self.has_resource_changed(resource):
            logger.debug("No changes found. Skipping resource [%s]", resource)
            return
        logger.debug("Processing [%s]", resource)
        with self.context_for_resource(resource) as context:
            if resource.simple_copy:
                target = File(self.site.config.deploy_root_path.child(
                    resource.relative_deploy_path))
                target.parent.make()
                logger.debug("Simply Copying [%s]", resource)
                resource.source_file.copy_to(target)
            elif resource.source_file.is_text:
                self.update_deps(resource)
                if resource.uses_template:
                    logger.debug("Rendering [%s]", resource)
                    try:
                        text = self.template.render_resource(resource,
                                        context)
                    except Exception:
                        logger.error("Error occurred when"
                            " processing template: [%s]" % resource)
                        raise
                else:
                    text = resource.source_file.read_all()
                    text = self.events.begin_text_resource(resource, text) or text

                text = self.events.text_resource_complete(
                                        resource, text) or text
                target = File(self.site.config.deploy_root_path.child(
                    resource.relative_deploy_path))
                target.parent.make()
                target.write(text)
                copymode(resource.source_file.path, target.path)
            else:
                target = File(self.site.config.deploy_root_path.child(
                    resource.relative_deploy_path))
                target.parent.make()
                logger.debug("Copying binary file [%s]", resource)
                self.events.begin_binary_resource(resource)
                resource.source_file.copy_to(target)
                self.events.binary_resource_complete(resource)
Exemplo n.º 25
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.º 26
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.º 27
0
    def _create_tag_archive(self, config):
        """
        Generates archives for each tag based on the given configuration.
        """
        if not 'template' in config:
            raise self.template.exception_class(
                "No Template specified in tagger configuration.")
        content = self.site.content.source_folder
        source = Folder(config.get('source', ''))
        target = content.child_folder(config.get('target', 'tags'))
        if not target.exists:
            target.make()

        # Write meta data for the configuration
        meta = config.get('meta', {})
        meta_text = u''
        if meta:
            import yaml
            meta_text = yaml.dump(meta, default_flow_style=False)

        extension = config.get('extension', 'html')
        template = config['template']

        archive_text = u"""
---
extends: false
%(meta)s
---

{%% set tag = site.tagger.tags['%(tag)s'] %%}
{%% set source = site.content.node_from_relative_path('%(node)s') %%}
{%% set walker = source['walk_resources_tagged_with_%(tag)s'] %%}
{%% extends "%(template)s" %%}
"""
        for tagname, tag in self.site.tagger.tags.to_dict().iteritems():
            tag_data = {
                "tag": tagname,
                "node": source.name,
                "template": template,
                "meta": meta_text
            }
            text = archive_text % tag_data
            archive_file = File(target.child("%s.%s" % (tagname, extension)))
            archive_file.delete()
            archive_file.write(text.strip())
            self.site.content.add_resource(archive_file)
Exemplo n.º 28
0
    def _create_group_archive(self, config,groupname):
        """
        Generates archives for each tag based on the given configuration.
        """
        if not 'template' in config:
            raise self.template.exception_class(
                "No Template specified in grouper configuration.")
        content = self.site.content.source_folder
        source = Folder(config.get('source', ''))
        target = content.child_folder(config.get('target', 'groups'))
        if not target.exists:
            target.make()

        # Write meta data for the configuration
        meta = config.get('meta', {})
        meta_text = u''
        if meta:
            import yaml
            meta_text = yaml.dump(meta, default_flow_style=False)

        extension = config.get('extension', 'html')
        template = config['template']

        archive_text = u"""
---
extends: false
%(meta)s
---

{%% set tag = site.groups_index['%(group)s'] %%}
{%% set source = site.content.node_from_relative_path('%(node)s') %%}
{%% set walker = source.walk_resources_grouped_by_%(group)s %%}
{%% extends "%(template)s" %%}
"""

        group_data = {
            "group": groupname,
            "node": source.name,
            "template": template,
            "meta": meta_text
        }
        text = archive_text % group_data
        archive_file = File(target.child("%s.%s" % (groupname, extension)))
        archive_file.delete()
        archive_file.write(text.strip())
        self.site.content.add_resource(archive_file)
Exemplo n.º 29
0
    def test_two_level_refer_with_var(self):
        text = """
===
is_processable: False
===
<div class="fulltext">
{% filter markdown|typogrify %}
{% mark heading %}
This is a heading
=================
{% endmark %}
{% reference content %}
Hyde & Jinja.
{% endreference %}
{% endfilter %}
</div>
"""

        text2 = """
{% set super = 'super.md' %}
{% refer to super as sup %}
<div class="justhead">
{% mark child %}
{{ sup.heading }}
{% endmark %}
{% mark cont %}
{{ sup.content }}
{% endmark %}
</div>
"""
        text3 = """
{% set incu = 'inc.md' %}
{% refer to incu as inc %}
{% filter markdown|typogrify %}
{{ inc.child }}
{{ inc.cont }}
{% endfilter %}
"""

        superinc = File(TEST_SITE.child('content/super.md'))
        superinc.write(text)

        html = assert_markdown_typogrify_processed_well(text2, text3)
        assert "mark" not in html
        assert "reference" not in html
Exemplo n.º 30
0
    def site_complete(self):
        """
        Generate archives.
        """

        content = self.site.content
        archive_config = None

        try:
            archive_config = attrgetter("tagger.archives")(self.site.config)
        except AttributeError:
            return

        self.logger.debug("Generating archives for tags")

        for name, config in archive_config.to_dict().iteritems():

            if not 'template' in config:
                raise self.template.exception_class(
                    "No Template sepecified in tagger configuration.")
            source = content.node_from_relative_path(config.get('source', ''))
            target = self.site.config.deploy_root_path.child_folder(
                            config.get('target', 'tags'))
            extension = config.get('extension', 'html')

            if not target.exists:
                target.make()

            template = config['template']
            text = "{%% extends \"%s\" %%}" % template

            for tag, resources in self.site.tagger.tags.to_dict().iteritems():
                context = {}
                context.update(self.site.context)
                context.update(dict(
                                    time_now=datetime.now(),
                                    site=self.site,
                                    node=source,
                                    tag=tag,
                                    walker=getattr(source,
                                        "walk_resources_tagged_with_%s" % tag)
                                ))
                archive_text = self.template.render(text, context)
                archive_file = File(target.child("%s.%s" % (tag, extension)))
                archive_file.write(archive_text)
Exemplo n.º 31
0
    def test_two_level_refer_with_var(self):
        text = """
===
is_processable: False
===
<div class="fulltext">
{% filter markdown|typogrify %}
{% mark heading %}
This is a heading
=================
{% endmark %}
{% reference content %}
Hyde & Jinja.
{% endreference %}
{% endfilter %}
</div>
"""

        text2 = """
{% set super = 'super.md' %}
{% refer to super as sup %}
<div class="justhead">
{% mark child %}
{{ sup.heading }}
{% endmark %}
{% mark cont %}
{{ sup.content }}
{% endmark %}
</div>
"""
        text3 = """
{% set incu = 'inc.md' %}
{% refer to incu as inc %}
{% filter markdown|typogrify %}
{{ inc.child }}
{{ inc.cont }}
{% endfilter %}
"""

        superinc = File(TEST_SITE.child('content/super.md'))
        superinc.write(text)

        html = assert_markdown_typogrify_processed_well(text2, text3)
        assert "mark" not in html
        assert "reference" not in html
Exemplo n.º 32
0
    def test_can_load_from_site_meta(self):
        d = {'title': 'A nice title',
            'author': 'Lakshmi Vyas'}
        text = """
---
title: Even nicer title
---
{%% 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/about2.html'))
        about2.write(text % d)
        meta = File(TEST_SITE.child('content/nodemeta.yaml'))
        meta.write(yaml.dump(d))
        s = Site(TEST_SITE)
        s.config.plugins = ['hyde.ext.plugins.meta.MetaPlugin']
        s.config.meta = {
            'author': 'Lakshmi',
            'twitter': 'lakshmivyas'
        }
        gen = Generator(s)
        gen.generate_all()
        res = s.content.resource_from_path(about2.path)
        assert hasattr(res, 'meta')
        assert hasattr(res.meta, 'title')
        assert hasattr(res.meta, 'author')
        assert hasattr(res.meta, 'twitter')
        assert res.meta.title == "Even nicer title"
        assert res.meta.author == "Lakshmi Vyas"
        assert res.meta.twitter == "lakshmivyas"
        target = File(Folder(s.config.deploy_root_path).child('about2.html'))
        text = target.read_all()
        q = PyQuery(text)
        for k, v in d.items():
            if not k == 'title':
                assert v in q("span." + k).text()
        assert q("span.title").text() == "Even nicer title"
Exemplo n.º 33
0
    def test_can_load_from_site_meta(self):
        d = {'title': 'A nice title',
            'author': 'Lakshmi Vyas'}
        text = """
---
title: Even nicer title
---
{%% 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/about2.html'))
        about2.write(text % d)
        meta = File(TEST_SITE.child('content/nodemeta.yaml'))
        meta.write(yaml.dump(d))
        s = Site(TEST_SITE)
        s.config.plugins = ['hyde.ext.plugins.meta.MetaPlugin']
        s.config.meta = {
            'author': 'Lakshmi',
            'twitter': 'lakshmivyas'
        }
        gen = Generator(s)
        gen.generate_all()
        res = s.content.resource_from_path(about2.path)
        assert hasattr(res, 'meta')
        assert hasattr(res.meta, 'title')
        assert hasattr(res.meta, 'author')
        assert hasattr(res.meta, 'twitter')
        assert res.meta.title == "Even nicer title"
        assert res.meta.author == "Lakshmi Vyas"
        assert res.meta.twitter == "lakshmivyas"
        target = File(Folder(s.config.deploy_root_path).child('about2.html'))
        text = target.read_all()
        q = PyQuery(text)
        for k, v in d.items():
            if not k == 'title':
                assert v in q("span." + k).text()
        assert q("span.title").text() == "Even nicer title"
Exemplo n.º 34
0
 def test_has_resource_changed(self):
     site = Site(TEST_SITE)
     site.load()
     resource = site.content.resource_from_path(TEST_SITE.child('content/about.html'))
     gen = Generator(site)
     gen.generate_all()
     assert not gen.has_resource_changed(resource)
     import time
     time.sleep(1)
     text = resource.source_file.read_all()
     resource.source_file.write(text)
     assert gen.has_resource_changed(resource)
     gen.generate_all()
     assert not gen.has_resource_changed(resource)
     time.sleep(1)
     l = File(TEST_SITE.child('layout/root.html'))
     l.write(l.read_all())
     assert gen.has_resource_changed(resource)
Exemplo n.º 35
0
 def test_has_resource_changed(self):
     site = Site(TEST_SITE)
     site.load()
     resource = site.content.resource_from_path(
         TEST_SITE.child('content/about.html'))
     gen = Generator(site)
     gen.generate_all()
     assert not gen.has_resource_changed(resource)
     import time
     time.sleep(1)
     text = resource.source_file.read_all()
     resource.source_file.write(text)
     assert gen.has_resource_changed(resource)
     gen.generate_all()
     assert not gen.has_resource_changed(resource)
     time.sleep(1)
     l = File(TEST_SITE.child('layout/root.html'))
     l.write(l.read_all())
     assert gen.has_resource_changed(resource)
Exemplo n.º 36
0
    def __generate_resource__(self, resource, incremental=False):
        if not resource.is_processable:
            logger.debug("Skipping [%s]", resource)
            return
        if incremental and not self.has_resource_changed(resource):
            logger.debug("No changes found. Skipping resource [%s]", resource)
            return
        logger.debug("Processing [%s]", resource)
        with self.context_for_resource(resource) as context:
            if resource.source_file.is_text:
                self.update_deps(resource)
                if resource.uses_template:
                    logger.debug("Rendering [%s]", resource)
                    context = self.events.begin_render_resource(
                        resource, context) or context
                    try:
                        text = self.template.render_resource(resource, context)
                    except Exception:
                        logger.error("Error occurred when"
                                     " processing template: [%s]" % resource)
                        raise
                    self.events.render_resource_complete(resource, context)
                else:
                    text = resource.source_file.read_all()
                    text = self.events.begin_text_resource(resource,
                                                           text) or text

                text = self.events.text_resource_complete(resource,
                                                          text) or text
                target = File(
                    self.site.config.deploy_root_path.child(
                        resource.relative_deploy_path))
                target.parent.make()
                target.write(text)
            else:
                logger.debug("Copying binary file [%s]", resource)
                self.events.begin_binary_resource(resource)
                target = File(
                    self.site.config.deploy_root_path.child(
                        resource.relative_deploy_path))
                target.parent.make()
                resource.source_file.copy_to(target)
                self.events.binary_resource_complete(resource)
Exemplo n.º 37
0
    def test_can_set_standard_attributes(self):
        text = """
---
is_processable: False
---
{% extends "base.html" %}
"""
        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()
        assert not res.meta.is_processable
        assert not res.is_processable
Exemplo n.º 38
0
    def test_can_set_standard_attributes(self):
        text = """
---
is_processable: False
---
{% extends "base.html" %}
"""
        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()
        assert not res.meta.is_processable
        assert not res.is_processable
Exemplo n.º 39
0
class Dependents(IterableUserDict):
    """
    Represents the dependency graph for hyde.
    """
    def __init__(self, sitepath, depends_file_name='.hyde_deps'):
        self.sitepath = Folder(sitepath)
        self.deps_file = File(self.sitepath.child(depends_file_name))
        self.data = {}
        if self.deps_file.exists:
            self.data = yaml.load(self.deps_file.read_all())
        import atexit
        atexit.register(self.save)

    def save(self):
        """
        Saves the dependency graph (just a dict for now).
        """
        if self.deps_file.parent.exists:
            self.deps_file.write(yaml.dump(self.data))
Exemplo n.º 40
0
class Dependents(IterableUserDict):
    """
    Represents the dependency graph for hyde.
    """

    def __init__(self, sitepath, depends_file_name='.hyde_deps'):
        self.sitepath = Folder(sitepath)
        self.deps_file = File(self.sitepath.child(depends_file_name))
        self.data = {}
        if self.deps_file.exists:
            self.data = yaml.load(self.deps_file.read_all())
        import atexit
        atexit.register(self.save)

    def save(self):
        """
        Saves the dependency graph (just a dict for now).
        """
        if self.deps_file.parent.exists:
            self.deps_file.write(yaml.dump(self.data))
Exemplo n.º 41
0
    def test_can_parse_blockdown(self):
        s = Site(TEST_SITE)
        s.config.plugins = ['hyde.ext.plugins.blockdown.BlockdownPlugin']
        txt ="This template tests to make sure blocks can be replaced with markdownish syntax."
        templ = """
{%% extends "base.html" %%}
=====title========
%s
====/title========"""

        content = (templ.strip() % txt).strip()
        bd = File(TEST_SITE.child('content/blockdown.html'))
        bd.write(content)
        gen = Generator(s)
        gen.generate_resource_at_path(bd.path)
        res = s.content.resource_from_path(bd.path)
        target = File(s.config.deploy_root_path.child(res.relative_deploy_path))
        assert target.exists
        text = target.read_all()
        q = PyQuery(text)
        assert q('title').text().strip() == txt.strip()
Exemplo n.º 42
0
    def test_reference(self):
        text = u"""
===
is_processable: False
===
{% filter markdown|typogrify %}
§§ heading
This is a heading
=================
§§ /heading

§§ content
Hyde & Jinja
§§ /

{% endfilter %}
"""

        text2 = u"""
※ inc.md as inc
{% filter markdown|typogrify %}
{{ inc.heading }}
{{ inc.content }}
{% endfilter %}
"""
        site = Site(TEST_SITE)
        site.config.plugins = [
            'hyde.ext.plugins.meta.MetaPlugin',
            'hyde.ext.plugins.markings.MarkingsPlugin',
            'hyde.ext.plugins.markings.ReferencePlugin']
        inc = File(site.content.source_folder.child('inc.md'))
        inc.write(text.strip())
        src = File(site.content.source_folder.child('src.html'))
        src.write(text2.strip())
        gen = Generator(site)
        gen.generate_all()
        f = File(site.config.deploy_root_path.child(src.name))
        assert f.exists
        html = f.read_all()
        assert_valid_conversion(html)
Exemplo n.º 43
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.sorter.time(site.content)|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'
Exemplo n.º 44
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'
Exemplo n.º 45
0
    def test_syntext(self):
        text = u"""
~~~~~~~~css~~~~~~~
.body{
    background-color: white;
}
~~~~~~~~~~~~~~~~~~
"""
        site = Site(TEST_SITE)
        site.config.plugins = [
            'hyde.ext.plugins.meta.MetaPlugin',
            'hyde.ext.plugins.syntext.SyntextPlugin']
        syn = File(site.content.source_folder.child('syn.html'))
        syn.write(text)
        gen = Generator(site)
        gen.generate_all()
        f = File(site.config.deploy_root_path.child(syn.name))
        assert f.exists
        html = f.read_all()
        assert html
        q = PyQuery(html)
        assert q('figure.code').length == 1
Exemplo n.º 46
0
    def test_can_load_front_matter(self):
        d = {"title": "A nice title", "author": "Lakshmi Vyas", "twitter": "lakshmivyas"}
        text = """
---
title: %(title)s
author: %(author)s
twitter: %(twitter)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/about2.html"))
        about2.write(text % d)
        s = Site(TEST_SITE)
        s.config.plugins = ["hyde.ext.plugins.meta.MetaPlugin"]
        gen = Generator(s)
        gen.generate_all()
        res = s.content.resource_from_path(about2.path)

        assert hasattr(res, "meta")
        assert hasattr(res.meta, "title")
        assert hasattr(res.meta, "author")
        assert hasattr(res.meta, "twitter")
        assert res.meta.title == "A nice title"
        assert res.meta.author == "Lakshmi Vyas"
        assert res.meta.twitter == "lakshmivyas"
        target = File(Folder(s.config.deploy_root_path).child("about2.html"))
        text = target.read_all()
        q = PyQuery(text)
        for k, v in d.items():
            assert v in q("span." + k).text()
Exemplo n.º 47
0
    def test_mark(self):
        text = u"""
===
is_processable: False
===
{% filter markdown|typogrify %}
§§ heading
This is a heading
=================
§§ /heading

§§ content
Hyde & Jinja
§§ /

{% endfilter %}
"""

        text2 = """
{% refer to "inc.md" as inc %}
{% filter markdown|typogrify %}
{{ inc.heading }}
{{ inc.content }}
{% endfilter %}
"""
        site = Site(TEST_SITE)
        site.config.plugins = [
            'hyde.ext.plugins.meta.MetaPlugin',
            'hyde.ext.plugins.markings.MarkingsPlugin']
        inc = File(TEST_SITE.child('content/inc.md'))
        inc.write(text)
        site.load()
        gen = Generator(site)
        gen.load_template_if_needed()

        template = gen.template
        html = template.render(text2, {}).strip()
        assert_valid_conversion(html)
Exemplo n.º 48
0
    def test_syntext(self):
        text = u"""
~~~~~~~~css~~~~~~~
.body{
    background-color: white;
}
~~~~~~~~~~~~~~~~~~
"""
        site = Site(TEST_SITE)
        site.config.plugins = [
            'hyde.ext.plugins.meta.MetaPlugin',
            'hyde.ext.plugins.syntext.SyntextPlugin'
        ]
        syn = File(site.content.source_folder.child('syn.html'))
        syn.write(text)
        gen = Generator(site)
        gen.generate_all()
        f = File(site.config.deploy_root_path.child(syn.name))
        assert f.exists
        html = f.read_all()
        assert html
        q = PyQuery(html)
        assert q('figure.code').length == 1
Exemplo n.º 49
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 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 expected.items():
            if k != 'nodemeta':
                assert v in q("span." + k).text()
Exemplo n.º 50
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 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 expected.items():
            if k != 'nodemeta':
                assert v in q("span." + k).text()
Exemplo n.º 51
0
    def test_tagger_metadata(self):
        conf = {
            "tagger": {
                "sorter": "time",
                "archives": {
                    "blog": {
                        "template": "emotions.j2",
                        "source": "blog",
                        "target": "blog/tags",
                        "extension": "html",
                        "meta": {
                            "author": "Tagger Plugin"
                        }
                    }
                },
                "tags": {
                    "sad": {
                        "emotions": ["Dissappointed", "Lost"]
                    },
                    "angry": {
                        "emotions": ["Irritated", "Annoyed", "Disgusted"]
                    }
                }
            }
        }

        text = """
<div id="author">{{ resource.meta.author }}</div>
<h1>Posts tagged: {{ tag }} in {{ node.name|title }}</h1>
Emotions:
<ul>
{% for emotion in tag.emotions %}
<li class="emotion">
{{ emotion }}
</li>
{% endfor %}
<ul>
{% for resource in walker() -%}
<li>
<a href="{{ content_url(resource.url) }}">{{ resource.meta.title }}</a>
</li>
{%- endfor %}
</ul>
"""
        template = File(TEST_SITE.child('layout/emotions.j2'))
        template.write(text)
        s = Site(TEST_SITE)
        s.config.update(conf)
        gen = Generator(s)
        gen.load_site_if_needed()
        gen.generate_all()

        tags_folder = self.deploy.child_folder('blog/tags')
        assert tags_folder.exists
        tags = ['sad', 'happy', 'angry', 'thoughts', 'events']
        archives = dict(
            (tag, File(tags_folder.child("%s.html" % tag))) for tag in tags)

        for tag, archive in archives.items():
            assert archive.exists

        from pyquery import PyQuery

        q = PyQuery(archives['sad'].read_all())
        assert len(q("li.emotion")) == 2
        assert q("#author").text() == "Tagger Plugin"

        q = PyQuery(archives['angry'].read_all())
        assert len(q("li.emotion")) == 3

        for tag, archive in archives.items():
            if tag not in ["sad", "angry"]:
                q = PyQuery(archives[tag].read_all())
                assert not len(q("li.emotion"))
Exemplo n.º 52
0
    def test_tagger_metadata(self):
        conf = {
           "tagger":{
               "sorter": "time",
               "archives": {
                    "blog": {
                        "template": "emotions.j2",
                        "source": "blog",
                        "target": "blog/tags",
                        "extension": "html",
                        "meta": {
                            "author": "Tagger Plugin"
                        }
                    }
               },
               "tags": {
                   "sad" : {
                       "emotions": ["Dissappointed", "Lost"]
                   },
                   "angry": {
                       "emotions": ["Irritated", "Annoyed", "Disgusted"]
                   }
               }
           }
        }

        text = """
<div id="author">{{ resource.meta.author }}</div>
<h1>Posts tagged: {{ tag }} in {{ node.name|title }}</h1>
Emotions:
<ul>
{% for emotion in tag.emotions %}
<li class="emotion">
{{ emotion }}
</li>
{% endfor %}
<ul>
{% for resource in walker() -%}
<li>
<a href="{{ content_url(resource.url) }}">{{ resource.meta.title }}</a>
</li>
{%- endfor %}
</ul>
"""
        template = File(TEST_SITE.child('layout/emotions.j2'))
        template.write(text)
        s = Site(TEST_SITE)
        s.config.update(conf)
        gen = Generator(s)
        gen.load_site_if_needed()
        gen.generate_all()

        tags_folder = self.deploy.child_folder('blog/tags')
        assert tags_folder.exists
        tags = ['sad', 'happy', 'angry', 'thoughts', 'events']
        archives = dict((tag, File(tags_folder.child("%s.html" % tag))) for tag in tags)

        for tag, archive in archives.items():
            assert archive.exists

        from pyquery import PyQuery

        q = PyQuery(archives['sad'].read_all())
        assert len(q("li.emotion")) == 2
        assert q("#author").text() == "Tagger Plugin"

        q = PyQuery(archives['angry'].read_all())
        assert len(q("li.emotion")) == 3

        for tag, archive in archives.items():
            if tag not in ["sad", "angry"]:
                q = PyQuery(archives[tag].read_all())
                assert not len(q("li.emotion"))