Created
December 17, 2009 09:52
-
-
Save ymnk/258654 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package hello.snippet | |
import _root_.scala.xml._ | |
import _root_.net.liftweb.http._ | |
import _root_.net.liftweb.util._ | |
import Helpers._ | |
import js._ | |
import js.JE._ | |
class AjaxSandbox { | |
def simple(xhtml: NodeSeq):NodeSeq = { | |
bind("f", xhtml, | |
"trigger" -> SHtml.ajaxButton( "push" , doSimple _ ) | |
) | |
} | |
def doSimple(): JsCmd = { | |
println("doSimple") | |
JsCmds.SetHtml( "placeholder", <h1>Ajax!</h1> ) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package hello | |
import _root_.java.io.File | |
import _root_.junit.framework._ | |
import Assert._ | |
import _root_.scala.xml.XML | |
import _root_.net.liftweb.util._ | |
import _root_.net.liftweb.common._ | |
object AppTest { | |
def suite: Test = { | |
val suite = new TestSuite(classOf[AppTest]) | |
suite | |
} | |
def main(args : Array[String]) { | |
_root_.junit.textui.TestRunner.run(suite) | |
} | |
} | |
/** | |
* Unit test for simple App. | |
*/ | |
class AppTest extends TestCase("app") { | |
/** | |
* Rigourous Tests :-) | |
*/ | |
def testOK() = assertTrue(true) | |
// def testKO() = assertTrue(false); | |
/** | |
* Tests to make sure the project's XML files are well-formed. | |
* | |
* Finds every *.html and *.xml file in src/main/webapp (and its | |
* subdirectories) and tests to make sure they are well-formed. | |
*/ | |
def testXml() = { | |
var failed: List[File] = Nil | |
def handledXml(file: String) = | |
file.endsWith(".xml") | |
def handledXHtml(file: String) = | |
file.endsWith(".html") || file.endsWith(".htm") || file.endsWith(".xhtml") | |
def wellFormed(file: File) { | |
if (file.isDirectory) | |
for (f <- file.listFiles) wellFormed(f) | |
if (file.isFile && handledXml(file.getName)) { | |
try { | |
XML.loadFile(file) | |
} catch { | |
case e: _root_.org.xml.sax.SAXParseException => failed = file :: failed | |
} | |
} | |
if (file.isFile && handledXHtml(file.getName)) { | |
PCDataXmlParser(new _root_.java.io.FileInputStream(file.getAbsolutePath)) match { | |
case Full(_) => // file is ok | |
case _ => failed = file :: failed | |
} | |
} | |
} | |
wellFormed(new File("src/main/webapp")) | |
val numFails = failed.size | |
if (numFails > 0) { | |
val fileStr = if (numFails == 1) "file" else "files" | |
val msg = "Malformed XML in " + numFails + " " + fileStr + ": " + failed.mkString(", ") | |
println(msg) | |
fail(msg) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package bootstrap.liftweb | |
import _root_.net.liftweb.util._ | |
import _root_.net.liftweb.common._ | |
import _root_.net.liftweb.http._ | |
import _root_.net.liftweb.http.provider._ | |
import _root_.net.liftweb.sitemap._ | |
import _root_.net.liftweb.sitemap.Loc._ | |
import Helpers._ | |
import _root_.net.liftweb.mapper.{DB, ConnectionManager, Schemifier, DefaultConnectionIdentifier, StandardDBVendor} | |
import _root_.java.sql.{Connection, DriverManager} | |
import _root_.hello.model._ | |
/** | |
* A class that's instantiated early and run. It allows the application | |
* to modify lift's environment | |
*/ | |
class Boot { | |
def boot { | |
if (!DB.jndiJdbcConnAvailable_?) | |
DB.defineConnectionManager(DefaultConnectionIdentifier, | |
new StandardDBVendor(Props.get("db.driver") openOr "org.h2.Driver", | |
Props.get("db.url") openOr "jdbc:h2:lift_proto.db", | |
Props.get("db.user"), Props.get("db.password"))) | |
// where to search snippet | |
LiftRules.addToPackages("hello") | |
Schemifier.schemify(true, Log.infoF _, User, Product) | |
// Build SiteMap | |
val entries = Menu(Loc("Home", List("index"), "Home")) :: | |
Menu(Loc("Static", Link(List("static"), true, "/static/index"), "Static Content")) :: | |
User.sitemap | |
LiftRules.setSiteMap(SiteMap(entries:_*)) | |
/* | |
* Show the spinny image when an Ajax call starts | |
*/ | |
LiftRules.ajaxStart = | |
Full(() => LiftRules.jsArtifacts.show("ajax-loader").cmd) | |
/* | |
* Make the spinny image go away when it ends | |
*/ | |
LiftRules.ajaxEnd = | |
Full(() => LiftRules.jsArtifacts.hide("ajax-loader").cmd) | |
LiftRules.early.append(makeUtf8) | |
LiftRules.loggedInTest = Full(() => User.loggedIn_?) | |
S.addAround(DB.buildLoanWrapper) | |
} | |
/** | |
* Force the request to be UTF-8 | |
*/ | |
private def makeUtf8(req: HTTPRequest) { | |
req.setCharacterEncoding("UTF-8") | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Project properties | |
#Thu Dec 17 11:56:22 JST 2009 | |
project.organization=hello | |
project.name=Hello | |
sbt.version=0.5.6 | |
project.version=1.0-SNAPSHOT | |
scala.version=2.7.7 | |
project.initialize=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:lift="http://liftweb.net/"> | |
<head> | |
<meta http-equiv="content-type" content="text/html; charset=UTF-8" /> | |
<meta name="description" content="" /> | |
<meta name="keywords" content="" /> | |
<title>Lift Web Framework</title> | |
<lift:CSS.blueprint /> | |
<lift:CSS.fancyType /> | |
<script id="jquery" src="/classpath/jquery.js" type="text/javascript"/> | |
<script id="json" src="/classpath/json.js" type="text/javascript"/> | |
<style type="text/css"> | |
/* <![CDATA[ */ | |
.sidebar ul { | |
margin:0; | |
padding:0; | |
border-bottom:1px solid #ccc; | |
} | |
.sidebar ul li { | |
margin:0; | |
padding:0; | |
list-style:none; | |
border:1px solid #ccc; | |
border-bottom:none; | |
} | |
.sidebar ul li a { | |
display:block; | |
padding:3px; | |
text-indent:30px; | |
text-decoration:none; | |
} | |
.sidebar ul li span { | |
display:block; | |
padding:3px; | |
text-indent:30px; | |
text-decoration:none; | |
} | |
.sidebar ul li a:hover { | |
background-color: #eee; | |
} | |
/* ]]> */ | |
</style> | |
</head> | |
<body> | |
<div class="container"> | |
<div class="column span-12 last" style="text-align: right"> | |
<h1 class="alt">lift-archetype-basic<img alt="" id="ajax-loader" style="display:none; margin-bottom: 0px; margin-left: 5px" src="/images/ajax-loader.gif"/></h1> | |
</div> | |
<hr/> | |
<div class="column span-6 colborder sidebar"> | |
<hr class="space" /> | |
<lift:Menu.builder /> | |
<div> | |
<lift:Msgs showAll="true"/> | |
<hr class="space" /> | |
</div> | |
</div> | |
<div class="column span-17 last"> | |
<lift:bind name="content" /> | |
</div> | |
<hr /> | |
<div class="column span-23 last" style="text-align: center"> | |
<h4 class="alt"> | |
<a href="http://liftweb.net"><i>Lift</i></a> | |
is Copyright 2007-2009 WorldWide Conferencing, LLC. Distributed under an Apache 2.0 License.</h4> | |
</div> | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.driver=com.mysql.jdbc.Driver | |
db.url=jdbc:mysql://localhost/SampleDB040 | |
db.user=XXXX | |
db.password=XXXX |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package hello.lib | |
import net.liftweb._ | |
import http._ | |
import util._ | |
import common._ | |
import _root_.java.util.Date | |
/** | |
* A factory for generating new instances of Date. You can create | |
* factories for each kind of thing you want to vend in your application. | |
* An example is a payment gateway. You can change the default implementation, | |
* or override the default implementation on a session, request or current call | |
* stack basis. | |
*/ | |
object DependencyFactory extends Factory { | |
implicit object time extends FactoryMaker(Helpers.now _) | |
/** | |
* objects in Scala are lazily created. The init() | |
* method creates a List of all the objects. This | |
* results in all the objects getting initialized and | |
* registering their types with the dependency injector | |
*/ | |
private def init() { | |
List(time) | |
} | |
init() | |
} | |
/* | |
/** | |
* Examples of changing the implementation | |
*/ | |
sealed abstract class Changer { | |
def changeDefaultImplementation() { | |
DependencyFactory.time.default.set(() => new Date()) | |
} | |
def changeSessionImplementation() { | |
DependencyFactory.time.session.set(() => new Date()) | |
} | |
def changeRequestImplementation() { | |
DependencyFactory.time.request.set(() => new Date()) | |
} | |
def changeJustForCall(d: Date) { | |
DependencyFactory.time.doWith(d) { | |
// perform some calculations here | |
} | |
} | |
} | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sbt._ | |
class HelloLiftProject(info: ProjectInfo) extends DefaultWebProject(info) | |
{ | |
val liftcore = "net.liftweb" % "lift-mapper" % "1.1-M8" % "compile" | |
val h2 = "com.h2database" % "h2" % "1.2.121" % "compile" | |
val servlet = "javax.servlet" % "servlet-api" % "2.5" % "provided" | |
val jetty6 = "org.mortbay.jetty" % "jetty" % "6.1.14" % "test" | |
// val derby = "org.apache.derby" % "derby" % "10.2.2.0" % "runtime" | |
val junit = "junit" % "junit" % "4.5" % "test" | |
val testing = "org.scala-tools.testing" % "specs" % "1.6.1" % "test" | |
val mysql = "mysql" % "mysql-connector-java" % "5.1.6" % "runtime" | |
val mockito = "org.mockito" % "mockito-core" % "1.8.1" % "test" | |
// required because Ivy doesn't pull repositories from poms | |
val smackRepo = "m2-repository-smack" at "http://maven.reucon.com/public" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package hello.snippet | |
import _root_.scala.xml.{NodeSeq, Text} | |
import _root_.net.liftweb._ | |
import _root_.net.liftweb.util._ | |
import _root_.net.liftweb.http._ | |
import _root_.net.liftweb.common._ | |
import hello.lib._ | |
import Helpers._ | |
import _root_.java.util.Date | |
class HelloWorld { | |
lazy val date: Box[Date] = DependencyFactory.inject[Date] // inject the date | |
def howdy(in: NodeSeq): NodeSeq = | |
Helpers.bind("b", in, "time" -> date.map(d => Text(d.toString))) | |
/* | |
lazy val date: Date = DependencyFactory.time.vend // create the date via factory | |
def howdy(in: NodeSeq): NodeSeq = Helpers.bind("b", in, "time" -> date.toString) | |
*/ | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package hello.snippet | |
import org.specs._ | |
import org.specs.runner.JUnit3 | |
import org.specs.runner.ConsoleRunner | |
import net.liftweb._ | |
import http._ | |
import net.liftweb.util._ | |
import net.liftweb.common._ | |
import org.specs.matcher._ | |
import org.specs.specification._ | |
import Helpers._ | |
import lib._ | |
class HelloWorldTestSpecsAsTest extends JUnit3(HelloWorldTestSpecs) | |
object HelloWorldTestSpecsRunner extends ConsoleRunner(HelloWorldTestSpecs) | |
object HelloWorldTestSpecs extends Specification { | |
val session = new LiftSession("", randomString(20), Empty) | |
val stableTime = now | |
override def executeExpectations(ex: Examples, t: =>Any): Any = { | |
S.initIfUninitted(session) { | |
DependencyFactory.time.doWith(stableTime) { | |
super.executeExpectations(ex, t) | |
} | |
} | |
} | |
"HelloWorld Snippet" should { | |
"Put the time in the node" in { | |
val hello = new HelloWorld | |
Thread.sleep(1000) // make sure the time changes | |
val str = hello.howdy(<span>Hello at <b:time/></span>).toString | |
str.indexOf(stableTime.toString) must be >= 0 | |
str.indexOf("Hello at") must be >= 0 | |
} | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<lift:surround with="default" at="content"> | |
<h2>Welcome to your project!</h2> | |
<p> | |
<lift:helloWorld.howdy> | |
<span>Welcome to lift-archetype-basic at <b:time/></span> | |
</lift:helloWorld.howdy> | |
</p> | |
<lift:userView.list> | |
<nav:records/> <br/> | |
<nav:first/> <nav:prev/> <nav:allpages> | </nav:allpages> <nav:next/> <nav:last/> | |
<table> | |
<tr> | |
<th><sort:id><lift:loc>ID</lift:loc></sort:id></th> | |
<th><sort:email><lift:loc>mail</lift:loc></sort:email></th> | |
<th><sort:nickname><lift:loc>nickname</lift:loc></sort:nickname></th> | |
</tr> | |
<f:users> | |
<tr> | |
<td><f:id /></td> | |
<td><f:email /></td> | |
<td><f:nickname /></td> | |
</tr> | |
</f:users> | |
</table> | |
</lift:userView.list> | |
<lift:requestView.acceptForm form="post"> | |
<table> | |
<tr> | |
<th>user </th><th> description </th> | |
<th></th> | |
</tr> | |
<lift:requestView.listForm form="post"> | |
<tr> | |
<td><f:user /></td><td><f:body /></td> | |
<td><f:accept />/<f:reject /></td> | |
</tr> | |
</lift:requestView.listForm> | |
</table> | |
</lift:requestView.acceptForm> | |
<lift:ajaxSandbox.simple> | |
<f:trigger /> | |
<div id="placeholder" /> | |
</lift:ajaxSandbox.simple> | |
</lift:surround> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<lift:surround with="default" at="content"> | |
Static content... everything you put in the /static | |
directory will be served without additions to SiteMap | |
</lift:surround> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import _root_.bootstrap.liftweb.Boot | |
import _root_.scala.tools.nsc.MainGenericRunner | |
object LiftConsole { | |
def main(args : Array[String]) { | |
// Instantiate your project's Boot file | |
val b = new Boot() | |
// Boot your project | |
b.boot | |
// Now run the MainGenericRunner to get your repl | |
MainGenericRunner.main(args) | |
// After the repl exits, then exit the scala script | |
exit(0) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 | |
http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>hello</groupId> | |
<artifactId>hello</artifactId> | |
<version>1.0-SNAPSHOT</version> | |
<packaging>war</packaging> | |
<name>hello Project</name> | |
<inceptionYear>2009</inceptionYear> | |
<properties> | |
<scala.version>2.7.7</scala.version> | |
</properties> | |
<repositories> | |
<repository> | |
<id>scala-tools.releases</id> | |
<name>Scala-Tools Maven2 Repository for Releases</name> | |
<url>http://scala-tools.org/repo-releases</url> | |
</repository> | |
</repositories> | |
<pluginRepositories> | |
<pluginRepository> | |
<id>scala-tools.org</id> | |
<name>Scala-Tools Maven2 Repository</name> | |
<url>http://scala-tools.org/repo-releases</url> | |
</pluginRepository> | |
</pluginRepositories> | |
<dependencies> | |
<dependency> | |
<groupId>net.liftweb</groupId> | |
<artifactId>lift-mapper</artifactId> | |
<version>1.1-M8</version> | |
</dependency> | |
<dependency> | |
<groupId>com.h2database</groupId> | |
<artifactId>h2</artifactId> | |
<version>1.2.121</version> | |
</dependency> | |
<dependency> | |
<groupId>javax.servlet</groupId> | |
<artifactId>servlet-api</artifactId> | |
<version>2.5</version> | |
<scope>provided</scope> | |
</dependency> | |
<dependency> | |
<groupId>junit</groupId> | |
<artifactId>junit</artifactId> | |
<version>4.5</version> | |
<scope>test</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.scala-tools.testing</groupId> | |
<artifactId>specs</artifactId> | |
<version>1.6.1</version> | |
<scope>test</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.mortbay.jetty</groupId> | |
<artifactId>jetty</artifactId> | |
<version>[6.1.6,7.0)</version> | |
<scope>test</scope> | |
</dependency> | |
<dependency> | |
<groupId>mysql</groupId> | |
<artifactId>mysql-connector-java</artifactId> | |
<version>5.1.6</version> | |
</dependency> | |
<dependency> | |
<groupId>org.mockito</groupId> | |
<artifactId>mockito-core</artifactId> | |
<version>1.8.1</version> | |
<scope>test</scope> | |
</dependency> | |
<!-- for LiftConsole --> | |
<dependency> | |
<groupId>org.scala-lang</groupId> | |
<artifactId>scala-compiler</artifactId> | |
<version>${scala.version}</version> | |
<scope>test</scope> | |
</dependency> | |
</dependencies> | |
<build> | |
<sourceDirectory>src/main/scala</sourceDirectory> | |
<testSourceDirectory>src/test/scala</testSourceDirectory> | |
<plugins> | |
<plugin> | |
<groupId>org.scala-tools</groupId> | |
<artifactId>maven-scala-plugin</artifactId> | |
<version>2.12.2</version> | |
<executions> | |
<execution> | |
<id>scala-compile</id> | |
<phase>process-resources</phase> | |
<goals> | |
<goal>compile</goal> | |
</goals> | |
</execution> | |
<execution> | |
<id>scala-testCompile</id> | |
<phase>process-test-resources</phase> | |
<goals> | |
<goal>testCompile</goal> | |
</goals> | |
</execution> | |
</executions> | |
</plugin> | |
<plugin> | |
<groupId>org.mortbay.jetty</groupId> | |
<artifactId>maven-jetty-plugin</artifactId> | |
<configuration> | |
<contextPath>/</contextPath> | |
<scanIntervalSeconds>5</scanIntervalSeconds> | |
</configuration> | |
</plugin> | |
<plugin> | |
<groupId>net.sf.alchim</groupId> | |
<artifactId>yuicompressor-maven-plugin</artifactId> | |
<executions> | |
<execution> | |
<goals> | |
<goal>compress</goal> | |
</goals> | |
</execution> | |
</executions> | |
<configuration> | |
<nosuffix>true</nosuffix> | |
</configuration> | |
</plugin> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-idea-plugin</artifactId> | |
<configuration> | |
<downloadSources>true</downloadSources> | |
</configuration> | |
</plugin> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-eclipse-plugin</artifactId> | |
<configuration> | |
<downloadSources>true</downloadSources> | |
<excludes> | |
<exclude>org.scala-lang:scala-library</exclude> | |
</excludes> | |
<classpathContainers> | |
<classpathContainer>ch.epfl.lamp.sdt.launching.SCALA_CONTAINER</classpathContainer> | |
</classpathContainers> | |
<projectnatures> | |
<java.lang.String>ch.epfl.lamp.sdt.core.scalanature</java.lang.String> | |
<java.lang.String>org.eclipse.jdt.core.javanature</java.lang.String> | |
</projectnatures> | |
<buildcommands> | |
<java.lang.String>ch.epfl.lamp.sdt.core.scalabuilder</java.lang.String> | |
</buildcommands> | |
</configuration> | |
</plugin> | |
</plugins> | |
</build> | |
<reporting> | |
<plugins> | |
<plugin> | |
<groupId>org.scala-tools</groupId> | |
<artifactId>maven-scala-plugin</artifactId> | |
<version>2.12.2</version> | |
</plugin> | |
</plugins> | |
</reporting> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package hello.model | |
import _root_.java.util.Date | |
import _root_.net.liftweb.mapper._ | |
import _root_.net.liftweb.util._ | |
//class Product extends LongKeyedMapper[Product] with IdPK { | |
class Product extends MyCommonMapper[Product] with IdPK { | |
def getSingleton = Product | |
object name extends MappedString(this, 255) | |
object title extends MappedString(this, 255) | |
object price extends MappedInt(this) | |
def destroy = this.delete_! | |
} | |
//object Product extends Product with LongKeyedMetaMapper[Product]{ | |
object Product extends Product with MyCommonMetaMapper[Product]{ | |
override def dbTableName = "products" | |
def findByName(name:String) = findAll(By(Product.name,name)) | |
} | |
trait MyCommonMapper[A <: MyCommonMapper[A]] extends LongKeyedMapper[A] { self: A => | |
object updated_at extends MappedDateTime(this) | |
object created_at extends MappedDateTime(this) | |
} | |
trait MyCommonMetaMapper[A <: MyCommonMapper[A]] extends LongKeyedMetaMapper[A] { self: A => | |
val fill_updated_at = (a:A) => { a.updated_at(new Date);() } | |
val fill_created_at = (a:A) => { a.created_at(new Date);() } | |
var before_create = List( fill_created_at ) | |
var before_update = List( fill_updated_at ) | |
override def beforeCreate = before_create | |
override def beforeSave = before_update | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package hello.snippet | |
import _root_.net.liftweb._ | |
import _root_.net.liftweb.http._ | |
import _root_.net.liftweb.util._ | |
import _root_.net.liftweb.common._ | |
import _root_.scala.xml.NodeSeq | |
import Helpers._ | |
//import hello.lib._ | |
import _root_.hello.model._ | |
class ProductLinkTo { | |
def edit( xhtml:NodeSeq ) = S.param("product_id") match { | |
case Full(id) => | |
Product.find(id.toLong) match { | |
case Full( p ) => <a href={"/product/edit/"+p.id}>{p.title} edit</a> | |
case _ => <span>Not Found</span> | |
} | |
case _ => <span>Access Error</span> | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package hello.snippet | |
import org.specs._ | |
import org.specs.mock.Mockito | |
import org.specs.runner.JUnit3 | |
import org.specs.runner.ConsoleRunner | |
import net.liftweb._ | |
import http._ | |
import net.liftweb.util._ | |
import net.liftweb.common._ | |
import org.specs.matcher._ | |
import org.specs.specification._ | |
import Helpers._ | |
import _root_.scala.xml.NodeSeq | |
import _root_.org.mockito.Matchers._ | |
import _root_.hello.model._ | |
object ProductLinkToSpec extends Specification with Mockito { | |
var request = mock[Req] | |
var session = new LiftSession("", StringHelpers.randomString(20), Empty) | |
def inSession(f: =>Any) { | |
S.init(request, session) { f } | |
} | |
def setParameter(name: String, value: String){ | |
request.param(name) returns Some(value) | |
} | |
new SpecContext{ | |
beforeSpec{ (new bootstrap.liftweb.Boot).boot } | |
aroundExpectations(inSession(_)) | |
} | |
"LinkTo Snippet" should { | |
"build link" in { | |
/* | |
var product_id = Product.create.title("product").saveMe.id.is | |
setParameter("product_id",product_id.toString) | |
val snippet = new ProductLinkTo | |
snippet.edit(NodeSeq.Empty) must \\("a") | |
Product.find(product_id).open_!.delete_! | |
*/ | |
"Hello at".indexOf("Hello at") must be >= 0 | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package hello.model | |
import org.specs._ | |
import org.specs.matcher._ | |
import org.specs.specification._ | |
object ProductTestSpecs extends Specification { | |
"Product" should { | |
"be available" in { | |
(new bootstrap.liftweb.Boot).boot | |
Product.count must notBeNull | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package hello.model | |
import _root_.java.util.Date | |
import _root_.net.liftweb.mapper._ | |
import _root_.net.liftweb.util._ | |
class Request extends LongKeyedMapper[Request] with IdPK { | |
def getSingleton = Request | |
object user extends MappedString(this, 255) | |
object body extends MappedString(this, 255) | |
def destroy = this.delete_! | |
def accept = {} | |
def reject = {} | |
} | |
object Request extends Request with LongKeyedMetaMapper[Request]{ | |
override def dbTableName = "products" | |
def findByName(name:String) = findAll(By(Request.user,user)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package hello.snippet | |
import _root_.net.liftweb._ | |
import _root_.net.liftweb.http._ | |
import _root_.net.liftweb.util._ | |
import _root_.net.liftweb.common._ | |
import _root_.scala.xml.NodeSeq | |
import _root_.scala.xml.Text | |
import Helpers._ | |
import _root_.hello.model._ | |
class RequestView { | |
def listForm(xhtml:NodeSeq) = Request.findAll.flatMap( r => { | |
bind("f", xhtml, | |
"user" -> Text( r.user ), | |
"body" -> Text( r.body ), | |
"accept" -> SHtml.submit("accept", () => doAccept(r.id) ), | |
"reject" -> SHtml.submit("reject", () => doReject(r.id) ) ) | |
}) | |
private def doAccept(id:Long){ | |
Request.find(id).open_!.accept | |
} | |
private def doReject(id:Long){ | |
Request.find(id).open_!.reject | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import _root_.org.mortbay.jetty.Connector | |
import _root_.org.mortbay.jetty.Server | |
import _root_.org.mortbay.jetty.webapp.WebAppContext | |
import org.mortbay.jetty.nio._ | |
object RunWebApp extends Application { | |
val server = new Server | |
val scc = new SelectChannelConnector | |
scc.setPort(8080) | |
server.setConnectors(Array(scc)) | |
val context = new WebAppContext() | |
context.setServer(server) | |
context.setContextPath("/") | |
context.setWar("src/main/webapp") | |
server.addHandler(context) | |
try { | |
println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP") | |
server.start() | |
while (System.in.available() == 0) { | |
Thread.sleep(5000) | |
} | |
server.stop() | |
server.join() | |
} catch { | |
case exc : Exception => { | |
exc.printStackTrace() | |
System.exit(100) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package hello.model | |
import _root_.net.liftweb.mapper._ | |
import _root_.net.liftweb.util._ | |
import _root_.net.liftweb.common._ | |
/** | |
* The singleton that has methods for accessing the database | |
*/ | |
object User extends User with MetaMegaProtoUser[User] { | |
override def dbTableName = "users" // define the DB table name | |
override def screenWrap = Full(<lift:surround with="default" at="content"> | |
<lift:bind /></lift:surround>) | |
// define the order fields will appear in forms and output | |
override def fieldOrder = List(id, firstName, lastName, email, | |
locale, timezone, password, textArea) | |
// comment this line out to require email validations | |
override def skipEmailValidation = true | |
} | |
/** | |
* An O-R mapped "User" class that includes first name, last name, password and we add a "Personal Essay" to it | |
*/ | |
class User extends MegaProtoUser[User] { | |
def getSingleton = User // what's the "meta" server | |
// define an additional field for a personal essay | |
object textArea extends MappedTextarea(this, 2048) { | |
override def textareaRows = 10 | |
override def textareaCols = 50 | |
override def displayName = "Personal Essay" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package hello.snippet | |
import _root_.net.liftweb._ | |
import _root_.net.liftweb.http._ | |
import _root_.net.liftweb.util._ | |
import _root_.net.liftweb.common._ | |
import _root_.net.liftweb.mapper.view._ | |
import _root_.scala.xml.NodeSeq | |
import _root_.scala.xml.Text | |
import Helpers._ | |
import _root_.hello.model._ | |
class UserView extends ModelSnippet[User] { | |
override val view = new ModelView( User, this ) | |
override def edit(xhtml: NodeSeq):NodeSeq = <h1>Edit</h1> | |
val paginator = | |
new Paginator(User, this, User.id, | |
"id" -> User.id, "email" -> User.email, "nickname" -> User.firstName ) | |
def list(xhtml: NodeSeq):NodeSeq = { | |
val innerTemplate = ( xhtml \\ "users" first ).descendant(1) | |
bind("f", | |
paginator.paginate(xhtml), | |
"users" -> bindUsers(innerTemplate) | |
) | |
} | |
private def bindUsers(xhtml: NodeSeq):NodeSeq = { | |
paginator.page.flatMap( user => { | |
bind("f", xhtml, | |
"id" -> Text( user.id.toString ), | |
"email" -> Text( user.email ), | |
"nickname" -> Text( user.firstName ) ) | |
}) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="ISO-8859-1"?> | |
<!DOCTYPE web-app | |
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" | |
"http://java.sun.com/dtd/web-app_2_3.dtd"> | |
<web-app> | |
<filter> | |
<filter-name>LiftFilter</filter-name> | |
<display-name>Lift Filter</display-name> | |
<description>The Filter that intercepts lift calls</description> | |
<filter-class>net.liftweb.http.LiftFilter</filter-class> | |
</filter> | |
<filter-mapping> | |
<filter-name>LiftFilter</filter-name> | |
<url-pattern>/*</url-pattern> | |
</filter-mapping> | |
</web-app> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div> | |
<div>Page <wizard:screen_number/> of <wizard:total_screens/></div> | |
<wizard:wizard_top> <div> <wizard:bind/> </div> </wizard:wizard_top> | |
<wizard:screen_top> <div> <wizard:bind/> </div> </wizard:screen_top> | |
<wizard:errors> <div> <ul> <wizard:item> <li> <wizard:bind/> </li> </wizard:item> </ul> </div> </wizard:errors> | |
<div> <wizard:fields> | |
<table> | |
<wizard:line> | |
<tr> | |
<td> | |
<wizard:label error_style="error"/> <wizard:help/> <wizard:field_errors> <ul> <wizard:error> <li> <wizard:bind/> </li> </wizard:error> </ul> </wizard:field_errors> | |
</td> | |
<td> <wizard:form/> </td> | |
</tr> | |
</wizard:line> | |
</table> | |
</wizard:fields> </div> | |
<div> <table> <tr> <td> <wizard:prev/> </td> <td> <wizard:cancel/> </td> <td> <wizard:next/> </td> </tr> </table> </div> | |
<wizard:screen_bottom> <div> <wizard:bind/> </div> </wizard:screen_bottom> | |
<wizard:wizard_bottom> <div> <wizard:bind/> </div> </wizard:wizard_bottom> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment