examples from the talk part of test suite

This commit is contained in:
Araq 2013-09-27 08:45:14 +02:00
commit 2f0671eb79
9 changed files with 153 additions and 3 deletions

33
examples/talk/dsl.nim Normal file
View file

@ -0,0 +1,33 @@
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 "Nimrod is quite capable"
echo mainPage()