Пример #1
0
Файл: css.py Проект: jperry/hyde
    def text_resource_complete(self, resource, text):
        """
        Save the file to a temporary place and run less compiler.
        Read the generated file and return the text as output.
        Set the target path to have a css extension.
        """
        if not self._should_parse_resource(resource):
            return

        supported = [
            "verbose", ("silent", "s"), ("compress", "x"), "O0", "O1", "O2",
            "include-path="
        ]

        less = self.app
        source = File.make_temp(text)
        target = File.make_temp('')
        args = [unicode(less)]
        args.extend(self.process_args(supported))
        args.extend([unicode(source), unicode(target)])
        try:
            self.call_app(args)
        except subprocess.CalledProcessError:
            raise self.template.exception_class(
                "Cannot process %s. Error occurred when "
                "processing [%s]" % (self.app.name, resource.source_file))
        return target.read_all()
Пример #2
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
Пример #3
0
    def test_context(self):
        site = Site(TEST_SITE, Config(TEST_SITE, config_dict={
            "context": {
                "data": {
                    "abc": "def"
                }
            }
        }))
        text = """
{% extends "base.html" %}

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

    I am a test template to make sure jinja2 generation works well with hyde.
    {{resource.name}}
{% endblock %}
"""
        site.load()
        resource = site.content.resource_from_path(
            TEST_SITE.child('content/about.html'))
        gen = Generator(site)
        resource.source_file.write(text)
        gen.generate_all()
        target = File(site.config.deploy_root_path.child(resource.name))
        assert "abc = def" in target.read_all()
Пример #4
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'
Пример #5
0
    def begin_site(self):
        """
        Configuration example
        ---------------------
        #yaml
        suffix:
            -
                target_extension:
                    - markdown
                    - md
                output_extension: html
            -
                target_extension:
                    - rst
                    - md
                output_extension: html
        """
        config = self.site.config
        if not hasattr(config, 'suffix'):
            return

        suffix_config = attrgetter('suffix')(config)

        for resource in self.site.content.walk_resources():
            for conf in suffix_config:
                conf = conf.to_dict()
                target = conf.get('target_extension', [])
                output = conf.get('output_extension', 'html')
                if resource.source_file.kind in target:
                    new_name = resource.source_file.name_without_extension + "." + output
                    target_folder = File(resource.relative_deploy_path).parent
                    resource.relative_deploy_path = target_folder.child(new_name)
Пример #6
0
    def begin_site(self):
        """
    Configuration example
    ---------------------
    #yaml
    suffix:
        -
            target_extension:
                - markdown
                - md
            output_extension: html
        -
            target_extension:
                - rst
                - md
            output_extension: html
    """
        config = self.site.config
        if not hasattr(config, 'suffix'):
            return

        suffix_config = attrgetter('suffix')(config)

        for resource in self.site.content.walk_resources():
            for conf in suffix_config:
                conf = conf.to_dict()
                target = conf.get('target_extension', [])
                output = conf.get('output_extension', 'html')
                if resource.source_file.kind in target:
                    new_name = resource.source_file.name_without_extension
                    if output:
                        new_name += "." + output
                    target_folder = File(resource.relative_deploy_path).parent
                    resource.relative_deploy_path = target_folder.child(
                        new_name)
Пример #7
0
def poll():
    running = File('/var/run/build')
    if running.exists:
        return
    queue_url = '{ "Ref" : "InputQueue" }'
    region = '{ "Ref" : "AWS::Region" }'
    aws_access_key = '{"Ref": "WorkerKeys"}'
    aws_secret_key = '{"Fn::GetAtt": ["WorkerKeys", "SecretAccessKey"]}'
    conn = sqsconnect(region,
                      aws_access_key_id=aws_access_key,
                      aws_secret_access_key=aws_secret_key)
    q = Queue(conn, queue_url)
    msg = q.read(600)
    if msg:
        body = msg.get_body()
        data = json.loads(body)
        status_url = data.get('status_url', None)
        running.write('.')
        try:
            run(data)
            q.delete_message(msg)
        except HandledException:
            raise
        except Exception, e:
            if status_url:
                post_status(status_url, dict(
                    state='error',
                    message=e.message
                ))
            raise
        else:
            print 'All done.'
        finally:
Пример #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/"
Пример #9
0
Файл: css.py Проект: jperry/hyde
        def import_to_include(match):
            """
            Converts a css import statement to include statemnt.
            """
            if not match.lastindex:
                return ''
            path = match.groups(1)[0]
            afile = File(
                File(resource.source_file.parent.child(
                    path)).fully_expanded_path)
            if len(afile.kind.strip()) == 0:
                afile = File(afile.path + '.styl')

            ref = self.site.content.resource_from_path(afile.path)

            if not ref:
                try:
                    include = self.settings.args.include
                except AttributeError:
                    include = False
                if not include:
                    raise self.template.exception_class(
                        "Cannot import from path [%s]" % afile.path)
            else:
                ref.is_processable = False
                return "\n" + \
                        self.template.get_include_statement(ref.relative_path) + \
                        "\n"
            return '@import "' + path + '"\n'
Пример #10
0
    def add_resource(self, a_file):
        """
        Adds a file to the parent node.  Also adds to to the
        hashtable of path to resource associations for quick lookup.
        """

        afile = File(a_file)

        resource = self.resource_from_path(afile)
        if resource:
            logger.debug("Resource exists at [%s]" % resource.relative_path)
            return resource

        if not afile.is_descendant_of(self.source_folder):
            raise HydeException("The given file [%s] does not reside"
                                " in this hierarchy [%s]" %
                                (afile, self.source_folder))

        node = self.node_from_path(afile.parent)

        if not node:
            node = self.add_node(afile.parent)
        resource = node.add_child_resource(afile)
        self.resource_map[str(afile)] = resource
        relative_path = resource.relative_path
        resource.simple_copy = any(fnmatch.fnmatch(relative_path, pattern)
                                   for pattern in self.site.config.simple_copy)

        logger.debug("Added resource [%s] to [%s]" %
                     (resource.relative_path, self.source_folder))
        return resource
Пример #11
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
Пример #12
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 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
Пример #13
0
    def text_resource_complete(self, resource, text):
        """
        Save the file to a temporary place and run less compiler.
        Read the generated file and return the text as output.
        Set the target path to have a css extension.
        """
        if not resource.source_file.kind == 'less' or not \
            self._should_parse_resource(resource):
            return

        supported = [
            "verbose",
            ("silent", "s"),
            ("compress", "x"),
            "O0",
            "O1",
            "O2",
            "include-path="
        ]

        less = self.app
        source = File.make_temp(text)
        target = File.make_temp('')
        args = [unicode(less)]
        args.extend(self.process_args(supported))
        args.extend([unicode(source), unicode(target)])
        try:
            self.call_app(args)
        except subprocess.CalledProcessError:
             raise self.template.exception_class(
                    "Cannot process %s. Error occurred when "
                    "processing [%s]" % (self.app.name, resource.source_file))
        return target.read_all()
Пример #14
0
    def add_resource(self, a_file):
        """
        Adds a file to the parent node.  Also adds to to the
        hashtable of path to resource associations for quick lookup.
        """

        afile = File(a_file)

        resource = self.resource_from_path(afile)
        if resource:
            logger.debug("Resource exists at [%s]" % resource.relative_path)
            return resource

        if not afile.is_descendant_of(self.source_folder):
            raise HydeException("The given file [%s] does not reside"
                                " in this hierarchy [%s]" %
                                (afile, self.source_folder))

        node = self.node_from_path(afile.parent)

        if not node:
            node = self.add_node(afile.parent)
        resource = node.add_child_resource(afile)
        self.resource_map[str(afile)] = resource
        relative_path = resource.relative_path
        resource.simple_copy = any(
            fnmatch.fnmatch(relative_path, pattern)
            for pattern in self.site.config.simple_copy)

        logger.debug("Added resource [%s] to [%s]" %
                     (resource.relative_path, self.source_folder))
        return resource
Пример #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"
Пример #16
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()
Пример #17
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
Пример #18
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
Пример #19
0
    def binary_resource_complete(self, resource):
        """
        Run jpegtran to compress the jpg file.
        """

        if not resource.source_file.kind == 'jpg':
            return

        supported = [
            "optimize",
            "progressive",
            "restart",
            "arithmetic",
            "perfect",
            "copy",
        ]
        source = File(
            self.site.config.deploy_root_path.child(
                resource.relative_deploy_path))
        target = File.make_temp('')
        jpegtran = self.app
        args = [unicode(jpegtran)]
        args.extend(self.process_args(supported))
        args.extend(["-outfile", unicode(target), unicode(source)])
        self.call_app(args)
        target.copy_to(source)
        target.delete()
Пример #20
0
    def test_pages_of_one_content(self):
        expected_page1_content = dedent('''\
            Another Sad Post

            /page2/pages_of_one.txt''')
        expected_page2_content = dedent('''\
            A Happy Post
            /pages_of_one.txt
            /page3/pages_of_one.txt''')
        expected_page3_content = dedent('''\
            An Angry Post
            /page2/pages_of_one.txt
            /page4/pages_of_one.txt''')
        expected_page4_content = dedent('''\
            A Sad Post
            /page3/pages_of_one.txt
            ''')

        page1 = self.deploy.child('pages_of_one.txt')
        content = File(page1).read_all()
        assert expected_page1_content == content

        page2 = self.deploy.child('page2/pages_of_one.txt')
        content = File(page2).read_all()
        assert expected_page2_content == content

        page3 = self.deploy.child('page3/pages_of_one.txt')
        content = File(page3).read_all()
        assert expected_page3_content == content

        page4 = self.deploy.child('page4/pages_of_one.txt')
        content = File(page4).read_all()
        assert expected_page4_content == content
Пример #21
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)
        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
Пример #22
0
 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)
Пример #23
0
def test_time_functions():
    f1 = File(__file__)
    t1 = f1.last_modified
    f2 = File.make_temp("I am new")
    t2 = f2.last_modified
    assert t1 < t2
    assert f2.has_changed_since(t1)
    assert f1.older_than(f2)
Пример #24
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)
Пример #25
0
 def begin_site(self):
     """
     Find all the coffee files and set their relative deploy path.
     """
     for resource in self.site.content.walk_resources():
         if resource.source_file.kind == 'coffee':
             new_name = resource.source_file.name_without_extension + ".js"
             target_folder = File(resource.relative_deploy_path).parent
             resource.relative_deploy_path = target_folder.child(new_name)
Пример #26
0
    def test_pages_of_one(self):
        pages = ['pages_of_one.txt', 'page2/pages_of_one.txt',
                 'page3/pages_of_one.txt', 'page4/pages_of_one.txt']
        files = [File(self.deploy.child(p)) for p in pages]
        for f in files:
            assert f.exists

        page5 = File(self.deploy.child('page5/pages_of_one.txt'))
        assert not page5.exists
Пример #27
0
Файл: css.py Проект: jperry/hyde
 def begin_site(self):
     """
     Find all the less css files and set their relative deploy path.
     """
     for resource in self.site.content.walk_resources():
         if self._should_parse_resource(resource):
             new_name = resource.source_file.name_without_extension + ".css"
             target_folder = File(resource.relative_deploy_path).parent
             resource.relative_deploy_path = target_folder.child(new_name)
Пример #28
0
Файл: css.py Проект: jperry/hyde
 def begin_site(self):
     """
     Find all the less css files and set their relative deploy path.
     """
     for resource in self.site.content.walk_resources():
         if self._should_parse_resource(resource):
             new_name = resource.source_file.name_without_extension + ".css"
             target_folder = File(resource.relative_deploy_path).parent
             resource.relative_deploy_path = target_folder.child(new_name)
Пример #29
0
def test_etag_unicode_same():
    f1 = File.make_temp(u"\x80\x81")
    etag1 = f1.etag
    f2 = File(f1.path)
    etag2 = f2.etag
    assert etag1 == etag2
    f3 = File.make_temp(u"\x80\x81")
    etag3 = f3.etag
    assert etag1 == etag3
Пример #30
0
def test_etag_same():
    f1 = File.make_temp("I am new")
    etag1 = f1.etag
    f2 = File(f1.path)
    etag2 = f2.etag
    assert etag1 == etag2
    f3 = File.make_temp("I am new")
    etag3 = f3.etag
    assert etag1 == etag3
Пример #31
0
 def begin_site(self):
     """
     Find all the coffee files and set their relative deploy path.
     """
     for resource in self.site.content.walk_resources():
         if resource.source_file.kind == 'coffee':
             new_name = resource.source_file.name_without_extension + ".js"
             target_folder = File(resource.relative_deploy_path).parent
             resource.relative_deploy_path = target_folder.child(new_name)
Пример #32
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()
Пример #33
0
class Concat(object):

    def __init__(self, out_file,
                    base_dir='.',
                    overwrite=True,
                    replace=None):
        if not replace:
            self.replace = {}
        elif not isinstance(replace, dict):
            raise Exception("vars must be a dictionary")
        else:
            self.replace = replace
        self.out_file = File(out_file)
        self.fp = None
        self.indent = ''
        if overwrite:
            self.out_file.delete()
        self.out_file.parent.make()
        self.base_dir = Folder(base_dir)

    def open(self, mode='a'):
        self.fp = open(self.out_file.path, mode)
        return self

    def __lshift__(self, stream):
        if not self.fp:
            self.open()
        if isinstance(stream, FILES):
            self.concat_files(stream, self.indent)
        elif isinstance(stream, BEGIN_INDENT):
            self.indent = stream.indent
        elif stream == END_INDENT or isinstance(stream, END_INDENT):
            self.indent = ''
        elif stream == END or isinstance(stream, END):
            self.indent = ''
            self.close()
        else:
            self.concat_string(unicode(stream), self.indent)
        return self

    def concat_files(self, files, indent=''):
        for line in files.walk_lines(self.base_dir):
            self.write(indent, line)

    def concat_string(self, text, indent=''):
        for line in text.splitlines(True):
            self.write(indent, line)

    def write(self, indent, line):
        text = indent + line
        for key, value in self.replace.iteritems():
            text = text.replace(key, value)
        self.fp.write(text)

    def close(self):
        if self.fp:
            self.fp.close()
Пример #34
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()
Пример #35
0
 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"
Пример #36
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()
Пример #37
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"
Пример #38
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
Пример #39
0
 def setup_class(cls):
     cls.SITE_PATH = File(__file__).parent.child_folder(
         'sites/test_jinja_with_config')
     cls.SITE_PATH.make()
     TEST_SITE_ROOT.copy_contents_to(cls.SITE_PATH)
     cls.config_file = File(cls.SITE_PATH.child('alternate.yaml'))
     with open(cls.config_file.path) as config:
         cls.config = Config(sitepath=cls.SITE_PATH,
                             config_dict=yaml.load(config))
     cls.SITE_PATH.child_folder('content').rename_to(
         cls.config.content_root)
Пример #40
0
 def setUp(self):
     TEST_SITE.make()
     TEST_SITE.parent.child_folder('sites/test_jinja').copy_contents_to(
         TEST_SITE)
     TEST_SITE.child_folder('content/media/js').make()
     JS = TEST_SITE.child_folder('content/scripts').make()
     S1 = JS.child_folder('s1').make()
     S2 = JS.child_folder('s2').make()
     S3 = JS.child_folder('s3').make()
     File(COMBINE_SOURCE.child('script.1.js')).copy_to(S1)
     File(COMBINE_SOURCE.child('script.2.js')).copy_to(S2)
     File(COMBINE_SOURCE.child('script.3.js')).copy_to(S3)
Пример #41
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
Пример #42
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
Пример #43
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
Пример #44
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()
Пример #45
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()
Пример #46
0
Файл: css.py Проект: jperry/hyde
 def import_to_include(match):
     if not match.lastindex:
         return ''
     path = match.groups(1)[0]
     afile = File(resource.source_file.parent.child(path))
     if len(afile.kind.strip()) == 0:
         afile = File(afile.path + '.less')
     ref = self.site.content.resource_from_path(afile.path)
     if not ref:
         raise self.template.exception_class(
             "Cannot import from path [%s]" % afile.path)
     ref.is_processable = False
     return self.template.get_include_statement(ref.relative_path)
Пример #47
0
def test_expires():
    bucket = new_bucket()
    bucket.make()
    bucket.set_policy()
    bucket.serve()
    content = '<h1>A new html file on S3</h1>'
    data_folder.make()
    f = File(data_folder.child('index.html'))
    f.write(content)
    home = Folder('/home')
    headers = {"Expires":get_expires()}
    bucket.add_file(f, target_folder=home.name, headers=headers)
    assert_headers_present(bucket.get_url() + '/home/index.html', headers)
Пример #48
0
def test_signed_url():
    bucket = new_bucket()
    bucket.make()
    content = '<h1>A new html file on S3</h1>'
    data_folder.make()
    f = File(data_folder.child('index.html'))
    f.write(content)
    home = Folder('/home')
    full_path = bucket.add_file(f, target_folder=home.name)
    url = bucket.get_signed_url(full_path)
    response = urllib2.urlopen(url)
    html = response.read()
    assert html == content
Пример #49
0
def test_etag():
    bucket = new_bucket()
    bucket.make()
    bucket.set_policy()
    bucket.serve()
    content = '<h1>A new html file on S3</h1>'
    data_folder.make()
    f = File(data_folder.child('index.html'))
    f.write(content)
    home = Folder('/home')
    bucket.add_file(f, target_folder=home.name)
    key = bucket.bucket.get_key('home/index.html')
    assert bucket.check_etag(key, f)
Пример #50
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
Пример #51
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
Пример #52
0
 def test_can_execute_optipng(self):
     s = Site(TEST_SITE)
     s.config.mode = "production"
     s.config.plugins = ['hyde.ext.plugins.images.OptiPNGPlugin']
     s.config.optipng = Expando(dict(args=dict(quiet="")))
     source = File(TEST_SITE.child('content/media/images/hyde-lt-b.png'))
     target = File(
         Folder(
             s.config.deploy_root_path).child('media/images/hyde-lt-b.png'))
     gen = Generator(s)
     gen.generate_resource_at_path(source)
     assert target.exists
     assert target.size < source.size
Пример #53
0
 def test_extends(self):
     another = """
     extends: site.yaml
     mode: production
     media_root: xxx
     """
     File(TEST_SITE.child('site.yaml')).write(self.conf2)
     File(TEST_SITE.child('another.yaml')).write(another)
     c = Config(sitepath=TEST_SITE, config_file='another.yaml')
     assert c.mode == 'production'
     assert c.content_root_path == TEST_SITE.child_folder('site/stuff')
     assert c.media_root_path == c.content_root_path.child_folder('xxx')
     assert c.media_url == TEST_SITE.child_folder('/media')
     assert c.deploy_root_path == Folder('~/deploy_site')
Пример #54
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)
Пример #55
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]
Пример #56
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
Пример #57
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
Пример #58
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(")
Пример #59
0
Файл: css.py Проект: jperry/hyde
    def begin_site(self):
        """
        Find all the sassycss files and set their relative deploy path.
        """
        self.scss.STATIC_URL = self.site.content_url('/')
        self.scss.STATIC_ROOT = self.site.config.content_root_path.path
        self.scss.ASSETS_URL = self.site.media_url('/')
        self.scss.ASSETS_ROOT = self.site.config.deploy_root_path.child(
            self.site.config.media_root)

        for resource in self.site.content.walk_resources():
            if self._should_parse_resource(resource):
                new_name = resource.source_file.name_without_extension + ".css"
                target_folder = File(resource.relative_deploy_path).parent
                resource.relative_deploy_path = target_folder.child(new_name)