(module spodwiki-bot mzscheme
        (require "bot.scm")
        (provide spodwiki-bot
                 (all-from "bot.scm"))

        ;;;; spodwiki-bot
         (roos-doc (sp "With this class, one can upload SPOD pages to a " (s% 'spodwiki) " site")
                   (s== "Synopsis")
                   (sverb "> (require (lib \"spodwiki-bot.scm\" \"webbot\")"
                          "> (define x (spodwiki-bot \"http://www.elemental-programming.org/wiki/wiki.php\"))"
                          "> (define p (-> x post-page \"abc\" #f #t (build-path \"roos_manual.pod\")))"
                          "> (read-string 1000000 p)"))
          (this (spodwiki-bot _wiki-url))
          (supers (form-data))
           (define _gen-url _wiki-url)

           (define (read-in path)
             (define (rd port)
               (let ((r (read-string 1024 port)))
                 (if (eq? r eof)
                       (close-input-port port)
                     (string-append r (rd port)))))
             (rd (open-input-file path)))

           (define (initialize)
             (-> this form-clear))

           (define (url)
             (string->url  _gen-url))

           (define (submit-url pagename)
             (set! _gen-url _wiki-url)
             (-> this form-add 'page    pagename)
             (-> this form-add 'submit  1)
             (-> this form-add 'display pagename)

           (define (submit-fields is-kwiki enable-toc text)
             (-> this form-add 'toc   (if enable-toc "on" "0"))
             (-> this form-add 'kwiki (if is-kwiki   "on" "0"))
             (-> this form-add 'spod   text)
             (-> this form-add 'commit "Commit"))
          ;;;;    public

           ;;;;        post-page
           ((define (sp "With this member, a page can be posted.")
                    (sp (s% "Input parameters : "))
                         (s\\ (s%% "pagename     : ") "The name of the page (can contain spaces).")
                         (s\\ (s%% "is-kwiki     : ") "This page consists only of kwiki wiki code (i.e. no SPOD involved.")
                         (s\\ (s%% "enable-toc   : ") "#t, generate table of contents; #f don't.")
                         (s\\ (s%% "text-or-path : ") "If " (s% "(path? text-or-path") ", the contents of that file are posted; otherwise the given text.")))
                    (sp (s%% "Returns          : ") (s% "<input-port>") " which can be read for the (html) result of the http server."))
              (post-page pagename is-kwiki enable-toc text-or-path)
                (if (path? text-or-path)
                    (-> this post-page pagename is-kwiki enable-toc (read-in text-or-path))
                      (submit-url    pagename)
                      (submit-fields is-kwiki enable-toc text-or-path)
                      (-> this form-post (url)))))
          ((constructor (sp (s% "Arguments: " "_wiki-url:<string>")))
        );;;; module