add --null switch to `raco pollen render` (closes #24)

pull/218/head
Matthew Butterick 4 years ago
parent 2509e0e82d
commit fc5ca9f659

@ -98,7 +98,7 @@ version print the version" (current-server-port) (make-publish-di
(define render-target-wanted (make-parameter (current-poly-target)))
(define render-with-subdirs? (make-parameter #f))
(define render-parallel? (make-parameter #f))
(define dry-run? (make-parameter #f))
(define special-output? (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
@ -108,7 +108,9 @@ version print the version" (current-server-port) (make-publish-di
[("-r" "--recursive") "Render subdirectories recursively"
(render-with-subdirs? 'recursive)]
[("-s" "--subdir") "Render subdirectories nonrecursively" (render-with-subdirs? 'include)]
[("-d" "--dry-run") "Print paths that would be rendered" (dry-run? #true)]
#:once-any
[("-d" "--dry-run") "Print paths that would be rendered" (special-output? 'dry-run)]
[("-n" "--null") "Suppress file output" (special-output? 'null)]
#:once-any
[("-p" "--parallel") "Render in parallel using all cores" (render-parallel? #true)]
[("-j" "--jobs") job-count "Render in parallel using <job-count> jobs" (render-parallel? (or (string->number job-count) (raise-argument-error 'handle-render "exact positive integer" job-count)))]
@ -116,7 +118,7 @@ version print the version" (current-server-port) (make-publish-di
other-args))
(define (handle-batch-render paths)
(apply render-batch (map very-nice-path paths) #:parallel (render-parallel?) #:dry-run (dry-run?)))
(apply render-batch (map very-nice-path paths) #:parallel (render-parallel?) #:special (special-output?)))
(parameterize ([current-poly-target (render-target-wanted)]) ;; applies to both cases
(let loop ([args parsed-args])

@ -1 +1 @@
1575833252
1576204032

@ -155,9 +155,11 @@
[(list wpidx wp 'wants-lock path)
(loop source-paths locks (append blocks (list (cons wp path))) completed-jobs completed-job-count)])])))
(define current-null-output? (make-parameter #f))
(define+provide/contract (render-batch #:parallel [wants-parallel-render? #false]
#:dry-run [wants-dry-run? #false] . paths-in)
((#:parallel any/c) (#:dry-run boolean?) #:rest (listof pathish?) . ->* . void?)
#:special [special-output #false] . paths-in)
((#:parallel any/c) (#:special (or/c boolean? symbol?)) #:rest (listof pathish?) . ->* . void?)
;; Why not just (for-each render ...)?
;; Because certain files will pass through multiple times (e.g., templates)
;; And with render, they would be rendered repeatedly.
@ -176,12 +178,13 @@
[_ (loop rest acc)])])))
(cond
[(null? expanded-source-paths) (message "[no paths to render]")]
[wants-dry-run? (for-each message expanded-source-paths)]
[else (for-each render-to-file-if-needed
(match wants-parallel-render?
;; returns crashed jobs for serial rendering
[#false expanded-source-paths]
[jobs-arg (parallel-render expanded-source-paths jobs-arg)]))]))
[(eq? special-output 'dry-run) (for-each message expanded-source-paths)]
[else (parameterize ([current-null-output? (eq? special-output 'null)])
(for-each render-to-file-if-needed
(match wants-parallel-render?
;; returns crashed jobs for serial rendering
[#false expanded-source-paths]
[jobs-arg (parallel-render expanded-source-paths jobs-arg)])))]))
(define (pagetree->paths pagetree-or-path)
(parameterize ([current-directory (current-project-root)])
@ -246,10 +249,11 @@
(message (format "from cache /~a"
(find-relative-path (current-project-root) output-path))))))]
[else (render-thunk)]))
(display-to-file render-result
output-path
#:exists 'replace
#:mode (if (string? render-result) 'text 'binary))))
(unless (current-null-output?)
(display-to-file render-result
output-path
#:exists 'replace
#:mode (if (string? render-result) 'text 'binary)))))
(define+provide/contract (render-to-file-if-needed source-path [maybe-template-path #f] [maybe-output-path #f] [maybe-render-thunk #f])
((complete-path?) ((or/c #f complete-path?) (or/c #f complete-path?) (or/c #f procedure?)) . ->* . void?)

@ -76,7 +76,10 @@ Adding the optional @exec{--local} switch will restrict the project server to re
This command can be invoked two ways: in source mode or directory mode.
In both modes, the optional @exec{--dry-run} or @exec{-d} switch prints the paths that would be rendered by this command without actually doing so.
In both modes, the optional @exec{--dry-run} or @exec{-d} switch prints the paths that would be rendered by this command without actually doing so.
In both modes, the optional @exec{--null} or @exec{-n} switch renders as usual, but doesn't write any files. (Convenient if you're arranging special render behavior, for instance writing to a database or network server.)
@bold{Source mode}: @racket[raco pollen render _source ...] will render only the source paths specified in @racket[_source ...]. Consistent with the usual command-line idiom, this can be a single path, a list of paths, or a pattern:

Loading…
Cancel
Save