framework icon indicating copy to clipboard operation
framework copied to clipboard

HtmlProperties setDoctype has no effect as htmlOutputHeader calls the original doctype

Open indrajitr opened this issue 12 years ago • 1 comments

as discussed on http://groups.google.com/group/liftweb/browse_thread/thread/6a0701b47e2200bc/80f0199bae1391c3#80f0199bae1391c3

I cooked up a proposed solution, see the trait "BaseType".

It only needs specs2

This pattern should work with the current way HtmlProperties works.



import org.specs2.mutable._

trait OldBaseType {

  def First: String

  def setFirst(newFirst: () => String) = {
    val old = this
    new OldBaseType {
      def First = newFirst()

      def Second = old.Second

      def Third = old.Third
    }
  }

  def Second: String

  def setSecond(newSecond: () => String) = {
    val old = this
    new OldBaseType {
      def First = old.First

      def Second = newSecond()

      def Third = old.Third
    }
  }

  def Third: String

  def setThird(newThird: () => String) = {
    val old = this
    new OldBaseType {
      def First = old.First

      def Second = old.Second

      def Third = newThird()
    }
  }
}

case class OldTestType(param: String) extends OldBaseType {
  def First =
    "HELLO"

  def Second =
    this.First + " WORLD"

  def Third =
    this.First + " " + this.Second + "!!!"
}

trait BaseType {

  def First(me:BaseType): String
  
  def First: String = First(this)

  def setFirst(newFirst: () => String) = {
    val old = this
    new BaseType {
      def First(me:BaseType) = old.First(me)
      
      override def First = newFirst()

      def Second(me:BaseType) = old.Second(me)

      def Third(me:BaseType) = old.Third(me)
    }
  }

  def Second(me:BaseType): String

  def Second: String = Second(this)

  def setSecond(newSecond: () => String) = {
    val old = this
    new BaseType {
      def First(me:BaseType) = old.First(me)

      def Second(me:BaseType) = old.Second(me)

      override def Second = newSecond()

      def Third(me:BaseType) =
        old.Third(me)
    }
  }


  def Third(me:BaseType): String

  def Third: String = Third(this)

  def setThird(newThird: () => String) = {
    val old = this
    new BaseType {
      def First(me:BaseType) = old.First(me)

      def Second(me:BaseType) = old.Second(me)

      def Third(me:BaseType) = old.Third(me)

      override def Third = newThird()
    }
  }
}

case class TestType(param: String) extends BaseType {
  def First(me:BaseType) =
    "HELLO"

  def Second(me:BaseType) =
    me.First + " WORLD"
  
  def Third(me:BaseType) =
    me.First + " " + me.Second + "!!!"
}

class TestProposed extends Specification {

  val t1 = TestType("")

  val t4 = TestType("").setFirst(()=>"GOODBYE")

  val t5 = t4.setSecond(()=>"YAY")

  val t6 = TestType("").setSecond(()=>"YOO")


  "test new" should {

    // specs wierdness (ambiguious overload) when i try to do
    // t1.Third must beEqualTo("HELLO HELLOW WORLD!!!")
    val basicString:String = t1.Third

    "nothing" in {
      basicString must beEqualTo("HELLO HELLO WORLD!!!")
    }

    "simple test" in {
      t4.Second must beEqualTo("GOODBYE WORLD")
    }

    "harder test" in {
      t4.Third must beEqualTo("GOODBYE GOODBYE WORLD!!!")
    }

    "another test" in {
      t5.Third must beEqualTo("HELLO YAY!!!")
    }

    "yet another test" in {
      t6.Third must beEqualTo("HELLO YOO!!!")
    }

  }

}

class TestOld extends Specification {

  val t1 = OldTestType("")

  val t4 = OldTestType("").setFirst(()=>"GOODBYE")

  val t5 = t4.setSecond(()=>"YAY")

  val t6 = OldTestType("").setSecond(()=>"YOO")


  "test old" should {

    // specs wierdness (ambiguious overload) when i try to do
    // t1.Third must beEqualTo("HELLO HELLOW WORLD!!!")
    val basicString:String = t1.Third

    "nothing" in {
      basicString must beEqualTo("HELLO HELLO WORLD!!!")
    }

    "simple test" in {
      t4.Second must beEqualTo("GOODBYE WORLD")
    }

    "harder test" in {
      t4.Third must beEqualTo("GOODBYE GOODBYE WORLD!!!")
    }

    "another test" in {
      t5.Third must beEqualTo("HELLO YAY!!!")
    }

    "yet another test" in {
      t6.Third must beEqualTo("HELLO YOO!!!")
    }

  }

}

indrajitr avatar Feb 07 '12 21:02 indrajitr

Imported from Assembla: http://www.assembla.com/spaces/liftweb/tickets/1194

github-importer avatar Feb 19 '12 21:02 github-importer