src/main/scala/net/tz/lift/boot/ProtoBoot.scala
author Tomas Zeman <tzeman@volny.cz>
Tue, 29 Mar 2011 13:13:30 +0200
changeset 7 d342cad74c09
child 19 5492a4e4e60d
permissions -rw-r--r--
Boot prototype

/*
 * Copyright 2011 Tomas Zeman <tzeman@volny.cz>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.tz.lift.boot

import net.liftweb.common._
import net.liftweb.http._
import net.liftweb.mapper._
import net.liftweb.sitemap._
import net.liftweb.sitemap.Loc._
import net.liftweb.util._
import net.liftweb.widgets.menu.MenuWidget
import net.tz.lift.snippet.ActionLinks
import net.tz.lift.util.YmdDateTimeConverter

/**
 * Prototype boot class to be either extended or copied.
 */
class ProtoBoot extends Logger {

  def boot = {
    /* DB stuff */
    /*
    S.addAround(DB.buildLoanWrapper())
    */

    if (Props.mode == Props.RunModes.Development)
      DB.addLogFunc { (dbLog, l) => dbLog.statementEntries.foreach { e =>
        debug("Query: " + e.statement)
    }}

    /* Date format */
    LiftRules.dateTimeConverter.default.set { () => YmdDateTimeConverter }

    /* Handle end slash and drop it (except for home page) */
    LiftRules.statelessRewrite.append {
      case RewriteRequest(ParsePath(xs,_,_,true),_,_) if (xs.size > 1) &&
        (xs.lastOption == Some("index")) =>
          RewriteResponse(xs dropRight 1)
    }

    /* Snippet dispatch */
    LiftRules.snippetDispatch.append {
      case "Menubar" => new AnyRef with DispatchSnippet {
        def dispatch: DispatchIt = {
          case _ => { xhtml => MenuWidget() }
        }
      }
      case "action-links" => ActionLinks
    }

    /* Sitemap */
    SiteMap.enforceUniqueLinks = false

    /*
    LiftRules.setSiteMap(SiteMap(
      Menu.i("Home") / "index" >> Hidden
    ))
    */

    /* Menu widget */
    MenuWidget.init()

    /* Http conf */
    LiftRules.logServiceRequestTiming = false
    LiftRules.early.append(_.setCharacterEncoding("UTF-8"))
  }

}

// vim: set ts=2 sw=2 et: