Changeset 12574 in project


Ignore:
Timestamp:
11/22/08 22:28:15 (11 years ago)
Author:
azul
Message:

Lots of fixes for new extensions system (update-notify-recursive).

File:
1 edited

Legend:

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

    r12533 r12574  
    44
    55(declare (export))
    6 (use svnwiki-extensions-support srfi-40 stream-ext srfi-1 svn-post-commit-hooks orders format-modular html-stream)
     6(use svnwiki-extensions-support srfi-40 stream-ext srfi-1 svn-post-commit-hooks orders format-modular html-stream content-type)
    77
    88(define *image-javascript*
     
    9090
    9191(define (svnwiki-image-handler-render env)
    92   (let-from-environment env (initial-header-depth path-in path static-url)
    93     (svnwiki-report-progress env "Image generate HTML: ~A~%" path)
    94     (let ((random-id (random 100000)))
    95       (html-stream
    96         (format #f "<h~A>" initial-header-depth)
    97         (svnwiki-get-title-html env)
    98         (format #f "</h~A>" initial-header-depth)
    99         ((ul class "svnwiki-image-links")
    100          (li ((a href (svnwiki-image-show-sizes-link env random-id)) "All sizes")))
    101         ((div id (format #f "svnwikiImageSizes~A" random-id)))
    102         ((script type "text/javascript" src (format #f "~A/xsvnwiki-helper/image/image" static-url)))
    103         ((img src (format #f "~A-~A" (last (string-split path "/")) (apply max (svnwiki-image-default-size env)))
    104               id (format #f "svnwikiImage~A" random-id)
    105               ; TODO: Use svnwiki:title as the alt parameter.
    106               alt (last (string-split path "/"))))
    107         (let ((author (get-props-parents-first "svnwiki:image:author" path-in path #f))
    108               (author-url (get-props-parents-first "svnwiki:image:author-url" path-in path #f)))
    109           (cond
    110             ((and author author-url)
    111               (html-stream
    112                 (p (b "Author:")
    113                    "\n"
    114                    ((a href author-url) author))))
    115             (author
    116               (html-stream
    117                 (p (b "Author:") "\n" author)))
    118             (else
    119               stream-null)))
    120         (let ((source (get-props-parents-first "svnwiki:image:source" path-in path #f)))
    121           (if source
    122             (html-stream
    123               (p (b "Source:") "\n" ((a href source) source)))
    124             stream-null))
    125         (get-props-parents-first "svnwiki:image:description" path-in path stream-null)
    126         (svnwiki-render-file-contents-tail env)))))
     92  (when (svnwiki-image-get-type env)
     93    (let-from-environment env (initial-header-depth path-in path static-url return)
     94      (svnwiki-report-progress env "Image generate HTML: ~A~%" path)
     95      (let ((random-id (random 100000)))
     96        (return
     97          (html-stream
     98            (format #f "<h~A>" initial-header-depth)
     99            (svnwiki-get-title-html env)
     100            (format #f "</h~A>" initial-header-depth)
     101            ((ul class "svnwiki-image-links")
     102             (li ((a href (svnwiki-image-show-sizes-link env random-id)) "All sizes")))
     103            ((div id (format #f "svnwikiImageSizes~A" random-id)))
     104            ((script type "text/javascript" src (format #f "~A/xsvnwiki-helper/image/image" static-url)))
     105            ((img src (format #f "~A-~A" (last (string-split path "/")) (apply max (svnwiki-image-default-size env)))
     106                  id (format #f "svnwikiImage~A" random-id)
     107                  ; TODO: Use svnwiki:title as the alt parameter.
     108                  alt (last (string-split path "/"))))
     109            (let ((author (get-props-parents-first "svnwiki:image:author" path-in path #f))
     110                  (author-url (get-props-parents-first "svnwiki:image:author-url" path-in path #f)))
     111              (cond
     112                ((and author author-url)
     113                 (html-stream
     114                   (p (b "Author:")
     115                      "\n"
     116                      ((a href author-url) author))))
     117                (author
     118                  (html-stream
     119                    (p (b "Author:") "\n" author)))
     120                (else
     121                  stream-null)))
     122            (let ((source (get-props-parents-first "svnwiki:image:source" path-in path #f)))
     123              (if source
     124                (html-stream
     125                  (p (b "Source:") "\n" ((a href source) source)))
     126                stream-null))
     127            (get-props-parents-first "svnwiki:image:description" path-in path stream-null)
     128            (svnwiki-render-file-contents-tail env)))))))
    127129
    128130(define (svnwiki-image-get-size env)
     
    176178        *image-javascript*))))
    177179
     180; Returns the image subtype as a string (eg. "png") or #f is the file is not an
     181; image.
     182
     183(define (svnwiki-image-get-type env)
     184  (let-from-environment env (path-in path path-out)
     185    (and-let* ((type-input (svnwiki-repository-property-get
     186                             "svn:mime-type"
     187                             (svnwiki-make-pathname path-in path)
     188                             #f))
     189               (ctype (content-type-make type-input))
     190               ((string=? (content-type-type ctype) "image"))
     191               (subtype (content-type-subtype ctype))
     192               ((member subtype *svnwiki-image-types*)))
     193      subtype)))
     194
    178195(define (svnwiki-image-update env)
    179196  (let-from-environment env (path-in path path-out)
    180197    (svnwiki-report-progress env "Image update start: ~A~%" path)
    181     (let* ((type-input (svnwiki-repository-property-get
    182                          "svn:mime-type"
    183                          (svnwiki-make-pathname path-in path)
    184                          #f))
    185            (type (if (member type-input *svnwiki-image-types*) type-input (car *svnwiki-image-types*))))
     198    (and-let* ((subtype (svnwiki-image-get-type env)))
    186199      (receive (size-x size-y)
    187200               (svnwiki-image-get-size env)
     
    194207                      (car size)
    195208                      (cadr size)
    196                       type
     209                      subtype
    197210                      (svnwiki-path-escape
    198211                        (svnwiki-make-pathname
    199212                          path-out
    200213                          (format #f "~A-~A" path (max (car size) (cadr size)))
    201                           type)))))
     214                          subtype)))))
    202215          (svnwiki-image-sizes size-x size-y))))))
    203216
     
    247260
    248261(svnwiki-extension-define 'render-file-contents 'image svnwiki-image-handler-render)
    249 (svnwiki-extension-define 'update-notify 'image svnwiki-image-update)
     262(svnwiki-extension-define 'update-notify-recursive 'image svnwiki-image-update)
    250263(svnwiki-extension-define 'start-update-notify 'image svnwiki-image-start-update-notify)
    251264(svnwiki-extension-define 'code-break 'image svnwiki-image-code-break)
Note: See TracChangeset for help on using the changeset viewer.