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

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

[elpa] 86/119: another example idea -- org export service


From: Eric Schulte
Subject: [elpa] 86/119: another example idea -- org export service
Date: Mon, 10 Mar 2014 16:57:47 +0000

eschulte pushed a commit to branch master
in repository elpa.

commit 3d21f39bd161c726bc452c5b1c57288936c8d238
Author: Eric Schulte <address@hidden>
Date:   Wed Jan 8 13:08:11 2014 -0700

    another example idea -- org export service
---
 NOTES                              |    8 +++++-
 examples/013-org-export-service.el |   44 ++++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/NOTES b/NOTES
index cf43c92..be84aaf 100644
--- a/NOTES
+++ b/NOTES
@@ -1,12 +1,12 @@
                                                            -*- org -*-
 
 * Notes
-* Tasks [14/24]
+* Tasks [15/25]
 ** DONE web sockets
 - http://en.wikipedia.org/wiki/WebSocket
 - http://tools.ietf.org/html/rfc6455
 
-** more examples [3/3]
+** more examples [4/4]
 *** DONE Org-mode agenda
 Already exists as part of org-ehtml.
 file:examples/011-org-agenda.el
@@ -17,6 +17,10 @@ file:examples/010-current-buffer.el
 
 *** DONE browse the BBDB
 file:examples/012-search-bbdb.el
+*** DONE org-mode export server
+1. upload a file
+2. supply an export type
+3. return the exported version of the file
 
 ** DONE handle large files
 When large files arrive quickly, the filter functions are called while
diff --git a/examples/013-org-export-service.el 
b/examples/013-org-export-service.el
new file mode 100644
index 0000000..89c187a
--- /dev/null
+++ b/examples/013-org-export-service.el
@@ -0,0 +1,44 @@
+;;; 013-org-export-service.el --- upload and export Org-mode files
+(defun ws/example-org-export-service (request)
+  (with-slots (process headers) request
+    (let ((file (cdr (assoc "file" headers)))
+          (type (cdr (assoc 'content (cdr (assoc "type" headers))))))
+      (if (not (and file type))
+          (progn
+            (ws-response-header process 200 '("Content-type" . "text/html"))
+            (process-send-string process "
+<html><body><form action=\"\" method=\"post\" enctype=\"multipart/form-data\">
+Export file: <input type=\"file\" name=\"file\"> to type
+<select name=\"type\">
+<option value=\"txt\">Text</option>
+<option value=\"html\">HTML</option>
+<option value=\"tex\">TeX</option>
+</select>
+<input type=\"submit\" value=\"submit\">.
+</form></body></html>"))
+        (let* ((orig (cdr (assoc 'filename file)))
+               (base (file-name-nondirectory
+                      (file-name-sans-extension orig)))
+               (backend (case (intern (downcase type))
+                          (html 'html)
+                          (tex  'latex)
+                          (txt  'ascii)
+                          (t (ws-error process "%S export not supported"
+                                       type))))
+               (path (concat base "." type)))
+          (let ((default-directory temporary-file-directory))
+            (when (or (file-exists-p orig) (file-exists-p path))
+              (ws-error process
+                        "File already exists on the server, try a new file."))
+            (with-temp-file orig (insert (cdr (assoc 'content file))))
+            (save-window-excursion (find-file orig)
+                                   ;; TODO: Steal personal data and
+                                   ;; ideas from uploaded Org-mode
+                                   ;; text.  Web services aren't free!
+                                   (org-export-to-file backend path)
+                                   (kill-buffer))
+            (ws-send-file process path)
+            (delete-file path)
+            (delete-file orig)))))))
+
+(ws-start '(((lambda (_) t) . ws/example-org-export-service)) 9013)



reply via email to

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