From 249c899dd1d10904be84bab79852bc279d397b3f Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Fri, 3 Jun 2016 10:39:51 -0700 Subject: [PATCH] add `--recursive` option to `raco pollen render` (closes #114) --- pollen/private/command.rkt | 21 +++++++++++++++------ pollen/private/ts.rktd | 2 +- pollen/scribblings/raco.scrbl | 3 ++- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/pollen/private/command.rkt b/pollen/private/command.rkt index 226a4c5..861050d 100644 --- a/pollen/private/command.rkt +++ b/pollen/private/command.rkt @@ -80,11 +80,14 @@ version print the version" (current-server-port) (make-publish-di (define (handle-render) (define render-target-wanted (make-parameter (current-poly-target))) + (define render-recursively? (make-parameter #f)) (define parsed-args (command-line #:program "raco pollen render" #:argv (vector-drop (current-command-line-arguments) 1) ; snip the 'render' from the front #:once-each [("-t" "--target") target-arg "Render target for poly sources" (render-target-wanted (->symbol target-arg))] + [("-r" "--recursive") "Render subdirectories" + (render-recursively? #t)] #:args other-args other-args)) (define path-args (if (empty? parsed-args) @@ -92,13 +95,14 @@ version print the version" (current-server-port) (make-publish-di parsed-args)) (parameterize ([current-directory (current-project-root)] [current-poly-target (render-target-wanted)]) - (define first-arg (car path-args)) - (if (directory-exists? first-arg) - (let ([dir first-arg]) ; now we know it's a dir + (define first-path-or-path-string (car path-args)) + (if (directory-exists? first-path-or-path-string) + (let render-one-dir ([dir (->complete-path first-path-or-path-string)]) (parameterize ([current-directory dir] [current-project-root dir]) - (define preprocs (filter preproc-source? (directory-list dir))) - (define static-pagetrees (filter pagetree-source? (directory-list dir))) + (define dirlist (directory-list dir)) + (define preprocs (filter preproc-source? dirlist)) + (define static-pagetrees (filter pagetree-source? dirlist)) ;; if there are no static pagetrees, use make-project-pagetree ;; (which will synthesize a pagetree if needed, which includes all sources) (define preprocs-and-static-pagetrees (append preprocs static-pagetrees)) @@ -111,7 +115,12 @@ version print the version" (current-server-port) (make-publish-di [else (displayln (format "rendering preproc & pagetree files in directory ~a" dir)) preprocs-and-static-pagetrees]))) - (apply render-batch batch-to-render))) + (apply render-batch batch-to-render) + (when (render-recursively?) + (for ([path (in-list dirlist)] + #:when (and (directory-exists? path) + (not (unpublished-path? path)))) + (render-one-dir (->complete-path path)))))) (begin ; first arg is a file (displayln (format "rendering ~a" (string-join (map ->string path-args) " "))) (apply render-batch path-args))))) diff --git a/pollen/private/ts.rktd b/pollen/private/ts.rktd index c53a19f..3778725 100644 --- a/pollen/private/ts.rktd +++ b/pollen/private/ts.rktd @@ -1 +1 @@ -1464906246 +1464975591 diff --git a/pollen/scribblings/raco.scrbl b/pollen/scribblings/raco.scrbl index 86e1043..bd91194 100644 --- a/pollen/scribblings/raco.scrbl +++ b/pollen/scribblings/raco.scrbl @@ -73,7 +73,7 @@ Render all preprocessor source files and then all pagetree files found in the cu This command can be invoked with extra arguments. -@racket[raco pollen render _directory] will perform the render described above, but in the specified directory. +@racket[raco pollen render _directory] will perform the render described above, but in the specified directory. By default, only files in the immediate directory are rendered. Adding the optional @exec{-r} or @exec{--recursive} switch will also render subdirectories recursively. Alternatively, the command can take a variable number of path arguments. @racket[raco pollen render _path ...] will render only the paths specified in @racket[_path ...]. Consistent with the usual command-line idiom, this can be a single path, a list of paths, or a pattern: @@ -90,6 +90,7 @@ Paths can also be specified as output rather than input paths, and the correspon The optional @exec{-t} or @exec{--target} switch specifies the render target for multi-output source files. If the target is omitted, the renderer will use whatever target appears first in @racket[(setup:poly-targets)]. + @terminal{ > raco pollen render -t pdf foo.poly.pm}