Example #1
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.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 d.items():

            assert site.config.base_url + quote(path) in html
        assert '/media/img/hyde-logo.png' in html
Example #2
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
Example #3
0
    def test_can_uglify(self):
        s = Site(TEST_SITE)
        s.config.plugins = ['hyde.ext.plugins.js.UglifyPlugin']
        s.config.mode = "production"
        source = TEST_SITE.child('content/media/js/jquery.js')
        target = File(Folder(s.config.deploy_root_path).child('media/js/jquery.js'))
        gen = Generator(s)
        gen.generate_resource_at_path(source)

        assert target.exists
        expected = File(UGLIFY_SOURCE.child('expected-jquery.js'))
        # TODO: Very fragile. Better comparison needed.
        assert target.read_all() == expected.read_all()
Example #4
0
    def test_can_uglify(self):
        s = Site(TEST_SITE)
        s.config.plugins = ['hyde.ext.plugins.uglify.UglifyPlugin']
        s.config.mode = "production"
        source = TEST_SITE.child('content/media/js/jquery.js')
        target = File(Folder(s.config.deploy_root_path).child('media/js/jquery.js'))
        gen = Generator(s)
        gen.generate_resource_at_path(source)

        assert target.exists
        expected = File(UGLIFY_SOURCE.child('expected-jquery.js'))
        # TODO: Very fragile. Better comparison needed.
        assert target.read_all() == expected.read_all()
Example #5
0
    def load(sitepath, ctx):
        """
        Load context from config data and providers.
        """
        context = {}
        try:
            context.update(ctx.data.__dict__)
        except AttributeError:
            # No context data found
            pass

        providers = {}
        try:
            providers.update(ctx.providers.__dict__)
        except AttributeError:
            # No providers found
            pass

        for provider_name, resource_name in providers.items():
            res = File(Folder(sitepath).child(resource_name))
            if res.exists:
                data = make_expando(
                    yaml.load(res.read_all(), Loader=yaml.FullLoader))
                context[provider_name] = data

        return context
Example #6
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
Example #7
0
File: model.py Project: jiivan/hyde
    def load(sitepath, ctx):
        """
        Load context from config data and providers.
        """
        context = {}
        try:
            context.update(ctx.data.__dict__)
        except AttributeError:
            # No context data found
            pass

        providers = {}
        try:
            providers.update(ctx.providers.__dict__)
        except AttributeError:
            # No providers found
            pass

        for provider_name, resource_name in list(providers.items()):
            res = File(Folder(sitepath).child(resource_name))
            if res.exists:
                data = make_expando(yaml.load(res.read_all()))
                context[provider_name] = data

        return context
Example #8
0
def test_function_with_transform():

    from jinja2 import contextfunction

    @contextfunction
    def url(context, base):
        return base + "/" + context["project"] + "/" + context["version"] + "/"

    context = {"version": "5.0.1", "project": "yinja"}

    yaml_text = """
yinja:
    text: project
    text2: version
    url: {{ url ('http://example.com') }}
"""
    env = dict(globals=dict(url=url))
    target = TEMP.child_file("test_function_with_transform")
    target.delete()
    result_path = transform(yaml_text, target.path, context, jinja_env=env)
    assert result_path
    result_path = File(result_path)
    assert result_path.exists
    result = yaml.load(result_path.read_all())
    result = result["yinja"]
    assert result["text"] == "project"
    assert result["text2"] == "version"
    assert result["url"] == "http://example.com/yinja/5.0.1/"
Example #9
0
    def test_url_cleaner(self):
        s = Site(TEST_SITE)
        cfg = """
           plugins:
                - hyde.ext.plugins.urls.UrlCleanerPlugin
           urlcleaner:
                index_file_names:
                    - about.html
                strip_extensions:
                    - html
                append_slash: true
           """
        s.config = Config(TEST_SITE, config_dict=yaml.load(cfg, Loader=yaml.FullLoader))
        text = """
   {% extends "base.html" %}

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

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

        from pyquery import PyQuery
        target = File(Folder(s.config.deploy_root_path).child('test.html'))
        text = target.read_all()
        q = PyQuery(text)
        assert q('a#index').attr("href") == '/'
        assert q('a#blog').attr(
            "href") == '/blog/2010/december/merry-christmas'
Example #10
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
Example #11
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()
Example #12
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()
Example #13
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'
Example #14
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:nth-child(1)").text().strip() == "Heading 1"
        assert q("h1:nth-child(2)").text().strip() == "Heading 2"
Example #15
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:nth-child(1)").text().strip() == "Heading 1"
        assert q("h1:nth-child(2)").text().strip() == "Heading 2"
Example #16
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()
Example #17
0
 def main(self, args, skip=False):
     conf = File(Folder(os.getcwd()).child(args.config))
     if not conf.exists:
         raise Exception(
             'Config file [{conf}] does not exist'.format(conf=conf.path))
     self.config = yaml.load(conf.read_all())
     self.config['file_path'] = conf.path
     if not skip:
         generator.render_project(self.config)
Example #18
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()
Example #19
0
 def test_plugin_chaining(self):
     self.site.config.plugins = [
         "hyde.tests.test_plugin.ConstantReturnPlugin",
         "hyde.tests.test_plugin.NoReturnPlugin",
     ]
     path = self.site.content.source_folder.child("about.html")
     gen = Generator(self.site)
     gen.generate_resource_at_path(path)
     about = File(Folder(self.site.config.deploy_root_path).child("about.html"))
     assert about.read_all() == "Jam"
 def test_plugin_chaining(self):
     self.site.config.plugins = [
         'test_plugin.ConstantReturnPlugin', 'test_plugin.NoReturnPlugin'
     ]
     path = self.site.content.source_folder.child('about.html')
     gen = Generator(self.site)
     gen.generate_resource_at_path(path)
     about = File(
         Folder(self.site.config.deploy_root_path).child('about.html'))
     assert about.read_all() == "Jam"
Example #21
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()
Example #22
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()
Example #23
0
 def test_generator(self):
     self.setup_config(['**/*.html', 'media/css/*.css'])
     s = Site(self.SITE_PATH, self.config)
     g = Generator(s)
     g.generate_all()
     source = s.content.resource_from_relative_path(
         'blog/2010/december/merry-christmas.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
Example #24
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()
Example #25
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
Example #26
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
Example #27
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
Example #28
0
 def test_generator(self):
     self.setup_config([
         '**/*.html',
         'media/css/*.css'
     ])
     s = Site(self.SITE_PATH, self.config)
     g = Generator(s)
     g.generate_all()
     source = s.content.resource_from_relative_path('blog/2010/december/merry-christmas.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
Example #29
0
    def test_scss(self):
        s = Site(TEST_SITE)
        s.config.mode = 'prod'
        s.config.plugins = ['hyde.ext.plugins.css.SassyCSSPlugin']
        source = TEST_SITE.child('content/media/css/site.scss')
        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(SCSS_SOURCE.child('expected-site.css')).read_all()
        assert_no_diff(expected_text, text)
Example #30
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()
Example #31
0
    def test_scss(self):
        s = Site(TEST_SITE)
        s.config.mode = 'prod'
        s.config.plugins = ['hyde.ext.plugins.css.SassyCSSPlugin']
        source = TEST_SITE.child('content/media/css/site.scss')
        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(SCSS_SOURCE.child('expected-site.css')).read_all()
        assert_no_diff(expected_text, text)
Example #32
0
    def test_can_execute_rjs(self):
        s = Site(TEST_SITE)
        s.config.plugins = ['hyde.ext.plugins.js.RequireJSPlugin']
        source = TEST_SITE.child('content/media/js/rjs.conf')
        target = File(Folder(s.config.deploy_root_path).child('media/js/app.js'))
        gen = Generator(s)
        gen.generate_resource_at_path(source)

        assert target.exists
        text = target.read_all()
        expected_text = File(RJS_SOURCE.child('app.js')).read_all()

        assert text == expected_text
        return
Example #33
0
    def test_can_execute_less(self):
        s = Site(TEST_SITE)
        s.config.plugins = ['hyde.ext.plugins.less.LessCSSPlugin']
        source = TEST_SITE.child('content/media/css/site.less')
        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(LESS_SOURCE.child('expected-site.css')).read_all()

        assert text == expected_text
        return
Example #34
0
    def test_can_execute_less(self):
        s = Site(TEST_SITE)
        s.config.plugins = ['hyde.ext.plugins.css.LessCSSPlugin']
        source = TEST_SITE.child('content/media/css/site.less')
        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(LESS_SOURCE.child('expected-site.css')).read_all()

        assert text == expected_text
        return
Example #35
0
    def test_no_uglify_in_dev_mode(self):
        s = Site(TEST_SITE)
        s.config.plugins = ['hyde.ext.plugins.js.UglifyPlugin']
        s.config.mode = "dev"
        source = TEST_SITE.child('content/media/js/jquery.js')
        target = File(
            Folder(s.config.deploy_root_path).child('media/js/jquery.js'))
        gen = Generator(s)
        gen.generate_resource_at_path(source)

        assert target.exists
        expected = UGLIFY_SOURCE.child_file('jquery.js').read_all()
        # TODO: Very fragile. Better comparison needed.
        text = target.read_all()
        assert_no_diff(expected, text)
Example #36
0
    def _test_combine(self, content):
        s = Site(TEST_SITE)
        s.config.plugins = [
            'hyde.ext.plugins.meta.MetaPlugin',
            'hyde.ext.plugins.combine.CombinePlugin']
        source = TEST_SITE.child('content/media/js/script.js')
        target = File(Folder(s.config.deploy_root_path).child('media/js/script.js'))
        File(source).write(content)

        gen = Generator(s)
        gen.generate_resource_at_path(source)

        assert target.exists
        text = target.read_all()
        return text, s
    def test_can_execute_rjs(self):
        s = Site(TEST_SITE)
        s.config.plugins = ['hyde.ext.plugins.js.RequireJSPlugin']
        source = TEST_SITE.child('content/media/js/rjs.conf')
        target = File(
            Folder(s.config.deploy_root_path).child('media/js/app.js'))
        gen = Generator(s)
        gen.generate_resource_at_path(source)

        assert target.exists
        text = target.read_all()
        expected_text = File(RJS_SOURCE.child('app.js')).read_all()

        assert text == expected_text
        return
Example #38
0
    def test_no_uglify_in_dev_mode(self):
        s = Site(TEST_SITE)
        s.config.plugins = ['hyde.ext.plugins.js.UglifyPlugin']
        s.config.mode = "dev"
        source = TEST_SITE.child('content/media/js/jquery.js')
        target = File(
            Folder(s.config.deploy_root_path).child('media/js/jquery.js'))
        gen = Generator(s)
        gen.generate_resource_at_path(source)

        assert target.exists
        expected = UGLIFY_SOURCE.child_file('jquery.js').read_all()
        # TODO: Very fragile. Better comparison needed.
        text = target.read_all()
        assert_no_diff(expected, text)
Example #39
0
    def test_uglify_with_extra_options(self):
        s = Site(TEST_SITE)
        s.config.plugins = ['hyde.ext.plugins.js.UglifyPlugin']
        s.config.mode = "production"
        s.config.uglify = Expando(dict(args={"nc":""}))
        source = TEST_SITE.child('content/media/js/jquery.js')
        target = File(Folder(s.config.deploy_root_path).child('media/js/jquery.js'))
        gen = Generator(s)
        gen.generate_resource_at_path(source)

        assert target.exists
        expected = File(UGLIFY_SOURCE.child('expected-jquery-nc.js'))
        # TODO: Very fragile. Better comparison needed.
        text = target.read_all()
        assert text.startswith("(function(")
Example #40
0
    def test_uglify_with_extra_options(self):
        s = Site(TEST_SITE)
        s.config.plugins = ['hyde.ext.plugins.uglify.UglifyPlugin']
        s.config.mode = "production"
        s.config.uglify = Expando(dict(args={"nc":""}))
        source = TEST_SITE.child('content/media/js/jquery.js')
        target = File(Folder(s.config.deploy_root_path).child('media/js/jquery.js'))
        gen = Generator(s)
        gen.generate_resource_at_path(source)

        assert target.exists
        expected = File(UGLIFY_SOURCE.child('expected-jquery-nc.js'))
        # TODO: Very fragile. Better comparison needed.
        text = target.read_all()
        assert text.startswith("(function(")
Example #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
Example #42
0
    def test_can_execute_stylus(self):
        s = Site(TEST_SITE)
        s.config.plugins = ['hyde.ext.plugins.css.StylusPlugin']
        paths = ['/usr/local/share/npm/bin/stylus']
        for path in paths:
            if File(path).exists:
                s.config.stylus = Expando(dict(app=path))
        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.css')).read_all()
        assert text.strip() == expected_text.strip()
Example #43
0
def transform(path, result_path, context=None, jinja_env=None):
    """
    Loads a yaml document from the given `path` and processes
    it as a jinja2 template.
    `result_path` The target file path for writing the output.
    `context` is passed to the template processor as data.
    `jinja_env` can contain custom extensions, filters and functions.
    See jinja2 documentation on the `environment` variable.
    """
    f = File(path)
    env = _get_jinja2_env(jinja_env)
    source = f.read_all() if f.exists else path
    t = env.from_string(source)
    result = t.render(context or dict())
    File(result_path).write(result)
    return result_path
Example #44
0
    def _test_combine(self, content):
        s = Site(TEST_SITE)
        s.config.plugins = [
            'hyde.ext.plugins.meta.MetaPlugin',
            'hyde.ext.plugins.structure.CombinePlugin'
        ]
        source = TEST_SITE.child('content/media/js/script.js')
        target = File(
            Folder(s.config.deploy_root_path).child('media/js/script.js'))
        File(source).write(content)

        gen = Generator(s)
        gen.generate_resource_at_path(source)

        assert target.exists
        text = target.read_all()
        return text, s
Example #45
0
    def test_uglify_with_extra_options(self):
        s = Site(TEST_SITE)
        s.config.plugins = ['hyde.ext.plugins.js.UglifyPlugin']
        s.config.mode = "production"
        s.config.uglify = Expando(
            dict(args={"comments": "/http\:\/\/jquery.org\/license/"}))
        source = TEST_SITE.child('content/media/js/jquery.js')
        target = File(
            Folder(s.config.deploy_root_path).child('media/js/jquery.js'))
        gen = Generator(s)
        gen.generate_resource_at_path(source)

        assert target.exists
        expected = UGLIFY_SOURCE.child_file('expected-jquery-nc.js').read_all()
        # TODO: Very fragile. Better comparison needed.
        text = target.read_all()
        assert_no_diff(expected, text)
Example #46
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"
Example #47
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"
Example #48
0
    def do_404(self):
        """
        Sends a 'not found' response.
        """
        site = self.server.site
        if self.path != site.config.not_found:
            self.redirect(site.config.not_found)
        else:
            res = site.content.resource_from_relative_deploy_path(site.config.not_found)

            message = "Requested resource not found"
            if not res:
                logger.error("Cannot find the 404 template [%s]." % site.config.not_found)
            else:
                f404 = File(self.translate_path(site.config.not_found))
                if f404.exists:
                    message = f404.read_all()
            self.send_response(200, message)
Example #49
0
    def test_can_execute_stylus(self):
        s = Site(TEST_SITE)
        s.config.plugins = ['hyde.ext.plugins.css.StylusPlugin']
        paths = ['/usr/local/bin/stylus', '/usr/local/share/npm/bin/stylus']
        for path in paths:
            if File(path).exists:
                s.config.stylus = Expando(dict(app=path))
        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.css')).read_all()
        assert text.strip() == expected_text.strip()
Example #50
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()
     import time
     time.sleep(1)
     assert not gen.has_resource_changed(resource)
     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)
Example #51
0
    def test_context_providers(self):
        site = Site(TEST_SITE, Config(TEST_SITE, config_dict={
            "context": {
                "data": {
                    "abc": "def"
                },
                "providers": {
                    "nav": "nav.yaml"
                }
            }
        }))
        nav = """
- home
- articles
- projects
"""
        text = """
{% extends "base.html" %}

{% block main %}
    {{nav}}
    {% for item in nav %}
    {{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
Example #52
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()
     import time
     time.sleep(1)
     assert not gen.has_resource_changed(resource)
     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)
Example #53
0
File: model.py Project: jperry/hyde
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))
Example #54
0
    def do_404(self):
        """
        Sends a 'not found' response.
        """
        site = self.server.site
        if self.path != site.config.not_found:
            self.redirect(site.config.not_found)
        else:
            res = site.content.resource_from_relative_deploy_path(
                site.config.not_found)

            message = "Requested resource not found"
            if not res:
                logger.error("Cannot find the 404 template [%s]." %
                             site.config.not_found)
            else:
                f404 = File(self.translate_path(site.config.not_found))
                if f404.exists:
                    message = f404.read_all()
            self.send_response(200, message)
Example #55
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))
Example #56
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.text.MarkingsPlugin',
            'hyde.ext.plugins.text.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)
Example #57
0
    def test_can_parse_blockdown(self):
        s = Site(TEST_SITE)
        s.config.plugins = ['hyde.ext.plugins.text.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()
Example #58
0
    def test_walk_resources_sorted_using_generator(self):
        s = Site(TEST_SITE)
        cfg = """
           meta:
               time: !!timestamp 2010-10-23
               title: NahNahNah
           plugins:
               - hyde.ext.plugins.meta.MetaPlugin
               - hyde.ext.plugins.meta.SorterPlugin
           sorter:
               time:
                   attr: meta.time
                   filters:
                       source_file.kind: html
           """
        s.config = Config(TEST_SITE, config_dict=yaml.load(cfg))
        text = """
   ---
    time: !!timestamp 2010-12-31
    title: YayYayYay
   ---
   {% extends "base.html" %}

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

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

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

        assert q('span.latest').text() == 'YayYayYay'
    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.text.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