Ejemplo n.º 1
0
 def _get_renderer(self):
     renderer = self.site['renderer']
     options = self.site.get(renderer, None)
     
     try:
         Renderer = load_entry_point('mynt', 'mynt.renderers', renderer)
     except DistributionNotFound as e:
         raise RendererException('The {0} renderer requires {1}.'.format(renderer, unicode(e)))
     except ImportError:
         try:
             Renderer = import_module('mynt.renderers.{0}'.format(renderer)).Renderer
         except ImportError:
             raise RendererException('The {0} renderer could not be found.'.format(renderer))
     
     return Renderer(self.src.path, options)
Ejemplo n.º 2
0
    def _render(self):
        self._process()

        logger.info('>> Rendering')

        self.renderer.register({
            'archives': self.archives,
            'posts': self.posts,
            'tags': self.tags
        })

        logger.debug('..  posts')

        for post in self.posts:
            try:
                self.pages.append(
                    Page(
                        self._get_path(post['url']),
                        self._pygmentize(
                            self.renderer.render(post['layout'],
                                                 {'post': post}))))
            except RendererException as e:
                raise RendererException(
                    e.message,
                    '{0} in post \'{1}\''.format(post['layout'],
                                                 post['title']))

        logger.debug('..  pages')

        for f in self.src:
            if f.extension not in ('.html', '.htm', '.xml'):
                continue

            template = f.path.replace(self.src.path, '')

            self.pages.append(
                Page(normpath(self.dest.path, template),
                     self._pygmentize(self.renderer.render(template))))

        if self.config['tag_layout'] and self.tags:
            logger.debug('..  tags')

            for name, data in self.tags:
                self.pages.append(
                    Page(
                        self._get_path(data['url']),
                        self._pygmentize(
                            self.renderer.render(self.config['tag_layout'],
                                                 {'tag': data}))))

        if self.config['archive_layout'] and self.archives:
            logger.debug('..  archives')

            for year, data in self.archives:
                self.pages.append(
                    Page(
                        self._get_path(data['url']),
                        self._pygmentize(
                            self.renderer.render(self.config['archive_layout'],
                                                 {'archive': data}))))
Ejemplo n.º 3
0
 def render(self, template, vars_ = {}):
     try:
         template = self.environment.get_template(template)
     except TemplateNotFound:
         raise RendererException('Template not found.')
     
     return template.render(**vars_)
Ejemplo n.º 4
0
    def render(self, template, data=None):
        data = data if data is not None else {}

        try:
            template = self.environment.get_template(template)
        except TemplateNotFound:
            raise RendererException('Template not found')

        return template.render(**data)
Ejemplo n.º 5
0
    def _get_renderer(self):
        renderer = self.site['renderer']
        options = self.site.get(renderer, None)

        try:
            Renderer = load_entry_point('mynt', 'mynt.renderers', renderer)
        except DistributionNotFound as error:
            raise RendererException(
                'Renderer could not be found: {0}'.format(renderer), error)
        except ImportError:
            try:
                module = 'mynt.renderers.{0}'.format(renderer)
                Renderer = import_module(module).Renderer
            except ImportError:
                raise RendererException(
                    'Renderer could not be imported: {0}'.format(renderer))

        return Renderer(self.source.path, options)
Ejemplo n.º 6
0
 def render(self, template, data = None, url = None):
     url = url if url is not None else template
     path = self._get_path(url)
     
     try:
         Timer.start()
         
         content = self._renderer.render(template, data)
         
         if self.site['pygmentize']:
             content = self._pygmentize(content)
         
         logger.debug('..  (%.3fs) %s', Timer.stop(), path.replace(self.dest.path, ''))
     except RendererException as e:
         raise RendererException(e.message,
             '{0} in container item {1}'.format(template, data.get('item', url)))
     
     return File(path, content)