Skip to content

Instantly share code, notes, and snippets.

@dydx
Created January 12, 2015 06:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dydx/acbcf5c0dd9eb6a6f6e6 to your computer and use it in GitHub Desktop.
Save dydx/acbcf5c0dd9eb6a6f6e6 to your computer and use it in GitHub Desktop.
http server with something resembling a templating language for 'dynamic' content
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