emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] 96/119: expand this example w/smart dir listings


From: Eric Schulte
Subject: [elpa] 96/119: expand this example w/smart dir listings
Date: Mon, 10 Mar 2014 16:57:51 +0000

eschulte pushed a commit to branch master
in repository elpa.

commit 63fd5c93ff71afab5664a9b338ca076b1a4d2c3e
Author: Eric Schulte <address@hidden>
Date:   Sun Jan 12 09:19:37 2014 -0700

    expand this example w/smart dir listings
---
 examples/007-org-mode-file-server.el |   46 +++++++++++++++++++++++++---------
 1 files changed, 34 insertions(+), 12 deletions(-)

diff --git a/examples/007-org-mode-file-server.el 
b/examples/007-org-mode-file-server.el
index d80b260..b34793f 100644
--- a/examples/007-org-mode-file-server.el
+++ b/examples/007-org-mode-file-server.el
@@ -6,16 +6,38 @@
        (let ((path (ws-in-directory-p ; check if path is in docroot
                     docroot (substring (cdr (assoc :GET headers)) 1))))
          (unless path (ws-send-404 process)) ; send 404 if not in docroot
-         (let* ((base (file-name-sans-extension path))
-                (type (case (intern (downcase (file-name-extension path)))
-                        (html 'html)
-                        (tex  'latex)
-                        (txt  'ascii)
-                        (t (ws-error process "%S export not supported"
-                                     (file-name-extension path)))))
-                (orig (concat base ".org")))
-           (unless (file-exists-p orig) (ws-send-404 process))
-           (save-window-excursion (find-file orig)
-                                  (org-export-to-file type path))
-           (ws-send-file process path)))))
+         (if (file-directory-p path)
+             (progn ;; send directory listing, convert org files to 
html/tex/txt
+               (ws-response-header proc 200 (cons "Content-type" "text/html"))
+               (process-send-string proc
+                 (concat "<ul>"
+                         (mapconcat
+                          (lambda (f)
+                            (let* ((full (expand-file-name f path))
+                                   (end (if (file-directory-p full) "/" ""))
+                                   (url (url-encode-url (concat f end))))
+                              (format "<li><a href=%s>%s</li>" url f)))
+                          (apply #'append
+                                 (mapcar
+                                  (lambda (f)
+                                    (list (concat f ".txt")
+                                          (concat f ".tex")
+                                          (concat f ".html")))
+                                  (mapcar #'file-name-sans-extension
+                                          (directory-files path nil
+                                                           "^[^\.].*org$"))))
+                          "\n") "</ul>")))
+           ;; Export the file as requested and return the result
+           (let* ((base (file-name-sans-extension path))
+                  (type (case (intern (downcase (file-name-extension path)))
+                          (html 'html)
+                          (tex  'latex)
+                          (txt  'ascii)
+                          (t (ws-error process "%S export not supported"
+                                       (file-name-extension path)))))
+                  (orig (concat base ".org")))
+             (unless (file-exists-p orig) (ws-send-404 process))
+             (save-window-excursion (find-file orig)
+                                    (org-export-to-file type path))
+             (ws-send-file process path))))))
    9007))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]