Перейти до вмісту

Lift/Структура проекту

Матеріал з Вікіпідручника

Дерево каталогів

[ред.]
|---lib
|---project
|      |---boot
|      |---build
|      |      |---Project.scala
|      |---build.properties
|---src
|    |---main
|    |    |---resources
|    |    |        |---props
|    |    |---scala
|    |    |    |---bootstrap
|    |    |    |        |---liftweb
|    |    |    |             |---Boot.scala
|    |    |    |---sample
|    |    |    |       |---comet
|    |    |    |       |---lib
|    |    |    |       |---model
|    |    |    |       |---snippet
|    |    |    |       |---view
|    |    |---webapp
|    |    |     |---images
|    |    |     |---static
|    |    |     |---templates-hidden
|    |    |                 |---default.html
|    |    |     |---WEB-INF
|    |    |     |      |---web.xml
|    |    |     |---index.html
|    |---test
|    |    |---resources
|    |    |---scala
|    |    |    |---sample

project/build.properties

[ред.]
#Project properties
#Thu Apr 07 05:59:21 EEST 2011
project.organization=sample
project.name=lift-test
sbt.version=0.7.4
project.version=1.0
build.scala.versions=2.8.1
project.initialize=false

project/build/Project.scala

[ред.]
import sbt._

class LiftProject(info: ProjectInfo) extends DefaultWebProject(info) {
  val liftVersion = "2.3"
  
  /**
   * Application dependencies
   */
  val webkit    = "net.liftweb" %% "lift-webkit" % liftVersion % "compile->default"
  val logback   = "ch.qos.logback" % "logback-classic" % "0.9.26" % "compile->default"
  
  val servlet   = "javax.servlet" % "servlet-api" % "2.5" % "provided->default"
  val jetty6    = "org.mortbay.jetty" % "jetty" % "6.1.22" % "test->default"  
  val junit     = "junit" % "junit" % "4.5" % "test->default"
  val specs     = "org.scala-tools.testing" %% "specs" % "1.6.6" % "test->default"
  
  /**
   * Maven repositories
   */
  lazy val scalatoolsSnapshots = ScalaToolsSnapshots
}

src/main/scala/bootstrap/liftweb/Boot.scala

[ред.]
package bootstrap.liftweb

import net.liftweb._
import http.{LiftRules, NotFoundAsTemplate, ParsePath}
import sitemap.{SiteMap, Menu, Loc}
import util.{ NamedPF }

class Boot {
  def boot {
  
    // where to search snippet
    LiftRules.addToPackages("sample")

    // build sitemap
    val entries = List(Menu("Home") / "index") :::
                  Nil
    
    LiftRules.uriNotFound.prepend(NamedPF("404handler"){
      case (req,failure) => NotFoundAsTemplate(
        ParsePath(List("exceptions","404"),"html",false,false))
    })
    
    LiftRules.setSiteMap(SiteMap(entries:_*))
    
    // set character encoding
    LiftRules.early.append(_.setCharacterEncoding("UTF-8"))    
    
  }
}

src/main/webapp/index.html

[ред.]
<lift:surround with="default" at="content"> 
  <h2>Welcome to your project!</h2> 
</lift:surround>

src/main/webapp/templates-hidden/default.html

[ред.]
<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>code:app:0.1-SNAPSHOT</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[ */
.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" />
        <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://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>

src/main/webapp/WEB-INF/web.xml

[ред.]

web.xml для Java Servlet API

<?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>