Skip to content

Instantly share code, notes, and snippets.

@ignacy
Created August 10, 2012 10:34
Show Gist options
  • Select an option

  • Save ignacy/3313271 to your computer and use it in GitHub Desktop.

Select an option

Save ignacy/3313271 to your computer and use it in GitHub Desktop.
(defun welcome-page-handler (httpcon)
(elnode-http-start httpcon "200" '("Content-type" . "text/html"))
(elnode-http-return httpcon (my-main-page)))
(defun html (x)
"Return valid HTML code constructed from passed list"
(if (not (listp x))
x
(let ((tag (car x))
(body (cdr x)))
(if (and (listp (car body)) (string= "attributes" (first (car body))))
(concat "<" tag " " (car (cdr (car body))) ">"
(apply 'concat (mapcar 'html (cdr body)))
"</" tag ">")
(concat "<" tag ">"
(apply 'concat (mapcar 'html body))
"</" tag ">")))))
(defun my-main-page ()
(html '("html"
("head"
("body"
("div"
("h1" "Hello world")
("div" "I don't" ("b" " like ") "plain html page look")
("br")
("div" ("attributes" "class=span9 style=\"color:red\"")
"This is a webpage served by elnode!")))))))
(elnode-start 'welcome-page-handler :port 8010 :host "localhost")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment