Skip to content

Commit

Permalink
Update lift-scalate to use scalate 1.4.1. Closes #894
Browse files Browse the repository at this point in the history
  • Loading branch information
indrajitr committed Feb 28, 2011
1 parent 3aba5c4 commit af1ede5
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 27 deletions.
47 changes: 32 additions & 15 deletions scalate/src/main/scala/net/liftweb/scalate/LiftTemplateEngine.scala
@@ -1,22 +1,39 @@
package net.liftweb.scalate /*
* Copyright 2010-2011 WorldWide Conferencing, LLC
*
* 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.liftweb
package scalate


import java.io.File import java.io.File

import tools.nsc.Global import tools.nsc.Global

import org.fusesource.scalate.layout.DefaultLayoutStrategy import org.fusesource.scalate.layout.DefaultLayoutStrategy
import org.fusesource.scalate.util.ClassPathBuilder import org.fusesource.scalate.util.{ClassPathBuilder, FileResourceLoader}
import org.fusesource.scalate.support.FileResourceLoader
import net.liftweb.http.LiftRules
import org.fusesource.scalate.{DefaultRenderContext, ResourceNotFoundException, Binding, TemplateEngine} import org.fusesource.scalate.{DefaultRenderContext, ResourceNotFoundException, Binding, TemplateEngine}
import net.liftweb.http.provider.servlet.HTTPServletContext
import net.liftweb.common.Logger import common._
import http.LiftRules
import http.provider.servlet.HTTPServletContext



/** /**
* A TemplateEngine using the Lift web abstractions * A TemplateEngine using the Lift web abstractions.
*
* @version $Revision : 1.1 $
*/ */

class LiftTemplateEngine extends TemplateEngine with Loggable {
class LiftTemplateEngine extends TemplateEngine {
bindings = List(Binding("context", classOf[DefaultRenderContext].getName, true, isImplicit = true)) bindings = List(Binding("context", classOf[DefaultRenderContext].getName, true, isImplicit = true))


if (useWebInfWorkingDirectory) { if (useWebInfWorkingDirectory) {
Expand Down Expand Up @@ -56,7 +73,7 @@ class LiftTemplateEngine extends TemplateEngine {
def realPath(uri: String): String = { def realPath(uri: String): String = {
LiftRules.context match { LiftRules.context match {
case http: HTTPServletContext => http.ctx.getRealPath(uri) case http: HTTPServletContext => http.ctx.getRealPath(uri)
case c => warn("Do not know how to get the real path of: " + uri + " for context: " + c); uri case c => logger.warn("Do not know how to get the real path of: " + uri + " for context: " + c); uri
} }
} }


Expand All @@ -65,7 +82,7 @@ class LiftTemplateEngine extends TemplateEngine {
realFile(uri) realFile(uri)
} }


override protected def toFileOrFail(uri: String): File = { protected def toFileOrFail(uri: String): File = {
val file = realFile(uri) val file = realFile(uri)
if (file == null) { if (file == null) {
throw new ResourceNotFoundException(resource = uri, root = context.realPath("/")) throw new ResourceNotFoundException(resource = uri, root = context.realPath("/"))
Expand Down Expand Up @@ -96,12 +113,12 @@ class LiftTemplateEngine extends TemplateEngine {
} }
*/ */
val path = context.realPath(uri) val path = context.realPath(uri)
debug("realPath for: " + uri + " is: " + path) logger.debug("realPath for: " + uri + " is: " + path)


var answer: File = null var answer: File = null
if (path != null) { if (path != null) {
val file = new File(path) val file = new File(path)
debug("file from realPath for: " + uri + " is: " + file) logger.debug("file from realPath for: " + uri + " is: " + file)
if (file.canRead) {answer = file} if (file.canRead) {answer = file}
} }
answer answer
Expand Down
37 changes: 25 additions & 12 deletions scalate/src/main/scala/net/liftweb/scalate/ScalateView.scala
@@ -1,15 +1,32 @@
package net.liftweb.scalate /*
* Copyright 2010-2011 WorldWide Conferencing, LLC
*
* 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.liftweb
package scalate


import _root_.net.liftweb.common._
import _root_.net.liftweb.util._
import _root_.net.liftweb.http._
import xml.NodeSeq import xml.NodeSeq


import common._
import util._
import http._


/** /**
* A {@link LiftView} which uses a <a href="http://scalate.fusesource.org/">Scalate</a> * A {@link LiftView} which uses a <a href="http://scalate.fusesource.org/">Scalate</a>
* template engine to resolve a URI and render it as markup * template engine to resolve a URI and render it as markup
*
* @version $Revision : 1.1 $
*/ */
class ScalateView(engine: LiftTemplateEngine = new LiftTemplateEngine()) extends LiftView with Logger { class ScalateView(engine: LiftTemplateEngine = new LiftTemplateEngine()) extends LiftView with Logger {


Expand Down Expand Up @@ -37,10 +54,7 @@ class ScalateView(engine: LiftTemplateEngine = new LiftTemplateEngine()) extends


def dispatch: PartialFunction[String, () => Box[NodeSeq]] = { def dispatch: PartialFunction[String, () => Box[NodeSeq]] = {
case v if (canLoad(v)) => case v if (canLoad(v)) =>
() => { () => Full(engine.layoutAsNodes(v))
val template = engine.load(v)
Full(engine.layoutAsNodes(template))
}
} }




Expand All @@ -64,8 +78,7 @@ class ScalateView(engine: LiftTemplateEngine = new LiftTemplateEngine()) extends
val uri: String = if (ext != "") createUri(path, ext) else { val uri: String = if (ext != "") createUri(path, ext) else {
List("scaml", "ssp").map(createUri(path, _)).find(engine.canLoad(_)).get List("scaml", "ssp").map(createUri(path, _)).find(engine.canLoad(_)).get
} }
val template = engine.load(uri) Full(TextResponse(engine.layout(uri)))
Full(TextResponse(engine.layout(template)))
} }
} }


Expand Down

0 comments on commit af1ede5

Please sign in to comment.