;;****************************************************************************
;;FILE:               html-update-index.el
;;LANGUAGE:           emacs lisp
;;SYSTEM:             POSIX
;;USER-INTERFACE:     NONE
;;DESCRIPTION
;;
;;    Builds an index of picture thumb nails.
;;
;;    ( used for example by: /data/pascal/pjb-bg/index.template )
;;
;;AUTHORS
;;    <PJB> Pascal Bourguignon <pjb@informatimago.com>
;;MODIFICATIONS
;;    2003-12-04 <PJB> Added this comment.
;;BUGS
;;LEGAL
;;    GPL
;;
;;    Copyright Pascal Bourguignon 2003 - 2003
;;
;;    This program is free software; you can redistribute it and/or
;;    modify it under the terms of the GNU General Public License
;;    as published by the Free Software Foundation; either version
;;    2 of the License, or (at your option) any later version.
;;
;;    This program is distributed in the hope that it will be
;;    useful, but WITHOUT ANY WARRANTY; without even the implied
;;    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
;;    PURPOSE.  See the GNU General Public License for more details.
;;
;;    You should have received a copy of the GNU General Public
;;    License along with this program; if not, write to the Free
;;    Software Foundation, Inc., 59 Temple Place, Suite 330,
;;    Boston, MA 02111-1307 USA
;;****************************************************************************
;;


(defun flow-table (number-of-columns table-attributes cell-list)
  "
RETURN: A string with the table filled with the cells from
        cell-list (a list of strings), over the specified
        number-of-columns.
"
  (with-output-to-string
    (if table-attributes
        (printf nil "<table %s>\n" table-attributes)
      (printf nil "<table>\n"))
    (loop for cell in cell-list
          for i = 0 then (1+ i)
          for close-tag = "" then "</tr>\n"
          do
          (when (= (mod i number-of-columns) 0)
            (printf nil "%s<tr>\n" close-tag))
          (printf nil "<td>%s</td>\n" cell)
          )
    (printf nil "</tr>\n")
    (printf nil "</table>\n")
    )
  );;flow-table


(defun get-thumb-nail-table ()
  "
RETURN: A string containing the thumb-nails table
"
  (let ((thumb-nail-dir "small"))
    (flow-table 5 "width=80%"
                (mapcar
                 (lambda (file)
                   (let ((nail (format "%s/%s" thumb-nail-dir file))
                         (name (replace-regexp-in-string "pjb-bg-\\(.*\\).jpg" "\\1" file t nil)))
                     (with-output-to-string
                       (printf nil (concatenate 'string
                                     "<a href=\"%s\">"
                                     "<img src=\"%s\" alt=\"%s\">"
                                     "</a>\n  ") file nail file)
                       (printf nil (concatenate 'string
                                     "<br><a href=\"%s\">%s</a>\n ") file name)
                       )))
                 (file-expand-wildcards "*.jpg") ))
    ));;get-thumb-nail-table


(defun update-index (directory)
  "
DO:   Generates a new index.html from index.template and the .jpg in the
      given directory.
"
  (interactive)
  (find-file (format "%s/index.template" directory))
  (kill-ring-save (point-min) (point-max))
  (kill-buffer (current-buffer))
  (find-file (format "%s/index.html" directory))
  (printf :stderr "%s\n" (format "%s/index.html" directory))
  (erase-buffer)
  (yank)
  (beginning-of-buffer)
  (let ((table (get-thumb-nail-table)))
    (when (re-search-forward "<!-- INSERT-THUMB-NAILS-HERE -->" nil t)
      (replace-match table t t))
    )
  (save-buffer 0)
  (kill-buffer (current-buffer))
  );;update-index


;;;; html-update-index.el             -- 2003-12-04 04:12:20 -- pascal   ;;;;
ViewGit