プロジェクト

全般

プロフィール

SourceFourth » 履歴 » リビジョン 2

リビジョン 1 (Yuumi Yoshida, 2008-06-29 19:18) → リビジョン 2/3 (Yuumi Yoshida, 2008-06-29 19:18)

* リスト1 
 <pre> {{{ 
 <html> 
   <body> 
     <h2>Asia League Ice Hockey</h2> 
     <table border="1"> 
     <%25 (for-each (lambda (row) %25> 
       <tr> 
        <td><%25= (getter row "no") %25></td> 
        <td><%25= (getter row "name") %25></td> 
        <td><%25= (getter row "g") %25></td> 
       </tr> 
      <%25 ) res) %25> 
      </table> 
   </body> 
 </html> 
 </pre> }}} 

 * リスト2 
 <pre> {{{ 
 (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 `(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 #`"(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 #`",(expand-templ (m 1)) (display ,(m 2) port) ,(expand-templ (m 3))")) 
        ((#/(.*?)<%25(.*?)%25>(.*)/ templ)  
         => (lambda(m) 
              #@",(expand-templ #`",(expand-templ (m 1)) ,(m 2) ,(expand-templ (m 3))")) 
        (else (format "(display ~s port)" templ)))) 
 </pre> }}}