From cd614ce11ec5ef8a0e800f7f12f621b0486971ce Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Wed, 19 Mar 2014 17:41:05 -0700 Subject: [PATCH] working on polcom render --- command.rkt | 14 ++++++++++++++ raco.rkt | 1 + render.rkt | 11 +++++++---- server-routes.rkt | 6 +++--- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/command.rkt b/command.rkt index 194307f..8d98afc 100644 --- a/command.rkt +++ b/command.rkt @@ -9,6 +9,20 @@ render renders all files in project directory clone copies rendered files to desktop [filename] renders individual file")) +(define (handle-render dir-or-path [port #f]) + `(begin + (require pollen/render pollen/world pollen/file sugar) + (parameterize ([current-directory (world:current-project-root)]) + (define dir-or-path ,dir-or-path) + (apply render-batch (map ->complete-path (if (not (directory-exists? dir-or-path)) + (begin + (displayln (format "Rendering ~a" dir-or-path)) + (list dir-or-path)) + (begin + (displayln (format "Rendering preproc & pagetree files in directory ~a" dir-or-path) + (apply append (map (λ(proc) (filter proc (directory-list dir-or-path))) (list preproc-source? pagetree-source?))))))))))) + + (define (handle-start directory [port #f]) (if (not (directory-exists? directory)) (error (format "~a is not a directory" directory)) diff --git a/raco.rkt b/raco.rkt index 6e49731..d999419 100644 --- a/raco.rkt +++ b/raco.rkt @@ -25,6 +25,7 @@ (case arg-command-name [(#f "help") (handle-help)] [("start") (handle-start arg-project-directory arg-server-port)] + [("render") (handle-render (vector-ref args 1))] [else (handle-else arg-command-name)]))) (select-syntax-for-command) diff --git a/render.rkt b/render.rkt index a7317d5..1b1d395 100644 --- a/render.rkt +++ b/render.rkt @@ -46,7 +46,9 @@ ;; And with render, they would be rendered repeatedly. ;; Using reset-modification-dates is sort of like session control. (reset-modification-dates) - (for-each render-to-file-if-needed xs)) + (for-each (λ(x) ((if (pagetree-source? x) + render-pagetree + render-to-file-if-needed) x)) xs)) (define/contract+provide (render-pagetree pagetree-or-path) @@ -54,10 +56,11 @@ (define pagetree (if (pagetree? pagetree-or-path) pagetree-or-path (cached-require pagetree-or-path world:main-pollen-export))) - (apply render-batch (pagetree->list pagetree))) + (parameterize ([current-directory (world:current-project-root)]) + (for-each render-from-source-or-output-path (map ->complete-path (pagetree->list pagetree))))) -(define/contract+provide (render-for-dev-server so-pathish #:force [force #f]) +(define/contract+provide (render-from-source-or-output-path so-pathish #:force [force #f]) ((pathish?) (#:force boolean?) . ->* . void?) (let ([so-path (->complete-path so-pathish)]) ; so-path = source or output path (could be either) (cond @@ -155,7 +158,7 @@ ((complete-path?) ((or/c #f complete-path?)) . ->* . bytes?) (match-define-values (source-dir _ _) (split-path source-path)) (define template-path (or maybe-template-path (get-template-for source-path))) - (render-for-dev-server template-path) ; because template might have its own preprocessor source + (render-from-source-or-output-path template-path) ; because template might have its own preprocessor source (define expr-to-eval `(begin (require (for-syntax racket/base)) diff --git a/server-routes.rkt b/server-routes.rkt index a7dca26..605dbab 100644 --- a/server-routes.rkt +++ b/server-routes.rkt @@ -55,7 +55,7 @@ ;; extract main xexpr from a path (define/contract (file->xexpr path #:render [wants-render #t]) ((complete-path?) (#:render boolean?) . ->* . txexpr?) - (when wants-render (render-for-dev-server path)) + (when wants-render (render-from-source-or-output-path path)) (dynamic-rerequire path) ; stores module mod date; reloads if it's changed (dynamic-require path world:main-pollen-export)) @@ -67,7 +67,7 @@ ;; just file->string with a render option (define/contract (slurp path #:render [wants-render #t]) ((complete-path?) (#:render boolean?) . ->* . string?) - (when wants-render (render-for-dev-server path)) + (when wants-render (render-from-source-or-output-path path)) (file->string path)) @@ -226,7 +226,7 @@ (define (route-default req) (logger req) (define force (equal? (get-query-value (request-uri req) 'force) "true")) - (render-for-dev-server (req->path req) #:force force) + (render-from-source-or-output-path (req->path req) #:force force) (next-dispatcher))