Permalink
Browse files

Closes #987. Exceptions in Views propogated. General Template cleanup

  • Loading branch information...
1 parent 7822ecc commit 95f2dc627a653d8bdcde0ce5ce81b8da6a4f8603 @dpp dpp committed Apr 26, 2011
@@ -13,13 +13,13 @@
* See the License for the specific language governing permissions
* and limitations under the License.
*/
-import scala.xml.{NodeSeq, Text}
-package net.liftweb {
+package net.liftweb
+package http
+
import common.{Box,Full,Empty,Failure}
import util.Props
-
-package http {
+import scala.xml.{NodeSeq, Text}
/**
* A collection of types and implicit transformations used to allow composition
@@ -108,10 +108,10 @@ object Bindings {
/**
* Apply this binder's binding function to the specified templated
- * looked up using TemplateFinder.findAnyTemplate
+ * looked up using Templates.apply
*/
def bind(templatePath: List[String]): NodeSeq = {
- TemplateFinder.findAnyTemplate(templatePath) map binding match {
+ Templates(templatePath) map binding match {
case Full(xhtml) => xhtml
case Failure(msg, ex, _) if Props.mode == Props.RunModes.Development => Text(ex.map(_.getMessage).openOr(msg))
case Empty if Props.mode == Props.RunModes.Development => Text("Unable to find template with path " + templatePath.mkString("/", "/", ""))
@@ -127,5 +127,3 @@ object Bindings {
override def apply(xhtml : NodeSeq) : NodeSeq = NodeSeq.Empty
}
}
-
-}}
@@ -40,9 +40,9 @@ object DefaultRoutines {
}
for {
- xml <- TemplateFinder.findAnyTemplate(realPath, loc) or
- TemplateFinder.findAnyTemplate("templates-hidden" :: realPath, loc) or
- TemplateFinder.findAnyTemplate(realPath.dropRight(1) :::
+ xml <- Templates(realPath, loc) or
+ Templates("templates-hidden" :: realPath, loc) or
+ Templates(realPath.dropRight(1) :::
("resources-hidden" ::
realPath.takeRight(1)), loc)
@@ -70,12 +70,12 @@ object DefaultRoutines {
* production mode, the resources will be cached (up to 2000
* resource bundles will be cached). <br/><br/>
*
- * The resource bundles will be loaded using TemplateFinder and converted
+ * The resource bundles will be loaded using Templates and converted
* via BundleBuilder. The routine will search for resources given the
* current Locale (see S.locale). If the current path is /foo/bar,
* the files /foo/_resources_bar, /templates-hidden/foo/_resources_bar,
* and /foo/resources-hidden/_resources_bar will be searched. The
- * search will be based on the TemplateFinder locale search rules. <br/><br/>
+ * search will be based on the Templates locale search rules. <br/><br/>
*
* In addition to page-specific resources, there are global resources searched
* in /_resources, /templates-hidden/_resources, and
@@ -90,7 +90,7 @@ object DefaultRoutines {
* easier to remember to update the localization.
*
* @see S.locale
- * @see TemplateFinder.findAnyTemplate
+ * @see Templates.apply
* @see BundleBuilder.convert
*
*/
@@ -1071,9 +1071,9 @@ trait LiftRules extends Factory with FormVendor with LazyLoggable {
/**
* Obtain the resource as an XML by name. If you're using this to load a template, consider using
- * the TemplateFinder object instead.
+ * the Template object instead.
*
- * @see TemplateFinder
+ * @see Template
*/
def loadResourceAsXml(name: String): Box[NodeSeq] = loadResourceAsString(name).flatMap(s => PCDataXmlParser(s))
@@ -1470,6 +1470,12 @@ trait LiftRules extends Factory with FormVendor with LazyLoggable {
}
+ /**
+ * The list of suffixes that Lift looks for in templates.
+ * By default, html, xhtml, and htm
+ */
+ @volatile var templateSuffixes: List[String] = List("html", "xhtml", "htm")
+
/**
* When a request is parsed into a Req object, certain suffixes are explicitly split from
* the last part of the request URI. If the suffix is contained in this list, it is explicitly split.
@@ -1220,8 +1220,7 @@ trait LiftScreen extends AbstractScreen with StatefulSnippet with ScreenWizardRe
protected def allTemplatePath: List[String] = LiftScreenRules.allTemplatePath.vend
protected def allTemplate: NodeSeq = {
- val ret = TemplateFinder.
- findAnyTemplate(allTemplatePath) openOr allTemplateNodeSeq
+ val ret = Templates(allTemplatePath) openOr allTemplateNodeSeq
ret
}
@@ -142,46 +142,9 @@ object LiftSession {
* Check to see if the template is marked designer friendly
* and lop off the stuff before the first surround
*/
- def checkForContentId(in: NodeSeq): NodeSeq = {
- def df(in: MetaData): Option[PrefixedAttribute] = in match {
- case Null => None
- case p: PrefixedAttribute
- if (p.pre == "l" || p.pre == "lift") &&
- (p.key == "content_id") => Some(p)
- case n => df(n.next)
- }
-
-
- in.flatMap {
- case e: Elem if e.label == "html" => df(e.attributes)
- case _ => None
- }.flatMap {
- md => Helpers.findId(in, md.value.text)
- }.headOption orElse
- in.flatMap {
- case e: Elem if e.label == "html" =>
- e.child.flatMap {
- case e: Elem if e.label == "body" => {
- e.attribute("class").flatMap {
- ns => {
- val clz = ns.text.charSplit(' ')
- clz.flatMap {
- case s if s.startsWith("lift:content_id=") =>
- Some(urlDecode(s.substring("lift:content_id=".length)))
- case _ => None
- }.headOption
-
- }
- }
- }
-
- case _ => None
- }
- case _ => None
- }.flatMap {
- id => Helpers.findId(in, id)
- }.headOption getOrElse in
- }
+ @deprecated("Use Templates.checkForContentId")
+ def checkForContentId(in: NodeSeq): NodeSeq =
+ Templates.checkForContentId(in)
}
@@ -509,8 +472,6 @@ private final case class PostPageFunctions(renderVersion: String,
*/
class LiftSession(private[http] val _contextPath: String, val uniqueId: String,
val httpSession: Box[HTTPSession]) extends LiftMerge with Loggable with HowStateful {
- import TemplateFinder._
-
val sessionHtmlProperties: SessionVar[HtmlProperties] =
new SessionVar[HtmlProperties](LiftRules.htmlProperties.vend(
S.request openOr Req.nil
@@ -979,9 +940,8 @@ class LiftSession(private[http] val _contextPath: String, val uniqueId: String,
def processTemplate(template: Box[NodeSeq], request: Req, path: ParsePath, code: Int): Box[LiftResponse] = {
overrideResponseCode.doWith(Empty) {
(template or findVisibleTemplate(path, request)).map {
- xhtmlBase =>
+ xhtml =>
fullPageLoad.doWith(true) { // allow parallel snippets
- val xhtml = LiftSession.checkForContentId(xhtmlBase)
// Phase 1: snippets & templates processing
val rawXml: NodeSeq = processSurroundAndInclude(PageName get, xhtml)
@@ -1205,7 +1165,7 @@ class LiftSession(private[http] val _contextPath: String, val uniqueId: String,
case s@_ if (!s.isEmpty) => s
case _ => List("index")
}
- findAnyTemplate(splits, S.locale)
+ Templates(splits, S.locale)
}
private[liftweb] def findTemplate(name: String): Box[NodeSeq] = {
@@ -1214,10 +1174,10 @@ class LiftSession(private[http] val _contextPath: String, val uniqueId: String,
case s => s
}
- findAnyTemplate("templates-hidden" :: splits, S.locale) match {
+ Templates("templates-hidden" :: splits, S.locale) match {
case Full(x) => Full(x)
case f: Failure if Props.devMode => f
- case _ => findAnyTemplate(splits, S.locale)
+ case _ => Templates(splits, S.locale)
}
}
@@ -1279,7 +1239,7 @@ class LiftSession(private[http] val _contextPath: String, val uniqueId: String,
} headOption
for{
- template <- findAnyTemplate(name, S.locale) ?~ ("Template " + name + " not found")
+ template <- Templates(name, S.locale) ?~ ("Template " + name + " not found")
res <- findElem(processSurroundAndInclude(name.mkString("/", "/", ""), template))
} yield res
}
@@ -119,7 +119,7 @@ trait MVCHelper extends LiftRules.DispatchPF {
def tryIt(path: List[String]): Box[NodeSeq] = path match {
case Nil => Empty
- case xs => TemplateFinder.findAnyTemplate(path) match {
+ case xs => Templates(path) match {
case ret@ Full(_) => ret
case _ => tryIt(path.dropRight(1))
}
@@ -1013,7 +1013,7 @@ class Req(val path: ParsePath,
S.statelessInit(this) {
(for {
session <- S.session
- template = TemplateFinder.findAnyTemplate(path.partPath)
+ template = Templates(path.partPath)
resp <- session.processTemplate(template, this, path, 404)
} yield resp) match {
case Full(resp) => resp
@@ -501,7 +501,7 @@ trait S extends HasParams with Loggable {
def templateFromTemplateAttr: Box[NodeSeq] =
for (templateName <- attr("template") ?~ "Template Attribute missing";
val tmplList = templateName.roboSplit("/");
- template <- TemplateFinder.findAnyTemplate(tmplList) ?~
+ template <- Templates(tmplList) ?~
"couldn't find template") yield template
@@ -1834,18 +1834,18 @@ for {
/**
* Find and process a template. This can be used to load a template from within some other Lift processing,
* such as a snippet or view. If you just want to retrieve the XML contents of a template, use
- * TemplateFinder.findAnyTemplate.
+ * Templates.apply.
*
* @param path The path for the template that you want to process
* @param snips any snippet mapping specific to this template run
* @return a Full Box containing the processed template, or a Failure if the template could not be found.
*
- * @see TempalateFinder # findAnyTemplate
+ * @see TempalateFinder # apply
*/
def runTemplate(path: List[String], snips: (String, NodeSeq => NodeSeq)*): Box[NodeSeq] =
mapSnippetsWith(snips :_*) {
for{
- t <- TemplateFinder.findAnyTemplate(path) ?~ ("Couldn't find template " + path)
+ t <- Templates(path) ?~ ("Couldn't find template " + path)
sess <- session ?~ "No current session"
} yield sess.processSurroundAndInclude(path.mkString("/", "/", ""), t)
}
@@ -61,6 +61,15 @@ trait SHtml {
implicit def funcPromote[T](f: T => String): PairStringPromoter[T] =
new PairStringPromoter[T]{def apply(in: T): String = f(in)}
+
+
+ type EnumerationTypeWorkaround = Enumeration#Value
+
+ implicit def enumToStrValPromo[EnumerationTypeWorkaround]: SHtml.PairStringPromoter[EnumerationTypeWorkaround] =
+ new SHtml.PairStringPromoter[EnumerationTypeWorkaround]{
+ def apply(in: EnumerationTypeWorkaround): String =
+ in.toString
+ }
}
/**
@@ -1992,9 +2001,9 @@ object AjaxContext {
case class AjaxContext(success: Box[String], failure: Box[String], responseType: AjaxType.Value)
-case class JsContext(override val success: Box[String], override val failure: Box[String]) extends AjaxContext(success, failure, AjaxType.JavaScript)
+class JsContext(override val success: Box[String], override val failure: Box[String]) extends AjaxContext(success, failure, AjaxType.JavaScript)
-case class JsonContext(override val success: Box[String], override val failure: Box[String]) extends AjaxContext(success, failure, AjaxType.JSON)
+class JsonContext(override val success: Box[String], override val failure: Box[String]) extends AjaxContext(success, failure, AjaxType.JSON)
object Html5ElemAttr {
/**
Oops, something went wrong.

0 comments on commit 95f2dc6

Please sign in to comment.