Created
November 4, 2011 14:40
-
-
Save nicferrier/1339475 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; wikiengine.el --- a WIKI engine -*- lexical-binding: t -*- | |
;; Copyright (C) 2011 Nic Ferrier | |
;; Author: Nic Ferrier - <nferrier@ferrier.me.uk> | |
;; Version: 0.1 | |
;; Keywords: hypermedia | |
;; 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 a pure Emacs Lisp wiki engine built with Elnode and the | |
;; Emacs Lisp WikiCreole parser. | |
;; | |
;; Right now we only handle retrieval. | |
;;; Code: | |
(require 'elnode) | |
(defconst wiki-docroot "/home/nferrier/elwikiengine/wiki" | |
"Where we will find the pages for our wiki. | |
CSS files can be in a sub-directory 'css' and Javascript files | |
can be in a subdirectory 'js'. | |
All other resources are assumed to be WIKI pages.") | |
(defun wiki-send (httpcon wikipage) | |
"A very low level WIKI handler. | |
Sends the WIKIPAGE to the HTTPCON." | |
(elnode-http-start httpcon 200 `("Content-type" . "text/html")) | |
(elnode-worker-elisp | |
httpcon | |
((target wikipage)) | |
(require 'creole) | |
(creole-wiki target :destination t))) | |
(defun wiki-handler (httpcon docroot) | |
"A low level handler for WIKI GET. | |
Send the WIKI page requested, which must exist under the DOCROOT | |
back to the HTTPCON." | |
(elnode-test-path | |
httpcon docroot | |
(lambda (httpcon docroot target-path) | |
(elnode-method | |
("GET" | |
(wiki-send httpcon target-path)) | |
("POST" | |
;; Might be a preview request in which case send back the WIKI | |
;; text that's been sent. | |
;; | |
;; Might be a save request in which case save the new text and | |
;; then send the wiki text. | |
(wiki-send httpcon target-path)))))) | |
(defun wiki-handler-maker (docroot) | |
"Make a handler for serving Wiki pages in DOCROOT. | |
This uses 'elnode-worker-elisp' to export WikiCreole pages to | |
HTML with 'creole'." | |
(lambda (httpcon) | |
(wiki-handler httpcon docroot))) | |
;; Setup the defaults | |
(defconst wiki-webserver | |
(elnode-webserver-handler-maker wiki-docroot) | |
"The webserver handler. | |
This is needed for serving Javascript or CSS files or any | |
collateral files used by the WIKI, such as images or source | |
code.") | |
(defconst wiki-wikiserver | |
(wiki-handler-maker wiki-docroot) | |
"The WIKI handler.") | |
(defun wiki-top-handler (httpcon) | |
(funcall wiki-wikiserver httpcon)) | |
(defconst wiki-urlmap | |
'(("localhost/wiki/\\([A-Za-z0-9.-]+\\)" . wiki-top-handler) | |
("css/.*" . wiki-webserver) | |
("js/.*" . wiki-webserver)) | |
"The URL mappings for the wiki.") | |
(defun wiki-default-handler (httpcon) | |
"A default handler passing HTTPCON for a WIKI. | |
This uses the 'wiki-urlmap' for the match table. It calls | |
'elnode-dispatcher' with 'wiki-urlmap'." | |
(elnode-hostpath-dispatcher httpcon wiki-urlmap)) | |
(add-to-list 'load-path (expand-file-name "~/elwikicreole")) | |
(provide 'wikiengine) | |
;;; wikiengine.el ends here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment