many improvements to regenerate

pull/9/head
Matthew Butterick 11 years ago
parent 7c9cac4e3a
commit 2f67c6a7ee

@ -13,8 +13,8 @@
[("regenerate") `(begin [("regenerate") `(begin
;; todo: take extensions off the comand line ;; todo: take extensions off the comand line
(displayln "Regenerate preproc & pmap files ...") (displayln "Regenerate preproc & pmap files ...")
(require "regenerate.rkt" "pollen-file-tools.rkt") (require "regenerate.rkt" "pollen-file-tools.rkt" "world.rkt")
(map force-regenerate (append-map project-files-with-ext (list POLLEN_PREPROC_EXT POLLEN_MAP_EXT))))] (apply regenerate-with-session (append-map project-files-with-ext (list POLLEN_PREPROC_EXT POLLEN_MAP_EXT))))]
[("clone") (let ([target-path [("clone") (let ([target-path
(if (> (len args) 1) (if (> (len args) 1)
(->path (get args 1)) (->path (get args 1))

@ -165,6 +165,6 @@
(define/contract (project-files-with-ext ext) (define/contract (project-files-with-ext ext)
(symbol? . -> . (listof complete-path?)) (symbol? . -> . (listof complete-path?))
(filter (λ(i) (has-ext? i ext)) (directory-list pollen-file-root))) (map ->complete-path (filter (λ(i) (has-ext? i ext)) (directory-list pollen-file-root))))
;; todo: write tests for project-files-with-ext ;; todo: write tests for project-files-with-ext

@ -1,11 +1,11 @@
#lang racket/base #lang racket/base
(require racket/list racket/path racket/port racket/system (require racket/list racket/path racket/port racket/system
racket/file racket/rerequire racket/contract) racket/file racket/rerequire racket/contract racket/bool)
(require "world.rkt" "tools.rkt" "pmap.rkt" "readability.rkt") (require "world.rkt" "tools.rkt" "pmap.rkt" "readability.rkt" "template.rkt")
(module+ test (require rackunit)) (module+ test (require rackunit))
(provide regenerate force-regenerate) (provide regenerate regenerate-with-session)
;; mod-dates is a hash that takes lists of paths as keys, ;; mod-dates is a hash that takes lists of paths as keys,
;; and lists of modification times as values. ;; and lists of modification times as values.
@ -74,87 +74,101 @@
;; convenience function for external modules to use ;; convenience function for external modules to use
(define/contract (force-regenerate x) (define/contract (regenerate-with-session . xs)
(pathish? . -> . void?) (() #:rest (listof pathish?) . ->* . void?)
(regenerate x #:force #t)) ;; This will trigger regeneration of all files.
;; Why not pass #:force #t through with regenerate?
;; Because certain files will pass through multiple times (e.g., templates)
;; And with #:force, they would be regenerated repeatedly.
;; Using reset-mod-dates is sort of like session control:
;; setting a state that persists through the whole operation.
(reset-mod-dates)
(for-each regenerate xs))
;; dispatches path to the right regeneration function ;; dispatches path to the right regeneration function
;; use #:force to refresh regardless of cached state ;; use #:force to refresh regardless of cached state
(define/contract (regenerate x #:force [force #f]) (define/contract (regenerate #:force [force #f] . xs)
((pathish?) (#:force boolean?) . ->* . void?) (() (#:force boolean?) #:rest (listof pathish?) . ->* . void?)
(let ([path (->complete-path (->path x))]) (define (&regenerate x)
(cond (let ([path (->complete-path (->path x))])
;; this will catch pp (preprocessor) files (cond
[(needs-preproc? path) (regenerate-with-preproc path #:force force)] ;; this will catch pp (preprocessor) files
;; this will catch p files, [(needs-preproc? path) (regenerate-with-preproc path #:force force)]
;; and files without extension that correspond to p files ;; this will catch p files,
[(needs-template? path) (regenerate-with-template path #:force force)] ;; and files without extension that correspond to p files
;; this will catch pmap (pollen map) files [(needs-template? path) (regenerate-with-template path #:force force)]
[(pmap-source? path) (let ([pmap (dynamic-require path 'main)]) ;; this will catch pmap (pollen map) files
(regenerate-with-pmap pmap #:force force))] [(pmap-source? path) (let ([pmap (dynamic-require path 'main)])
[(file-exists? path) (message "Regenerate: passing through" (->string (file-name-from-path path)))] (regenerate-with-pmap pmap #:force force))]
[else (error "File not found:" (->string (file-name-from-path path)))]))) [(equal? FALLBACK_TEMPLATE_NAME (->string (file-name-from-path path)))
(message "Regenerate: using fallback template")]
[(file-exists? path) (message "Regenerate: passing through" (->string (file-name-from-path path)))]
[else (error "Regenerate couldn't find" (->string (file-name-from-path path)))])))
(for-each &regenerate xs))
;; todo: write tests ;; todo: write tests
;; todo: write contract & tests (define/contract (regenerating-message path)
(define (regenerating-message path) (any/c . -> . void?)
;; you can actually stuff whatever string you want into path — ;; you can actually stuff whatever string you want into path —
;; if it's not really a path, file-name-from-path won't choke ;; if it's not really a path, file-name-from-path won't choke
(message "Regenerating:" (->string (file-name-from-path path)))) (message "Regenerating:" (->string (file-name-from-path path))))
;; todo: write contract & tests (define/contract (regenerated-message path)
(define (regenerated-message path) (any/c . -> . void?)
(message "Regenerated:" (->string (file-name-from-path path)))) (message "Regenerated:" (->string (file-name-from-path path))))
;; todo: these are misnamed. Not "complete" (define/contract (complete-preproc-source-path x)
(define (complete-preproc-source-path x) (pathish? . -> . complete-path?)
(define path (->path x)) (let ([path (->path x)])
(if (preproc-source? path) (->complete-path (if (preproc-source? path)
path path
(make-preproc-source-path path))) (make-preproc-source-path path)))))
;; todo: tests
(define/contract (complete-preproc-output-path x)
(pathish? . -> . complete-path?)
(let ([path (->path x)])
(->complete-path (if (preproc-source? path)
(make-preproc-output-path path)
path))))
;; todo: tests
(define (complete-preproc-output-path x)
(define path (->path x))
(if (preproc-source? path)
(make-preproc-output-path path)
path))
(define/contract (regenerate-with-preproc x #:force [force #f]) (define/contract (regenerate-with-preproc x #:force [force #f])
(((and/c pathish? (((and/c pathish?
(flat-named-contract 'file-exists (flat-named-contract 'file-exists
(λ(x) (file-exists? (complete-preproc-source-path x)))))) (#:force boolean?) . ->* . void?) (λ(x) (file-exists? (complete-preproc-source-path x)))))) (#:force boolean?) . ->* . void?)
;; x might be either a preproc-source path or preproc-output path
;; path might be either a preproc-source path or preproc-output path
;; figure out which, then compute the other
(define source-path (complete-preproc-source-path x)) (define source-path (complete-preproc-source-path x))
(define output-path (complete-preproc-output-path x)) (define output-path (complete-preproc-output-path x))
;; Three conditions under which we refresh: ;; Three conditions under which we refresh:
(if (or (if (or
;; 1) explicitly forced refresh ;; 1) explicitly forced refresh
force force
;; 2) output file doesn't exist (so it definitely won't appear in mod-dates) ;; 2) output file doesn't exist (so it definitely won't appear in mod-dates)
;; also, this is convenient for development: ;; also, this is convenient for development:
;; you can trigger a refresh just by deleting the file ;; you can trigger a refresh just by deleting the file
(not (file-exists? output-path)) (not (file-exists? output-path))
;; 3) file otherwise needs refresh (e.g., it changed) ;; 3) file otherwise needs refresh (e.g., it changed)
(mod-date-expired? source-path)) (mod-date-expired? source-path))
;; use single quotes to escape spaces in pathnames ;; use single quotes to escape spaces in pathnames
(let ([command (format "~a '~a' > '~a'" RACKET_PATH source-path output-path)]) (let ([command (format "~a '~a' > '~a'" RACKET_PATH source-path output-path)])
(regenerating-message (format "~a from ~a" (regenerating-message (format "~a from ~a"
(file-name-from-path output-path) (file-name-from-path output-path)
(file-name-from-path source-path))) (file-name-from-path source-path)))
(store-refresh-in-mod-dates source-path) (store-refresh-in-mod-dates source-path)
;; discard output using open-output-nowhere ;; discard output using open-output-nowhere
(parameterize ([current-output-port (open-output-nowhere)]) (parameterize ([current-output-port (open-output-nowhere)])
(system command)) (system command))
(regenerated-message output-path)) (regenerated-message output-path))
;; otherwise, skip file because there's no trigger for refresh ;; otherwise, skip file because there's no trigger for refresh
(message "File is up to date:" (->string (file-name-from-path output-path))))) (message "File is up to date:" (->string (file-name-from-path output-path)))))
;; todo: write tests ;; todo: write tests
@ -209,18 +223,25 @@
;; set the template, regenerate the source file with template, and catch the output. ;; set the template, regenerate the source file with template, and catch the output.
;; 1) Set the template. ;; 1) Set the template.
(define template-path (define template-path
(build-path source-dir (or
;; if template name provided and exists, use that ;; Build the possible paths and use the first one
(if (and template-name (file-exists? (build-path source-dir template-name))) ;; that either exists, or has a preproc source that exists.
template-name (ormap (λ(p) (if (ormap file-exists? (list p (make-preproc-source-path p))) p #f))
;; Otherwise — try to get template name out of meta fields. (filter-not false?
;; todo: consider that template file in metas (list
;; may not refer to a file that exists. ;; path based on template-name
;; what then? (and template-name (build-path source-dir template-name))
(let ([source-metas (dynamic-require source-path 'metas)]) ;; path based on metas
(if (TEMPLATE_META_KEY . in? . source-metas) (let ([source-metas (dynamic-require source-path 'metas)])
(get source-metas TEMPLATE_META_KEY) (and (TEMPLATE_META_KEY . in? . source-metas)
DEFAULT_TEMPLATE))))) (build-path source-dir
(get source-metas TEMPLATE_META_KEY))))
;; path using default template name
(build-path source-dir DEFAULT_TEMPLATE))))
;; if none of these work, make temporary template file
(let ([tp (build-path source-dir FALLBACK_TEMPLATE_NAME)])
(display-to-file #:exists 'replace fallback-template-data tp)
tp)))
;; refresh template (it might have its own preprocessor file) ;; refresh template (it might have its own preprocessor file)
(regenerate template-path #:force force) (regenerate template-path #:force force)
@ -242,7 +263,11 @@
(let ([page-result (render-source-with-template source-path template-path)]) (let ([page-result (render-source-with-template source-path template-path)])
(display-to-file #:exists 'replace page-result output-path) (display-to-file #:exists 'replace page-result output-path)
(regenerated-message (file-name-from-path output-path)))) (regenerated-message (file-name-from-path output-path))))
(message "File is up to date:" (->string (file-name-from-path output-path))))) (message "Regenerate with template: file is up to date:" (->string (file-name-from-path output-path))))
;; delete fallback template if needed
(let ([tp (build-path source-dir FALLBACK_TEMPLATE_NAME)])
(when (file-exists? tp) (delete-file tp))))
(define/contract (render-source-with-template source-path template-path) (define/contract (render-source-with-template source-path template-path)
@ -272,8 +297,10 @@
;; regenerate files listed in a pmap file ;; regenerate files listed in a pmap file
(define/contract (regenerate-with-pmap pmap #:force [force #f]) (define/contract (regenerate-with-pmap pmap #:force [force #f])
(pmap? . -> . void?) ((pmap?) (#:force boolean?) . ->* . void?)
;; pass force parameter through ;; pass force parameter through
(for-each (λ(i) (regenerate i #:force force)) (all-pages pmap))) (for-each (λ(i) (regenerate i #:force force)) (all-pages pmap)))
;; todo: write test ;; todo: write test

@ -6,8 +6,6 @@
(displayln "Pollen server starting...") (displayln "Pollen server starting...")
(define pollen-file-root (current-directory))
(define/contract (route-wrapper route-proc) (define/contract (route-wrapper route-proc)
;; todo: make better contract for return value ;; todo: make better contract for return value
((complete-path? . -> . tagged-xexpr?) . -> . procedure?) ((complete-path? . -> . tagged-xexpr?) . -> . procedure?)

@ -0,0 +1,89 @@
#lang racket/base
(require racket/list racket/string xml xml/path)
(require "readability.rkt" "debug.rkt" "predicates.rkt" "tools.rkt")
;; setup for test cases
(module+ test (require rackunit))
(provide (all-defined-out))
;; todo: better fallback template
(define fallback-template-data "FALLBACK! ◊(put-as-html main)")
;; todo: tests & contracts for this subsection
(define (from x query)
; cache x
(let ([x (put x)])
; try finding it in metas, if not, find it in main, if not then return false
(or (from-metas x query) (from-main x query))))
(define (from-main x query) ; this used to be plain from
; check results first
(let* ([x (put x)]
[results (se-path*/list (list query) x)])
; if results exist, send back xexpr as output
(if (not (empty? results))
`(,query ,@results) ; todo: why use query as tag?
#f)))
(define (from-metas x key)
(let* ([x (put x)]
[meta-hash (make-meta-hash x)]
[key (->symbol key)])
(if (in? meta-hash key)
`(value ,(get meta-hash key)) ;todo: why use value as tag?
#f)))
(define (put x)
; handles either xexpr or pollen file as input
(cond
; pass through xexpr as is
; put is optional for xexprs.
; it's only here to make the idiom smooth.
[(tagged-xexpr? x) x]
; todo: how to externalize pollen main tag into world name?
[(file-exists? (->path x)) (dynamic-require x 'main)]
; also try adding pollen file extension
; this makes put compatible with map references
[(let ([x (make-pollen-source-path x)])
(when (file-exists? x)
(put x)))]
[else (error "put: need named xexpr or pollen file, but got" x)]))
(define (merge x)
(cond
[(tagged-xexpr? x)
; return content of xexpr.
; pollen language rules will splice these into the main flow.
(if (empty? x)
""
(let-values([(name attr content) (break-tagged-xexpr x)])
content))]
[(string? x) (list x)]))
#|(define (merge-strings x)
(when (empty? x) (error "merge-strings got empty x"))
;todo: filter metas?
; leaning toward no. Simplest behavior.
; function is not intended to be used with whole pollen body anyhow.
(let ([x (merge x)])
(string-join (filter string? (flatten x)) " ")))|#
(define (merge-strings x)
(string-join (filter string? (flatten x)) " "))
(define (make-html x)
(if (tagged-xexpr? x)
(xexpr->string x)
(let ([x (->list x)])
(when (andmap xexpr? x)
(string-join (map xexpr->string x) "")))))
; generate *-as-html versions of functions
(define-values (put-as-html merge-as-html merge-strings-as-html)
(apply values (map (λ(proc) (λ(x) (make-html (proc x)))) (list put merge merge-strings))))

@ -1 +0,0 @@
◊(put-as-html main)

@ -0,0 +1,3 @@
OH JOY
◊(put-as-html main)

@ -0,0 +1,5 @@
#lang planet mb/pollen/pre
OH JOY
"◊"(put-as-html main)

@ -0,0 +1,3 @@
OH JOY
put-as-htmlroot-functionptopicclasssmallBibliographyplcThis is not, by any measure, a comprehensive bibliography. Rather, its a selection of favorites from my own bookshelf that I consult most frequently in my work as a writer and a typographer.psubheadwritingpBryan A. Garner, bookGarners Modern American Usage, 3rd ed. (New York: Oxford University Press, 2009).pindentedstyleposition:relative;top:-0.4emLong before he agreed to write the foreword for my book bookTypography for Lawyers, Bryan Garner was a hero of mine. Garner thinks and writes about American English in a way thats rigorous, convincing, and accessible. He is stern but not shrill; authoritative but not authoritarian. He is a vigorous advocate for clear, simple writing. His work should be mandatory reading for all writers.psubheadTypographypMatthew Butterick, bookTypography for Lawyers (Houston: Jones McClure Publishing, 2010).pindentedstyleposition:relative;top:-0.4emThe precursor to bookButtericks Practical Typography. Lawyer or not, consider buying a copy, because its a virtuous act. See xrefhow to pay for this book.pJan Middendorp, bookShaping Text (Amsterdam: BIS Publishers, 2012).pindentedstyleposition:relative;top:-0.4emIf you get a second book on typography, get this one. Middendorps beautifully written and illustrated book is full of careful details and lucid explanations.pCarolina de Bartolo, bookExplorations in Typography (slinkexplorationsintypography.comhttp://explorationsintypography.com, 2011).pindentedstyleposition:relative;top:-0.4emUsing a Spiekermann essay from bookStop Stealing Sheep (see below), de Bartolo shows how different typesetting choices change the effect of the text.pCyrus Highsmith, bookInside Paragraphs (Boston: Font Bureau, 2012).pindentedstyleposition:relative;top:-0.4emHighsmiths charmingly hand-illustrated book focuses on the paragraph as a unit of typographic interest.pRobert Bringhurst, bookThe Elements of Typographic Style, 3rd ed. (Vancouver: Hartley and Marks Publishers, 2004).pindentedstyleposition:relative;top:-0.4emBringhursts book has become something of a standard reference guide among professional typographers, bringing together the history, theory, and practice of typography.pEllen Lupton, bookThinking With Type, 2nd ed. (New York: Princeton Architectural Press, 2010).pindentedstyleposition:relative;top:-0.4emIntended as an introduction to typography for design students, Luptons book is more accessible than Bringhursts. It includes full-color illustrations from every era of typography.psubheadFontspErik Spiekermann and E. M. Ginger, bookStop Stealing Sheep & Find Out How Type Works, 2nd ed. (Berkeley, California: Adobe Press, 2002).pindentedstyleposition:relative;top:-0.4emGinger & Spiekermann, a self-described typomaniac (and author of the xrefforeword) explain how fonts work, and how they differ in appearance and in function. My font xrefHermes is among those featured.pStephen Coles, bookThe Anatomy of Type (London: Quid Publishing Ltd., 2012).pindentedstyleposition:relative;top:-0.4emExplores the major categories of fonts and their characteristic qualities by examining 100 fonts in detail.psubheadDesign principlespEdward Tufte, bookEnvisioning Information, 4th printing ed. (Cheshire, Connecticut: Graphics Press, 1990).pEdward Tufte, bookThe Visual Display of Quantitative Information, 2nd ed. (Cheshire, Connecticut: Graphics Press, 2001).pindentedstyleposition:relative;top:-0.4emThese are two of my favorite books of all time. Tufte makes an eloquent and compelling case for why design matters. Both books are fantastically interesting and beautifully illustrated with examples of information design from many historical periods.pWilliam Lidwell, Kritina Holden, and Jill Butler, bookUniversal Principles of Design, 2nd ed. (Beverly, Massachusetts: Rockport Publishers, 2010).pindentedstyleposition:relative;top:-0.4emAn excellent and accessible introduction to design principles that apply not only to printed documents, but to all objects that we interact with.

@ -1,5 +1,7 @@
#lang planet mb/pollen #lang planet mb/pollen
meta["template" "-stain.html"]
topic['((class "small"))]{Bibliography} topic['((class "small"))]{Bibliography}
lc{T}his is not, by any measure, a comprehensive bibliography. Rather, its a selection of favorites from my own bookshelf that I consult most frequently in my work as a writer and a typographer. lc{T}his is not, by any measure, a comprehensive bibliography. Rather, its a selection of favorites from my own bookshelf that I consult most frequently in my work as a writer and a typographer.

@ -0,0 +1 @@
FALLBACK! put-as-htmlroot-functionpdquo“Hello” world, arent you—yes, you—about 12 inches tall?bloqIn a blockpWefooblesquoLovepGoodnightbrmoonpbar

@ -1,3 +0,0 @@
#lang planet mb/pollen
I'm in a subdirectory.

@ -1,3 +0,0 @@
#lang planet mb/pollen
This is a test of the regen system.

@ -0,0 +1 @@
<root-function><p><topic class="small">Bibliography</topic></p><p><lc>T</lc>his is not, by any measure, a comprehensive bibliography. Rather, its a selection of favorites from my own bookshelf that I consult most frequently in my work as a writer and a typographer.</p><p><subhead>writing</subhead></p><p>Bryan A. Garner, <book>Garners Modern American Usage</book>, 3rd ed. (New York: Oxford University Press, 2009).</p><p><indented style="position:relative;top:-0.4em">Long before he agreed to write the foreword for my book <book>Typography for Lawyers</book>, Bryan Garner was a hero of mine. Garner thinks and writes about American English in a way thats rigorous, convincing, and accessible. He is stern but not shrill; authoritative but not authoritarian. He is a vigorous advocate for clear, simple writing. His work should be mandatory reading for all writers.</indented></p><p><subhead>Typography</subhead></p><p>Matthew Butterick, <book>Typography for Lawyers</book> (Houston: Jones McClure Publishing, 2010).</p><p><indented style="position:relative;top:-0.4em">The precursor to <book>Buttericks Practical Typography</book>. Lawyer or not, consider buying a copy, because its a virtuous act. See <xref>how to pay for this book.</xref></indented></p><p>Jan Middendorp, <book>Shaping Text</book> (Amsterdam: BIS Publishers, 2012).</p><p><indented style="position:relative;top:-0.4em">If you get a second book on typography, get this one. Middendorps beautifully written and illustrated book is full of careful details and lucid explanations.</indented></p><p>Carolina de Bartolo, <book>Explorations in Typography</book> (<slink>explorationsintypography.comhttp://explorationsintypography.com</slink>, 2011).</p><p><indented style="position:relative;top:-0.4em">Using a Spiekermann essay from <book>Stop Stealing Sheep</book> (see below), de Bartolo shows how different typesetting choices change the effect of the text.</indented></p><p>Cyrus Highsmith, <book>Inside Paragraphs</book> (Boston: Font Bureau, 2012).</p><p><indented style="position:relative;top:-0.4em">Highsmiths charmingly hand-illustrated book focuses on the paragraph as a unit of typographic interest.</indented></p><p>Robert Bringhurst, <book>The Elements of Typographic Style</book>, 3rd ed. (Vancouver: Hartley and Marks Publishers, 2004).</p><p><indented style="position:relative;top:-0.4em">Bringhursts book has become something of a standard reference guide among professional typographers, bringing together the history, theory, and practice of typography.</indented></p><p>Ellen Lupton, <book>Thinking With Type</book>, 2nd ed. (New York: Princeton Architectural Press, 2010).</p><p><indented style="position:relative;top:-0.4em">Intended as an introduction to typography for design students, Luptons book is more accessible than Bringhursts. It includes full-color illustrations from every era of typography.</indented></p><p><subhead>Fonts</subhead></p><p>Erik Spiekermann and E. M. Ginger, <book>Stop Stealing Sheep &amp; Find Out How Type Works</book>, 2nd ed. (Berkeley, California: Adobe Press, 2002).</p><p><indented style="position:relative;top:-0.4em">Ginger &amp; Spiekermann, a self-described typomaniac (and author of the <xref>foreword</xref>) explain how fonts work, and how they differ in appearance and in function. My font <xref>Hermes</xref> is among those featured.</indented></p><p>Stephen Coles, <book>The Anatomy of Type</book> (London: Quid Publishing Ltd., 2012).</p><p><indented style="position:relative;top:-0.4em">Explores the major categories of fonts and their characteristic qualities by examining 100 fonts in detail.</indented></p><p><subhead>Design principles</subhead></p><p>Edward Tufte, <book>Envisioning Information</book>, 4th printing ed. (Cheshire, Connecticut: Graphics Press, 1990).</p><p>Edward Tufte, <book>The Visual Display of Quantitative Information</book>, 2nd ed. (Cheshire, Connecticut: Graphics Press, 2001).</p><p><indented style="position:relative;top:-0.4em">These are two of my favorite books of all time. Tufte makes an eloquent and compelling case for why design matters. Both books are fantastically interesting and beautifully illustrated with examples of information design from many historical periods.</indented></p><p>William Lidwell, Kritina Holden, and Jill Butler, <book>Universal Principles of Design</book>, 2nd ed. (Beverly, Massachusetts: Rockport Publishers, 2010).</p><p><indented style="position:relative;top:-0.4em">An excellent and accessible introduction to design principles that apply not only to printed documents, but to all objects that we interact with.</indented></p></root-function>

@ -1,26 +1,5 @@
#lang planet mb/pollen #lang planet mb/pollen
index
typography-in-ten-minutes pollen-file-1
summary-of-key-rules pollen-file-2
foreword
introduction
how-to-use
how-to-pay-for-this-book
◊why-typography-matters{
what-is-typography
where-do-the-rules-come-from}
◊type-composition{
straight-and-curly-quotes
one-space-between-sentences
trademark-and-copyright-symbols
ligatures}
◊appendix{
printers-and-paper
how-to-make-a-pdf
typewriter-habits
common-accented-characters
identifying-fonts
bibliography
charter
mb-lectures-and-articles}

@ -1 +0,0 @@
This will print bar: bar

@ -1,5 +0,0 @@
#lang planet mb/pollen/pre
(define foo "bar")
This will print bar: foo

@ -216,56 +216,3 @@
(hash "foo" "haw"))) (hash "foo" "haw")))
;; todo: tests & contracts for this subsection
(define (put x)
; handles either xexpr or pollen file as input
(cond
; pass through xexpr as is
; put is optional for xexprs.
; it's only here to make the idiom smooth.
[(tagged-xexpr? x) x]
; todo: how to externalize pollen main tag into world name?
[(file-exists? (->path x)) (dynamic-require x 'main)]
; also try adding pollen file extension
; this makes put compatible with map references
[(let ([x (make-pollen-source-path x)])
(when (file-exists? x)
(put x)))]
[else (error "put: need named xexpr or pollen file, but got" x)]))
(define (merge x)
(cond
[(tagged-xexpr? x)
; return content of xexpr.
; pollen language rules will splice these into the main flow.
(if (empty? x)
""
(let-values([(name attr content) (break-tagged-xexpr x)])
content))]
[(string? x) (list x)]))
#|(define (merge-strings x)
(when (empty? x) (error "merge-strings got empty x"))
;todo: filter metas?
; leaning toward no. Simplest behavior.
; function is not intended to be used with whole pollen body anyhow.
(let ([x (merge x)])
(string-join (filter string? (flatten x)) " ")))|#
(define (merge-strings x)
(string-join (filter string? (flatten x)) " "))
(define (make-html x)
(if (tagged-xexpr? x)
(xexpr->string x)
(let ([x (->list x)])
(when (andmap xexpr? x)
(string-join (map xexpr->string x) "")))))
; generate *-as-html versions of functions
(define-values (put-as-html merge-as-html merge-strings-as-html)
(apply values (map (λ(proc) (λ(x) (make-html (proc x)))) (list put merge merge-strings))))

@ -7,13 +7,14 @@
(define TEMPLATE_FIELD_DELIMITER POLLEN_EXPRESSION_DELIMITER) (define TEMPLATE_FIELD_DELIMITER POLLEN_EXPRESSION_DELIMITER)
(define DEFAULT_TEMPLATE "-main.html") (define DEFAULT_TEMPLATE "-main.html")
(define TEMPLATE_META_KEY 'template) (define FALLBACK_TEMPLATE_NAME "-temp-fallback-template.html")
(define TEMPLATE_META_KEY "template")
(define POLLEN_MAP_EXT 'pmap) (define POLLEN_MAP_EXT 'pmap)
(define DEFAULT_POLLEN_MAP "main.pmap") (define DEFAULT_POLLEN_MAP "main.pmap")
(define POLLEN_MAP_PARENT_KEY 'parent) (define POLLEN_MAP_PARENT_KEY 'parent)
(define MAIN_POLLEN_EXPORT 'body) (define MAIN_POLLEN_EXPORT 'main)
;(define META_POLLEN_TAG 'metas) ;(define META_POLLEN_TAG 'metas)
;(define META_POLLEN_EXPORT 'metas) ;(define META_POLLEN_EXPORT 'metas)

Loading…
Cancel
Save