better checks for get-template-for

pull/15/merge
Matthew Butterick 10 years ago
parent b4af1936d5
commit ec4863b4a0

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -183,6 +183,7 @@
(complete-path? . -> . (or/c #f complete-path?)) (complete-path? . -> . (or/c #f complete-path?))
(match-define-values (source-dir _ _) (split-path source-path)) (match-define-values (source-dir _ _) (split-path source-path))
(and (templated-source? source-path) ; doesn't make sense if it's not a templated source format (and (templated-source? source-path) ; doesn't make sense if it's not a templated source format
(let ([output-path (->output-path source-path)])
(or ; Build the possible paths and use the first one that either exists, or has existing source (template, preproc, or null) (or ; Build the possible paths and use the first one that either exists, or has existing source (template, preproc, or null)
(ormap (λ(p) (if (ormap file-exists? (list p (->template-source-path p) (->preproc-source-path p) (->null-source-path p))) p #f)) (ormap (λ(p) (if (ormap file-exists? (list p (->template-source-path p) (->preproc-source-path p) (->null-source-path p))) p #f))
(filter (λ(x) (->boolean x)) ; if any of the possibilities below are invalid, they return #f (filter (λ(x) (->boolean x)) ; if any of the possibilities below are invalid, they return #f
@ -191,9 +192,9 @@
(let ([source-metas (cached-require source-path 'metas)]) (let ([source-metas (cached-require source-path 'metas)])
(and ((->symbol world:template-meta-key) . in? . source-metas) (and ((->symbol world:template-meta-key) . in? . source-metas)
(build-path source-dir (select-from-metas (->string world:template-meta-key) source-metas))))) ; path based on metas (build-path source-dir (select-from-metas (->string world:template-meta-key) source-metas))))) ; path based on metas
(and (filename-extension (->output-path source-path)) (build-path (world:current-project-root) (and (filename-extension output-path) (build-path (world:current-project-root)
(add-ext world:default-template-prefix (get-ext (->output-path source-path)))))))) ; path to default template (add-ext world:default-template-prefix (get-ext output-path))))))) ; path to default template
(build-path (world:current-server-extras-path) world:fallback-template)))) ; fallback template (and (filename-extension output-path) (build-path (world:current-server-extras-path) (add-ext world:fallback-template-prefix (get-ext output-path)))))))) ; fallback template
(define/contract (file-needed-rerequire? source-path) (define/contract (file-needed-rerequire? source-path)

@ -90,8 +90,8 @@ The magic character that indicates a Pollen command, function, or variable. Init
@defthing[world:default-template-prefix string?] @defthing[world:default-template-prefix string?]
Prefix of the default template. Initialized to @racket["template"]. Prefix of the default template. Initialized to @racket["template"].
@defthing[world:fallback-template string?] @defthing[world:fallback-template-prefix string?]
Name of the fallback template (i.e., the template used to render a Pollen markup file when no other template can be found). Initialized to @racket["fallback.html.pt"]. Used to generate the name of the fallback template (i.e., the template used to render a Pollen markup file when no other template can be found). Prefix is combined with the output suffix of the source file. Initialized to @racket["fallback"].
@defthing[world:template-meta-key symbol?] @defthing[world:template-meta-key symbol?]
Meta key used to store a template name for that particular source file. Initialized to @racket['template]. Meta key used to store a template name for that particular source file. Initialized to @racket['template].

@ -28,7 +28,7 @@
(define template-command-marker #\∂) (define template-command-marker #\∂)
(define default-template-prefix "template") (define default-template-prefix "template")
(define fallback-template "fallback.html") (define fallback-template-prefix "fallback")
(define template-meta-key "template") (define template-meta-key "template")
(define main-pollen-export 'doc) ; don't forget to change fallback template too (define main-pollen-export 'doc) ; don't forget to change fallback template too

Loading…
Cancel
Save