有电梯吗+扩展完整示例?

发布于 2024-10-26 12:32:24 字数 67 浏览 6 评论 0原文

有 hello scalate 的例子,但是太简单了,不好学。 我想知道如何整合升力和升级,例如升力彗星、升力形式...

There are hello scalate example, but it's too simple to learn.
I want to know how integirat lift and scalate, for example, lift comet, lift form ...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

活泼老夫 2024-11-02 12:32:24

事实证明,Lift scalate 模块 (2.5) 的当前版本不起作用(在与代码片段和 Comet 集成的意义上)。问题是 scalate 模块将 scalate 渲染器放入管道中,作为生成完整响应的东西。

因此,您的诈骗文件将呈现,但它们不支持提升标签。

为了获得您真正想要的东西,您应该侵入模板加载器(幸运的是,Lift 允许您这样做)。

我玩了一下这个,并从模块中删除了一些代码。这对我有用(尽管它需要很多东西,例如模板缓存、区域设置支持、开发模式与生产模式,也许还有一些配置参数(例如,在生产模式下,您是否希望 scalate 每次都处理诈骗,或者只是在初始加载时处理) 其中

在 Boot.scala 中:

ScalamdTemplateLoader.init

ScalamdTemplateLoader.scala 的

... other imports ...
import net.liftmodules.scalate.LiftTemplateEngine

object ScalamdTemplateLoader extends Loggable {
  val renderer = new LiftTemplateEngine
  def init = {
    LiftRules.externalTemplateResolver.default.set(scalateTemplateLoader _)
  }

  protected def createUri(path: List[String], ext: String): String = path.mkString("/") +
    (if (ext.length > 0) "." + ext else "")

  protected def canLoad(v: String): Boolean = {
    renderer.canLoad(v)
  }

  def canRender(path: List[String], ext: String): Boolean = {
    if (ext == "") {
      canLoad(createUri(path, "scaml")) || canLoad(createUri(path, "ssp"))
    } else {
      val uri = createUri(path, ext)
      (uri.endsWith(".ssp") || uri.endsWith(".scaml")) && canLoad(uri)
    }
  }

  def scalateTemplateLoader: PartialFunction[(Locale, List[String]), Box[NodeSeq]] = {
    case (l: Locale, path: List[String]) if (canRender(path, "")) => {
      val uri: String = List("scaml", "ssp").map(createUri(path, _)).find(renderer.canLoad(_)).get
      val rawTemplate = renderer.layout(uri)
      val is = new ByteArrayInputStream(rawTemplate.getBytes("UTF-8"));
      val parserFunction: InputStream => Box[NodeSeq] = S.htmlProperties.htmlParser
      parserFunction(is)
    }
  }
}

大部分代码是直接从模块中删除的(请参阅 ScalateView...这会导致 LiftResponse)...通过将其作为外部模板加载器放入并运行通过 S.htmlParser,我们最终得到一个输入到整个 lift 子系统的模板...scalate 用作 Lift 的模板源,而不是响应源

输入这样的模板时:

%html{:xmlns => "http://www.w3.org/1999/xhtml", "xml:lang" => "en", :lang => "en"}
  %body
    %p Hi there
    %div.crap This is some crap
    %div(class="lift:Demo1.currentTime")
      %p I am having fun at 
      %span.time

当我 从 Demo1 片段获取预期响应:

class Demo1 {
  def currentTime(n : NodeSeq) : NodeSeq = <span class="time">{ new Date().toString }</span>
}

It turns out that the current incarnation of the Lift scalate module (2.5) does not work (in the sense of integrating with snippets and comet). The problem is that the scalate module puts the scalate renderer into the pipeline as something that generates a completed response.

Thus, your scaml files will render, but they will not support lift tags.

To get what you really want, you should hack into the Template loader (which Lift, fortunately, allows you to do).

I played with this a bit, and ripped off a bit of code from the module. This works for me (though it needs many things, like caching of template, locale support, development mode vs production mode, perhaps some config parameters (e.g. in production mode do you want scalate to process the scaml every time, or just on initial load?).

In Boot.scala:

ScalamdTemplateLoader.init

where ScalamdTemplateLoader.scala is

... other imports ...
import net.liftmodules.scalate.LiftTemplateEngine

object ScalamdTemplateLoader extends Loggable {
  val renderer = new LiftTemplateEngine
  def init = {
    LiftRules.externalTemplateResolver.default.set(scalateTemplateLoader _)
  }

  protected def createUri(path: List[String], ext: String): String = path.mkString("/") +
    (if (ext.length > 0) "." + ext else "")

  protected def canLoad(v: String): Boolean = {
    renderer.canLoad(v)
  }

  def canRender(path: List[String], ext: String): Boolean = {
    if (ext == "") {
      canLoad(createUri(path, "scaml")) || canLoad(createUri(path, "ssp"))
    } else {
      val uri = createUri(path, ext)
      (uri.endsWith(".ssp") || uri.endsWith(".scaml")) && canLoad(uri)
    }
  }

  def scalateTemplateLoader: PartialFunction[(Locale, List[String]), Box[NodeSeq]] = {
    case (l: Locale, path: List[String]) if (canRender(path, "")) => {
      val uri: String = List("scaml", "ssp").map(createUri(path, _)).find(renderer.canLoad(_)).get
      val rawTemplate = renderer.layout(uri)
      val is = new ByteArrayInputStream(rawTemplate.getBytes("UTF-8"));
      val parserFunction: InputStream => Box[NodeSeq] = S.htmlProperties.htmlParser
      parserFunction(is)
    }
  }
}

most of this code is ripped directly from the module (see ScalateView...which results in a LiftResponse)...by putting it in as an external template loader, and running that through the S.htmlParser, we end up with a template that is fed into the entire lift subsystems...scalate is used as the template source for Lift, instead of the response source.

When I feed in a template like this:

%html{:xmlns => "http://www.w3.org/1999/xhtml", "xml:lang" => "en", :lang => "en"}
  %body
    %p Hi there
    %div.crap This is some crap
    %div(class="lift:Demo1.currentTime")
      %p I am having fun at 
      %span.time

I get the expected response from the Demo1 snippet:

class Demo1 {
  def currentTime(n : NodeSeq) : NodeSeq = <span class="time">{ new Date().toString }</span>
}
深者入戏 2024-11-02 12:32:24

与任何其他 Lift 模板机制相同。

可以调用片段:

<div class="lift:MySnippet">...</div>

Comet 只是一个片段:

<div class="lift:comet?type=MyCometThing">...</div>

https://groups.google .com/d/topic/liftweb/f_zOj3ZOLQg/discussion

The same way as with any other Lift templating mechanism.

Snippets can be invoked:

<div class="lift:MySnippet">...</div>

and Comet is just a snippet:

<div class="lift:comet?type=MyCometThing">...</div>

https://groups.google.com/d/topic/liftweb/f_zOj3ZOLQg/discussion

放肆 2024-11-02 12:32:24

您可以在 pdf 中找到很多内容

You will find lots of them in This pdf

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文