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

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

[elpa] 62/119: example serving Org-mode files exported on demand


From: Eric Schulte
Subject: [elpa] 62/119: example serving Org-mode files exported on demand
Date: Mon, 10 Mar 2014 16:57:29 +0000

eschulte pushed a commit to branch master
in repository elpa.

commit d693833dd903ee9c0dc599280cfde6da50cb4f1a
Author: Eric Schulte <address@hidden>
Date:   Sat Jan 4 10:51:06 2014 -0700

    example serving Org-mode files exported on demand
---
 doc/web-server.texi                |   15 +++++++++++++--
 examples/7-org-mode-file-server.el |   23 +++++++++++++++++++++++
 2 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/doc/web-server.texi b/doc/web-server.texi
index b93e4fa..0f5bb9a 100644
--- a/doc/web-server.texi
+++ b/doc/web-server.texi
@@ -159,6 +159,7 @@ These examples demonstrate usage.
 * URL Parameter Echo::          Echo Parameters from a URL query string
 * POST Echo::                   Echo POST parameters back
 * Basic Authentication::        BASIC HTTP Authentication
+* Org-mode Export Server::      Export files to HTML and Tex
 @end menu
 
 @node Hello World, Hello World UTF8, Usage Examples, Usage Examples
@@ -227,7 +228,8 @@ in a @code{POST} request.
 
 @verbatiminclude ../examples/5-post-echo.el
 
address@hidden Basic Authentication, Function Index, POST Echo, Usage Examples
address@hidden Basic Authentication, Org-mode Export Server, POST Echo, Usage 
Examples
address@hidden Basic Authentication
 
 The following example demonstrates BASIC HTTP authentication.  The
 handler prompts an unauthenticated client for authentication by
@@ -248,10 +250,19 @@ Note: BASIC HTTP authentication passes user credentials 
in plain text
 between the client and the server and should generally only be used
 with HTTPS network encryption.  While the Emacs web server currently
 doesn't support HTTPS network encryption it may be run behind an HTTPS
-proxy server (e.g., Apache) which does support HTTPS.
+proxy server (e.g., Apache or Nginx) with HTTPS support.
 
 @verbatiminclude ../examples/6-basic-authentication.el
 
address@hidden Org-mode Export Server, Function Index, Basic Authentication, 
Usage Examples
address@hidden Org-mode Export Server
+
+The following example exports a directory of Org-mode files as either
+text, HTML or LaTeX.  The Org-mode export engine is used to export
+files on-demand as they are requested.
+
address@hidden ../examples/7-org-mode-file-server.el
+
 @node Function Index, Copying, Usage Examples, Top
 @chapter Function Index
 @cindex function index
diff --git a/examples/7-org-mode-file-server.el 
b/examples/7-org-mode-file-server.el
new file mode 100644
index 0000000..856634c
--- /dev/null
+++ b/examples/7-org-mode-file-server.el
@@ -0,0 +1,23 @@
+;;; file-server.el --- serve on-demand exported Org-mode files
+(lexical-let ((docroot default-directory))
+  (ws-start
+   (list
+    (cons '(:GET . ".*")
+      (lambda (request)
+        (with-slots (process headers) request
+          (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)))))))
+   9007))



reply via email to

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