summary refs log tree commit diff stats
path: root/tests/showoff/thtml2.nim
blob: faeb4e50d618a9d4dec5670306238f31b7d720fa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
discard """
  output: "<html><head><title>now look at this</title></head><body><ul><li>Nim is quite capable</li></ul></body></html>"
"""

import strutils

template html(name: expr, matter: stmt) {.immediate.} =
  proc name(): string =
    result = "<html>"
    matter
    result.add("</html>")

template nestedTag(tag: expr) {.immediate.} =
  template tag(matter: stmt) {.immediate.} =
    result.add("<" & astToStr(tag) & ">")
    matter
    result.add("</" & astToStr(tag) & ">")

template simpleTag(tag: expr) {.immediate.} =
  template tag(matter: expr) {.immediate.} =
    result.add("<$1>$2</$1>" % [astToStr(tag), matter])

nestedTag body
nestedTag head
nestedTag ul
simpleTag title
simpleTag li


html mainPage:
  head:
    title "now look at this"
  body:
    ul:
      li "Nim is quite capable"

echo mainPage()