From c025de31dcb1005358ef47c9fc90201c81799b0f Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Tue, 7 Jan 2014 18:32:34 -0800 Subject: [PATCH] updates --- command.rkt | 5 ++++ debug.rkt | 4 ++-- server-routes.rkt | 21 ++++++++++------- server.rkt | 9 ++++--- setup.rkt | 34 ++++++++++++++++++++------- startup.rkt | 5 ++-- tests/server-routes/{foo.p => foo.pd} | 0 world.rkt | 2 ++ 8 files changed, 56 insertions(+), 24 deletions(-) rename tests/server-routes/{foo.p => foo.pd} (100%) diff --git a/command.rkt b/command.rkt index a6a9099..3314d4c 100644 --- a/command.rkt +++ b/command.rkt @@ -10,6 +10,11 @@ [arg (if (> (len args) 0) (get args 0) "")]) (display (format "~a: " POLLEN_COMMAND_FILE)) (case arg + [("help") (displayln "valid commands are +polcom start (starts project server) +polcom render (renders all files in project directory) +polcom clone (copies rendered files to desktop) +polcom [filename] (renders individual file)")] [("start") `(require "server.rkt")] [("render") `(begin ;; todo: take extensions off the comand line diff --git a/debug.rkt b/debug.rkt index 8332a17..26a4e6e 100644 --- a/debug.rkt +++ b/debug.rkt @@ -24,7 +24,7 @@ (set! last-message-time now) (if then (- now then) - "--")) + "0")) (define (zero-fill str count) (set! str (~a str)) @@ -59,7 +59,7 @@ (string-append (string-join time-fields ":") (if (< (date-hour date) 12) "am" "pm"))) (define (make-debug-timestamp) - (format "[~a ~as]" (make-timestamp) (seconds-since-last-message))) + (format "[~a ∆~as]" (make-timestamp) (seconds-since-last-message))) (define (message . items) (displayln (string-join `(,(make-debug-timestamp) ,@(map (λ(x)(if (string? x) x (~v x))) items))) (current-error-port))) diff --git a/server-routes.rkt b/server-routes.rkt index bc021aa..9aa2f06 100644 --- a/server-routes.rkt +++ b/server-routes.rkt @@ -19,8 +19,9 @@ (dynamic-rerequire path) ; stores module mod date; reloads if it's changed (dynamic-require path 'main)) -(module+ test - (check-equal? (file->xexpr (build-path (current-directory) "tests/server-routes/foo.p") #:render #f) '(root "\n" "foo"))) +;; todo: rewrite this test, obsolete since filename convention changed +;;(module+ test +;; (check-equal? (file->xexpr (build-path (current-directory) "tests/server-routes/foo.p") #:render #f) '(root "\n" "foo"))) ;; read contents of file to string ;; just file->string with a render option @@ -94,15 +95,19 @@ #:key path->string stringoutput-path pollen-files)) ;; Make a combined list of pollen files and post-pollen files, in alphabetical order (define all-pollen-files (sort (append pollen-files post-pollen-files) #:key path->string stringstring f) "polcom")) ;todo: generalize this test + (not ((->string f) . starts-with? . ".")) + (not (f . in? . all-pollen-files)))) + (directory-list pollen-project-directory))) + + (message leftover-files) + ;; Utility function for making file rows (define (make-file-row file routes) ;; Utility function for making cells @@ -123,14 +128,14 @@ `(td (a ((href ,target)) ,name)))) `(tr ,(make-link-cell 'direct) ,@(map make-link-cell routes))) - (if (andmap empty? (list ptree-files all-pollen-files all-preproc-files template-files)) + (if (andmap empty? (list ptree-files all-pollen-files all-preproc-files template-files leftover-files)) '(body "No files yet. Get to work!") `(body (style ((type "text/css")) "td a { display: block; width: 100%; height: 100%; padding: 8px; }" "td:hover {background: #eee}") (table ((style "font-family:Concourse T3;font-size:115%")) ;; options for ptree files and template files - ,@(map (λ(file) (make-file-row file '(raw))) (append ptree-files template-files)) + ,@(map (λ(file) (make-file-row file '(raw))) (append leftover-files ptree-files template-files)) ;; options for pollen files ,@(map (λ(file) (make-file-row file '(raw source xexpr force))) post-pollen-files) diff --git a/server.rkt b/server.rkt index e307d06..aa37898 100755 --- a/server.rkt +++ b/server.rkt @@ -6,7 +6,9 @@ (require "server-routes.rkt" "predicates.rkt" "debug.rkt") (define port-number 8088) -(message (format "Starting webserver at http://localhost:~a" port-number)) + +(message (format "Project directory is ~a" pollen-project-directory)) +(message (format "Project server is http://localhost:~a" port-number) "(Ctrl-C to exit)") (define (logger req) (define client (request-client-ip req)) @@ -24,7 +26,7 @@ (define-values (start url) (dispatch-rules - [("start") (λ(req) + [("pollen") (λ(req) (logger req) (response/xexpr (route-index)))] [("source" (string-arg)) (route-wrapper route-source)] @@ -37,7 +39,8 @@ (route-default req) (next-dispatcher))])) -(message "Ready to rock. Type ^C to exit") +(message (format "Project dashboard is http://localhost:~a/pollen" port-number)) +(message "Ready to rock") (serve/servlet start diff --git a/setup.rkt b/setup.rkt index c67e54a..45097fb 100644 --- a/setup.rkt +++ b/setup.rkt @@ -4,16 +4,29 @@ (provide setup) +(define cd (current-directory)) + (define (make-polcom-data racket-path) (format "#! ~a #lang racket/base (require pollen/command) -; pollen setup run on ~a" +; pollen setup run in ~a on ~a" racket-path + cd (format "~a at ~a" (make-datestamp) (make-timestamp)))) (define (setup) - (define cd (current-directory)) + ; this function is just for export. + ; it hides the test-only parameter + (setup-testable #f)) + +(define (setup-testable test-only) + (message (format "Set up ~a as a pollen directory? ['y' or 'yes']" cd)) + (define setup-confirm (->string (read))) + (when (not (or (equal? setup-confirm "y") (equal? setup-confirm "yes"))) + (begin + (message "Aborting setup") + (exit))) (message (format "Setting up ~a as a pollen directory" cd)) (define racket-path (string-trim (with-output-to-string (λ() (system "which racket"))))) @@ -27,12 +40,17 @@ (begin (message (format "Deleting existing polcom file in ~a" cd)) (delete-file polcom-filename))) - (message (format "Creating new polcom file in ~a" cd)) (with-handlers ([exn:fail? (λ(e) (message "Couldn't write polcom file. Aborting setup"))]) - (display-to-file polcom-data polcom-filename) - (with-output-to-string (λ() (system (format "chmod 755 ~a" polcom-filename)))) + (when (not test-only) + (begin + (message (format "Creating new polcom file in ~a" cd)) + (display-to-file polcom-data polcom-filename) + (with-output-to-string (λ() (system (format "chmod 755 ~a" polcom-filename)))))) (message "Setup complete") - (message (format "Run '~a~a start' to start pollen development server" cd polcom-filename)) + (message (format "Run '~a~a start' to start project server" cd polcom-filename)) (message (format "Or run '~a~a help' for a list of commands" cd polcom-filename)) - (exit))) - (message "No path to racket binary. Aborting setup"))) \ No newline at end of file + (when (not test-only) (exit)))) + (message "No path to racket binary. Aborting setup"))) + +(module+ main + (setup-testable #t)) \ No newline at end of file diff --git a/startup.rkt b/startup.rkt index 6e19f56..0248941 100644 --- a/startup.rkt +++ b/startup.rkt @@ -1,4 +1,3 @@ #lang racket/base -(require "debug.rkt") -(message "Starting Pollen") -(message "Using Racket" (version)) +(require "debug.rkt" "world.rkt") +(message (format "Welcome to Pollen ~a" POLLEN_VERSION) (format "(Racket ~a)" (version))) diff --git a/tests/server-routes/foo.p b/tests/server-routes/foo.pd similarity index 100% rename from tests/server-routes/foo.p rename to tests/server-routes/foo.pd diff --git a/world.rkt b/world.rkt index 97a6e3e..e764082 100644 --- a/world.rkt +++ b/world.rkt @@ -2,6 +2,8 @@ (provide (all-defined-out)) +(define POLLEN_VERSION "0.001") + (define POLLEN_PREPROC_EXT 'p) (define POLLEN_SOURCE_EXT 'pd) (define TEMPLATE_FILE_PREFIX "-")