14.4 File
(require pollen/file) | package: pollen |
A utility module that provides functions for working with Pollen source and output files. In ordinary use, you probably won’t need these. But if you want to do more elaborate Pollen hacking, here they are.
Pollen handles six kinds of source files:
Preprocessor, with file extension .pp
Markup, with file extension .pm
Markdown, with file extension .pmd
Null, with file extension .p
Scribble, with file extension .scrbl
Pagetree, with file extension .ptree. This is the only source type that does not produce an output file.
The functions in this module rely on file extensions specified in pollen/setup. These extensions can be overridden within a project — see How to override setup values.
For each kind of Pollen source file, the corresponding output file name is derived by removing the extension from the name of the source file. So the preprocessor source file "default.css.pp" would become "default.css". (See Saving & naming your source file if this rings no bells.)
Scribble files work differently — the corresponding output file is the source file but with an "html" extension rather than "scrbl". So "pollen.scrbl" would become "pollen.html".
For more about Pollen’s file model, see File formats.
procedure
(preproc-source? val) → boolean?
val : any/c
procedure
(markup-source? val) → boolean?
val : any/c
procedure
(markdown-source? val) → boolean?
val : any/c
procedure
(null-source? val) → boolean?
val : any/c
procedure
(scribble-source? val) → boolean?
val : any/c
procedure
(pagetree-source? val) → boolean?
val : any/c
> (preproc-source? "main.css.pp") #t
> (markup-source? "default.html.pm") #t
> (markdown-source? "default.html.pmd") #t
> (null-source? "index.html.p") #t
> (scribble-source? "file.scrbl") #t
> (pagetree-source? "index.ptree") #t
procedure
(->preproc-source-path p) → path?
p : pathish?
procedure
(->markup-source-path p) → path?
p : pathish?
procedure
(->markdown-source-path p) → path?
p : pathish?
procedure
(->null-source-path p) → path?
p : pathish?
procedure
(->scribble-source-path p) → path?
p : pathish?
> (define name "default.html")
> (->preproc-source-path name) #<path:default.html.pp>
> (->markup-source-path name) #<path:default.html.pm>
> (->markdown-source-path name) #<path:default.html.pmd>
> (->scribble-source-path name) #<path:default.scrbl>
> (->null-source-path name) #<path:default.html.p>
procedure
(get-source p) → (or/c #f path?)
p : pathish?
procedure
(get-markup-source p) → (or/c #f path?)
p : pathish?
procedure
(get-markdown-source p) → (or/c #f path?)
p : pathish?
procedure
(get-preproc-source p) → (or/c #f path?)
p : pathish?
procedure
(get-null-source p) → (or/c #f path?)
p : pathish?
procedure
(get-scribble-source p) → (or/c #f path?)
p : pathish?
The omnibus get-source will check source formats in this order: get-markup-source, get-markdown-source, get-preproc-source, get-null-source, and get-scribble-source.
The type-specific variants will, of course, only return a source file of the specified type.
In all cases, if there is no corresponding source, return #f.
procedure
(->output-path p) → path?
p : pathish?
If p has a poly output type, then ->output-path uses current-poly-target as the output-path extension.
Otherwise, there are no type-specific variants for this function because the output path of a Pollen source file is determined by its name.
> (->output-path "main.css.pp") #<path:main.css>
> (->output-path "default.html.pm") #<path:default.html>
> (->output-path "index.html.p") #<path:index.html>
> (->output-path "file.scrbl") #<path:file.html>