Paste Code
Paste Blends
Paste Images
; PDB to HTML - A script for GIMP by Barak Itkin <lightningismyname@gmail.com>
; A script to dump the output of the GIMP PDB to an HTML documentation file

(define PDB-TYPES '(PDB-INT32 PDB-INT16 PDB-INT8 PDB-FLOAT PDB-STRING PDB-INT32ARRAY
PDB-INT16ARRAY PDB-INT8ARRAY PDB-FLOATARRAY PDB-STRINGARRAY
PDB-COLOR PDB-REGION PDB-DISPLAY PDB-IMAGE PDB-LAYER PDB-CHANNEL
PDB-DRAWABLE PDB-SELECTION PDB-COLORARRAY PDB-VECTORS PDB-PARASITE
PDB-STATUS))

(define (type-from-num num)
(list-ref PDB-TYPES num)
)

(define PROC-TYPES '(INTERNAL PLUGIN EXTENSION TEMPORARY))

(define (proc-type-from-num num)
(list-ref PROC-TYPES num)
)

(define (db-to-html)
(let* ((name "")
(blurb "")
(help "")
(author "")
(copyright "")
(date "")
(proc-type "")

(query (gimp-procedural-db-query name blurb help author copyright date proc-type))
(proc_count (car query))
(procs (cadr query))

(get-blurb car)
(get-help cadr)
(get-author caddr)
(get-copyright cadddr)
(get-date (lambda (proc-info) (list-ref proc-info 4)))
(get-proc-type (lambda (proc-info) (proc-type-from-num (list-ref proc-info 5))))
(get-num-args (lambda (proc-info) (list-ref proc-info 6)))
(get-num-values (lambda (proc-info) (list-ref proc-info 7)))

(i 0)
;(proc-name "")
(proc-info '())
(data-info '())
(arg-count 0)
(val-count 0)

(get-d-type (lambda (data-info) (type-from-num (car data-info))))
(get-d-name cadr)
(get-d-desc caddr)

(indentation "")
(indent! (lambda () (set! indentation (string-append indentation " "))))
(unindent! (lambda () (set! indentation (substring indentation 2))))
(write-line (lambda arguments (display indentation) (for-each display arguments) (display "\n")))

(write-table-start (lambda () (write-line "<table>")))
(write-table-end (lambda () (write-line "</table>")))
(write-header-cell (lambda (val) (write-line "<th>" val "</th>")))
(write-cell (lambda (val) (write-line "<td>" val "</td>")))
(write-table-line (lambda (header . vals)
(write-line "<tr>")
(indent!)
(write-header-cell header)
(for-each write-cell vals)
(unindent!)
(write-line "</tr>")))
(write-table-head (lambda headers
(write-line "<tr>")
(indent!)
(for-each write-header-cell headers)
(unindent!)
(write-line "</tr>"))))

(write-line "<html>")
(indent!)
(write-line "<head>")
(indent!)
(write-line "<style type=\"text/css\">")
(write-line "th:first-child, th:first-child + th {width: 175px}")
(write-line "th {text-align: left}")
(write-line "table, tr, td, th {border: 0px}")
(write-line "table {width: auto}")
(write-line "td {margin: 0px 25px}")
(write-line "</style>")
(unindent!)
(write-line "</head>")
(unindent!)

(indent!)
(write-line "<body>")
(for-each
(lambda (proc-name)
(set! proc-info (gimp-procedural-db-proc-info proc-name))
(set! arg-count (get-num-args proc-info))
(set! val-count (get-num-values proc-info))

(write-line "<h2>" proc-name "</h2>")

(write-table-start)
(indent!)
(write-table-line "Blurb" (get-blurb proc-info))
(write-table-line "Help" (get-help proc-info))
(write-table-line "Author" (get-author proc-info))
(write-table-line "Copyright" (get-copyright proc-info))
(write-table-line "Date" (get-date proc-info))
(write-table-line "Procedure-Type" (get-proc-type proc-info))
(unindent!)
(write-table-end)

(if (not (= val-count 0))
(begin
(write-line "<h3>Arguments:</h3>")
(write-table-start)
(indent!)
(write-table-head "Name" "Type" "Description")
(set! i 0)
(while (< i arg-count)
(begin
(set! data-info (gimp-procedural-db-proc-arg proc-name i))
(write-table-line (get-d-name data-info) (get-d-type data-info) (get-d-desc data-info))
(set! i (+ 1 i))
)
)
(unindent!)
(write-table-end)
)
)

(if (not (= val-count 0))
(begin
(write-line "<h3>Return Values:</h3>")
(write-table-start)
(indent!)
(write-table-head "Name" "Type" "Description")
(set! i 0)
(while (< i val-count)
(begin
(set! data-info (gimp-procedural-db-proc-val proc-name i))
(write-table-line (get-d-name data-info) (get-d-type data-info) (get-d-desc data-info))
(set! i (+ 1 i))
)
)
(unindent!)
(write-table-end)
)
)

(write-line "<hr />")
)

procs)

(write-line "</body>")
(unindent!)
(write-line "</html>")

)
)

(define (db-to-html-file file)
(with-output-to-file file db-to-html)
)
  1. ; PDB to HTML - A script for GIMP by Barak Itkin <lightningismyname@gmail.com>
  2. ; A script to dump the output of the GIMP PDB to an HTML documentation file
  3.  
  4. (define PDB-TYPES '(PDB-INT32 PDB-INT16 PDB-INT8 PDB-FLOAT PDB-STRING PDB-INT32ARRAY
  5.                     PDB-INT16ARRAY PDB-INT8ARRAY PDB-FLOATARRAY PDB-STRINGARRAY
  6.                     PDB-COLOR PDB-REGION PDB-DISPLAY PDB-IMAGE PDB-LAYER PDB-CHANNEL
  7.                     PDB-DRAWABLE PDB-SELECTION PDB-COLORARRAY PDB-VECTORS PDB-PARASITE
  8.                     PDB-STATUS))
  9.  
  10. (define (type-from-num num)
  11.     (list-ref PDB-TYPES num)
  12.   )
  13.  
  14. (define PROC-TYPES '(INTERNAL PLUGIN EXTENSION TEMPORARY))
  15.  
  16. (define (proc-type-from-num num)
  17.     (list-ref PROC-TYPES num)
  18.   )
  19.  
  20. (define (db-to-html)
  21.   (let* ((name "")
  22.          (blurb "")
  23.          (help "")
  24.          (author "")
  25.          (copyright "")
  26.          (date "")
  27.          (proc-type "")
  28.  
  29.          (query (gimp-procedural-db-query name blurb help author copyright date proc-type))
  30.          (proc_count (car query))
  31.          (procs (cadr query))
  32.  
  33.          (get-blurb       car)
  34.          (get-help        cadr)
  35.          (get-author      caddr)
  36.          (get-copyright   cadddr)
  37.          (get-date       (lambda (proc-info) (list-ref proc-info 4)))
  38.          (get-proc-type  (lambda (proc-info) (proc-type-from-num (list-ref proc-info 5))))
  39.          (get-num-args   (lambda (proc-info) (list-ref proc-info 6)))
  40.          (get-num-values (lambda (proc-info) (list-ref proc-info 7)))
  41.  
  42.          (i 0)
  43.          ;(proc-name "")
  44.          (proc-info '())
  45.          (data-info '())
  46.          (arg-count 0)
  47.          (val-count 0)
  48.  
  49.          (get-d-type (lambda (data-info) (type-from-num (car data-info))))
  50.          (get-d-name cadr)
  51.          (get-d-desc caddr)
  52.  
  53.          (indentation       "")
  54.          (indent!           (lambda () (set! indentation (string-append indentation "  "))))
  55.          (unindent!         (lambda () (set! indentation (substring indentation 2))))
  56.          (write-line        (lambda arguments (display indentation) (for-each display arguments) (display "\n")))
  57.  
  58.          (write-table-start (lambda () (write-line "<table>")))
  59.          (write-table-end   (lambda () (write-line "</table>")))
  60.          (write-header-cell (lambda (val) (write-line "<th>" val "</th>")))
  61.          (write-cell        (lambda (val) (write-line "<td>" val "</td>")))
  62.          (write-table-line  (lambda (header . vals)
  63.                              (write-line "<tr>")
  64.                                (indent!)
  65.                                (write-header-cell header)
  66.                                (for-each write-cell vals)
  67.                                (unindent!)
  68.                              (write-line "</tr>")))
  69.          (write-table-head  (lambda headers
  70.                              (write-line "<tr>")
  71.                                (indent!)
  72.                                (for-each write-header-cell headers)
  73.                                (unindent!)
  74.                              (write-line "</tr>"))))
  75.  
  76.     (write-line "<html>")
  77.       (indent!)
  78.       (write-line "<head>")
  79.         (indent!)
  80.         (write-line "<style type=\"text/css\">")
  81.         (write-line "th:first-child, th:first-child + th {width: 175px}")
  82.         (write-line "th {text-align: left}")
  83.         (write-line "table, tr, td, th {border: 0px}")
  84.         (write-line "table {width: auto}")
  85.         (write-line "td {margin: 0px 25px}")
  86.         (write-line "</style>")
  87.         (unindent!)
  88.       (write-line "</head>")
  89.       (unindent!)
  90.  
  91.     (indent!)
  92.     (write-line "<body>")
  93.     (for-each
  94.       (lambda (proc-name)
  95.         (set! proc-info (gimp-procedural-db-proc-info proc-name))
  96.         (set! arg-count (get-num-args proc-info))
  97.         (set! val-count (get-num-values proc-info))
  98.  
  99.         (write-line "<h2>" proc-name "</h2>")
  100.  
  101.         (write-table-start)
  102.           (indent!)
  103.           (write-table-line "Blurb" (get-blurb proc-info))
  104.           (write-table-line "Help" (get-help proc-info))
  105.           (write-table-line "Author" (get-author proc-info))
  106.           (write-table-line "Copyright" (get-copyright proc-info))
  107.           (write-table-line "Date" (get-date proc-info))
  108.           (write-table-line "Procedure-Type" (get-proc-type proc-info))
  109.           (unindent!)
  110.         (write-table-end)
  111.  
  112.         (if (not (= val-count 0))
  113.           (begin
  114.             (write-line "<h3>Arguments:</h3>")
  115.             (write-table-start)
  116.               (indent!)
  117.               (write-table-head "Name" "Type" "Description")
  118.               (set! i 0)
  119.               (while (< i arg-count)
  120.                 (begin
  121.                   (set! data-info (gimp-procedural-db-proc-arg proc-name i))
  122.                   (write-table-line (get-d-name data-info) (get-d-type data-info) (get-d-desc data-info))
  123.                   (set! i (+ 1 i))
  124.                   )
  125.                 )
  126.               (unindent!)
  127.             (write-table-end)
  128.             )
  129.           )
  130.  
  131.         (if (not (= val-count 0))
  132.           (begin
  133.             (write-line "<h3>Return Values:</h3>")
  134.             (write-table-start)
  135.               (indent!)
  136.               (write-table-head "Name" "Type" "Description")
  137.               (set! i 0)
  138.               (while (< i val-count)
  139.                 (begin
  140.                   (set! data-info (gimp-procedural-db-proc-val proc-name i))
  141.                   (write-table-line (get-d-name data-info) (get-d-type data-info) (get-d-desc data-info))
  142.                   (set! i (+ 1 i))
  143.                   )
  144.                 )
  145.               (unindent!)
  146.             (write-table-end)
  147.             )
  148.           )
  149.  
  150.         (write-line "<hr />")
  151.       )
  152.  
  153.       procs)
  154.  
  155.     (write-line "</body>")
  156.     (unindent!)
  157.     (write-line "</html>")
  158.  
  159.     )
  160.   )
  161.  
  162. (define (db-to-html-file file)
  163.   (with-output-to-file file db-to-html)
  164. )
go to heaven