I have been playing with templates and noticed that it is possible to accumulate multiple <title/> tags in the <head/> tag, which isn't compliant to XHTML. Here is a suggested patch which merges the <title/ > tags space separating them...
That should allow templates to progressively add to the title. I had considered initially just picking the first, but that may not be the correct one... Regards, Marc --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~----------~----~----~----~------~----~------~--~---
*** HeadHelper.scala.orig 2009-01-16 08:33:01.000000000 +1100 --- HeadHelper.scala 2009-01-17 09:45:54.000000000 +1100 *************** *** 25,30 **** --- 25,61 ---- def identity(xml: NodeSeq) : NodeSeq = xml def mergeToHtmlHead(xhtml: NodeSeq) : NodeSeq = { + def ret(xhtml: NodeSeq): NodeSeq = insertTitle(removeTitle(xhtml), mergeTitle(xhtml)) + + // There should only be one <title/> tag in a xhtml <head/> + def mergeTitle(in: NodeSeq): NodeSeq = + <title>{(for (title <- in \ "head" \ "title") yield title.text).mkString(" ")}</title> + + def removeTitle(in: NodeSeq): NodeSeq = in flatMap { + case e: Elem if e.label == "title" => + NodeSeq.Empty + case e: Elem => + Elem(e.prefix, e.label, e.attributes, e.scope, removeTitle(e.child) :_*) + case Group(g) => + Group(removeTitle(g)) + case x => x + } + + def insertTitle(in: NodeSeq, title: NodeSeq): NodeSeq = { + def insertInHEAD(in: NodeSeq): NodeSeq = in flatMap { + case e: Elem if e.label == "head" => + Elem(e.prefix, e.label, e.attributes, e.scope, title ++ e.child :_*) + case x => x + } + def insertAfterHTML(in: NodeSeq): NodeSeq = in flatMap { + case e: Elem if e.label == "html" => + Elem(e.prefix, e.label, e.attributes, e.scope, insertInHEAD(e.child): _*) + case x => x + } + insertAfterHTML(in) + } + + def trimText(in: NodeSeq): NodeSeq = in flatMap { case e: Elem => Elem(e.prefix, e.label, e.attributes, e.scope, trimText(e.child) :_*) *************** *** 45,51 **** head <- body \\ "head") yield trimText(head.child)). toList.removeDuplicates.flatMap(a => a) ! if (headInBody.isEmpty) xhtml else { def xform(in: NodeSeq, inBody: Boolean): NodeSeq = in flatMap { case e: Elem if !inBody && e.label == "body" => --- 76,82 ---- head <- body \\ "head") yield trimText(head.child)). toList.removeDuplicates.flatMap(a => a) ! if (headInBody.isEmpty) ret(xhtml) else { def xform(in: NodeSeq, inBody: Boolean): NodeSeq = in flatMap { case e: Elem if !inBody && e.label == "body" => *************** *** 66,75 **** case x => x } ! xform(xhtml, false) } } - } --- 97,105 ---- case x => x } ! ret(xform(xhtml, false)) } } }
---------------------------------------- *** HeadHelper.scala.orig 2009-01-16 08:33:01.000000000 +1100 --- HeadHelper.scala 2009-01-17 09:45:54.000000000 +1100 *************** *** 25,30 **** --- 25,61 ---- def identity(xml: NodeSeq) : NodeSeq = xml def mergeToHtmlHead(xhtml: NodeSeq) : NodeSeq = { + def ret(xhtml: NodeSeq): NodeSeq = insertTitle(removeTitle(xhtml), mergeTitle(xhtml)) + + // There should only be one <title/> tag in a xhtml <head/> + def mergeTitle(in: NodeSeq): NodeSeq = + <title>{(for (title <- in \ "head" \ "title") yield title.text).mkString(" ")}</title> + + def removeTitle(in: NodeSeq): NodeSeq = in flatMap { + case e: Elem if e.label == "title" => + NodeSeq.Empty + case e: Elem => + Elem(e.prefix, e.label, e.attributes, e.scope, removeTitle(e.child) :_*) + case Group(g) => + Group(removeTitle(g)) + case x => x + } + + def insertTitle(in: NodeSeq, title: NodeSeq): NodeSeq = { + def insertInHEAD(in: NodeSeq): NodeSeq = in flatMap { + case e: Elem if e.label == "head" => + Elem(e.prefix, e.label, e.attributes, e.scope, title ++ e.child :_*) + case x => x + } + def insertAfterHTML(in: NodeSeq): NodeSeq = in flatMap { + case e: Elem if e.label == "html" => + Elem(e.prefix, e.label, e.attributes, e.scope, insertInHEAD(e.child): _*) + case x => x + } + insertAfterHTML(in) + } + + def trimText(in: NodeSeq): NodeSeq = in flatMap { case e: Elem => Elem(e.prefix, e.label, e.attributes, e.scope, trimText(e.child) :_*) *************** *** 45,51 **** head <- body \\ "head") yield trimText(head.child)). toList.removeDuplicates.flatMap(a => a) ! if (headInBody.isEmpty) xhtml else { def xform(in: NodeSeq, inBody: Boolean): NodeSeq = in flatMap { case e: Elem if !inBody && e.label == "body" => --- 76,82 ---- head <- body \\ "head") yield trimText(head.child)). toList.removeDuplicates.flatMap(a => a) ! if (headInBody.isEmpty) ret(xhtml) else { def xform(in: NodeSeq, inBody: Boolean): NodeSeq = in flatMap { case e: Elem if !inBody && e.label == "body" => *************** *** 66,75 **** case x => x } ! xform(xhtml, false) } } - } --- 97,105 ---- case x => x } ! ret(xform(xhtml, false)) } } }