Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

First pass at seventhings

  • Loading branch information...
commit 44712abf6cdac8d8d1139b0487ee5d895fd58d68 0 parents
@dpp dpp authored
Showing with 644 additions and 0 deletions.
  1. +55 −0 .gitignore
  2. +9 −0 project/build.properties
  3. +22 −0 project/build/LiftProject.scala
  4. +1 −0  sbt
  5. BIN  sbt-launcher.jar
  6. +2 −0  sbt.bat
  7. 0  src/main/resources/.keep
  8. 0  src/main/resources/props/default.props
  9. +1 −0  src/main/resources/src/scala
  10. +52 −0 src/main/scala/bootstrap/liftweb/Boot.scala
  11. 0  src/main/scala/net/liftweb/seventhings/comet/.keep
  12. +57 −0 src/main/scala/net/liftweb/seventhings/lib/DependencyFactory.scala
  13. 0  src/main/scala/net/liftweb/seventhings/model/.keep
  14. +25 −0 src/main/scala/net/liftweb/seventhings/snippet/HelloWorld.scala
  15. 0  src/main/scala/net/liftweb/seventhings/view/.keep
  16. +21 −0 src/main/webapp/WEB-INF/web.xml
  17. BIN  src/main/webapp/images/ajax-loader.gif
  18. +18 −0 src/main/webapp/index.html
  19. +5 −0 src/main/webapp/static/index.html
  20. +85 −0 src/main/webapp/templates-hidden/default.html
  21. +57 −0 src/main/webapp/templates-hidden/wizard-all.html
  22. 0  src/test/resources/.keep
  23. +15 −0 src/test/scala/LiftConsole.scala
  24. +33 −0 src/test/scala/RunWebApp.scala
  25. +76 −0 src/test/scala/code/AppTest.scala
  26. +64 −0 src/test/scala/code/XmlSourceSpecs.scala
  27. +46 −0 src/test/scala/code/snippet/HelloWorldTest.scala
55 .gitignore
@@ -0,0 +1,55 @@
+# use glob syntax.
+syntax: glob
+*.ser
+*.class
+*~
+*.bak
+*.off
+*.old
+.DS_Store
+
+# logs
+derby.log
+
+# eclipse conf file
+.settings
+.classpath
+.project
+.manager
+.externalToolBuilders
+
+# ensime/emacs conf files
+.ensime
+.scala_dependencies
+
+# building
+target
+null
+tmp*
+dist
+test-output
+
+# sbt
+target
+lib_managed
+src_managed
+project/boot
+
+# 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 project/build.properties
@@ -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.1
+project.initialize=false
22 project/build/LiftProject.scala
@@ -0,0 +1,22 @@
+import sbt._
+
+class LiftProject(info: ProjectInfo) extends DefaultWebProject(info) {
+ val liftVersion = "2.3-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-wizard" % liftVersion % "compile->default",
+ "org.mortbay.jetty" % "jetty" % "6.1.22" % "test->default",
+ "junit" % "junit" % "4.5" % "test->default",
+ "ch.qos.logback" % "logback-classic" % "0.9.26",
+ "org.scala-tools.testing" %% "specs" % "1.6.6" % "test->default",
+ "com.h2database" % "h2" % "1.2.138"
+ ) ++ super.libraryDependencies
+}
1  sbt
@@ -0,0 +1 @@
+java -Xmx512M -Xss2M -XX:+CMSClassUnloadingEnabled -jar `dirname $0`/sbt-launcher.jar "$@"
BIN  sbt-launcher.jar
Binary file not shown
2  sbt.bat
@@ -0,0 +1,2 @@
+set SCRIPT_DIR=%~dp0
+java -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256m -Xmx512M -Xss2M -jar "%SCRIPT_DIR%\sbt-launcher.jar" %*
0  src/main/resources/.keep
No changes.
0  src/main/resources/props/default.props
No changes.
1  src/main/resources/src/scala
52 src/main/scala/bootstrap/liftweb/Boot.scala
@@ -0,0 +1,52 @@
+package bootstrap.liftweb
+
+import net.liftweb._
+import util._
+import Helpers._
+
+import common._
+import http._
+import sitemap._
+import Loc._
+import mapper._
+
+
+/**
+ * A class that's instantiated early and run. It allows the application
+ * to modify lift's environment
+ */
+class Boot {
+ def boot {
+ // where to search snippet
+ LiftRules.addToPackages("net.liftweb.seventhings")
+
+ // Build SiteMap
+ def sitemap = SiteMap(
+ 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")))
+
+ // set the sitemap. Note if you don't want access control for
+ // each page, just comment this line out.
+ LiftRules.setSiteMapFunc(() => sitemap)
+
+ //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"))
+
+ // Use HTML5 for rendering
+ LiftRules.htmlProperties.default.set((r: Req) =>
+ new Html5Properties(r.userAgent))
+
+ }
+}
0  src/main/scala/net/liftweb/seventhings/comet/.keep
No changes.
57 src/main/scala/net/liftweb/seventhings/lib/DependencyFactory.scala
@@ -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
+ }
+ }
+}
+*/
+}
+}
0  src/main/scala/net/liftweb/seventhings/model/.keep
No changes.
25 src/main/scala/net/liftweb/seventhings/snippet/HelloWorld.scala
@@ -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
+ */
+}
+
+}
+}
0  src/main/scala/net/liftweb/seventhings/view/.keep
No changes.
21 src/main/webapp/WEB-INF/web.xml
@@ -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>
BIN  src/main/webapp/images/ajax-loader.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 src/main/webapp/index.html
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+ <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>
+
5 src/main/webapp/static/index.html
@@ -0,0 +1,5 @@
+<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>
+
85 src/main/webapp/templates-hidden/default.html
@@ -0,0 +1,85 @@
+<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 class="lift:Menu.title">App: </title>
+ <style class="lift:CSS.blueprint"></style>
+ <style class="lift:CSS.fancyType"></style>
+ <script id="jquery" src="/classpath/jquery.js" type="text/javascript"></script>
+ <script id="json" src="/classpath/json.js" type="text/javascript"></script>
+ <style type="text/css">
+/* <![CDATA[ */
+.edit_error_class {
+ display: block;
+ color: red;
+}
+
+.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">app<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" >
+
+ <span class="lift:Menu.builder"></span>
+
+ <div class="lift:Msgs?showAll=true"></div>
+ <hr class="space" />
+ </div>
+
+ <div class="column span-17 last">
+ <div id="content">The main content will get bound here</div>
+ </div>
+
+ <hr />
+ <div class="column span-23 last" style="text-align: center">
+ <h4 class="alt">
+ <a href="http://www.liftweb.net"><i>Lift</i></a>
+ is Copyright 2007-2010 WorldWide Conferencing, LLC.
+ Distributed under an Apache 2.0 License.</h4>
+ </div>
+ </div>
+ </body>
+</html>
57 src/main/webapp/templates-hidden/wizard-all.html
@@ -0,0 +1,57 @@
+<div>
+ <wizard:screen_info><div>Page <wizard:screen_number></wizard:screen_number> of <wizard:total_screens></wizard:total_screens></div></wizard:screen_info>
+ <wizard:wizard_top> <div> <wizard:bind></wizard:bind> </div> </wizard:wizard_top>
+ <wizard:screen_top> <div> <wizard:bind></wizard:bind> </div> </wizard:screen_top>
+ <wizard:errors> <div> <ul> <wizard:item> <li> <wizard:bind></wizard:bind> </li> </wizard:item> </ul> </div> </wizard:errors>
+ <div>
+ <wizard:fields>
+ <table>
+ <tbody>
+ <tr lift:bind="wizard:line">
+ <td>
+ <wizard:label>
+ <label wizard:for="">
+ <wizard:bind></wizard:bind>
+ </label>
+ </wizard:label>
+ <wizard:help>
+ <span>
+ <wizard:bind></wizard:bind>
+ </span>
+ </wizard:help>
+ <wizard:field_errors>
+ <ul>
+ <wizard:error>
+ <li>
+ <wizard:bind></wizard:bind>
+ </li>
+ </wizard:error>
+ </ul>
+ </wizard:field_errors>
+ </td>
+ <td>
+ <wizard:form></wizard:form>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </wizard:fields>
+ </div>
+ <div>
+ <table>
+ <tr>
+ <td>
+ <wizard:prev></wizard:prev>
+ </td>
+ <td>
+ <wizard:cancel></wizard:cancel>
+ </td>
+ <td>
+ <wizard:next></wizard:next>
+ </td>
+ </tr>
+ </table>
+ </div>
+ <wizard:screen_bottom> <div> <wizard:bind></wizard:bind> </div> </wizard:screen_bottom>
+ <wizard:wizard_bottom> <div> <wizard:bind></wizard:bind> </div> </wizard:wizard_bottom>
+</div>
0  src/test/resources/.keep
No changes.
15 src/test/scala/LiftConsole.scala
@@ -0,0 +1,15 @@
+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)
+ }
+}
33 src/test/scala/RunWebApp.scala
@@ -0,0 +1,33 @@
+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)
+ }
+ }
+}
76 src/test/scala/code/AppTest.scala
@@ -0,0 +1,76 @@
+package code
+
+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)
+ }
+ }
+}
64 src/test/scala/code/XmlSourceSpecs.scala
@@ -0,0 +1,64 @@
+package code
+
+import java.io.File
+
+import scala.xml.XML
+
+import org.specs.Specification
+import org.specs.runner.JUnit4
+
+import net.liftweb.common.Full
+import net.liftweb.util.PCDataXmlParser
+
+class XmlSourceSpecsTest extends JUnit4(XmlSourceSpecs)
+
+object XmlSourceSpecs extends Specification {
+
+ "XML Sources" should {
+ "be well-formed" in {
+ /**
+ * 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.
+ */
+ 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 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(", ")
+ fail(msg)
+ }
+
+ numFails must_== 0
+ }
+ }
+}
46 src/test/scala/code/snippet/HelloWorldTest.scala
@@ -0,0 +1,46 @@
+package code {
+package snippet {
+
+import org.specs._
+import org.specs.runner.JUnit4
+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 JUnit4(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>Welcome to your Lift app at <span id="time">Time goes here</span></span>).toString
+
+ str.indexOf(stableTime.toString) must be >= 0
+ str.indexOf("Hello at") must be >= 0
+ }
+ }
+}
+
+}
+}
Please sign in to comment.
Something went wrong with that request. Please try again.