thtml2.nim 761 B

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