dsl.nim 621 B

12345678910111213141516171819202122232425262728293031323334
  1. import strutils
  2. template html(name, matter: untyped) =
  3. proc name(): string =
  4. result = "<html>"
  5. matter
  6. result.add("</html>")
  7. template nestedTag(tag: untyped) =
  8. template tag(matter: typed) =
  9. result.add("<" & astToStr(tag) & ">")
  10. matter
  11. result.add("</" & astToStr(tag) & ">")
  12. template simpleTag(tag: untyped) =
  13. template tag(matter: untyped) =
  14. result.add("<$1>$2</$1>" % [astToStr(tag), matter])
  15. nestedTag body
  16. nestedTag head
  17. nestedTag ul
  18. simpleTag title
  19. simpleTag li
  20. html mainPage:
  21. head:
  22. title "now look at this"
  23. body:
  24. ul:
  25. li "Nim is quite capable"
  26. echo mainPage()