Skip to content

Commit

Permalink
added samle webserver application
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Landgraf committed Apr 29, 2010
1 parent 4dfde73 commit 7caab5d
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
15 changes: 15 additions & 0 deletions examples/website/config.ru
@@ -0,0 +1,15 @@
$LOAD_PATH.unshift(File.join("..", "..", "lib"))
require "rlisp"

interpreter = Lisp::Interpreter.new
interpreter.import("web.lisp")

app =lambda do |env|
[
200,
{'Content-Type' => 'text/html'},
interpreter.eval([:rack_handler, env])
]
end

run app
54 changes: 54 additions & 0 deletions examples/website/web.lisp
@@ -0,0 +1,54 @@
;; Helper

(defmacro (defun)
(defun name parameter expr)
(label name (lambda parameter expr)))

(defun tag (name text) (string "<" name ">" text "</" name ">"))

(defun tag_class (name class text) (
string "<" name " class='" class "'>" text "</" name ">"))

(defun h1 (text) (tag h1 text))

(defun para (text) (tag p text))

(defun div (class text) (tag_class div class text))

(defun pre (text) (tag pre text))

(defun html (title text)
(string
(tag html
(string
(tag head (tag "title" title))
(tag body text)
)
)
)
)

;; Website

(setq TITLE "RLISP Webserver")

(defun template (content)
(html TITLE
(string
(div container content)
)
)
)

(defun start_page(env)
(template
(string
(h1 TITLE)
(para "Welcome to the first rlisp site!")
(para "It's very cool")
(para (string (+ 23 42)))
)
)
)

(defun rack_handler (env) (start_page env))

0 comments on commit 7caab5d

Please sign in to comment.