source: project/demonstrations/awful/fortune/fortune-server.scm @ 20676

Last change on this file since 20676 was 20676, checked in by Mario Domenech Goulart, 11 years ago

demonstrations: added an awful fortune server using sqlite and ajax

  • Property svn:executable set to *
File size: 918 bytes
RevLine 
[20676]1#!/usr/bin/awful
2
3(use awful html-tags awful-sql-de-lite)
4
5(enable-db)
6(db-credentials "fortunes.db")
7
8(define random-fortune
9  (let ((num-fortunes #f))
10    (lambda ()
11      (unless num-fortunes
12        (set! num-fortunes (caar ($db "select count(id) from fortunes"))))
13      (car ($db (conc "select sentence, author from fortunes where id="
14                      (random num-fortunes)))))))
15
16(define-page (main-page-path)
17  (lambda ()
18    (ajax "new-fortune" 'new-fortune 'click
19          (lambda ()
20            (let ((fortune (random-fortune)))
21              `((sentence . ,(car fortune))
22                (author . ,(cadr fortune)))))
23          update-targets: #t)
24
25    (<div> id: "content"
26           (<div> id: "sentence" "Click the button below to get a new fortune")
27           (<div> id: "author")
28           (<button> id: "new-fortune" "New fortune")))
29
30  css: "fortune.css"
31  use-ajax: #t
32  charset: "utf-8")
Note: See TracBrowser for help on using the repository browser.