/scalate-core/src/test/scala/org/fusesource/scalate/ssp/MadsForIssueTest.scala

http://github.com/scalate/scalate · Scala · 89 lines · 61 code · 8 blank · 20 comment · 0 complexity · 1405d37a07b392526750e0e80125272a MD5 · raw file

  1. /**
  2. * Copyright (C) 2009-2011 the original author or authors.
  3. * See the notice.md file distributed with this work for additional
  4. * information regarding copyright ownership.
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. package org.fusesource.scalate.ssp
  19. import org.fusesource.scalate.{ TemplateTestSupport }
  20. /**
  21. * @version $Revision : 1.1 $
  22. */
  23. class MadsForIssueTest extends TemplateTestSupport {
  24. test("issue with #for") {
  25. val template = compileSsp("using #for", """<%@ var fields:List[String] %>
  26. start
  27. <% fields.foreach{ field => %>
  28. f1 ${field}
  29. <% } %>
  30. #for( field <- fields)
  31. f2 ${field}
  32. #end
  33. done
  34. """)
  35. assertTrimOutput("""start
  36. f1 a
  37. f1 b
  38. f2 a
  39. f2 b
  40. done""", template, Map("fields" -> List("a", "b")))
  41. }
  42. test("mads sample") {
  43. val attributes = Map(
  44. "name" -> "Cheese",
  45. "thePackage" -> "org.acme.cheese",
  46. "fields" -> List("foo", "bar"))
  47. val template = compileSsp("Mads sample", """
  48. <%@ var name:String %>
  49. <%@ var thePackage:String %>
  50. <%@ var fields:List[String] %>
  51. package ${thePackage}
  52. import net.liftweb._
  53. import mapper._
  54. import http._
  55. import SHtml._
  56. import util._
  57. class ${name} extends LongKeyedMapper[${name}] with IdPK {
  58. def getSingleton = ${name}
  59. <% fields.foreach{ field => %>
  60. object ${field} extends MappedField(this)
  61. <% } %>
  62. #for(field <- fields)
  63. object ${field} extends MappedField(this)
  64. #end
  65. }
  66. object ${name} extends ${name} with LongKeyedMetaMapper[${name}]
  67. """)
  68. val output = engine.layout("dummy.ssp", template, attributes)
  69. debug("Output:")
  70. debug(output)
  71. }
  72. }