diff --git a/pollen/private/command.rkt b/pollen/private/command.rkt index aef485f..8c4b4eb 100644 --- a/pollen/private/command.rkt +++ b/pollen/private/command.rkt @@ -80,14 +80,15 @@ 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 render-with-subdirs? (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)] + [("-r" "--recursive") "Render subdirectories recursively" + (render-with-subdirs? 'recursive)] + [("-s" "--subdir") "Render subdirectories nonrecursively" (render-with-subdirs? 'include)] #:args other-args other-args)) (define path-args (if (empty? parsed-args) @@ -95,11 +96,13 @@ 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-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)]) + ;; special case: one directory as argument + (if (and (= 1 (length path-args)) (directory-exists? (car path-args))) + (let render-one-dir ([dir (->complete-path (car path-args))]) (parameterize ([current-directory dir] - [current-project-root dir]) + [current-project-root (case (render-with-subdirs?) + [(recursive) dir] + [else (current-project-root)])]) (define dirlist (directory-list dir)) (define preprocs (filter preproc-source? dirlist)) (define static-pagetrees (filter pagetree-source? dirlist)) @@ -115,12 +118,12 @@ version print the version" (current-server-port) (make-publish-di (displayln (format "rendering preproc & pagetree files in directory ~a" dir)) (append preprocs static-pagetrees)]))) (apply render-batch batch-to-render) - (when (render-recursively?) + (when (render-with-subdirs?) (for ([path (in-list dirlist)] #:when (and (directory-exists? path) (not (omitted-path? path)))) (render-one-dir (->complete-path path)))))) - (begin ; first arg is a file + (begin (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 2b91395..eb47904 100644 --- a/pollen/private/ts.rktd +++ b/pollen/private/ts.rktd @@ -1 +1 @@ -1519949495 +1520460708 diff --git a/pollen/scribblings/raco.scrbl b/pollen/scribblings/raco.scrbl index c723f3b..0bdf38c 100644 --- a/pollen/scribblings/raco.scrbl +++ b/pollen/scribblings/raco.scrbl @@ -74,15 +74,9 @@ Adding the optional @exec{--local} switch will restrict the project server to re @section{@exec{raco pollen render}} -Render all preprocessor source files and then all pagetree files found in the current directory. If none of these files are found, a pagetree will be generated for the directory (which will include all source files) and then rendered. +This command can be invoked two ways: in source mode or directory mode. -This command can be invoked with extra arguments. - -@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. Certain directories are automatically omitted from recursive renders, including Pollen caches and source-control directories (like @tt{.git} and @tt{.svn}). You can omit other paths by overriding @racket[default-omitted-path?]. You can override these omissions — that is, force a path to be included in a recursive render — by overriding @racket[default-extra-path?]. - -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: +@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: @terminal{ > raco pollen render foo.html.pm @@ -103,7 +97,21 @@ The optional @exec{-t} or @exec{--target} switch specifies the render target for See also @seclink["raco-pollen-render-poly"]. -@bold{Warning}: In all cases, the newly rendered output file will overwrite any previous output file. +@italic{Warning}: In all cases, the newly rendered output file will overwrite any previous output file. + + +@bold{Directory mode}: @racket[raco pollen render _directory] renders all preprocessor source files and then all pagetree files found in the specified directory. If none of these files are found, a pagetree will be generated for the directory (which will include all source files) and then rendered. If the @racket[_directory] argument is omitted, the command defaults to the current directory. + +In directory mode, this command can be invoked with two other optional arguments (in addition to the @exec{--target} switch mentioned above): + +The @exec{--subdir} or @exec{-s} switch also renders subdirectories. @racket[current-project-root] remains fixed at the initial directory, just as it would be in the project server after invoking @racket[raco pollen start]. + +Certain subdirectories are automatically ignored, including Racket and Pollen private directories (like @tt{compiled}) and source-control directories (like @tt{.git} and @tt{.svn}). You can omit other paths by overriding @racket[default-omitted-path?]. You can override these omissions — that is, force a path to be included in a recursive render — by overriding @racket[default-extra-path?]. + +The @exec{--recursive} or @exec{-r} switch renders subdirectories recursively. Meaning, each subdirectory is treated like an independent subproject, and @racket[current-project-root] moves around accordingly. In many projects, there won't be any difference between the @exec{-s} and @exec{-r} switches. But if the difference matters in your project, you have them both. + + + @section{@exec{raco pollen publish}}