Esempio n. 1
0
    def test_target_file(self):
        testdata = ({
            'basedir': '/mysite/deploy',
            'url': '/contact/',
            'expected': '/mysite/deploy/contact/index.html'
        }, {
            'basedir':
            '/mysite/deploy',
            'url':
            '/artikel/linguistik/ikon_sprache.html',
            'expected':
            '/mysite/deploy/artikel/linguistik/ikon_sprache.html'
        }, {
            'basedir': '/mysite/deploy',
            'url': 'tags/code',
            'expected': '/mysite/deploy/tags/code/index.html'
        }, {
            'basedir': '/mysite/deploy',
            'url': 'tags/code/rss.xml',
            'expected': '/mysite/deploy/tags/code/rss.xml'
        })

        for t in testdata:
            self.assertEqual(t['expected'],
                             path.target_file(t['basedir'], t['url']))
Esempio n. 2
0
    def write_index(self, url, collection):
        """Write an auto-generated index.html file."""

        check_doc_url = '/{}'.format(path.join(url, self.index_filename))
        # make sure there exists no document at the index url
        if check_doc_url not in self.docs:
            # Ugly fix for issue #32: delete description var. This is called
            # for every index, instead of once for all, because write_index is
            # called in serve mode. Also there may remain other vars causing
            # future problems.
            # Emptying the vars dict does not work either, because the index
            # key is set in build_index and needed.
            if 'description' in self.template.vars:
                del self.template.vars['description']

            title = self.index_title(url)

            self.template.vars['docs'] = collection.docs
            self.template.vars['title'] = title
            self.template.vars['canonical'] = '{:s}/{:s}/'.format(self.base_url, url)

            page = self.template.env.get_template(collection.template)
            content = page.render(self.template.vars)

            filename = path.target_file(self.dir_deploy, url)
            write(filename, content)

            # write directory RSS file
            self.write_rss(title, url, collection.docs)
Esempio n. 3
0
    def write_index(self, url, collection):
        """Write an auto-generated index.html file."""

        check_doc_url = '/{}'.format(path.join(url, self.index_filename))
        # make sure there exists no document at the index url
        if check_doc_url not in self.docs:
            # Ugly fix for issue #32: delete description var. This is called
            # for every index, instead of once for all, because write_index is
            # called in serve mode. Also there may remain other vars causing
            # future problems.
            # Emptying the vars dict does not work either, because the index
            # key is set in build_index and needed.
            if 'description' in self.template.vars:
                del self.template.vars['description']

            title = self.index_title(url)

            self.template.vars['docs'] = collection.docs
            self.template.vars['title'] = title

            page = self.template.env.get_template(collection.template)
            content = page.render(self.template.vars)

            filename = path.target_file(self.dir_deploy, url)
            write(filename, content)

            # write directory RSS file
            self.write_rss(title, url, collection.docs)
Esempio n. 4
0
def write_content(dir_target, headers, body):
    """Write a file that can be parsed as content.

    This is can be used in scripts that extend Logya, but is not used in core
    at the moment.
    """

    write(path.target_file(dir_target, headers['url']),
          encode_content(headers, body))
Esempio n. 5
0
File: writer.py Progetto: yaph/logya
def write_content(dir_target, headers, body):
    """Write a file that can be parsed as content.

    This is can be used in scripts that extend Logya, but is not used in core
    at the moment.
    """

    write(
        path.target_file(dir_target, headers['url']),
        encode_content(headers, body))
Esempio n. 6
0
    def write_rss(self, feed_title, url, docs):
        """Write RSS 2.0 XML file in target directory"""

        self.template.vars['url'] = self.base_url
        self.template.vars['title'] = feed_title
        self.template.vars['description'] = feed_title
        self.template.vars['last_build'] = datetime.datetime.now()
        self.template.vars['docs'] = docs

        content = self.pages['rss'].render(self.template.vars)

        filename = path.target_file(
            self.dir_deploy, path.join(url, 'rss.xml'))
        write(filename, content)
Esempio n. 7
0
    def write_rss(self, feed_title, url, docs):
        """Write RSS 2.0 XML file in target directory"""

        self.template.vars['url'] = self.base_url
        self.template.vars['title'] = feed_title
        self.template.vars['description'] = feed_title
        self.template.vars['last_build'] = datetime.datetime.now()
        self.template.vars['docs'] = docs

        page = self.template.env.get_template(self.templates['rss'])
        content = page.render(self.template.vars)

        filename = path.target_file(
            self.dir_deploy, path.join(url, 'rss.xml'))
        write(filename, content)
Esempio n. 8
0
File: writer.py Progetto: yaph/logya
    def write(self, doc, template):
        """Render and write document to created file."""

        # Make a copy so no previous doc attributes are retained, that don't
        # exist in current doc.
        tpl_vars = self.template.vars.copy()
        tpl_vars.update(doc)

        # Set additional template variables.
        tpl_vars['canonical'] = tpl_vars['base_url'] + tpl_vars['url']

        # Pre-render doc body so Jinja2 template tags can be used in content.
        tpl_vars['body'] = self.template.env.from_string(
            tpl_vars.get('body', '')).render(tpl_vars)

        page = self.template.get_page(doc, template)
        content = page.render(tpl_vars)

        write(path.target_file(self.dir_target, doc['url']), content)
Esempio n. 9
0
    def write(self, doc, template):
        """Render and write document to created file."""

        # Make a copy so no previous doc attributes are retained, that don't
        # exist in current doc.
        tpl_vars = self.template.vars.copy()
        tpl_vars.update(doc)

        # Set additional template variables.
        tpl_vars['canonical'] = tpl_vars['base_url'] + tpl_vars['url']

        # Pre-render doc body so Jinja2 template tags can be used in content.
        tpl_vars['body'] = self.template.env.from_string(
            tpl_vars.get('body', '')).render(tpl_vars)

        page = self.template.get_page(doc, template)
        content = page.render(tpl_vars)

        write(path.target_file(self.dir_target, doc['url']), content)
Esempio n. 10
0
    def test_target_file(self):
        testdata = ({
            'basedir': '/mysite/deploy',
            'url': '/contact/',
            'expected': '/mysite/deploy/contact/index.html'
        }, {
            'basedir': '/mysite/deploy',
            'url': '/artikel/linguistik/ikon_sprache.html',
            'expected': '/mysite/deploy/artikel/linguistik/ikon_sprache.html'
        }, {
            'basedir': '/mysite/deploy',
            'url': 'tags/code',
            'expected': '/mysite/deploy/tags/code/index.html'
        }, {
            'basedir': '/mysite/deploy',
            'url': 'tags/code/rss.xml',
            'expected': '/mysite/deploy/tags/code/rss.xml'
        })

        for t in testdata:
            self.assertEqual(
                t['expected'],
                path.target_file(t['basedir'], t['url']))
        if body:
            body.append(resources)

        doc = {
            'created': datetime.now(),
            'description': body[0].split('. ')[0] + '.',
            'groups': groups,
            'muscles': muscles,
            'template': 'exercise.html',
            'title': name,
            'variants': variants
        }
        # Files shall be saved as md files, so calling write_content directly
        # is not possible as it would save as html.
        filename = target_file(logya.dir_content, '/exercise/{}.md'.format(slugify(name)))
        if not os.path.exists(filename):
            write(filename, encode_content(doc, '\n\n'.join(body)))

        # Create stub files for variants
        for variant in variants:
            filename = target_file(logya.dir_content, '/exercise/{}.md'.format(slugify(variant)))
            if not os.path.exists(filename):
                ex_variants = list(set(variants).union(set([name])).difference(set([variant])))
                doc = {
                    'created': datetime.now(),
                    'description': '',
                    'groups': groups,
                    'muscles': muscles,
                    'template': 'exercise.html',
                    'title': variant,
Esempio n. 12
0
        if body:
            body.append(resources)

        doc = {
            'created': datetime.now(),
            'description': body[0].split('. ')[0] + '.',
            'groups': groups,
            'muscles': muscles,
            'template': 'exercise.html',
            'title': name,
            'variants': variants
        }
        # Files shall be saved as md files, so calling write_content directly
        # is not possible as it would save as html.
        filename = target_file(logya.dir_content,
                               '/exercise/{}.md'.format(slugify(name)))
        if not os.path.exists(filename):
            write(filename, encode_content(doc, '\n\n'.join(body)))

        # Create stub files for variants
        for variant in variants:
            filename = target_file(logya.dir_content,
                                   '/exercise/{}.md'.format(slugify(variant)))
            if not os.path.exists(filename):
                ex_variants = list(
                    set(variants).union(set([name])).difference(set([variant
                                                                     ])))
                doc = {
                    'created': datetime.now(),
                    'description': '',
                    'groups': groups,