Skip to content
This repository has been archived by the owner on Aug 12, 2019. It is now read-only.

Commit

Permalink
Added the basic sbt project
Browse files Browse the repository at this point in the history
  • Loading branch information
dpp committed Nov 1, 2010
0 parents commit 1465c0a
Show file tree
Hide file tree
Showing 23 changed files with 667 additions and 0 deletions.
54 changes: 54 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# use glob syntax.
syntax: glob
*.ser
*.class
*~
*.bak
*.off
*.old
.DS_Store

# logs
derby.log

# eclipse conf file
.settings
.classpath
.project
.manager

# building
target
build
null
tmp*
dist
test-output

# sbt
target
lib_managed
src_managed
project/boot

# db
lift_proto*

# other scm
.svn
.CVS
.hg*

# switch to regexp syntax.
# syntax: regexp
# ^\.pc/

# IntelliJ
*.iml
*.ipr
*.iws
.idea

# Pax Runner (for easy OSGi launching)
runner

9 changes: 9 additions & 0 deletions lift_basic/project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#Project properties
#Fri Apr 23 11:24:20 PDT 2010
project.organization=Lift
project.name=Lift SBT Template
sbt.version=0.7.4
project.version=0.1
def.scala.version=2.7.7
build.scala.versions=2.8.0
project.initialize=false
21 changes: 21 additions & 0 deletions lift_basic/project/build/LiftProject.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import sbt._

class LiftProject(info: ProjectInfo) extends DefaultWebProject(info) {
val liftVersion = "2.2-SNAPSHOT"

// uncomment the following if you want to use the snapshot repo
val scalatoolsSnapshot = ScalaToolsSnapshots

// If you're using JRebel for Lift development, uncomment
// this line
// override def scanDirectories = Nil

override def libraryDependencies = Set(
"net.liftweb" %% "lift-webkit" % liftVersion % "compile->default",
"net.liftweb" %% "lift-mapper" % liftVersion % "compile->default",
"org.mortbay.jetty" % "jetty" % "6.1.22" % "test->default",
"junit" % "junit" % "4.5" % "test->default",
"org.scala-tools.testing" %% "specs" % "1.6.5" % "test->default",
"com.h2database" % "h2" % "1.2.138"
) ++ super.libraryDependencies
}
Empty file.
Empty file.
74 changes: 74 additions & 0 deletions lift_basic/src/main/scala/bootstrap/liftweb/Boot.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package bootstrap.liftweb

import net.liftweb._
import util._
import Helpers._

import common._
import http._
import sitemap._
import Loc._
import mapper._

import code.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_?) {
val vendor =
new StandardDBVendor(Props.get("db.driver") openOr "org.h2.Driver",
Props.get("db.url") openOr
"jdbc:h2:lift_proto.db;AUTO_SERVER=TRUE",
Props.get("db.user"), Props.get("db.password"))

LiftRules.unloadHooks.append(vendor.closeAllConnections_! _)

DB.defineConnectionManager(DefaultConnectionIdentifier, vendor)
}

// Use Lift's Mapper ORM to populate the database
// you don't need to use Mapper to use Lift... use
// any ORM you want
Schemifier.schemify(true, Schemifier.infoF _, User)

// where to search snippet
LiftRules.addToPackages("code")

// Build SiteMap
val entries = List(
Menu.i("Home") / "index", // the simple way to declare a menu

// more complex because this menu allows anything in the
// /static path to be visible
Menu(Loc("Static", Link(List("static"), true, "/static/index"),
"Static Content"))) :::
// the User management menu items
User.sitemap

// set the sitemap. Note if you don't want access control for
// each page, just comment this line out.
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)

// Force the request to be UTF-8
LiftRules.early.append(_.setCharacterEncoding("UTF-8"))

// What is the function to test if a user is logged in?
LiftRules.loggedInTest = Full(() => User.loggedIn_?)

// Make a transaction span the whole HTTP request
S.addAround(DB.buildLoanWrapper)
}
}
Empty file.
57 changes: 57 additions & 0 deletions lift_basic/src/main/scala/code/lib/DependencyFactory.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package code {
package 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
}
}
}
*/
}
}
38 changes: 38 additions & 0 deletions lift_basic/src/main/scala/code/model/User.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package code {
package 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"
}
}

}
}
25 changes: 25 additions & 0 deletions lift_basic/src/main/scala/code/snippet/HelloWorld.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package code {
package snippet {

import _root_.scala.xml.{NodeSeq, Text}
import _root_.net.liftweb.util._
import _root_.net.liftweb.common._
import _root_.java.util.Date
import code.lib._
import Helpers._

class HelloWorld {
lazy val date: Box[Date] = DependencyFactory.inject[Date] // inject the date

// replace the contents of the element with id "time" with the date
def howdy = "#time *" #> date.map(_.toString)

/*
lazy val date: Date = DependencyFactory.time.vend // create the date via factory
def howdy = "#time *" #> date.toString
*/
}

}
}
Empty file.
21 changes: 21 additions & 0 deletions lift_basic/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?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>
Binary file added lift_basic/src/main/webapp/images/ajax-loader.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions lift_basic/src/main/webapp/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta content="text/html; charset=UTF-8" http-equiv="content-type" /><title>Home</title></head>
<body class="lift:content_id=main">
<div id="main" class="lift:surround?with=default;at=content">
<h2>Welcome to your project!</h2>
<p>
<span class="lift:helloWorld.howdy">
Welcome to your Lift app at <span id="time">Time goes here</span>
</span>
</p>
</div>
</body>
</html>

11 changes: 11 additions & 0 deletions lift_basic/src/main/webapp/static/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta content="text/html; charset=UTF-8" http-equiv="content-type" /><title>Home</title></head>
<body class="lift:content_id=main">
<div id="main" class="lift:surround?with=default;at=content">
Static content... everything you put in the /static
directory will be served without additions to SiteMap
</div>
</body>
</html>

Loading

0 comments on commit 1465c0a

Please sign in to comment.