Changeset 14905 in project


Ignore:
Timestamp:
06/06/09 15:14:12 (10 years ago)
Author:
azul
Message:

Allow other extensions to define their own types of editors for properties. I expect to use this for the googlemap extension.

File:
1 edited

Legend:

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

    r12772 r14905  
    4848; At the very minimal, most wikis should do the following:
    4949;
    50 ; svn ps svnwiki:handler "$(wiki pg svnwiki:handler .) properties" .
     50; svn ps svnwiki:handler "$(svn pg svnwiki:handler .) properties" .
    5151; svn ps svnwiki:properties:list 'svnwiki:title svnwiki:tags' .
    5252; svn ps svnwiki:properties:name:svnwiki:title 'Title' .
     
    5454; svn ps svnwiki:properties:help:svnwiki:title 'Title for this page, the filename will be used if empty' .
    5555; svn ps svnwiki:properties:help:svnwiki:tags 'Space-separated list of tags for this page' .
     56;
     57; If you have the googlemap extension, you may want to do this:
     58;
     59; svn ps svnwiki:properties:list "svnwiki:title svnwiki:tags svnwiki:location" .
     60; svn ps svnwiki:properties:name:svnwiki:location 'Location'
     61; svn ps svnwiki:properties:help:svnwiki:location 'Location associated with this page' .
    5662
    5763; Return the list of properties that should be used for a given path.
     
    148154                   ""))))))))))
    149155
    150 ; The first element in the list will be the default
    151 
    152 (define *edit-properties-input*
    153   `((text ,edit-properties-text)
    154     (select ,edit-properties-select)))
     156(define (save-properties-simple env property)
     157  (let ((old-value (get-current-value env property))
     158        (new-value (get-value env property)))
     159    (and (not (stream= char=? old-value new-value))
     160         (begin
     161           (svnwiki-repository-property-set
     162             property
     163             (svnwiki-repository-path env)
     164             new-value)
     165           #t))))
     166
     167(define *edit-properties-default*
     168  `(text ,edit-properties-text ,save-properties-simple))
     169
     170(define (metadata-edit-type-register env)
     171  (let-from-environment env (return)
     172    (return *edit-properties-default*)
     173    (return `(select ,edit-properties-select ,save-properties-simple))))
     174
     175(svnwiki-extension-define 'metadata-edit-type-register 'metadata metadata-edit-type-register)
    155176
    156177; If properties are defined for the file for this request and it is not a
     
    166187
    167188(define (edit-properties env)
    168   (call-with-properties
    169     env
    170     (lambda (properties)
    171       (let-from-environment env (return path-in path)
    172         (return
    173           (html-stream
    174             (h2 "Properties")
    175             (stream-concatenate
    176               (stream-map
    177                 (lambda (property)
    178                   (html-stream
    179                     (p (b (get-props-parents-first (format #f "svnwiki:properties:name:~A" (stream->string property)) path-in path property))
    180                        (let ((help (get-props-parents-first (format #f "svnwiki:properties:help:~A" (stream->string property)) path-in path "")))
    181                          (if (string=? help "")
    182                            ""
    183                            (html-stream " (" help ")")))
    184                        ":"
    185                        (br)
    186                        ((cadr (or (assoc (get-props-parents-first (format #f "svnwiki:properties:type:~A" (stream->string property)) path-in path "")
    187                                          *edit-properties-input*)
    188                                   (car *edit-properties-input*)))
    189                         env
    190                         property))))
    191                 (get-svn-properties env)))))))))
     189  (let-from-environment env (return path-in path user-input)
     190    (when (stream-null? (user-input 'section stream-null))
     191      (call-with-properties
     192        env
     193        (lambda (properties)
     194          (return
     195            (html-stream
     196              (h2 "Properties")
     197              (stream-concatenate
     198                (stream-map
     199                  (lambda (property)
     200                    (html-stream
     201                      (p (b (get-props-parents-first (format #f "svnwiki:properties:name:~A" (stream->string property)) path-in path property))
     202                         (let ((help (get-props-parents-first (format #f "svnwiki:properties:help:~A" (stream->string property)) path-in path "")))
     203                           (if (string=? help "")
     204                             ""
     205                             (html-stream " (" help ")")))
     206                         ":"
     207                         (br)
     208                         ((cadr (find-property-editor env))
     209                          env
     210                          property))))
     211                  (get-properties env))))))))))
     212
     213(define (find-property-editor env property)
     214  (let-from-environment env (path-in path)
     215    (or (and-let* ((type (get-props-parents-first (format #f "svnwiki:properties:type:~A" (stream->string property)) path-in path ""))
     216                   (editors (stream->list (call-extensions-delay env 'metadata-edit-type-register))))
     217          (assoc editors type))
     218        *edit-properties-default*)))
    192219
    193220(svnwiki-extension-define 'edit-form-section 'properties edit-properties)
     
    201228          (stream-for-each
    202229            (lambda (property)
    203               (let ((old-value (get-current-value env property))
    204                     (new-value (get-value env property)))
    205                 (unless (stream= char=? old-value new-value)
    206                   (set! changes #t)
    207                   (svnwiki-repository-property-set
    208                     property
    209                     (svnwiki-repository-path env)
    210                     new-value))))
     230              (when ((caddr (find-property-editor env property)) env property)
     231                (set! changes #t)))
    211232            properties)
    212233          (when changes
Note: See TracChangeset for help on using the changeset viewer.