Skip to content

Commit

Permalink
Migrated a bunch of samples to use the CSS binding rather than manual…
Browse files Browse the repository at this point in the history
… binds
  • Loading branch information
timperrett committed Apr 17, 2011
1 parent 2bb980e commit 689136b
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 150 deletions.
4 changes: 2 additions & 2 deletions chapter-6/src/main/scala/bootstrap/liftweb/Boot.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class Boot {
Menu("Implementing LiftView sub-type") / "MyView" / "sample"
),
Menu("Requests, Sessions & Cookies") / "state" / "index" submenus(
Menu("Implementing a RequestVar[Box[String]]") / "wizard" / "request_var",
Menu("Getting and setting a cookie value") / "wizard" / "cookie_handling"
Menu("Implementing a RequestVar[Box[String]]") / "state" / "request_var",
Menu("Getting and setting a cookie value") / "state" / "cookie_handling"
),
Menu("LiftScreen and Wizard") / "wizard" / "index" submenus(
Menu("Basic LiftScreen implementation") / "wizard" / "lift_screen_one",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import net.liftweb.widgets.autocomplete.AutoComplete
class AutoCompleteSample {
private val data = List("Timothy","Derek","Ross","Tyler","Indrajit","Harry","Greg","Debby")

def sample(xhtml: NodeSeq): NodeSeq =
bind("f", xhtml,
"find_name" -> AutoComplete("",
(current,limit) => data.filter(_.toLowerCase.startsWith(current.toLowerCase)),
x => println("Submitted: " + x))
)
def sample = "*" #> AutoComplete("", (current,limit) =>
data.filter(_.toLowerCase.startsWith(current.toLowerCase)),
x => println("Submitted: " + x))
}
25 changes: 10 additions & 15 deletions chapter-6/src/main/scala/sample/snippet/CookieSample.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,26 @@ import net.liftweb.util.Helpers._
import net.liftweb.http.{DispatchSnippet,S,SHtml}
import net.liftweb.http.provider.HTTPCookie

// listing 6.15
// listing 6.13
class CookieSample extends DispatchSnippet {
override def dispatch = {
case "add" => add _
case "delete" => delete _
case "add" => add
case "delete" => delete
case _ => display _
}

private val cookieName = "liftinaction.sample"

private def action(does: String, using: () => Any, xhtml: NodeSeq) =
bind("c",xhtml,
"button" -> SHtml.submit(does,
() => {using(); S.redirectTo(S.uri)}))
private def action(does: String, using: () => Any) =
"*" #> SHtml.submit(does, () => {using(); S.redirectTo(S.uri)})

def delete(xhtml: NodeSeq): NodeSeq =
action("Delete Cookie", () => S.deleteCookie(cookieName), xhtml)
def delete = action("Delete Cookie",
() => S.deleteCookie(cookieName))

def add(xhtml: NodeSeq): NodeSeq =
action("Create Cookie", () => S.addCookie(
HTTPCookie(cookieName,"I love cookies")), xhtml)
def add = action("Create Cookie", () => S.addCookie(
HTTPCookie(cookieName,"I love cookies")))

def display(xhtml: NodeSeq): NodeSeq =
S.findCookie(cookieName).map { cookie =>
def display(xhtml: NodeSeq) = S.findCookie(cookieName).map { cookie =>
Text("Cookie found!: %s".format(cookie))
} openOr Text("No cookie set.")

}
12 changes: 7 additions & 5 deletions chapter-6/src/main/scala/sample/snippet/RequestVarSample.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ object sample extends RequestVar[Box[String]](Empty)

object RequestVarSample extends DispatchSnippet {
def dispatch = {
case _ => render _
case _ => render
}
def render = {
"type=text" #> SHtml.text(
sample.is.openOr(""),
v => sample(Box.!!(v))) &
"type=submit" #> SHtml.onSubmitUnit(() => println(sample.is))
}
def render(xhtml: NodeSeq): NodeSeq = bind("f",xhtml,
"value" -> SHtml.text(sample.is.openOr(""), v => sample(Box.!!(v))),
"submit" -> SHtml.submit("Submit", () => println(sample.is))
)
}
7 changes: 3 additions & 4 deletions chapter-6/src/main/webapp/state/cookie_handling.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<lift:surround with="single_bind" at="content">
<h1>Cookies</h1>

<p>Attempted looking for cookie: <strong><lift:cookie_sample /></strong></p>
<p>Attempted looking for cookie: <strong lift="cookie_sample">Cookie Name</strong></p>
<p>
<lift:cookie_sample.add form="post"><c:button /></lift:cookie_sample.add>
<input type="button" lift="cookie_sample.add?form=post" />
<br />
<lift:cookie_sample.delete form="post"><c:button /></lift:cookie_sample.delete>
<input type="button" lift="cookie_sample.delete?form=post" />
</p>
</lift:surround>
7 changes: 4 additions & 3 deletions chapter-6/src/main/webapp/state/request_var.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<lift:surround with="single_bind" at="content">
<h2>RequestVar sample</h2>

<lift:request_var_sample form="post">
<p><f:value /> <f:submit /></p>
</lift:request_var_sample>
<form lift="request_var_sample?form=post">
<p><input type="text" /><br />
<input type="submit" /></p>
</form>

</lift:surround>
6 changes: 2 additions & 4 deletions chapter-6/src/main/webapp/widgets/auto_complete.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<lift:surround with="single_bind" at="content">
<h1>Auto Complete Widget</h1>

<lift:auto_complete_sample.sample form="post">
<form lift="auto_complete_sample.sample?form=post">
<p>Type a name here: <f:find_name /></p>
</lift:auto_complete_sample.sample>

</form>
</lift:surround>
112 changes: 1 addition & 111 deletions lift-in-action.tmproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>currentDocument</key>
<string>chapter-6/src/main/webapp/snippets/lazy_loading.html</string>
<key>documents</key>
<array>
<dict>
Expand Down Expand Up @@ -35,118 +33,10 @@
<key>firstVisibleLine</key>
<integer>0</integer>
</dict>
<key>chapter-6/src/main/scala/sample/snippet/LazyLoading.scala</key>
<dict>
<key>caret</key>
<dict>
<key>column</key>
<integer>0</integer>
<key>line</key>
<integer>14</integer>
</dict>
<key>firstVisibleColumn</key>
<integer>0</integer>
<key>firstVisibleLine</key>
<integer>0</integer>
</dict>
<key>chapter-6/src/main/webapp/snippets/intermediate_example.html</key>
<dict>
<key>caret</key>
<dict>
<key>column</key>
<integer>0</integer>
<key>line</key>
<integer>3</integer>
</dict>
<key>firstVisibleColumn</key>
<integer>0</integer>
<key>firstVisibleLine</key>
<integer>0</integer>
</dict>
<key>chapter-6/src/main/webapp/snippets/lazy_loading.html</key>
<dict>
<key>caret</key>
<dict>
<key>column</key>
<integer>16</integer>
<key>line</key>
<integer>11</integer>
</dict>
<key>firstVisibleColumn</key>
<integer>0</integer>
<key>firstVisibleLine</key>
<integer>0</integer>
</dict>
<key>chapter-8/src/main/scala/sample/lib/RestExampleAdvanced.scala</key>
<dict>
<key>caret</key>
<dict>
<key>column</key>
<integer>2</integer>
<key>line</key>
<integer>28</integer>
</dict>
<key>firstVisibleColumn</key>
<integer>0</integer>
<key>firstVisibleLine</key>
<integer>0</integer>
</dict>
<key>chapter-9/src/main/scala/bootstrap/liftweb/Boot.scala</key>
<dict>
<key>caret</key>
<dict>
<key>column</key>
<integer>4</integer>
<key>line</key>
<integer>11</integer>
</dict>
<key>firstVisibleColumn</key>
<integer>0</integer>
<key>firstVisibleLine</key>
<integer>0</integer>
</dict>
<key>chapter-9/src/main/scala/sample/comet/Clock.scala</key>
<dict>
<key>caret</key>
<dict>
<key>column</key>
<integer>0</integer>
<key>line</key>
<integer>22</integer>
</dict>
<key>firstVisibleColumn</key>
<integer>0</integer>
<key>firstVisibleLine</key>
<integer>0</integer>
</dict>
<key>chapter-9/src/main/scala/sample/comet/RockPaperScissors.scala</key>
<dict>
<key>caret</key>
<dict>
<key>column</key>
<integer>40</integer>
<key>line</key>
<integer>137</integer>
</dict>
<key>firstVisibleColumn</key>
<integer>0</integer>
<key>firstVisibleLine</key>
<integer>112</integer>
</dict>
</dict>
<key>openDocuments</key>
<array>
<string>chapter-8/src/main/scala/sample/lib/RestExampleAdvanced.scala</string>
<string>chapter-9/src/main/scala/bootstrap/liftweb/Boot.scala</string>
<string>chapter-9/src/main/scala/sample/comet/Clock.scala</string>
<string>chapter-9/src/main/scala/sample/comet/RockPaperScissors.scala</string>
<string>chapter-6/src/main/scala/sample/snippet/LazyLoading.scala</string>
<string>chapter-6/src/main/webapp/snippets/lazy_loading.html</string>
<string>chapter-6/src/main/webapp/snippets/intermediate_example.html</string>
</array>
<key>showFileHierarchyDrawer</key>
<true/>
<key>windowFrame</key>
<string>{{348, 181}, {876, 673}}</string>
<string>{{514, 71}, {876, 673}}</string>
</dict>
</plist>

0 comments on commit 689136b

Please sign in to comment.