add `--recursive` option to `raco pollen render` (closes #114)

pull/115/head
Matthew Butterick 9 years ago
parent 3bd62c82af
commit 249c899dd1

@ -80,11 +80,14 @@ version print the version" (current-server-port) (make-publish-di
(define (handle-render) (define (handle-render)
(define render-target-wanted (make-parameter (current-poly-target))) (define render-target-wanted (make-parameter (current-poly-target)))
(define render-recursively? (make-parameter #f))
(define parsed-args (command-line #:program "raco pollen render" (define parsed-args (command-line #:program "raco pollen render"
#:argv (vector-drop (current-command-line-arguments) 1) ; snip the 'render' from the front #:argv (vector-drop (current-command-line-arguments) 1) ; snip the 'render' from the front
#:once-each #:once-each
[("-t" "--target") target-arg "Render target for poly sources" [("-t" "--target") target-arg "Render target for poly sources"
(render-target-wanted (->symbol target-arg))] (render-target-wanted (->symbol target-arg))]
[("-r" "--recursive") "Render subdirectories"
(render-recursively? #t)]
#:args other-args #:args other-args
other-args)) other-args))
(define path-args (if (empty? parsed-args) (define path-args (if (empty? parsed-args)
@ -92,13 +95,14 @@ version print the version" (current-server-port) (make-publish-di
parsed-args)) parsed-args))
(parameterize ([current-directory (current-project-root)] (parameterize ([current-directory (current-project-root)]
[current-poly-target (render-target-wanted)]) [current-poly-target (render-target-wanted)])
(define first-arg (car path-args)) (define first-path-or-path-string (car path-args))
(if (directory-exists? first-arg) (if (directory-exists? first-path-or-path-string)
(let ([dir first-arg]) ; now we know it's a dir (let render-one-dir ([dir (->complete-path first-path-or-path-string)])
(parameterize ([current-directory dir] (parameterize ([current-directory dir]
[current-project-root dir]) [current-project-root dir])
(define preprocs (filter preproc-source? (directory-list dir))) (define dirlist (directory-list dir))
(define static-pagetrees (filter pagetree-source? (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 ;; if there are no static pagetrees, use make-project-pagetree
;; (which will synthesize a pagetree if needed, which includes all sources) ;; (which will synthesize a pagetree if needed, which includes all sources)
(define preprocs-and-static-pagetrees (append preprocs static-pagetrees)) (define preprocs-and-static-pagetrees (append preprocs static-pagetrees))
@ -111,7 +115,12 @@ version print the version" (current-server-port) (make-publish-di
[else [else
(displayln (format "rendering preproc & pagetree files in directory ~a" dir)) (displayln (format "rendering preproc & pagetree files in directory ~a" dir))
preprocs-and-static-pagetrees]))) 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 (begin ; first arg is a file
(displayln (format "rendering ~a" (string-join (map ->string path-args) " "))) (displayln (format "rendering ~a" (string-join (map ->string path-args) " ")))
(apply render-batch path-args))))) (apply render-batch path-args)))))

@ -1 +1 @@
1464906246 1464975591

@ -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. 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: 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)]. 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{ @terminal{
> raco pollen render -t pdf foo.poly.pm} > raco pollen render -t pdf foo.poly.pm}

Loading…
Cancel
Save