Welcome to the CHICKEN Scheme pasting service
awfully simple wiki pasted by mario-goulart on Mon Apr 6 22:01:05 2015
(use awful irregex posix utils) (define wiki-dir "wiki") (create-directory wiki-dir 'recursively) (enable-sxml #t) (define-page (irregex "/[^/]*") (lambda (path) (with-request-variables ((edit (nonempty as-boolean)) (content (nonempty as-string))) (let ((wiki-file (make-pathname wiki-dir (if (equal? path "/") "index" path)))) (cond (edit `(form (@ (action ,path) (method post)) (textarea (@ (name "content")) ,(if (file-exists? wiki-file) (read-all wiki-file) "")) (input (@ (type "submit"))))) (content (with-output-to-file wiki-file (cut print content)) (redirect-to path)) (else (if (file-exists? wiki-file) `((pre ,(read-all wiki-file)) (a (@ (href ,(string-append path "?edit=1"))) "Edit")) (redirect-to (string-append path "?edit=1")))))))) method: '(get post))
the wiki I'm using as note-taking app pasted by mario-goulart on Tue Apr 7 14:18:12 2015
;; free variables in this example: ;; base-dir: app web base dir. E.g., /mario ;; wiki-dir: filesystem path to the directory where wiki pages will be stored ;; define-auth-page: a wrapper around define-page which requires authentication (define-auth-page (irregex (make-pathname (main-page-path) "wiki/[^/]*")) (lambda (path) (with-request-variables ((edit (nonempty as-boolean)) content) (let ((wiki-file (make-pathname wiki-dir (if (equal? path (make-pathname (list base-dir "wiki") #f)) "index" (pathname-strip-directory path))))) (cond (edit `(form (@ (action ,path) (method post)) (textarea (@ (name "content") (autofocus) (rows 30)) ,(if (file-exists? wiki-file) (read-all wiki-file) "")) (br) (input (@ (type "submit") (value "Save"))))) (content (if (equal? content "") (begin (when (file-read-access? wiki-file) (delete-file wiki-file)) (redirect-to (make-pathname (list base-dir "wiki") #f))) (begin (with-output-to-file wiki-file (cut print content)) (redirect-to path)))) (else (if (file-read-access? wiki-file) `(,(with-input-from-file wiki-file markdown->sxml) (a (@ (href ,(string-append path "?edit=1"))) "Edit") " " (a (@ (href "https://github.com/adam-p/markdown-here/wiki/Markdown-Here-Cheatsheet") (target "_blank")) "Help") (hr) (ul (@ (id "wiki-pages-listing")) ,@(map (lambda (file) `(li (a (@ (href ,(make-pathname (list base-dir "wiki") file))) ,file))) (sort (directory wiki-dir) string<)))) (redirect-to (string-append path "?edit=1")))))))) method: '(get post))
My version of the wiki wiki way pasted by C-Keen on Tue Apr 7 20:56:22 2015
(use awful irregex posix utils lowdown srfi-13) (define wiki-dir "wiki") (create-directory wiki-dir 'recursively) (define starting-page "WelcomeVisitors") (define all-pages "AllPages") (enable-sxml #t) (define-page (irregex "/[^/]*") (lambda (path) (with-request-variables ((edit (nonempty as-boolean)) (content (nonempty as-string))) (when (equal? path "/") (redirect-to starting-page)) (let ((edit-path (string-append path "?edit=1")) (wiki-file (make-pathname wiki-dir path)) (page-name (string-trim path #\/))) `((h1 ,page-name) (hr) ,(cond ((equal? page-name "AllPages") `(ul ,@(map (lambda (f) `(li (a (@ (href ,(pathname-file f))) ,(pathname-file f)))) (find-files wiki-dir)))) (edit `(form (@ (action ,path) (method post)) (textarea (@ (name "content") (cols 80) (rows 50) (autofocus)) ,(if (file-exists? wiki-file) (read-all wiki-file) "")) (input (@ (type "submit") (value "Save"))))) (content (with-output-to-file wiki-file (cut print content)) (redirect-to path)) (else `(,(if (file-exists? wiki-file) `((pre ,(read-all wiki-file)) (hr) (a (@ (href ,edit-path)) "Edit")) `((p "The page " ,page-name " does not exist yet.") (hr) (a (@ (href ,edit-path)) "Create"))) " | ") )) (a (@ (href ,starting-page)) "Home") " | " (a (@ (href ,all-pages)) "AllPages"))))) method: '(get post))
mario-goulart: now with dirty littl' search pasted by C-Keen on Tue Apr 7 22:01:11 2015
(use awful irregex posix utils lowdown srfi-13) (define wiki-dir "wiki") (create-directory wiki-dir 'recursively) (define starting-page "WelcomeVisitors") (define all-pages "AllPages") (enable-sxml #t) (define-page (irregex "/[^/]*") (lambda (path) (with-request-variables ((edit (nonempty as-boolean)) (content (nonempty as-string)) (search (nonempty as-string))) (when (equal? path "/") (redirect-to starting-page)) (let ((edit-path (string-append path "?edit=1")) (wiki-file (make-pathname wiki-dir path)) (page-name (string-trim path #\/))) `((h1 ,page-name) (hr) ,(cond ((equal? page-name "AllPages") `((ul ,@(map (lambda (f) `(li (a (@ (href ,(pathname-file f))) ,(pathname-file f)))) (find-files wiki-dir))) (hr))) (edit `(form (@ (action ,path) (method post)) (textarea (@ (name "content") (cols 80) (rows 50) (autofocus)) ,(if (file-exists? wiki-file) (read-all wiki-file) "")) (input (@ (type "submit") (value "Save"))))) (content (with-output-to-file wiki-file (cut print content)) (redirect-to path)) (search `((h2 "Search results for " ,search) (ul ,(with-input-from-pipe (sprintf "grep -ri ~a ~s" (qs search) wiki-dir) (lambda () (map (lambda (l) (let* ((r (string-split l ":")) (p (pathname-file (car r))) (c (cdr r))) `(li (a (@ (href ,p)) ,p) " : " ,c))) (read-lines))))))) (else `(,(if (file-exists? wiki-file) `(,(with-input-from-file wiki-file markdown->sxml) (hr) (a (@ (href ,edit-path)) "Edit")) `((p "The page " ,page-name " does not exist yet.") (hr) (a (@ (href ,edit-path)) "Create"))) " | ") )) (a (@ (href ,starting-page)) "Home") " | " (a (@ (href ,all-pages)) "AllPages") (form (@ (action ,path) (method post)) (input (@ (type "text") (name "search"))) (input (@ (type "submit") (value "Search")))))))) method: '(get post))
wiki wiki: now with better "UX" pasted by C-Keen on Wed Apr 8 20:47:34 2015
(use awful irregex posix utils lowdown srfi-13) (define wiki-dir "wiki") (create-directory wiki-dir 'recursively) (define starting-page "WelcomeVisitors") (define all-pages "AllPages") (enable-sxml #t) (define-page (irregex "/[^/]*") (lambda (path) (with-request-variables ((edit (nonempty as-boolean)) (content (nonempty as-string)) (search (nonempty as-string))) (when (equal? path "/") (redirect-to starting-page)) (let ((edit-path (string-append path "?edit=1")) (wiki-file (make-pathname wiki-dir path)) (page-name (string-trim path #\/))) `((h1 (a (@ (href ,(string-append path "?search=" page-name))) ,page-name)) (hr) ,(cond ((equal? page-name "AllPages") `((ul ,@(map (lambda (f) `(li (a (@ (href ,(pathname-file f))) ,(pathname-file f)))) (find-files wiki-dir))) (hr))) (edit `((p (a (@ (href "https://github.com/adam-p/markdown-here/wiki/Markdown-Here-Cheatsheet") (target "_blank")) "EditingHelp")) (form (@ (action ,path) (method post)) (textarea (@ (name "content") (cols 80) (rows 25) (autofocus)) ,(if (file-exists? wiki-file) (read-all wiki-file) "")) (input (@ (type "submit") (value "Save")))))) (content (with-output-to-file wiki-file (cut print content)) (redirect-to path)) (search `((h2 "Search results for " ,search) (ul ,(with-input-from-pipe (sprintf "grep -ri ~a ~s" (qs search) wiki-dir) (lambda () (map (lambda (l) (let* ((r (string-split l ":")) (p (pathname-file (car r))) (c (cdr r))) `(li (a (@ (href ,p)) ,p) " : " ,c))) (read-lines))))))) (else `(,(if (file-exists? wiki-file) `(,(with-input-from-file wiki-file markdown->sxml) (hr) (a (@ (href ,edit-path)) "Edit")) `((p "The page " ,page-name " does not exist yet.") (hr) (a (@ (href ,edit-path)) "Create"))) " | ") )) (a (@ (href ,starting-page)) "Home") " | " (a (@ (href ,all-pages)) "AllPages") " | " (form (@ (action ,path) (method post)) (input (@ (type "text") (name "search"))) (input (@ (type "submit") (value "Search")))))))) method: '(get post))
mario-goulart: wiki with hello js editor WYSIWYG added by C-Keen on Thu Apr 9 14:47:18 2015
(use awful irregex posix utils lowdown srfi-13) (define wiki-dir "wiki") (define script-dir "wiki-libs") (create-directory wiki-dir 'recursively) (define start-page "WelcomeVisitor") (define all-pages "AllPages") (enable-sxml #t) ;; Grab the javascript files from hellojs.org's demo / the git repo (define-page (irregex "/[^/]*") (lambda (path) (with-request-variables ((edit (nonempty as-boolean)) (content (nonempty as-string)) (search (nonempty as-string))) (when (equal? path "/") (redirect-to start-page)) (let ((edit-path (string-append path "?edit=1")) (wiki-file (make-pathname wiki-dir path)) (page-name (string-trim path #\/))) `((script (@ (src ,(make-pathname script-dir "jquery.min.js")))) (script (@ (src ,(make-pathname script-dir "jquery-ui.min.js")))) (script (@ (src ,(make-pathname script-dir "rangy-core.js")))) (script (@ (src ,(make-pathname script-dir "hallo.js")))) (script (@ (src ,(make-pathname script-dir "showdown.js")))) (script (@ (src ,(make-pathname script-dir "to-markdown.js")))) (script (@ (src ,(make-pathname script-dir "editor.js")))) (link (@ (rel stylesheet) (href ,(make-pathname script-dir "css/font-awesome.css")))) ;; XXX ugh... (h1 (a (@ (href ,(string-append path "?search=" page-name))) ,page-name)) (hr) ,(cond ((equal? page-name all-pages) `((ul ,@(map (lambda (f) `(li (a (@ (href ,(pathname-file f))) ,(pathname-file f)))) (find-files wiki-dir))) (hr))) (edit (let ((content (if (file-exists? wiki-file) (read-all wiki-file) "This is a new page, please edit"))) `((div (@ (class editable)) ,(markdown->sxml content)) (div (@ (id "wiki-dialog"))) (form (@ (action ,path) (method post)) (textarea (@ (id "source") (name "content") (cols 80) (rows 25) (hidden)) ,content) (hr) (input (@ (type "submit") (value "Save"))))))) (content (with-output-to-file wiki-file (cut print content)) (redirect-to path)) (search `((h2 "Search results for " ,search) (ul ,(with-input-from-pipe (sprintf "grep -ri ~a ~s" (qs search) wiki-dir) (lambda () (map (lambda (l) (let* ((r (string-split l ":")) (p (pathname-file (car r))) (c (cdr r))) `(li (a (@ (href ,p)) ,p) " : " ,c))) (read-lines))))))) (else `(,(if (file-exists? wiki-file) `(,(with-input-from-file wiki-file markdown->sxml) (hr) (a (@ (href ,edit-path)) "Edit")) (redirect-to edit-path)) " | ") )) (a (@ (href ,start-page)) ,start-page) " | " (a (@ (href ,all-pages)) ,all-pages) " | " (form (@ (action ,path) (method post)) (input (@ (type "text") (name "search"))) (input (@ (type "submit") (value "Search")))))))) method: '(get post))