[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)
- [elpa] 76/119: and more web-socket progress, (continued)
- [elpa] 76/119: and more web-socket progress, Eric Schulte, 2014/03/10
- [elpa] 74/119: beginning to implement web-socket support, Eric Schulte, 2014/03/10
- [elpa] 77/119: handle chunked receipt of web-socket messages, Eric Schulte, 2014/03/10
- [elpa] 78/119: hold, Eric Schulte, 2014/03/10
- [elpa] 79/119: beginning to add convenience macro for web sockets, Eric Schulte, 2014/03/10
- [elpa] 81/119: implemented ws-web-socket-frame to send replies, Eric Schulte, 2014/03/10
- [elpa] 80/119: helpers for handling web socket connections, Eric Schulte, 2014/03/10
- [elpa] 82/119: web-sockets are working, Eric Schulte, 2014/03/10
- [elpa] 84/119: more examples, Eric Schulte, 2014/03/10
- [elpa] 85/119: renaming example files, Eric Schulte, 2014/03/10
- [elpa] 86/119: another example idea -- org export service,
Eric Schulte <=
- [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, 2014/03/10
- [elpa] 98/119: TODO chunked encoding, Eric Schulte, 2014/03/10