Giter Site home page Giter Site logo

jinja_app_loader's Introduction

jinja_app_loader

Jinja 2 loader for resource-based apps.

You can setup it like:

    jinja_app.loader.Loader(
        root_dir='my_templates',
        app_subdir='app_temlates',
    )

And it will look for template myapp/template.html in the next order:

  • my_templates/myapp/template.html
  • path of myapp module + app_templates/template.html

Available params:

  • root_dir - first source of templates, you can use it to rewrite apps-defined templates, default: templates
  • app_subdir - templates folder inside apps (python modules or packages), default: templates
  • lstrip - remove left whitespaces for each template string, default: False

jinja_app_loader's People

Contributors

imbolc avatar

Watchers

 avatar  avatar  avatar

jinja_app_loader's Issues

support for pkg_resources resource management

I've been looking at the code to get started on the pkg_resources pull request, but I want to get the basic logic squared with you first.

I'm looking at L42.

It looks like app_subdir is ignored if root_dir is specified. This seems a little counterintuitive.

Also, if a / is present in template, this is taken to mean that the part before the slash is an app. What if this is instead meant to be a subdirectory of the app_subdir directory? Moreover, if no / is present in template, nothing is done at all.

So the template should either be at:

  • root_dir/template
  • template[0]/app_subdir/template[1:]

This is confusing, since you're doing some undocumented parsing on the template, in a place where I really would not expect that.

Looking at the documentation, and the init parameters, I would expect:

  • root_dir/template if app_subdir is None
  • root_dir/app_subdir/template

My pull request would add:

  • application/app_subdir/template where application path is loaded by pkg_resources

Every time I think of a way to simplify this API, I get the strong urge to just use the built-in jinja template loader options, since they provide the same functionality but with a cleaner API.

if you really want to keep using this, I would propose to rename root_dir to absolute_path, and app_subdir to template_subdir for clarity 's sake. I would also append templates_subdir to absolute_path, and remove all template parsing in favour of the pkg_resources resource manager API.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.