[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 94/119: example serving Org-mode files as JSON
From: |
Eric Schulte |
Subject: |
[elpa] 94/119: example serving Org-mode files as JSON |
Date: |
Mon, 10 Mar 2014 16:57:50 +0000 |
eschulte pushed a commit to branch master
in repository elpa.
commit b82f15c5c2d4a6935ff7a4b753a1095fe95820ec
Author: Eric Schulte <address@hidden>
Date: Sat Jan 11 18:24:45 2014 -0700
example serving Org-mode files as JSON
---
examples/014-org-json.el | 24 ++++++++++++++++++++++++
1 files changed, 24 insertions(+), 0 deletions(-)
diff --git a/examples/014-org-json.el b/examples/014-org-json.el
new file mode 100644
index 0000000..822175a
--- /dev/null
+++ b/examples/014-org-json.el
@@ -0,0 +1,24 @@
+;;; org-json.el --- Serve Org-mode pages as json
+;; suggested by nicferrier
+(require 'json)
+(lexical-let ((docroot "/tmp/"))
+ (ws-start
+ (lambda (request)
+ (with-slots (process headers) request
+ (let ((path (ws-in-directory-p
+ docroot (substring (cdr (assoc :GET headers)) 1))))
+ (unless (and path (file-exists-p path))
+ (ws-send-404 process))
+ (save-window-excursion
+ (find-file path)
+ (ws-response-header process 200
+ '("Content-type" . "application/json"))
+ (process-send-string process
+ (let ((tree (org-element-parse-buffer)))
+ (org-element-map tree
+ (append org-element-all-objects org-element-all-elements)
+ (lambda (el)
+ (org-element-put-property el :parent "none")
+ (org-element-put-property el :structure "none")))
+ (json-encode tree)))))))
+ 9014))
- [elpa] 81/119: implemented ws-web-socket-frame to send replies, (continued)
- [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, 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 <=
- [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
- [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