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

pull/218/head
Matthew Butterick 5 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-target-wanted (make-parameter (current-poly-target)))
(define render-with-subdirs? (make-parameter #f)) (define render-with-subdirs? (make-parameter #f))
(define render-parallel? (make-parameter #f)) (define render-parallel? (make-parameter #f))
(define dry-run? (make-parameter #f)) (define special-output? (make-parameter #f))
(define parsed-args (define parsed-args
(command-line #:program "raco pollen render" (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
@ -108,7 +108,9 @@ version print the version" (current-server-port) (make-publish-di
[("-r" "--recursive") "Render subdirectories recursively" [("-r" "--recursive") "Render subdirectories recursively"
(render-with-subdirs? 'recursive)] (render-with-subdirs? 'recursive)]
[("-s" "--subdir") "Render subdirectories nonrecursively" (render-with-subdirs? 'include)] [("-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 #:once-any
[("-p" "--parallel") "Render in parallel using all cores" (render-parallel? #true)] [("-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)))] [("-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)) other-args))
(define (handle-batch-render paths) (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 (parameterize ([current-poly-target (render-target-wanted)]) ;; applies to both cases
(let loop ([args parsed-args]) (let loop ([args parsed-args])

@ -1 +1 @@
1575833252 1576204032

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

@ -78,6 +78,9 @@ 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: @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