document support for multiple templates in ◊(define-meta template ...)

pull/108/merge
Matthew Butterick 9 years ago
parent 9088c858d1
commit 167a759b31

@ -77,7 +77,18 @@ Note that @racket[_pagetree] or @racket[_pagetree_source] is used strictly as a
Find a template file for @racket[_source-path], with the following priority: Find a template file for @racket[_source-path], with the following priority:
@itemlist[#:style 'ordered @itemlist[#:style 'ordered
@item{If the @racket[metas] for @racket[_source-path] have a key for @code[(format "~a" world:template-meta-key)], then use the value of this key.} @item{If the @racket[metas] for @racket[_source-path] have a key for @code[(format "~a" world:template-meta-key)], then use the value of this key, e.g. —
@code{◊(define-meta template "my-template.html")}
If your project has @seclink["fourth-tutorial"]{multiple output targets}, you can supply a list of templates, and the template with an extension matching the current output target will be selected automatically, e.g. —
@code{◊(define-meta template (list "my-template.html" "my-template.txt" "my-template.pdf"))}
}
@item{If this key doesn't exist, or refers to a nonexistent file, look for a default template with the name @code[(format "~a.[output extension]" world:default-template-prefix)]. Meaning, if @racket[_source-path] is @code[(format "intro.html.~a" world:markup-source-ext)], the output path would be @code["intro.html"], so the default template would be @code[(format "~a.html" world:default-template-prefix)]. Look for this default template in the same directory as the source file, and then search upwards within successive parent directories. (Corollary: a default template in the project root will apply to all files in the project unless overridden within a subdirectory.)} @item{If this key doesn't exist, or refers to a nonexistent file, look for a default template with the name @code[(format "~a.[output extension]" world:default-template-prefix)]. Meaning, if @racket[_source-path] is @code[(format "intro.html.~a" world:markup-source-ext)], the output path would be @code["intro.html"], so the default template would be @code[(format "~a.html" world:default-template-prefix)]. Look for this default template in the same directory as the source file, and then search upwards within successive parent directories. (Corollary: a default template in the project root will apply to all files in the project unless overridden within a subdirectory.)}

@ -1,6 +1,6 @@
#lang scribble/manual #lang scribble/manual
@(require scribble/eval racket/date (for-label racket/file racket/system pollen/decode plot pollen/world pollen/tag racket/base pollen/template txexpr racket/list racket/string)) @(require scribble/eval racket/date (for-label racket/file racket/system pollen/decode plot pollen/world pollen/tag racket/base pollen/template txexpr racket/list racket/string pollen/render))
@(require "mb-tools.rkt") @(require "mb-tools.rkt")
@(define my-eval (make-base-eval)) @(define my-eval (make-base-eval))
@ -200,7 +200,7 @@ The goal of this whole endeavor is to derive multiple output files from one sour
◊(apply string-append (filter string? (flatten doc))) ◊(apply string-append (filter string? (flatten doc)))
}|] }|]
What we're doing here is converting the X-expression to text in a smarter way. We use @racket[local-require] to bring in @racket[racket/list] so we can use the @racket[flatten] function. Then, to understand what the next line does, just read it from the inside out: ``Take the @racket[doc] export from the source file (which is an X-expression), @racket[flatten] it into a list, @racket[filter] out everything that's not a @racket[string?] (creating a list that's only strings) and @racket[apply] the @racket[string-append] function to these, resulting in one big string.'' Which is exactly what we need for a plain-text file. What we're doing here is converting the X-expression to text in a smarter way. We use @racket[local-require] to bring in @racket[racket/list] so we can use the @racket[flatten] function. Then, to understand what the next line does, just read it from the inside out: ``Take the @racket[doc] export from the source file (which is an X-expression), @racket[flatten] it into a list, @racket[filter] with @racket[string?] (creating a list that's only strings) and @racket[apply] the @racket[string-append] function to these, resulting in one big string.'' Which is exactly what we need for a plain-text file.
When you return to the project server and click on @filepath{cv.txt.pm}, you'll see the result: When you return to the project server and click on @filepath{cv.txt.pm}, you'll see the result:
@ -211,6 +211,7 @@ Today is @(date->string (current-date)). I really want this job.}
So far, so good. We've got legible plain text. But we've completely lost our formatting. Let's fix that. So far, so good. We've got legible plain text. But we've completely lost our formatting. Let's fix that.
@margin-note{Have you ever used @code{◊(define-meta template ...)} to specify a template for a particular source file? You can still use this in a multiple-output project — just supply a list of templates rather than a single template. See @racket[get-template-for].}
@subsubsection{Branching tag functions} @subsubsection{Branching tag functions}

Loading…
Cancel
Save