I want to apply a function to the template source before is parsed by the Tornado Template engine.
Like Jinja2 Preprocessor method http://jinja.pocoo.org/docs/api/#low-level-api
Can I do something like this without touching the template loader?
If not, should be good add this option the templates (preprocess = [method1,method2,..])
Why do you dismiss the idea of touching the template loader? That seems like the natural place to put such a feature (where would this "preprocess" directive go otherwise?). We'd just need to refactor the BaseLoader interface so there's a subclass-overridable method between the reading of the raw template data and the creation of the template (or maybe just allow the template class to be passed in instead of always using Template).
Touching the template loader is not the best way for apply preprocess to templates, because of the preprocessing method shouldnt depend on the loader used.
Jinja2 template system also integrates the preprocess method inside the Template Class https://github.com/mitsuhiko/jinja2/blob/master/jinja2/environment.py#L417
The template loader is the only practical place for preprocessing to occur since it's the part that is most configurable by the application. With a little refactoring of the loader interface it would be possible to make one template loader that wraps another so you could mix preprocessing with different types of underlying loaders.