プロジェクト

全般

プロフィール

操作

SourceFourth » 履歴 » リビジョン 2

« 前 | リビジョン 2/3 (差分) | 次 »
Yuumi Yoshida, 2008-06-29 19:18


  • リスト1



    Asia League Ice Hockey

    <%25 (for-each (lambda (row) %25>

    <%25= (getter row "no") %25>
    <%25= (getter row "name") %25>
    <%25= (getter row "g") %25>

    <%25 ) res) %25>


  • リスト2

    (define (render path params)
    (let* ((conn (dbi-connect "dbi:sqlite3:alih.db"))
    (pos (cgi-get-parameter "pos" params))
    (res
    (if (and pos (rxmatch #/[DFG]$/ pos))
    (dbi-do conn "SELECT no, name, g FROM player where pos=? order by no"
    '() pos)
    (dbi-do conn "SELECT no, name, g FROM player order by no")))
    (getter (relation-accessor res)))
    (dbi-close conn)
    (template "list.tmpl" res getter)))

(define-macro (template tmpl-file . args)
@(templ-render ,tmpl-file (quote ,args) (list ,@args)))

(define (templ-render templ-file vars args)
(apply (eval (read-from-string (templ-func templ-file vars)) (interaction-environment))
args))

(define (templ-func templ-file vars)
(read-from-string
#@"(lambda ,vars
(let1 port (open-output-string)
,(expand-templ (file->string templ-file))
(get-output-string port)))"))

(define (expand-templ templ)
(cond ((#/(.?)<%25=(.?)%25>(.)/ templ)
=> (lambda(m)
#@",(expand-templ (m 1)) (display ,(m 2) port) ,(expand-templ (m 3))"))
((#/(.
?)<%25(.?)%25>(.)/ templ)
=> (lambda(m)
#@",(expand-templ (m 1)) ,(m 2) ,(expand-templ (m 3))"))
(else (format "(display ~s port)" templ))))

Yuumi Yoshida さんがほぼ16年前に更新 · 2件の履歴