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

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

demonstrations/awful/fortune: bug fix and improved `random-fortune' (excellent tips from Peter Bex)

  • Property svn:executable set to *
File size: 735 bytes
Line 
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  (car ($db "select sentence, author from fortunes order by random() limit 1")))
10
11(define-page (main-page-path)
12  (lambda ()
13    (ajax "new-fortune" 'new-fortune 'click
14          (lambda ()
15            (let ((fortune (random-fortune)))
16              `((sentence . ,(car fortune))
17                (author . ,(cadr fortune)))))
18          update-targets: #t)
19
20    (<div> id: "content"
21           (<div> id: "sentence" "Click the button below to get a new fortune")
22           (<div> id: "author")
23           (<button> id: "new-fortune" "New fortune")))
24
25  css: "fortune.css"
26  use-ajax: #t
27  charset: "utf-8")
Note: See TracBrowser for help on using the repository browser.