src/main/scala/net/tz/lift/boot/ProtoBoot.scala
changeset 7 d342cad74c09
child 19 5492a4e4e60d
equal deleted inserted replaced
6:9ef417a2b170 7:d342cad74c09
       
     1 /*
       
     2  * Copyright 2011 Tomas Zeman <tzeman@volny.cz>
       
     3  *
       
     4  * Licensed under the Apache License, Version 2.0 (the "License");
       
     5  * you may not use this file except in compliance with the License.
       
     6  * You may obtain a copy of the License at
       
     7  *
       
     8  *     http://www.apache.org/licenses/LICENSE-2.0
       
     9  *
       
    10  * Unless required by applicable law or agreed to in writing, software
       
    11  * distributed under the License is distributed on an "AS IS" BASIS,
       
    12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
    13  * See the License for the specific language governing permissions and
       
    14  * limitations under the License.
       
    15  */
       
    16 package net.tz.lift.boot
       
    17 
       
    18 import net.liftweb.common._
       
    19 import net.liftweb.http._
       
    20 import net.liftweb.mapper._
       
    21 import net.liftweb.sitemap._
       
    22 import net.liftweb.sitemap.Loc._
       
    23 import net.liftweb.util._
       
    24 import net.liftweb.widgets.menu.MenuWidget
       
    25 import net.tz.lift.snippet.ActionLinks
       
    26 import net.tz.lift.util.YmdDateTimeConverter
       
    27 
       
    28 /**
       
    29  * Prototype boot class to be either extended or copied.
       
    30  */
       
    31 class ProtoBoot extends Logger {
       
    32 
       
    33   def boot = {
       
    34     /* DB stuff */
       
    35     /*
       
    36     S.addAround(DB.buildLoanWrapper())
       
    37     */
       
    38 
       
    39     if (Props.mode == Props.RunModes.Development)
       
    40       DB.addLogFunc { (dbLog, l) => dbLog.statementEntries.foreach { e =>
       
    41         debug("Query: " + e.statement)
       
    42     }}
       
    43 
       
    44     /* Date format */
       
    45     LiftRules.dateTimeConverter.default.set { () => YmdDateTimeConverter }
       
    46 
       
    47     /* Handle end slash and drop it (except for home page) */
       
    48     LiftRules.statelessRewrite.append {
       
    49       case RewriteRequest(ParsePath(xs,_,_,true),_,_) if (xs.size > 1) &&
       
    50         (xs.lastOption == Some("index")) =>
       
    51           RewriteResponse(xs dropRight 1)
       
    52     }
       
    53 
       
    54     /* Snippet dispatch */
       
    55     LiftRules.snippetDispatch.append {
       
    56       case "Menubar" => new AnyRef with DispatchSnippet {
       
    57         def dispatch: DispatchIt = {
       
    58           case _ => { xhtml => MenuWidget() }
       
    59         }
       
    60       }
       
    61       case "action-links" => ActionLinks
       
    62     }
       
    63 
       
    64     /* Sitemap */
       
    65     SiteMap.enforceUniqueLinks = false
       
    66 
       
    67     /*
       
    68     LiftRules.setSiteMap(SiteMap(
       
    69       Menu.i("Home") / "index" >> Hidden
       
    70     ))
       
    71     */
       
    72 
       
    73     /* Menu widget */
       
    74     MenuWidget.init()
       
    75 
       
    76     /* Http conf */
       
    77     LiftRules.logServiceRequestTiming = false
       
    78     LiftRules.early.append(_.setCharacterEncoding("UTF-8"))
       
    79   }
       
    80 
       
    81 }
       
    82 
       
    83 // vim: set ts=2 sw=2 et: