Esempio n. 1
0
    def __init__(self, *args, **kwargs):
        for idx, item in enumerate(('context', 'settings', 'path', 'theme',
                'output_path', 'markup')):
            setattr(self, item, args[idx])

        for arg, value in kwargs.items():
            setattr(self, arg, value)

        # templates cache
        self._templates = {}
        self._templates_path = os.path.expanduser(
                os.path.join(self.theme, 'templates'))

        theme_path = os.path.join(os.path.dirname(os.path.abspath(__file__)))

        simple_loader = FileSystemLoader(theme_path,
                                         "themes", "simple", "templates")
        self._env = Environment(
            loader=ChoiceLoader([
                FileSystemLoader(self._templates_path),
                simple_loader,  # implicit inheritance
                PrefixLoader({'!simple': simple_loader})  # explicit one
            ]),
            extensions=self.settings.get('JINJA_EXTENSIONS', []),
        )

        debug('template list: {0}'.format(self._env.list_templates()))

        # get custom Jinja filters from user settings
        custom_filters = self.settings.get('JINJA_FILTERS', {})
        self._env.filters.update(custom_filters)
Esempio n. 2
0
 def run(self):
     id = directives.nonnegative_int(self.arguments.pop(0))
     log.debug(self.arguments)
     return [
         nodes.raw(
             '', 
             self.html.format(
                 path=self.widget_path,
                 id=id,
                 type=self.type,
                 autoplay=('autoplay&' if 'autoplay' in self.arguments else '')
             ), 
             format='html'
         )
     ]