Changeset 12570 in project


Ignore:
Timestamp:
11/22/08 16:22:49 (13 years ago)
Author:
azul
Message:

Lots of fixes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release/3/svnwiki-discuss/trunk/svnwiki-discuss.scm

    r12533 r12570  
    3232                   (else "~I Discussion (~N)")))))))))))
    3333
    34 (define (discuss-update-directory-accept env)
     34(define (is-discuss-level env i)
    3535  (let-from-environment env (path)
    3636    (and-let* ((path)
    37                (comps (string-split path "/"))
    38                ((> (length comps) 1)))
    39       (string=? "xsvnwiki-discuss" (last (butlast comps))))))
     37               (comps (reverse (string-split path "/")))
     38               ((> (length comps) i)))
     39      (string=? "xsvnwiki-discuss" (list-ref comps i)))))
    4040
    4141(when "SVNWIKI_UNITTESTS"
    42   (assert (discuss-update-directory-accept (environment ((path "xsvnwiki-discuss/foo")))))
    43   (assert (discuss-update-directory-accept (environment ((path "bar/xsvnwiki-discuss/foo")))))
    44   (assert (not (discuss-update-directory-accept (environment ((path "bar/foo"))))))
    45   (assert (not (discuss-update-directory-accept (environment ((path #f)))))))
    46 
    47 ; TODO: Figure out what we need to do here.  Maybe register links.
    48 
    49 (define (discuss-update-directory-meta env)
    50   (and (discuss-update-directory-accept env)
    51        (let-from-environment env (for-each-change)
    52          (for-each-change
    53            (lambda (env entry)
    54              (discuss-update-file-meta env))))))
    55 
    56 ; TODO: estraier-update-document!
    57 
    58 (define (discuss-update-file-meta env)
    59   #f)
     42  (assert (is-discuss-level (environment ((path "xsvnwiki-discuss/foo"))) 1))
     43  (assert (is-discuss-level (environment ((path "bar/xsvnwiki-discuss/foo"))) 1))
     44  (assert (not (is-discuss-level (environment ((path "bar/foo"))) 1)))
     45  (assert (not (is-discuss-level (environment ((path "xsvnwiki-discuss/bar/foo"))) 1)))
     46  (assert (not (is-discuss-level (environment ((path #f))) 1))))
    6047
    6148(define *comments-separator*
    6249  (html-stream (hr)))
    6350
    64 (define (discuss-update-directory-content env)
    65   (let-from-environment env (path-in path path-out return regenerate-page)
    66     (and-let* (((discuss-update-directory-accept env))
    67                (new-path-output (svnwiki-make-pathname #f path "text/html"))
    68                (env (environment env ((path-out-real new-path-output)))))
    69       ; Regenerate its associated page so its counters for the number of posts
    70       ; looks right.  In the future that counter should probably be loaded
    71       ; dynamically with AJAX.  However, we also need to regenerate it so that
    72       ; the emails for the discussion get sent out.
    73       (regenerate-page (svnwiki-discuss->normal path))
    74       (svnwiki-report-progress env (svnwiki-translate env "Generating discussion page for: ~A~%") path)
    75       (write-file-with-tmp path "text/html" path-out
    76         (svnwiki-render-template
    77           env
    78           "Discuss: "
    79           (stream-append
    80             (stream-concatenate
    81               (stream-intersperse
    82                 (stream-map
    83                   (lambda (comment-path)
    84                     (svnwiki-report-progress env (svnwiki-translate env "Generating discussion page for: ~A (comment ~A)~%") path comment-path)
    85                     (let ((comment-path-full (svnwiki-make-pathname path comment-path)))
    86                       (stream-append
    87                         (let ((subject (get-props-parents-first "svnwiki:mail:headers:subject" path-in comment-path-full)))
    88                           (if subject
    89                             (html-stream (h2 (stream-html-escape subject)))
    90                             stream-null))
    91                         (render-file-contents
    92                           ; TODO: Maybe we need path-original or something like that to get links right?
    93                           (environment env ((path comment-path-full)))
    94                           path)
    95                         ; TODO: Show the date
    96                         (html-stream
    97                           (p ((span class "author")
    98                               (stream-html-escape (get-props-parents-first "svnwiki:mail:headers:from" path-in comment-path-full "Anonymous")))
    99                              ", "
    100                              ((span class "date")
    101                               (seconds->string
    102                                 (string->number (car (string-split comment-path ":"))))))))))
    103                   (list->stream (sort (directory (svnwiki-repository-path env)) string<?)))
    104                 *comments-separator*))
    105             (html-stream
    106               ((div id "post-comment")
    107                (show-edit-form env))))
    108           'view))
    109       (return #t))))
     51(define (update-notify env)
     52  (when (is-discuss-level env 1)
     53    (let-from-environment env (path-in path regenerate-page path-out)
     54      (let* ((new-path-output (svnwiki-make-pathname path "index"))
     55             (env (environment env ((path-out-real new-path-output))))
     56             (path-normal (svnwiki-discuss->normal path)))
     57        ; Regenerate its associated page so its counters for the number of posts
     58        ; looks right.  In the future that counter should probably be loaded
     59        ; dynamically with AJAX.  However, we also need to regenerate it so that
     60        ; the emails for the discussion get sent out.
     61        (when (and (file-exists? (svnwiki-make-pathname path-in path-normal))
     62                   ; This can happen if it was a regular file but it has been
     63                   ; turned to a directory (probably with an index file) but the
     64                   ; discussion has not been moved.
     65                   (not (directory? (svnwiki-make-pathname path-in path-normal))))
     66          (regenerate-page path-normal))
     67        (svnwiki-report-progress env (svnwiki-translate env "Generating discussion page for: ~A: ~A~%") path new-path-output)
     68        (write-file-with-tmp new-path-output "text/html" path-out
     69          (svnwiki-render-template
     70            env
     71            "Discuss: "
     72            (stream-append
     73              (stream-concatenate
     74                (stream-intersperse
     75                  (stream-map
     76                    (lambda (comment-path)
     77                      (svnwiki-report-progress env (svnwiki-translate env "Generating discussion page for: ~A (comment ~A)~%") path comment-path)
     78                      (let ((comment-path-full (svnwiki-make-pathname path comment-path)))
     79                        (stream-append
     80                          (let ((subject (get-props-parents-first "svnwiki:mail:headers:subject" path-in comment-path-full)))
     81                            (if (and subject (not (string=? subject "")))
     82                              (html-stream (h2 (stream-html-escape subject)))
     83                              stream-null))
     84                          (render-file-contents
     85                            ; TODO: Maybe we need path-original or something like that to get links right?
     86                            (environment env ((path comment-path-full)))
     87                            path)
     88                          ; TODO: Show the date
     89                          (html-stream
     90                            (p ((span class "author")
     91                                (stream-html-escape (get-props-parents-first "svnwiki:mail:headers:from" path-in comment-path-full "Anonymous")))
     92                               ", "
     93                               ((span class "date")
     94                                (seconds->string
     95                                  (string->number (car (string-split comment-path ":"))))))))))
     96                    (list->stream (sort (directory (svnwiki-repository-path env)) string<?)))
     97                  *comments-separator*))
     98              (html-stream
     99                ((div id "post-comment")
     100                 (show-edit-form env))))
     101            'view))))))
    110102
    111 (svnwiki-extension-define 'render-bottmon-span 'discuss-counter discuss-counter)
    112 (svnwiki-extension-define 'update-directory-meta 'discuss discuss-update-directory-meta)
    113 (svnwiki-extension-define 'update-directory-content 'discuss discuss-update-directory-content)
     103(define (discuss-render env)
     104  (when (is-discuss-level env 2)
     105    (let-from-environment env (return)
     106      (return (html-stream "TODO: write this code")))))
     107
     108; TODO: enable
     109;(svnwiki-extension-define 'render-file-contents 'discuss discuss-render)
     110(svnwiki-extension-define 'render-bottom-span 'discuss-counter discuss-counter)
     111(svnwiki-extension-define 'update-notify-recursive 'discuss update-notify)
Note: See TracChangeset for help on using the changeset viewer.