Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
An example using elnode.el
;;; elnode-org-export-as.el --- An example using elnode.el.
;; Copyright (C) 2011 Takumi KINJO
;; Author: Takumi KINJO <takumi.kinjo@gmail.com>
;; Created: 5th May 2011
;; Version: 0
;; Keywords: lisp
;; This file is NOT part of GNU Emacs.
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; This is an example using elnode.el and is tested on
;; org-mode 7.5. (check M-x org-version)
;; About elnode.el, see https://github.com/nicferrier/elnode.
;;
;; To run this, follow instructions.
;;
;; This uses auto-install. If you have had already it, skip Step1.
;;
;; Step1. Install auto-install
;;
;; Type below commands in your shell.
;; (about auto-install, see http://www.emacswiki.org/emacs/AutoInstall)
;;
;; (cd ~/.emacs.d; curl -O http://www.emacswiki.org/emacs/download/auto-install.el)
;;
;; Step2. Install elnode.el and org-html5presentation
;;
;; Eval below expressions.
;;
;; (add-to-list 'load-path "~/.emacs.d") ; if needed
;; (require 'auto-install) ; if needed
;; (auto-install-from-url "https://github.com/kinjo/elnode/raw/master/elnode.el") ;; small fix version
;; (auto-install-from-url "https://gist.github.com/raw/509761/93c051ddc79eb81d6916fa3422d42ceed4de4141/org-html5presentation.el")
;;
;; Step3. Setup
;;
;; Eval below all expressions or write in your ~/.emacs.
;;
;; Step4. Browse your org file from your web browser
;;
;; http://localhost:8000/your_org.org.html,
;; http://localhost:8000/your_org.org.txt or
;; http://localhost:8000/your_org.org.presentation
(require 'elnode)
(require 'org-html5presentation)
(defvar elnode-example-docroot "~/")
(defun elnode-example-chop-ext (path ext)
""
(save-match-data
(and (string-match (format "\.%s$" ext) path)
(substring path 0 (match-beginning 0)))))
(defun elnode-example-handler (httpcon)
"Demonstration function"
(let* ((path (concat elnode-example-docroot (elnode-http-pathinfo httpcon)))
(ext (file-name-extension path)))
(if (or (string-equal ext "html") (string-equal ext "txt") (string-equal ext "presentation"))
(let ((path (elnode-example-chop-ext path ext)))
(elnode-http-return
httpcon
(with-current-buffer
(find-file-noselect path)
(with-current-buffer
(let ((buf (get-buffer-create "*org-export-as-html-buffer*")))
(cond
((string-equal ext "txt")
(elnode-http-start httpcon "200" '("Content-type" . "text/plain"))
(org-export-as-ascii nil nil nil buf))
((string-equal ext "html")
(elnode-http-start httpcon "200" '("Content-type" . "text/html"))
(org-export-as-html nil nil nil buf))
((string-equal ext "presentation")
(elnode-http-start httpcon "200" '("Content-type" . "text/html"))
(org-export-as-html5presentation nil nil nil buf)))
buf)
(buffer-string)))))
(progn
(elnode-http-start httpcon "200" '("Content-type" . "text/html"))
(if (file-regular-p path)
(elnode-http-return
httpcon
(with-current-buffer
(find-file-noselect path)
(with-current-buffer
(let ((buf (get-buffer-create "*org-export-as-html-buffer*")))
(org-export-as-html nil nil nil buf) buf)
(buffer-string))))
(elnode-http-return httpcon (format "<html>
<head><title>elnode-org-export-as</title></head>
<body><p>Browse your org file.</p><p>Specify URL by a relative path from %s.<br />For example, use http://localhost:8000/test/foo.org.html or http://localhost:8000/foo.org.txt when your org file is %stest/foo.org.</p></body>
</html>" elnode-example-docroot elnode-example-docroot)))))))
(setq elnode-hostpath-default-table '(("[^/]+/.*" . elnode-example-handler)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment