How to use the jinja.FileSystemLoader function in Jinja

To help you get started, we’ve selected a few Jinja examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ibid / ibid / ibid / source / http.py View on Github external
# Released under terms of the MIT/X/Expat Licence. See COPYING for details.

import logging

from twisted.web import server, resource, static, xmlrpc, soap
from twisted.application import internet
from twisted.internet import reactor
from jinja import Environment, FileSystemLoader

import ibid
from ibid.source import IbidSourceFactory
from ibid.event import Event
from ibid.config import Option, IntOption
from ibid.utils import locate_resource

templates = Environment(loader=FileSystemLoader(
                               locate_resource('ibid', 'templates')))

class Index(resource.Resource):

    def __init__(self, name, *args, **kwargs):
        resource.Resource.__init__(self, *args, **kwargs)
        self.name = name
        self.log = logging.getLogger('source.%s' % name)
        self.template = templates.get_template('index.html')

    def render_GET(self, request):
        return self.template.render(rpc=ibid.rpc.keys()).encode('utf-8')

class Message(resource.Resource):

    def __init__(self, name, *args, **kwargs):
github btbytes / pyofc2 / examples.py View on Github external
#generate demo-html files
    env = Environment(loader=FileSystemLoader('templates'))
    tmpl = env.get_template('code.html')
    
    
    for e in examples:
        fname = e['name']+'.html'
        outf = open(fname, 'w')
        e.update({'sidebar':sidebar})
        output = tmpl.render(**e) 
        outf.write(output)
        outf.close()

    #generate doc-html files
    env = Environment(loader=FileSystemLoader('templates'))
    tmpl = env.get_template('doc.html')


    for e in docs:
        fname = e['name']+'.html'
        outf = open(fname, 'w')
        e.update({'sidebar':sidebar})
        output = tmpl.render(**e) 
        outf.write(output)
        outf.close()        
        
    print 'Build complete.'
    print 'Run ./start.sh and visit http://localhost:8000/'
github btbytes / pyofc2 / demo / examples.py View on Github external
outf = open(e['datafile'], 'w')
        outf.write(e['json'])
        outf.close()     

    sidebar = '<dl>%s</dl>'
    links = []
    for cat in categories:
        links.append('<dt class="el2">%s</dt><dd>' % cat)
        for e in examples: #inefficient.. much
            if cat == e['cat']:
                links.append('<li><a href="%s">%s</a></li>' %(e['name']+'.html', e['title']))      
        links.append('</dd>')
    sidebar = sidebar % '\n'.join(links)
        
    #generate demo-html files
    env = Environment(loader=FileSystemLoader('templates'))
    tmpl = env.get_template('code.html')
    
    
    for e in examples:
        fname = e['name']+'.html'
        outf = open(fname, 'w')
        e.update({'sidebar':sidebar})
        output = tmpl.render(**e) 
        outf.write(output)
        outf.close()

    #generate doc-html files
    env = Environment(loader=FileSystemLoader('templates'))
    tmpl = env.get_template('doc.html')
github pallets / jinja / jdebug.py View on Github external
frm = sys._getframe()
        result = []
        for obj in gc.get_objects():
            if id(obj) not in self.guarded_objects and \
               obj is not frm and obj is not result:
                result.append(obj)
        return result


m = MemoryGuard()


if __name__ == '__main__':
    if len(sys.argv) > 1:
        from jinja import FileSystemLoader
        e.loader = FileSystemLoader(sys.argv[1])
    if len(sys.argv) > 2:
        p(f=sys.argv[2])
    else:
        p(sys.stdin.read())
github TurboGears / tg2 / tg / environment.py View on Github external
def template_loaded(template):
                "Plug-in our i18n function to Genshi."
                genshi.template.filters.insert(0, Translator(ugettext))
                
            config['pylons.app_globals'].genshi_loader = TemplateLoader(
                paths['templates'], auto_reload=True)
            
            config['pylons.app_globals'].renderer_functions = render_genshi  
                
        if 'jinja' in base_config.renderers:
            # Create the Jinja Environment
            from jinja import ChoiceLoader, Environment, FileSystemLoader
            from tg.render import render_jinja
            
            config['pylons.app_globals'].jinja_env = Environment(loader=ChoiceLoader(
                    [FileSystemLoader(path) for path in paths['templates']]))
            # Jinja's unable to request c's attributes without strict_c
            config['pylons.strict_c'] = True
            
            config['pylons.app_globals'].renderer_functionsloa = render_jinja
        
        # If you'd like to change the default template engine used to render
        # text/html content, edit these options.
        config['buffet.template_engines'].pop()
        template_location = '%s.templates' %base_config.package.__name__
        config.add_template_engine(base_config.default_renderer, 
                                   template_location,  {})

        if base_config.use_sqlalchemy:  
            # Setup SQLAlchemy database engine
            from sqlalchemy import engine_from_config
            engine = engine_from_config(config, 'sqlalchemy.')
github pallets / jinja / www / generate.py View on Github external
from jinja import Environment, FileSystemLoader
from jinja.filters import stringfilter
from pygments import highlight
from pygments.lexers import get_lexer_by_name
from pygments.formatters import HtmlFormatter


_data_re = re.compile(
    r'(?P.*?).*?'
    r'(?P.*?).*?'
    r'(?P.*?)(?sm)'
)

formatter = HtmlFormatter(cssclass='syntax', encoding=None, style='pastie')

env = Environment('&lt;%', '%&gt;', '&lt;%=', '%&gt;', loader=FileSystemLoader('.',
    cache_folder='/tmp'), trim_blocks=True)
env.filters['pygmentize'] = stringfilter(lambda v, l:
    highlight(v.strip(), get_lexer_by_name(l), formatter))


def get_files(folder):
    for fn in os.listdir(folder):
        fn = os.path.join(folder, fn)
        if os.path.isdir(fn):
            for item in get_files(fn):
                yield item
        elif fn.endswith('.tmpl'):
            yield fn


# generate static stuff
github btbytes / pyofc2 / demo / examples.py View on Github external
#generate demo-html files
    env = Environment(loader=FileSystemLoader('templates'))
    tmpl = env.get_template('code.html')
    
    
    for e in examples:
        fname = e['name']+'.html'
        outf = open(fname, 'w')
        e.update({'sidebar':sidebar})
        output = tmpl.render(**e) 
        outf.write(output)
        outf.close()

    #generate doc-html files
    env = Environment(loader=FileSystemLoader('templates'))
    tmpl = env.get_template('doc.html')


    for e in docs:
        fname = e['name']+'.html'
        outf = open(fname, 'w')
        e.update({'sidebar':sidebar})
        output = tmpl.render(**e) 
        outf.write(output)
        outf.close()        
        
    print 'Build complete.'
    print 'Run ./start.sh and visit http://localhost:8000/'
github pallets / jinja / jinja2 / contrib / _djangosupport.py View on Github external
def configure(convert_filters=DEFAULT_FILTERS, loader=None, **options):
    """
    Initialize the system.
    """
    global env

    if env:
        warnings.warn("Jinja already initialized.")
        return

    # setup environment
    if loader is None:
        loaders = tuple(FileSystemLoader(l) for l in settings.TEMPLATE_DIRS)
        if not loaders:
            loader = None
        elif len(loaders) == 1:
            loader = loaders[0]
        else:
            loader = ChoiceLoader(loaders)
    env = Environment(loader=loader, **options)

    # convert requested filters
    for name in convert_filters:
        env.filters[name] = convert_django_filter(name)

    # import templatetags of installed apps
    for app in settings.INSTALLED_APPS:
        try:
            __import__(app + '.templatetags')