Instantly share code, notes, and snippets.

Embed
What would you like to do?
package bootstrap.liftweb
import _root_.net.liftweb.common._
import _root_.net.liftweb.util._
import _root_.net.liftweb.http._
import _root_.net.liftweb.sitemap._
import _root_.net.liftweb.sitemap.Loc._
import Helpers._
/**
* A class that's instantiated early and run. It allows the application
* to modify lift's environment
*/
class Boot {
def boot {
println("In boot")
getClass.getClassLoader match {
case rcl: java.net.URLClassLoader =>
println("Classpath:" + rcl.getURLs.mkString("\n ", "\n ",""))
}
// where to search snippet
LiftRules.addToPackages("reactive.web")
reactive.web.Reactions.initComet
// Build SiteMap
val entries = Menu(Loc("Home", List("index"), "Home")) ::
Menu(Loc("Clock", List("clock"), "Clock")) ::
Menu(Loc("Echo", List("echo"), "Echo")) ::
Nil
LiftRules.setSiteMap(SiteMap(entries:_*))
}
}
<lift:surround with="default" at="content">
<!-- 必須 -->
<div class="lift:reactive" />
<!-- CSS Selector Snippet (Lift2.2 or later) -->
<div class="lift:ClockCSSSnippet">
<span id="clock" />
</div>
<!-- Old Snippet -->
<lift:clockOldSnippet >
<ns:clock />
</lift:clockOldSnippet >
</lift:surround>
package reactive
package web
package snippet
import _root_.scala.xml._
import net.liftweb.util.{Helpers, BindPlus}
import Helpers._
import BindPlus._
import net.liftweb.http._
class ClockCSSSnippet extends ReactiveSnippet {
val clockES = new Timer(interval = 1000, cancel = ()=> !isPageAlive)
val clockSig = clockES.hold(0L)
val clockSpan = Span( clockSig.map( t => Text((new java.util.Date).toString )) )
def render = "#clock" #> clockSpan
}
class ClockOldSnippet extends ReactiveSnippet{
val clockES = new Timer(interval = 1000, cancel = ()=> !isPageAlive)
val clockSig = clockES.hold(0L)
val clockSpan = Span( clockSig.map( t => Text((new java.util.Date).toString )) )
def render(xhtml:NodeSeq) :NodeSeq =
bind( "ns", xhtml, "clock" -> clockSpan )
}
<lift:surround with="default" at="content">
<div class="lift:reactive" />
<div class="lift:EchoSnippet">
<input id="field" /><br />
エコー: "<span id="echo"/>"<br />
</div>
</lift:surround>
package reactive
package web
package snippet
import _root_.scala.xml._
import net.liftweb.util.{Helpers, BindPlus}
import Helpers._
import BindPlus._
import net.liftweb.http._
class EchoSnippet extends ReactiveSnippet {
val field = TextInput()
field.value updateOn field.keyUp
val fieldValue = field.value.value map { v =>
println( "passed from client:"+v );
Text(v)
}
println( fieldValue ); //MappedSignal
val echo = Span( fieldValue )
def render =
"#field" #> field &
"#echo" #> echo
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment