Created
August 10, 2012 10:34
-
-
Save ignacy/3313271 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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