简体   繁体   English

龙卷风:UIModule用于包含缩小的javascript

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM