ず's WiLiKi

WiLiKi/マクロ/comment




1行コメントマクロの習作

使用方法

1行コメントをつけたいページに下記のように書く。

[[$comment]]

一度書き込むと、下記のように展開される。

- [[$$comment XXXX-XXXXXXXXX]]

コメント

毎日コメントSPAMを書かれてさすがにうざいので、デモ用のコメント欄は消しました。 下記のソースを元に自分で試してみてください。

ソース

;
; WiLiKi comment macro by zu
;

(use  gauche.regexp)
(select-module wiliki.macro)

(define (cmd-comment arg)
        `((form
             (@ (method POST) (action "index.cgi"))
             (br)
             (input (@ (type hidden) (name c) (value comment)))
             (input (@ (type hidden) (name id) (value ,arg)))
             (input (@ (type hidden) (name p) (value ,(ref (wiliki:current-page)
 'key))))
             (input (@ (type hidden) (name l) (value ,(wiliki:lang))))
             (input (@ (type hidden) (name mtime) (value ,(ref (wiliki:current-p
age) 'mtime))))
             (input (@ (type text) (name user)(size 10)))
             (input (@ (type text) (name comment)(size 50)))
             (br)
             (input (@ (type submit) (name submit) (value submit)))
        ))
)
;;           (@ (method POST) (action (cgi-name-of (wiliki))))

(define (cmd-comment-init)
        `(,(format "- [[$$comment ~s-~d]]" (gensym) (sys-time))) )


(define-reader-macro (comment arg) (cmd-comment arg))
(define-writer-macro (comment) (cmd-comment-init))

(select-module wiliki)

(define-method wiliki-main ((self <wiliki>))
  (cgi-main
   (lambda (param)
     (let ((pagename (get-page-name self param))
           (command  (cgi-get-parameter "c" param))
           (language (cgi-get-parameter "l" param :convert string->symbol)))
       (parameterize
           ((wiliki self)
            (lang   (or language (language-of self))))
        (cgi-output-character-encoding (output-charset))
        (textdomain (lang))
        (cond
         ;; command may #t if we're looking at the page named "c".
         ((or (not command) (eq? command #t))
          (with-db (cut cmd-view pagename)))
         ((equal? command "lv")
          (with-db (cut cmd-lwp-view pagename)))
         ((equal? command "e")
          (with-db (cut cmd-edit pagename)))
         ((equal? command "a")
          (with-db cmd-all))
         ((equal? command "r")
          (with-db cmd-recent-changes))
         ((equal? command "h")
          (with-db (cut cmd-history pagename)))
         ((equal? command "hd")
          (with-db (cut cmd-diff pagename
                        (cgi-get-parameter "t" param :convert x->integer
                                           :default 0)
                        (cgi-get-parameter "t1" param :convert x->integer
                                           :default 0))))
         ((equal? command "hv")
          (with-db (cut cmd-viewold pagename
                        (cgi-get-parameter "t" param :convert x->integer
                                           :default 0))))
         ((equal? command "s")
          (with-db
           (cut cmd-search (cgi-get-parameter "key" param :convert cv-in))))
         ((equal? command "c")
          (with-db
           (cut
            (if (cgi-get-parameter "commit" param :default #f)
              cmd-commit-edit
              cmd-preview)
            pagename
            (cgi-get-parameter "content" param :convert cv-in)
            (cgi-get-parameter "mtime" param
                               :convert x->integer
                               :default 0)
            (cgi-get-parameter "logmsg" param :convert cv-in)
            (cgi-get-parameter "donttouch" param :default #f))
           :write))
         ((equal? command "comment")
          (if (or (string=? (cgi-get-parameter "id" param :default "") "")
                  (string=? (cgi-get-parameter "comment" param :default "") ""))
             (with-db (cut cmd-view pagename))
             (with-db
               (cut
                 cmd-commit-edit
                 pagename
                 (let* ((page (ref (wiliki-db-get pagename #f) 'content))
                        (user      (cgi-get-parameter "user" param :convert cv-i
n))
                        (comment   (cgi-get-parameter "comment" param :convert c
v-in))
                        (id     (cgi-get-parameter "id" param :convert cv-in))
                        (form (regexp-quote (format "- [[$$comment ~a]]" id))))
                       (regexp-replace (string->regexp form) page (format "- ~a
[[~a]] ~a\r\n\\0" comment user (wiliki:format-time (sys-time)))))
                 (cgi-get-parameter "mtime" param
                               :convert x->integer
                               :default 0)
                 ""
                 #f)
                 :write)))
         ((equal? command "rss")
          (with-db (cut rss-page (db))))
         ))))
   :merge-cookies #t
   :on-error error-page))


マクロなど


2






[トップ] / [最近の更新] [一覧] / [RSS] / [お問い合わせ・情報提供]

本サイトはAmazonアソシエイト等のアフィリエイトサービスを利用しています
running on WiLiKi and Gauche