SourceFourth » 履歴 » バージョン 3
Yuumi Yoshida, 2015-08-03 22:24
1 | 1 | Yuumi Yoshida | * リスト1 |
---|---|---|---|
2 | 3 | Yuumi Yoshida | ~~~ |
3 | 1 | Yuumi Yoshida | <html> |
4 | <body> |
||
5 | <h2>Asia League Ice Hockey</h2> |
||
6 | <table border="1"> |
||
7 | 3 | Yuumi Yoshida | <% (for-each (lambda (row) %> |
8 | 1 | Yuumi Yoshida | <tr> |
9 | 3 | Yuumi Yoshida | <td><%= (getter row "no") %></td> |
10 | <td><%= (getter row "name") %></td> |
||
11 | <td><%= (getter row "g") %></td> |
||
12 | 1 | Yuumi Yoshida | </tr> |
13 | 3 | Yuumi Yoshida | <% ) res) %> |
14 | 1 | Yuumi Yoshida | </table> |
15 | </body> |
||
16 | </html> |
||
17 | 3 | Yuumi Yoshida | ~~~ |
18 | 1 | Yuumi Yoshida | |
19 | * リスト2 |
||
20 | 3 | Yuumi Yoshida | ~~~ |
21 | 1 | Yuumi Yoshida | (define (render path params) |
22 | (let* ((conn (dbi-connect "dbi:sqlite3:alih.db")) |
||
23 | (pos (cgi-get-parameter "pos" params)) |
||
24 | (res |
||
25 | (if (and pos (rxmatch #/^[DFG]$/ pos)) |
||
26 | (dbi-do conn "SELECT no, name, g FROM player where pos=? order by no" |
||
27 | '() pos) |
||
28 | (dbi-do conn "SELECT no, name, g FROM player order by no"))) |
||
29 | (getter (relation-accessor res))) |
||
30 | (dbi-close conn) |
||
31 | (template "list.tmpl" res getter))) |
||
32 | |||
33 | (define-macro (template tmpl-file . args) |
||
34 | 2 | Yuumi Yoshida | @(templ-render ,tmpl-file (quote ,args) (list ,@args))) |
35 | 1 | Yuumi Yoshida | |
36 | (define (templ-render templ-file vars args) |
||
37 | (apply (eval (read-from-string (templ-func templ-file vars)) (interaction-environment)) |
||
38 | args)) |
||
39 | |||
40 | (define (templ-func templ-file vars) |
||
41 | (read-from-string |
||
42 | 2 | Yuumi Yoshida | #@"(lambda ,vars |
43 | 1 | Yuumi Yoshida | (let1 port (open-output-string) |
44 | ,(expand-templ (file->string templ-file)) |
||
45 | (get-output-string port)))")) |
||
46 | |||
47 | (define (expand-templ templ) |
||
48 | 3 | Yuumi Yoshida | (cond ((#/(.*?)<%=(.*?)%>(.*)/ templ) |
49 | 1 | Yuumi Yoshida | => (lambda(m) |
50 | 2 | Yuumi Yoshida | #@",(expand-templ (m 1)) (display ,(m 2) port) ,(expand-templ (m 3))")) |
51 | 3 | Yuumi Yoshida | ((#/(.*?)<%(.*?)%>(.*)/ templ) |
52 | 1 | Yuumi Yoshida | => (lambda(m) |
53 | 2 | Yuumi Yoshida | #@",(expand-templ (m 1)) ,(m 2) ,(expand-templ (m 3))")) |
54 | 1 | Yuumi Yoshida | (else (format "(display ~s port)" templ)))) |
55 | 3 | Yuumi Yoshida | ~~~ |