Permalink
Browse files

Updated for ScalaX preso

  • Loading branch information...
1 parent 1b5dbbf commit 35c97cf50bf4f74d33080d984fc4b80a4f5b3e03 @dpp committed Dec 1, 2013
@@ -86,10 +86,14 @@ class Boot {
("div *+" #> str).apply(nodes)
case ("sloth", str, nodes, _) =>
- LAFuture.build({
- Thread.sleep(100)
- ("div *+" #> str).apply(nodes)
- })
+ LAFuture.build({
+ Thread.sleep(100)
+ ("div *+" #> str).apply(nodes)
+ })
+ }
+
+ LiftRules.tagProcessor.append {
+ case ("hr", elem, session) => (elem % ("class" -> "hr-class"))
}
JavaScriptContext.install()
@@ -2,19 +2,46 @@ package code.lib
import net.liftweb.http.rest.RestHelper
import net.liftweb.actor.LAFuture
+import net.liftweb.util.Helpers
+import net.liftweb.http.{ForbiddenResponse, LiftResponse, Req, LiftRules}
+import net.liftweb.common.{Full, Box}
-/**
- * Created with IntelliJ IDEA.
- * User: dpp
- * Date: 2/12/13
- * Time: 5:21 PM
- * To change this template use File | Settings | File Templates.
- */
object DelayedRest extends RestHelper {
serve {
case "delay" :: Nil Get _ =>
- LAFuture.build({
- Thread.sleep(2000)
- <b>Hello</b>})
+ LAFuture.build({
+ Thread.sleep(2000)
+ <b>Hello</b>
+ })
+
+ case "delay" :: Helpers.AsInt(delay) :: Nil Get _ if delay > 0 =>
+ LAFuture(() => {
+ Thread.sleep(delay.toLong * 1000L)
+ <i>I slept for
+ {delay}
+ seconds</i>
+ })
}
}
+
+object Guards {
+ def isOkay_? = Helpers.randomInt(100) > 50
+
+ def guardAs404(in: LiftRules.DispatchPF): LiftRules.DispatchPF =
+ new LiftRules.DispatchPF {
+ def apply(v1: Req): () => Box[LiftResponse] = in(v1)
+
+ def isDefinedAt(x: Req): Boolean = isOkay_? && in.isDefinedAt(x)
+ }
+
+ def guardAs403(in: LiftRules.DispatchPF): LiftRules.DispatchPF =
+ new LiftRules.DispatchPF {
+ def apply(v1: Req): () => Box[LiftResponse] =
+ if (!isOkay_?)
+ () => Full(ForbiddenResponse("Verboten"))
+ else
+ in(v1)
+
+ def isDefinedAt(x: Req): Boolean = in.isDefinedAt(x)
+ }
+}
@@ -24,8 +24,7 @@ object ActNice {
}
}
- Script(JsRaw("var sendToServer = " + sess.clientActorFor(serverActor).toJsCmd).cmd &
- JsRaw("function changeNode(str) {document.getElementById(\"foo\").innerHTML = str;}").cmd)
+ Script(JsRaw("var sendToServer = " + sess.clientActorFor(serverActor).toJsCmd).cmd)
}) openOr NodeSeq.Empty
}
}
@@ -1,33 +0,0 @@
-package code.snippet
-
-import xml.NodeSeq
-import net.liftweb._
-import http._
-import js.JE.JsRaw
-import js.JsCmds.Script
-
-
-/**
- * Created with IntelliJ IDEA.
- * User: dpp
- * Date: 3/26/13
- * Time: 3:15 PM
- * To change this template use File | Settings | File Templates.
- */
-object Munger {
-def render: NodeSeq =
- (for {
- sess <- S.session
- } yield Script(JsRaw("var myFuncs = "+sess.buildRoundtrip(List(
- "thing" -> thing _,
- "foo" -> woof _)).toJsCmd).cmd)) openOr NodeSeq.Empty
-
- def thing(s: String): Stream[String] = {
- var x = 0
- (s + x) #:: {Thread.sleep(1000); x += 1; s + x} #:: {Thread.sleep(1000); x += 1; s + x} #:: Stream.empty[String]
- }
-
- def woof(s: String): String = {
- s + ": returned from server"
- }
-}
@@ -0,0 +1,41 @@
+package code.snippet
+
+import xml.NodeSeq
+import net.liftweb._
+import http._
+import js.JE.JsRaw
+import js.JsCmds.Script
+
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: dpp
+ * Date: 3/26/13
+ * Time: 3:15 PM
+ * To change this template use File | Settings | File Templates.
+ */
+object PromisingStuff {
+def render: NodeSeq =
+ (for {
+ sess <- S.session
+ } yield Script(JsRaw("var myFuncs = "+sess.buildRoundtrip(List(
+ "thing" -> thing _)).toJsCmd).cmd)) openOr NodeSeq.Empty
+
+ def thing(s: String): Stream[String] = {
+ var x = 0
+ (s + x) #:: {Thread.sleep(1000); x += 1; s + x} #::
+ {Thread.sleep(1000); x += 1; s + x} #::
+ {Thread.sleep(1000); x += 1; s + x} #::
+ {Thread.sleep(1000); x += 1; s + x} #::
+ {Thread.sleep(1000); x += 1; s + x} #::
+ {Thread.sleep(1000); x += 1; s + x} #::
+ {Thread.sleep(1000); x += 1; s + x} #::
+ {Thread.sleep(1000); x += 1; s + x} #::
+ {Thread.sleep(1000); x += 1; s + x} #::
+ {Thread.sleep(1000); x += 1; s + x} #::
+ {Thread.sleep(1000); x += 1; s + x} #::
+ {Thread.sleep(1000); x += 1; s + x} #::
+ {Thread.sleep(1000); x += 1; s + x} #::
+ Stream.empty[String]
+ }
+}
@@ -10,11 +10,3 @@ import net.liftweb.util.ClearClearable
class TimeNow {
def render = "1 *+" #> (new Date).toString
}
-
-class RandomList {
- def render = "li *" #> (0 to randomInt(10)).map(_ => "<b>"+randomString(5)+"</b>")
-}
-
-class FixedList {
- def render = "li *" #> List("1", "fish", "red", "star") & ClearClearable
-}
View
@@ -7,34 +7,13 @@
<body class="lift:content_id=main">
<div id="main" class="lift:surround?with=default;at=content">
- <div>
- Simple Stuff
- <hr>
-
- <ul data-lift="FixedList">
- <li>A list item</li>
- <li class="clearable">Another list item</li>
- </ul>
- </div>
-
-
- <div>
- Random Stuff
- <hr>
-
- <ul data-lift="RandomList">
- <li>A list item</li>
- </ul>
- </div>
-
-
- <div data-lift="Munger">
-
+ <div data-lift="PromisingStuff">
+ <!-- Promise-related scripts will be inserted here -->
</div>
- <div data-wombat="David">My wombat is named:</div>
- <div data-sloth="Archer">My sloth is named:</div>
+ <div data-wombat="David">My wombat is named: </div>
+ <div data-sloth="Archer">My sloth is named: </div>
<hr>
@@ -51,7 +30,7 @@
<div>Enter some text <input id="in2"> and
- <button onclick="myFuncs.thing(document.getElementById('in2').value).onSuccess(function(v) {document.getElementById('foo2').innerHTML = v;})">Click me</button>
+ <button onclick="myFuncs.thing(document.getElementById('in2').value).then(function(v) {document.getElementById('foo2').textContent = v;})">Click me</button>
</div>
<p>
@@ -70,61 +49,38 @@
<li data-jssource="* *+ #> ['fpx',2,'dog', 'hi']">Wombat: </li>
</ul>
+
+ <script>
+ function changeNode(str) {
+ document.getElementById("foo").textContent = str;
+ }
+ </script>
+
<ul>
<li data-jssource="[{'name': 'David', age: 49},{'name': 'Wombat'}, {name: 'Archer', age: 9}]">
<span data-jssource="* *+ #> it.name">Name: </span>
<span data-jssource="* *+ #> it.age">Age: </span>
</li>
</ul>
-
- <div>
- Visi stuff here!
- Tax Rate: <input id="taxRate"><br>
- Taxable: <input id="taxable"><br>
- Non-taxable: <input id="nonTaxable"><br>
- <hr>
- Total: <span id="Total"></span><br>
- Tax: <span id="Tax"></span><br>
- Prod: <span id="prod"></span><br>
-
-
- <script data-visi="true">
- # Whole Example
-
- This is a complete example of a Visi model. The input section defines what sources (inputs) are supplied to the model. Each time one of those sources changes, Visi recomputes the dependent sinks (outputs) and updates the sinks based on the business logic.
-
-
- The inputs: taxRate, taxable, and nonTaxable
-
- ```
- /* A big multi-line expression */
- ?taxRate // source the tax rate
- ?taxable // the taxable amount
- ?nonTaxable // the nontaxable amount
- ```
-
- Perform the computations calculating the subtotal, the tax amount and the total.
-
- ```
- // computation
- subtotal = taxable + nonTaxable
- tax = taxable * taxRate
- total = subtotal + tax
- ```
-
- Output the stuff.
-
- ```
- // the output or "sink" section
- "Total" = total // sink the total
- "Tax" = tax // sink the tax
- ````
-
- </script>
+ <div data-sloth="Archer">My sloth is named:</div>
+ <div data-sloth="Archer">My sloth is named:</div>
+ <div data-sloth="Archer">My sloth is named:</div>
+ <div data-sloth="Archer">My sloth is named:</div>
+ <div data-sloth="Archer">My sloth is named:</div>
+ <div data-sloth="Archer">My sloth is named:</div>
+ <div data-sloth="Archer">My sloth is named:</div>
+ <div data-sloth="Archer">My sloth is named:</div>
+ <div data-sloth="Archer">My sloth is named:</div>
+ <div data-sloth="Archer">My sloth is named:</div>
+ <div data-sloth="Archer">My sloth is named:</div>
+ <div data-sloth="Archer">My sloth is named:</div>
+ <div data-sloth="Archer">My sloth is named:</div>
+ <div data-sloth="Archer">My sloth is named:</div>
+ <div data-sloth="Archer">My sloth is named:</div>
+ <div data-sloth="Archer">My sloth is named:</div>
- </div>
</p>
</div>

0 comments on commit 35c97cf

Please sign in to comment.