;;; -*- mode: Lisp; Syntax: Common-Lisp; -*- ;;; ;;; Copyright (c) 2009 by the authors. ;;; ;;; See LICENCE for details. (in-package :hu.dwim.projectional-editor) ;; KLUDGE: (setf sdl:*default-color* sdl:*black*) ;; TODO: this is needed to measure text width during layout (sdl:initialise-default-font (make-instance 'sdl:ttf-font-definition :size 18 :filename (asdf:system-relative-pathname :hu.dwim.projectional-editor "etc/Inconsolata.otf"))) ;; TODO: use font from CSS (def file-serving-entry-points *projectional-editor-application* ("static/" (asdf:system-relative-pathname :hu.dwim.projectional-editor "etc/"))) (def entry-point (*projectional-editor-application* :path "projectional-editor") (with-entry-point-logic (:ensure-session #t :ensure-frame #t) (make-buffered-functional-html-response ((+header/status+ +http-ok+)) (render-examples)))) (def entry-point (*projectional-editor-application* :path "projectional-editor/example/demo") (with-entry-point-logic (:ensure-session #t :ensure-frame #t) (make-buffered-functional-html-response ((+header/status+ +http-ok+)) (bind (((editor document projection) (or (root-component-of *frame*) (setf (root-component-of *frame*) (bind ((name (string-upcase (first *entry-point-relative-path*))) (editor (make-editor)) (document (funcall (format-symbol :hu.dwim.projectional-editor.test "MAKE-TEST-DOCUMENT/~A" name))) (projection (funcall (format-symbol :hu.dwim.projectional-editor.test "MAKE-TEST-PROJECTION/~A->GRAPHICS" name)))) (list editor document projection)))))) (catch :quit-editor (funcall (read-from-devices editor document projection))) (render-document document projection))))) (def entry-point (*projectional-editor-application* :path "projectional-editor/example/document") (with-entry-point-logic (:ensure-session #t :ensure-frame #t) (make-buffered-functional-html-response ((+header/status+ +http-ok+)) (bind (((document projection) (bind ((name (string-upcase (first *entry-point-relative-path*))) (document (funcall (format-symbol :hu.dwim.projectional-editor.test "MAKE-TEST-DOCUMENT/~A" name))) (projection (funcall (find-symbol "MAKE-TEST-PROJECTION/T->GRAPHICS" :hu.dwim.projectional-editor.test)))) (list document projection)))) (render-document document projection))))) (def class* example () ((name :type string) (description :type string) (document :type document) (projection :type projection))) (def function make-example (name description) (make-instance 'example :name name :description description :document (funcall (format-symbol :hu.dwim.projectional-editor.test "MAKE-TEST-DOCUMENT/~A" (string-upcase name))) :projection (funcall (format-symbol :hu.dwim.projectional-editor.test "MAKE-TEST-PROJECTION/~A->GRAPHICS" (string-upcase name))))) (def function collect-examples () (list (make-example "String" "The most trivial example is a simple string. In this example the document is directly projected to graphics.") (make-example "Graphics" "This example demonstrates the graphics data structure. The graphics document does not need to be projected, becasuse it is already in the language of the output device.") (make-example "Text" "This example demonstrates the styled text data structure. Characters may have foreground color, background color and font. The text document is directly projected to graphics.") (make-example "List" "TODO") (make-example "Table" "TODO") (make-example "Tree" "TODO") (make-example "Book" "TODO") (make-example "JSON" "The JSON format is a widely used and well documented syntax for a non trivial data structure.") (make-example "XML" "TODO") (make-example "Java" "TODO") (make-example "lisp-form" "TODO") (make-example "walked-lisp-form" "TODO") #+nil (make-example "nested" "TODO") #+nil (make-example "complex" "TODO") #+nil (make-example "t" "TODO"))) (def function render-examples ()

,(iter (for index :from 1) (for example :in (collect-examples)) (for name = (name-of example)) (for projection = (projection-of example))

,@(iter (for element :in (labels ((collect-atomic-projections (projection) (if (typep projection 'sequential) (mappend #'collect-atomic-projections (elements-of projection)) (list projection)))) (collect-atomic-projections projection))) (for projection-name = (string-downcase (class-name (class-of element)))) (for document-name = (subseq projection-name (+ (search "->" projection-name) 4))) `str(" ") ) " "
>)>>) (def function render-document (document projection) > > >>)