[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))
- [elpa] 85/119: renaming example files, (continued)
- [elpa] 85/119: renaming example files, Eric Schulte, 2014/03/10
- [elpa] 86/119: another example idea -- org export service, Eric Schulte, 2014/03/10
- [elpa] 87/119: update server stopping w/requests process field, Eric Schulte, 2014/03/10
- [elpa] 83/119: supports web sockets, Eric Schulte, 2014/03/10
- [elpa] 75/119: more web-socket implementation, Eric Schulte, 2014/03/10
- [elpa] 91/119: more tutorial, Eric Schulte, 2014/03/10
- [elpa] 94/119: example serving Org-mode files as JSON, Eric Schulte, 2014/03/10
- [elpa] 93/119: helper function to serve directory listings, Eric Schulte, 2014/03/10
- [elpa] 90/119: tutorials, Eric Schulte, 2014/03/10
- [elpa] 88/119: accept single-function handlers, Eric Schulte, 2014/03/10
- [elpa] 96/119: expand this example w/smart dir listings,
Eric Schulte <=
- [elpa] 98/119: TODO chunked encoding, Eric Schulte, 2014/03/10
- [elpa] 99/119: serve files with htmlize Emacs fontification, Eric Schulte, 2014/03/10
- [elpa] 97/119: added ws-stop-all convenience function, Eric Schulte, 2014/03/10
- [elpa] 89/119: authorization helper, Eric Schulte, 2014/03/10
- [elpa] 92/119: simpler handler in example, Eric Schulte, 2014/03/10
- [elpa] 102/119: updated content- transfer-encoding notes, Eric Schulte, 2014/03/10
- [elpa] 103/119: set Content-length when serving files, Eric Schulte, 2014/03/10
- [elpa] 95/119: better ws-send-directory-list, Eric Schulte, 2014/03/10
- [elpa] 106/119: TODO Content and Transfer encodings, Eric Schulte, 2014/03/10
- [elpa] 104/119: tweak notes, Eric Schulte, 2014/03/10