home | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Lift Framework example source code file (BindHelpersSpec.scala)

This example Lift Framework source code file (BindHelpersSpec.scala) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Lift Framework tags/keywords

dog, empty, full, hello, hello, hi, list, list, nodeseq, nodeseq, some, text, text, third

The Lift Framework BindHelpersSpec.scala source code

/*
 * Copyright 2007-2011 WorldWide Conferencing, LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.liftweb
package util

import xml._

import org.specs.Specification

import common._
import BindHelpers._


/**
 * Systems under specification for BindHelpers.
 */
object BindHelpersSpec extends Specification("BindHelpers Specification") {

  "the mixinAttributes function" should {
    "mixin in all the attributes" in {
      mixinAttributes(<input />)() must ==/()
    }

    "not mix in the element label" in {
      mixinAttributes(<input />)(
) must ==/() } "handle the empty cases gracefully" in { mixinAttributes(<input />)(
) must ==/() } "not lose existing attributes" in { mixinAttributes(<input id="10" />)(
) must ==/() } "replace attributes with updated values" in { mixinAttributes(<input id="10" />)(
) must ==/() } } "the chooseTemplate function" should { "select the node matching a given tag and prefix" in { chooseTemplate("choose", "tag", <h>that) must ==/(Text("that")) } "select the first node matching a given tag and prefix" in { chooseTemplate("choose", "tag", <h>thatthose) must ==/(Text("that")) } "return an empty NodeSeq if no node is found" in { chooseTemplate("choose", "tag", <h>) must be_==(NodeSeq.Empty) } } "the bind(Map, NodeSeq) function" should { "replace the content of a lift:bind node with the content of a map where the key is the value of the attribute 'name'" in { val map = Map("hello" -> <h1>, "world" -> ) val liftbind = <body> <lift:bind name="hello">changethis </body> bind(map, liftbind) must ==/(<body>

) } "bind should not peserve attrs on a bound element" in { val res:NodeSeq = bind("ledger", <ledger:entry ledger:id="foo" ledger:class="bar" />, "entry" -> ) res must ==/(<foo/>) } } "the bindlist function" should { "replace the content of a lift:bind node with the content of a map where the key is the value of the attribute 'name'" in { val maps = List(Map("hello" -> <h1>, "world" -> )) val liftbind = <body> <lift:bind name="hello">changethis </body> bindlist(maps, liftbind).get must ==/(<body>

) } } "the bind(namespace, NodeSeq, BindParams*) function" should { "replace a node named 'namespace:bindparam name' in a NodeSeq with the String value of the BindParam" in { bind("user", <t>replacethis, "tag" -> "world") must ==/(world) } "replace a node named 'namespace:bindparam name' in a NodeSeq with the Symbol value of the BindParam" in { bind("user", <t>replacethis, "tag" -> 'world) must ==/(world) } "replace a node named 'namespace:bindparam name' in a NodeSeq with the Symbol value of the BindParam via lift:bind attribute" in { bind("user", <t>
replacethis
, "tag" -> 'world) must ==/(world) } "replace a node named 'namespace:bindparam name' in a NodeSeq with the NodeSeq value of the BindParam" in { bind("user", <user:tag>replacethis, "tag" -> ) must ==/() } "replace a node named 'namespace:bindparam name' in a NodeSeq with the NodeSeq value of the BindParam" in { bind("user", <user:tag>replacethis, "tag" -> ) must ==/() } "replace a node named 'namespace:bindparam name' in a NodeSeq with the function application of a FuncBindParam" in { bind("user", <t>hello, FuncBindParam("tag", (n: NodeSeq) => Text(n.text + " world"))) must ==/(hello world) } "properly convert a NodeSeq => NodeSeq to a FuncBindParam" in { bind("user", <t>hello, "tag" -> ((n: NodeSeq) => Text(n.text + " world"))) must ==/(hello world) } "replace an attribute value named 'namespace:bindparam name' in a NodeSeq with a value from a BindParam" in { bind("user", <t user:hello="toreplace">, "hello" -> Text("world")) must ==/() } "replace an attribute value named 'namespace:bindparam name' in a NodeSeq with a calculated value from a FuncBindParam" in { bind("user", <t user:tag="hello">, FuncBindParam("tag", (n: NodeSeq) => Text(n.text + " world"))) must ==/() } "replace an attribute named 'namespace:bindparam name' in a NodeSeq with a new attribute name and value from an AttrBindParam" in { bind("user", <t user:tag="toreplace">, AttrBindParam("tag", Text("world"), "hello")) must ==/() } "replace an attribute named 'namespace:bindparam name' in a NodeSeq with a new attribute name and value from an AttrBindParam using a String" in { bind("user", <t user:tag="toreplace">, AttrBindParam("tag", "world", "hello")) must ==/() } "replace an attribute named 'namespace:bindparam name' in a NodeSeq with a new attribute name and calculated value from an FuncAttrBindParam" in { bind("user", <t user:tag="dear">, FuncAttrBindParam("tag", (n: NodeSeq) =>Text(n.text + " world"), "hello")) must ==/() } "replace an attribute named 'namespace:bindparam name' in a NodeSeq with a blank attribute name and calculated value from an FuncAttrOptionBindParam" in { bind("user", <t user:tag="dear">, FuncAttrOptionBindParam("tag", (n: NodeSeq) => None, "hello")) must ==/() } "replace an attribute named 'namespace:bindparam name' in a NodeSeq with a new attribute name and calculated value from an FuncAttrOptionBindParam" in { bind("user", <t user:tag="dear">, FuncAttrOptionBindParam("tag", (n: NodeSeq) => Some(Text(n.text + " world")), "hello")) must ==/() } "replace an attribute named 'namespace:bindparam name' in a NodeSeq with a blank attribute name and calculated value from an FuncAttrBoxBindParam" in { bind("user", <t user:tag="dear">, FuncAttrBoxBindParam("tag", (n: NodeSeq) => Empty, "hello")) must ==/() } "replace an attribute named 'namespace:bindparam name' in a NodeSeq with a new attribute name and calculated value from an FuncAttrOptionBindParam" in { bind("user", <t user:tag="dear">, FuncAttrBoxBindParam("tag", (n: NodeSeq) => Full(Text(n.text + " world")), "hello")) must ==/() } } "findOption" should { "find an id" in { val xml = <foo>Dog
findOption(xml) { e => e.attribute("id"). filter(_.text == "3").map(i => e) }.get must ==/ (<woof id="3"/>) } "not find an ide" in { val xml = <foo>Dog findOption(xml) { e => e.attribute("id"). filter(_.text == "3").map(i => e) } must_== None } "not find a the wrong id" in { val xml = <foo>Dog findOption(xml) { e => e.attribute("id"). filter(_.text == "3").map(i => e) } must_== None } } "findBox" should { "find an id" in { val xml = <foo>Dog findBox(xml) { e => e.attribute("id"). filter(_.text == "3"). map(i => e) }.open_! must ==/ (<woof id="3"/>) } "not find an ide" in { val xml = <foo>Dog findBox(xml) { e => e.attribute("id"). filter(_.text == "3").map(i => e) } must_== Empty } "not find a the wrong id" in { val xml = <foo>Dog findBox(xml) { e => e.attribute("id"). filter(_.text == "3").map(i => e) } must_== Empty } } "replaceIdNode" should { "replace a node" in { Helpers.replaceIdNode(<foo>, "dog", <baz/>) must ==/ () } "Ignore if no id match" in { Helpers.replaceIdNode(<foo>, "dog", <baz/>) must ==/ () } } "the xmlParam function" should { "find the value of an attribute in an xml fragment" in { xmlParam(<t hello="world">world, "hello") must_== Full("world") } "return Empty if the value is empty" in { xmlParam(<t hello="">world, "hello") must_== Empty } "return Empty if the attribute is not found" in { xmlParam(<t hello="">world, "notfound") must_== Empty } } "Add CSS Class" should { "add a new attribute" in { (addCssClass("foo", <b/>) \ "@class").text must_== "foo" } "append an existing attribute" in { (addCssClass("foo", <b class="dog"/>) \ "@class").text must_== "dog foo" } } "The bind helpers should deal correctly with <select>" should { "do <select> correctly" in { val xhtml = <select name="days"> def options(xhtml: NodeSeq): NodeSeq = { <option value="7">week } val res = bind("stats", xhtml, "options" -> options _) res must ==/(<select name="days">) } "do <input> correctly" in { val xhtml = <input name="days"> def options(xhtml: NodeSeq): NodeSeq = { <option value="7">week } val res = bind("stats", xhtml, "options" -> options _) res must ==/(<input name="days">) } "do <div> correctly" in { val xhtml = <div>
def options(xhtml: NodeSeq): NodeSeq = { <option value="7">week } val res = bind("stats", xhtml, "options" -> options _) res must ==/(<div>
) } } "the bindByName bind(namespace, NodeSeq, BindParams*) function" should { "mix in if the element if the type of the elements are the same" in { bind("user", <t>, "tag" -> ) must ==/() } "replace the element if the replacement element type is not a bindByName type" in { bind("user", <t>, "tag" -> "world") must ==/(world) } "replace the value is value is a null string" in { bind("user", <t>, "tag" -> ) must ==/() } "handle a checkbox" in { bind("user", <t>, "tag" -> (<input /> ++ <input type="checkbox" name="F893599644556MN4" value="true"/>) ) must ==/() } } "head removal" should { "remove <head>" in { Helpers.stripHead(<head>hello) must ==/(hello) } "ignore non-head" in { Helpers.stripHead(<head3>hello) must ==/(hello) } "String subhead" in { Helpers.stripHead(<head3>hello) must ==/(hello) } } "Binding attributes" should { "handle static, unprefixed attributes" in { BindHelpers.bind("test", <div>
, AttrBindParam("x", "staticUnprefixed", "id")) must ==/(<div>
) } "handle dynamic, unprefixed attributes" in { // The Unprefixed attributes that Lift merges in cause the XML equals comparison to fail // stringifying and then reparsing fixes it. XML.loadString( BindHelpers.bind("test", <div>
, FuncAttrBindParam("x", {ns : NodeSeq => ns }, "id")).toString) must ==/(<div>
) } "handle static, prefixed attributes" in { BindHelpers.bind("test", <div>
, AttrBindParam("x", "staticPrefixed", ("result","id"))) must ==/(<div>
) } "handle dynamic, prefixed attributes" in { BindHelpers.bind("test", <div>
, FuncAttrBindParam("x", {ns : NodeSeq => ns}, ("result","id"))) must ==/(<div>
) } } } object CssBindHelpersSpec extends Specification { "css bind helpers" should { "clear clearable" in { ClearClearable(<b>) must ==/ () } "substitute a String by id" in { ("#foo" #> "hello")(<b>) must ==/ (hello) } "not duplicate classes" in { def anchor(quesType: String, value: String) = { <a href="foo" class="selected">(value) } var page = 1 var elements = List("1","2","3","4") val xml = <div class="lift:Bug.attack bug"> <div id="question" class="question"> <a href="#" class="L">1 <a href="#" class="U">1 <a href="#" class="D">1 </div> <div class="navigation"> <button class="previous">Previous </div> </div> val sel = ".question" #> elements.map(value => { ".question [id]" #> ("question-" + value) & ".question [class]" #> ("question-" + value) & ".L" #> anchor("L", value) & ".U" #> anchor("U", value) & ".D" #> anchor("D", value) }) val res = sel(xml) ((res \\ "a").head \ "@class").head.text must_== "selected L" } "Compound selector" in { val res = (".foo [href]" #> "http://dog.com" & ".bar [id]" #> "moo").apply( <a class="foo bar" href="#"/>) (res \ "@href").text must_== "http://dog.com" (res \ "@id").text must_== "moo" } "not stack overflow on Elem" in { val xf = "* [id]" #> "xx" & "* [style]" #> "border:thin solid black" & "* *" #> <a/> } "not stack overflow on Elem" in { val xf = "* [id]" #> "xx" & "* [style]" #> "border:thin solid black" & "* *+" #> <a/> xf(<div/>) } "not stack overflow on Elem" in { val xf = "* [id]" #> "xx" & "* [style]" #> "border:thin solid black" & "* -*" #> <a/> xf(<div/>) } "support modifying attributes along with body" in { val org = <a>foo val func = "a [href]" #> "dog" & "a *" #> "bar" val res = func(org) res.toString must_== "<a href=\"dog\">bar" } "substitute a String by id" in { ("#foo" replaceWith "hello")(<b>) must ==/ (hello) } "Select a node" in { ("#foo ^^" #> "hello")(<div>
) must ==/ () } "Another nested select" in { val template = <span> <div id="meow"> <lift:loc locid="asset.import.chooseFile"> <span id="file_upload"> <input type="submit" value="import" />

</div> <div id="get"> <lift:loc locid="asset.import.chooseFile"> <span id="file_upload"> <input type="submit" value="import" />

</div> </span> val xf = "#get ^^" #> "ignore" & "#file_upload" #> <input type="moose"/> val ret = xf(template) ret(0).asInstanceOf[Elem].label must_== "div" ret.length must_== 1 (ret \ "@id").text must_== "get" (ret \\ "input").length must_== 2 ((ret \\ "input").toList(0) \ "@type").map(_.text) must_== List("moose") } "Child nested select" in { val template = <span> <div id="meow"> <lift:loc locid="asset.import.chooseFile"> <span id="file_upload"> <input type="submit" value="import" />

</div> <div id="get"> <lift:loc locid="asset.import.chooseFile"> <span id="file_upload"> <input type="submit" value="import" />

</div> </span> val xf = "#get ^*" #> "ignore" & "#file_upload" #> <input type="moose"/> val ret = xf(template) (ret \\ "div").length must_== 0 (ret \\ "input").length must_== 2 ((ret \\ "input").toList(0) \ "@type").map(_.text) must_== List("moose") } "Select a node and transform stuff" in { val ret = ("#foo ^^" #> "hello" & "span [id]" #> "bar")(<span id="foo"/>) ret(0).asInstanceOf[Elem].label must_== "span" ret.length must_== 1 (ret \ "@id").text must_== "bar" } "Select a node and transform stuff deeply nested" in { val ret = ("#foo ^^" #> "hello" & "span [id]" #> "bar")(<div>
) ret(0).asInstanceOf[Elem].label must_== "span" ret.length must_== 1 (ret \ "@id").text must_== "bar" } "Select a node and transform stuff deeply nested 2" in { val ret = ("#foo ^^" #> "hello" & "span [id]" #> "bar")(<div>
) ret(0).asInstanceOf[Elem].label must_== "span" ret.length must_== 1 (ret \ "@id").text must_== "bar" (ret \ "@dog").text must_== "woof" } "substitute multiple Strings by id" in { ("#foo" #> "hello" & "#baz" #> "bye")(<b>
Hello
) must ==/ ({Text("bye")}{Text("hello")}) } "bind href and None content" in { val opt: Option[String] = None val res = ("top *" #> opt & "top [href]" #> "frog")(<top>cat) res.text must_== "" (res \ "@href").text.mkString must_== "frog" } "bind href and Some content" in { val opt: Option[String] = Some("Dog") val res = ("top *" #> opt & "top [href]" #> "frog")(<top>cat) res.text must_== "Dog" (res \ "@href").text.mkString must_== "frog" } "bind href and Some content with multiple attrs" in { val opt: Option[String] = Some("Dog") val res = ("top *" #> opt & "top [meow]" #> "woof" & "top [href]" #> "frog")(<top href="#">cat) res.text must_== "Dog" (res \ "@href").text.mkString must_== "frog" (res \ "@meow").text.mkString must_== "woof" } "option transform on *" in { val opt: Option[String] = None val res = ("* *" #> opt.map(ignore => "Dog"))(<top>cat) res.head must_== <top> } "append attribute to a class with spaces" in { val stuff = List("a", "b") val res = ("* [class+]" #> stuff)(<top class="q">cat) (res \ "@class").text must_== "q a b" } "append attribute to an href" in { val stuff = List("&a=b", "&b=d") val res = ("* [href+]" #> stuff)(<top href="q?z=r">cat) (res \ "@href").text must_== "q?z=r&a=b&b=d" } "remove an attribute from a class" in { val func = ".foo [class!]" #> "andOther" (func(<span class="foo andOther" />) \ "@class").text must_== "foo" } "remove an attribute from a class and the attribute if it's the only one left" in { val func = ".foo [class!]" #> "foo" val res = func(<span class="foo" />) (res \ "@class").length must_== 0 } "not remove a non-existant class" in { val func = ".foo [class!]" #> "bar" val res = func(<span class="foo" />) (res \ "@class").text must_== "foo" } "remove an attribute from an attribute" in { val func = "span [href!]" #> "foo" val res = func(<span href="foo" />) (res \ "@href").length must_== 0 } "not remove a non-existant href" in { val func = "span [href!]" #> "bar" val res = func(<span href="foo bar" />) (res \ "@href").text must_== "foo bar" } "option transform on *" in { val opt: Option[Int] = Full(44) val res = ("* *" #> opt.map(ignore => "Dog"))(<top>cat) res must ==/ (<top>Dog) } "option transform on *" in { val opt: Box[String] = Empty val res = ("* *" #> opt.map(ignore => "Dog"))(<top>cat) res.head must_== <top> } "option transform on *" in { val opt: Box[Int] = Some(44) val res = ("* *" #> opt.map(ignore => "Dog"))(<top>cat) res must ==/ (<top>Dog) } "transform on *" in { val res = ("* *" #> "Dog")(<top>cat) res must ==/ (<top>Dog) } "transform child content on *+" in { val res = ("* *+" #> "moose")(<a>I like ) res.text must_== "I like moose" } "transform child content on -*" in { val res = ("* -*" #> "moose")(<a> I like) res.text must_== "moose I like" } "transform on li" in { val res = ("li *" #> List("Woof", "Bark") & ClearClearable)( <ul>
  • meow
  • a
  • a
  • ) res must ==/ (<ul>
  • Woof
  • Bark
  • ) } "substitute multiple Strings by id" in { (("#foo" replaceWith "hello") & ("#baz" replaceWith "bye"))(<b>
    Hello
    ) must ==/ ({Text("bye")}{Text("hello")}) } "substitute multiple Strings with a List by id" in { ("#foo" #> "hello" & "#baz" #> List("bye", "bye"))(<b>
    Hello
    ) must ==/ ({Text("bye")}{Text("bye")}{Text("hello")}) } "substitute multiple Strings with a List by id" in { (("#foo" replaceWith "hello") & ("#baz" replaceWith List("bye", "bye")))(<b>
    Hello
    ) must ==/ ({Text("bye")}{Text("bye")}{Text("hello")}) } "substitute multiple Strings with a List of XML by id" in { val answer = ("#foo" #> "hello" & "#baz" #> List[NodeSeq](<i/>, Meow))(
    Hello
    ) (answer \ "i").length must_== 2 (answer \ "i")(0) must ==/ (<i id="baz" frog="dog"/>) (answer \ "i")(1) must ==/ (<i frog="dog">Meow) } "substitute multiple Strings with a List of XML by id" in { val answer = (("#foo" replaceWith "hello") & ("#baz" replaceWith List[NodeSeq](<i/>, Meow)))(
    Hello
    ) (answer \ "i").length must_== 2 (answer \ "i")(0) must ==/ (<i id="baz" frog="dog"/>) (answer \ "i")(1) must ==/ (<i frog="dog">Meow) } "substitute by name" in { val answer = ("name=moose" #> <input name="goof"/>).apply ( <div>) (answer \ "input")(0) must ==/ (<input name="goof" value="start" id="79"/>) } "substitute by name" in { val answer = ("name=moose" replaceWith <input name="goof"/>).apply ( <div>) (answer \ "input")(0) must ==/ (<input name="goof" value="start" id="79"/>) } "substitute by name with attrs" in { val answer = ("name=moose" #> <input name="goof" value="8" id="88"/>).apply ( <div>) (answer \ "input")(0) must ==/ (<input name="goof" value="8" id="88"/>) } "substitute by name with attrs" in { val answer = ("name=moose" replaceWith <input name="goof" value="8" id="88"/>).apply ( <div>) (answer \ "input")(0) must ==/ (<input name="goof" value="8" id="88"/>) } "substitute by a selector with attrs" in { val answer = ("cute=moose" #> <input name="goof" value="8" id="88"/>).apply ( <div>) (answer \ "input")(0) must ==/ (<input cute="moose" name="goof" value="8" id="88"/>) } "substitute by a selector with attrs" in { val answer = ("cute=moose" replaceWith <input name="goof" value="8" id="88"/>).apply ( <div>) (answer \ "input")(0) must ==/ (<input cute="moose" name="goof" value="8" id="88"/>) } "Map of funcs" in { val func: NodeSeq => NodeSeq = "#horse" #> List(1,2,3).map(".item *" #> _) val answer: NodeSeq = func(<span>
    frogi
    ) answer must ==/ (<span>
    frog1
    frog2
    frog3
    ) } "merge classes" in { val answer = ("cute=moose" #> <input class="a" name="goof" value="8" id="88"/>).apply ( <div>) (answer \ "input")(0) must ==/ (<input class="a b" cute="moose" name="goof" value="8" id="88"/>) } "merge classes" in { val answer = ("cute=moose" replaceWith <input class="a" name="goof" value="8" id="88"/>).apply ( <div>) (answer \ "input")(0) must ==/ (<input class="a b" cute="moose" name="goof" value="8" id="88"/>) } "list of strings" in { val answer = ("#moose *" #> List("a", "b", "c", "woof") & ClearClearable).apply ( <ul> <li id="moose">first <li class="clearable">second <li class="clearable">Third </ul>) val lis = (answer \ "li").toList lis.length must_== 4 lis(0) must ==/ (<li id="moose">a) lis(3) must ==/ (<li>woof) } "list of Nodes" in { val answer = ("#moose *" #> List[NodeSeq](<i>"a", Text("b"), Text("c"), woof) & ClearClearable).apply ( <ul> <li id="moose">first <li class="clearable">second <li class="clearable">Third </ul>) val lis = (answer \ "li").toList lis.length must_== 4 lis(0) must ==/ (<li id="moose">"a") lis(3) must ==/ (<li>woof) } "set href" in { val answer = ("#moose [href]" #> "Hi" & ClearClearable).apply ( <ul>first
  • second
  • Third
  • ) (answer \ "a" \ "@href").text must_== "Hi" (answer \ "li").length must_== 0 } "set href and subnodes" in { val answer = ("#moose [href]" #> "Hi" & ClearClearable).apply ( <ul>first
  • second
  • Third
  • ) (answer \ "a" \ "@href").text must_== "Hi" (answer \\ "li").length must_== 0 } "list of strings" in { val answer = (("#moose *" replaceWith List("a", "b", "c", "woof")) & ClearClearable).apply ( <ul> <li id="moose">first <li class="clearable">second <li class="clearable">Third </ul>) val lis = (answer \ "li").toList lis.length must_== 4 lis(0) must ==/ (<li id="moose">a) lis(3) must ==/ (<li>woof) } "bind must bind to subnodes" in { val html = <ul class="users"> <li class="user" userid=""> <img class="userimg" src=""/> </li> </ul> val lst = List(1,2,3) val f = ".users *" #> ("li" #> lst.map(i => ".user [userid]" #> i)) (f(html) \\ "ul").length must_== 1 (f(html) \\ "li").length must_== 3 } "list of Nodes" in { val answer = (("#moose *" replaceWith List[NodeSeq](<i>"a", Text("b"), Text("c"), woof)) & ClearClearable).apply ( <ul> <li id="moose">first <li class="clearable">second <li class="clearable">Third </ul>) val lis = (answer \ "li").toList lis.length must_== 4 lis(0) must ==/ (<li id="moose">"a") lis(3) must ==/ (<li>woof) } "set href" in { val answer = (("#moose [href]" replaceWith "Hi") & ClearClearable).apply ( <ul>first
  • second
  • Third
  • ) (answer \ "a" \ "@href").text must_== "Hi" (answer \ "li").length must_== 0 } "set href and subnodes" in { val answer = (("#moose [href]" replaceWith "Hi") & ClearClearable).apply ( <ul>first
  • second
  • Third
  • ) (answer \ "a" \ "@href").text must_== "Hi" (answer \\ "li").length must_== 0 } } } /** * This class doesn't actually perform any tests, but insures that * the implicit conversions work correctly */ object CheckTheImplicitConversionsForToCssBindPromoter { val bog = new ToCssBindPromoter(Empty, Empty) import BindHelpers._ "foo" #> "baz" bog #> "Hello" bog #> <span/> bog #> 1 bog #> 'foo bog #> 44L bog #> false bog #> List(<span/>) bog #> Full(<span/>) bog #> Some(<span/>) bog #> List("Hello") bog #> Full("Dog") bog #> Some("Moo") bog #> List((null: Bindable)) bog #> Full((null: Bindable)) bog #> Some((null: Bindable)) bog #> nsToNs _ bog #> nsToOptNs _ bog #> nsToBoxNs _ bog #> nsToSeqNs _ bog #> nsToString _ bog #> nsToOptString _ bog #> nsToBoxString _ bog #> nsToSeqString _ val nsf: NodeSeq => NodeSeq = bog #> "Hello" & bog #> <span/> & bog #> 1 & bog #> 'foo & bog #> 44L & bog #> false "foo" #> "Hello" "foo" #> <span/> "foo" #> 1 "foo" #> 'foo "foo" #> 44L "foo" #> false "foo" #> List(<span/>) "foo" #> Full(<span/>) "foo" #> Some(<span/>) "foo" #> List("Hello") "foo" #> Full("Dog") "foo" #> Some("Moo") "foo" #> List((null: Bindable)) "foo" #> Full((null: Bindable)) "foo" #> Some((null: Bindable)) "foo" #> nsToNs _ "foo" #> nsToOptNs _ "foo" #> nsToBoxNs _ "foo" #> nsToSeqNs _ "foo" #> nsToString _ "foo" #> nsToOptString _ "foo" #> nsToBoxString _ "foo" #> nsToSeqString _ "#foo" #> Set("a", "b", "c") val nsf2: NodeSeq => NodeSeq = "foo" #> "Hello" & "foo" #> <span/> & "foo" #> 1 & "foo" #> 'foo & "foo" #> 44L & "foo" #> false "bar" #> List("1","2","3").map(s => "baz" #> s) "bar" #> Full(1).map(s => ("baz" #> s): CssBindFunc) "bar" #> Some(1).map(s => ("baz" #> s): CssBindFunc) def nsToNs(in: NodeSeq): NodeSeq = in def nsToOptNs(in: NodeSeq): Option[NodeSeq] = Some(in) def nsToBoxNs(in: NodeSeq): Box[NodeSeq] = Full(in) def nsToSeqNs(in: NodeSeq): Seq[NodeSeq] = List(in) def nsToString(in: NodeSeq): String = in.text def nsToOptString(in: NodeSeq): Option[String] = Some(in.text) def nsToBoxString(in: NodeSeq): Box[String] = Full(in.text) def nsToSeqString(in: NodeSeq): Seq[String] = List(in.text) }

    Other Lift Framework examples (source code examples)

    Here is a short list of links related to this Lift Framework BindHelpersSpec.scala source code file:



    my book on functional programming

     

    new blog posts

     

    Copyright 1998-2019 Alvin Alexander, alvinalexander.com
    All Rights Reserved.

    A percentage of advertising revenue from
    pages under the /java/jwarehouse URI on this website is
    paid back to open source projects.