[英]tornado: UIModule for including minified javascript
I'd like to build a Tornado UIModule
which would allow me to include a Javascript file but minify it before rendering. 我想构建一个Tornado
UIModule
,它将允许我包含一个Javascript文件,但在渲染前将其最小化 。 Eg 例如
{% module include_jsmin("file.js") %}
{%module include_jsmin(“ file.js”)%}
My only problem is that I don't seem to find an elegant way to grab hold of the Template Loader for the application. 我唯一的问题是,我似乎没有找到一种优雅的方法来抓住应用程序的模板加载器。
How would I do that? 我该怎么办?
Edit : I know about the render_string
method in the UIModule
but unfortunately the configured path to the templates isn't available. 编辑 :我知道的
render_string
的方法UIModule
但不幸的是,以模板配置的路径不可用。
Found a neat way: 找到了一种整洁的方法:
-Configure the tornado application with a tornado.template.Loader
using the setting template_loader
: make sure to specify the absolute path to the root of your template dir -通过设置
template_loader
使用tornado.template.Loader
配置tornado应用程序:确保指定模板目录根目录的绝对路径
-Use the render_string
in the UIModule
to grab hold of file you wish to process -使用
render_string
中的UIModule
来抓取您要处理的文件
class JsonMinify(UIModule):
def render(self, path):
code=self.render_string(path)
return slimit.minify(code)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.