将Scalate集成到Play 2.0中 [英] Integrating Scalate into Play 2.0

查看:94
本文介绍了将Scalate集成到Play 2.0中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我欣赏的Play 2.0框架的一个功能是静态编译视图.如果控制器在未提供正确数量的类型正确的参数的情况下呈现视图,则会引发编译错误.这样就大大提高了可维护性,因为不必通过运行应用程序来测试控制器的视图差异,而是在编译时出现.

A feature of the Play 2.0 framework I appreciate is statically compiled views. If a controller renders a view without supplying the correct number of well-typed arguments, a compile error is thrown. This greatly increases maintainability as controller<>view discrepancies don't have to be tested by running the application but appear at compile time instead.

但是,标准的Play 2.0视图模板使用纯HTML结合Scala作为一种语言.我想使用Scalate,以便可以将Scala与不太冗长的Scaml或Jade模板语言结合使用.但是我不想使用Scalate在运行时编译视图,因为我会失去上面提到的静态编译视图的优势.

However, the standard Play 2.0 view templates use plain HTML combined with Scala as a language. I want to use Scalate so I can combine Scala with the much less verbose Scaml or Jade templating languages. But I don't want to use Scalate to compile my views on runtime, because I'll lose the advantage of statically compiled views I've mentioned above.

因此,我尝试按照

Therefore, I've tried implementing static compilation of my Jade views using the xsbt-scalate-generator as described elsewhere. This only gets me halfway though - the plugin when configured correctly manages to produce corresponding .class files, but it names and packages them differently than normal Play 2.0 views. A default Play 2.0 view named index.scala.html gets compiled to a file index.class in the package views.html. However, a Jade view named index.jade creates a file $_scalate_$default_jade.class in the default (blank) package. This class is not importable and not usable in a Java Play 2.0 controller.

如何以仅在控制器中编写return ok(views.html.index.render(args));的方式生成Scalate视图的类文件?

How can I generate the class files of my Scalate views in such a way that I could just write return ok(views.html.index.render(args)); in my controllers?

(看来生成的类至少提供了一个名为render()的方法)

(It does appear the generated classes provide a method named render() at least)

推荐答案

我开始做了一个插件来做到这一点.检阅我的工作: https://github.com/kryptt/play2-scalate-plugin

I started out a plugin to do just that. Checkout my work on: https://github.com/kryptt/play2-scalate-plugin

这篇关于将Scalate集成到Play 2.0中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆