Created
January 12, 2015 06:26
-
-
Save dydx/acbcf5c0dd9eb6a6f6e6 to your computer and use it in GitHub Desktop.
http server with something resembling a templating language for 'dynamic' content
This file contains 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
Iota := Object clone do ( | |
stack := nil | |
output := nil | |
init := method ( | |
stack = List clone | |
output = List clone | |
) | |
squareBrackets := method ( | |
for(arg, 0, call argCount - 1, | |
output append (call evalArgAt(arg)) | |
) | |
output append(stack pop) | |
"" | |
) | |
forward := method ( | |
name := call message name | |
attrs := call message arguments map(arguments) map (pair, | |
k := pair at(0) asString exSlice(1, -1) | |
v := pair at(1) | |
" " .. k .. "=" .. v | |
) join | |
if(call message next ?name == "squareBrackets", | |
output append("<" .. name .. attrs .. ">") | |
stack push("</" .. name .. ">") | |
self | |
, // else | |
output append("<" .. name .. attrs .. "/>") | |
"" | |
) | |
) | |
) | |
server := HttpServer clone do ( | |
setPort(5000) | |
setHost("localhost") | |
renderResponse := method(request, response, | |
response body = createBody | |
) | |
createBody := method ( | |
Iota clone do ( | |
html [ | |
head [ | |
title [ "the title" ] | |
] | |
body [ | |
div( class="foo", id="bar") [ | |
"hello world", br | |
"this is a test" | |
] | |
] | |
] | |
) output join | |
) | |
) | |
server start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment