working on regenerate

pull/9/head
Matthew Butterick 11 years ago
parent 0c3cc6c676
commit 35cee26d69

@ -9,9 +9,9 @@
(case arg
[("serve") `(require "server.rkt")]
[("regenerate") `(begin
(displayln "Regenerate all...")
(require "regenerate.rkt")
(regenerate-all-files))]
(displayln "Regenerate preproc & pmap files ...")
(require "regenerate.rkt" "pollen-file-tools.rkt")
(map regenerate (append-map project-files-with-ext (list POLLEN_PREPROC_EXT POLLEN_MAP_EXT))))]
[("clone") (let ([target-path
(if (> (len args) 1)
(->path (get args 1))

@ -7,7 +7,7 @@
(provide (all-defined-out))
; get the values out of the file, or make them up
(define pmap-file (build-path START_DIR DEFAULT_MAP))
(define pmap-file (build-path START_DIR DEFAULT_POLLEN_MAP))
(define pmap-main empty)
@ -35,12 +35,12 @@
;; xexpr with tag as name, parent as attr, children as elements with tag as next parent
(make-tagged-xexpr tag attr (map (λ(c) (add-parents c tag)) children)))]
;; single map entry: convert to xexpr with parent
[else (make-tagged-xexpr (->symbol x) (make-xexpr-attr 'parent (->string parent)))]))
[else (make-tagged-xexpr (->symbol x) (make-xexpr-attr POLLEN_MAP_PARENT_KEY (->string parent)))]))
(module+ test
(define test-pmap-main `(pmap-main "foo" "bar" (one (two "three"))))
(check-equal? (main->pmap test-pmap-main)
'(pmap-main ((parent "")) (foo ((parent "pmap-main"))) (bar ((parent "pmap-main"))) (one ((parent "pmap-main")) (two ((parent "one")) (three ((parent "two"))))))))
`(pmap-main ((,POLLEN_MAP_PARENT_KEY "")) (foo ((,POLLEN_MAP_PARENT_KEY "pmap-main"))) (bar ((,POLLEN_MAP_PARENT_KEY "pmap-main"))) (one ((,POLLEN_MAP_PARENT_KEY "pmap-main")) (two ((,POLLEN_MAP_PARENT_KEY "one")) (three ((,POLLEN_MAP_PARENT_KEY "two"))))))))
@ -62,15 +62,14 @@
(module+ test
(check-equal? (remove-parents
'(pmap-main ((parent "")) (foo ((parent ""))) (bar ((parent "")))
(one ((parent "")) (two ((parent "one")) (three ((parent "two")))))))
`(pmap-main ((,POLLEN_MAP_PARENT_KEY "")) (foo ((,POLLEN_MAP_PARENT_KEY ""))) (bar ((,POLLEN_MAP_PARENT_KEY ""))) (one ((,POLLEN_MAP_PARENT_KEY "")) (two ((,POLLEN_MAP_PARENT_KEY "one")) (three ((,POLLEN_MAP_PARENT_KEY "two")))))))
'(pmap-main (foo) (bar) (one (two (three))))))
(module+ test
(let ([sample-main `(pmap-root "foo" "bar" (one (two "three")))])
(check-equal? (main->pmap sample-main)
'(pmap-root ((parent "")) (foo ((parent "pmap-root"))) (bar ((parent "pmap-root"))) (one ((parent "pmap-root")) (two ((parent "one")) (three ((parent "two")))))))))
`(pmap-root ((,POLLEN_MAP_PARENT_KEY "")) (foo ((,POLLEN_MAP_PARENT_KEY "pmap-root"))) (bar ((,POLLEN_MAP_PARENT_KEY "pmap-root"))) (one ((,POLLEN_MAP_PARENT_KEY "pmap-root")) (two ((,POLLEN_MAP_PARENT_KEY "one")) (three ((,POLLEN_MAP_PARENT_KEY "two")))))))))

@ -7,6 +7,10 @@
(module+ test (require rackunit))
; helper functions for regenerate functions
(define pollen-file-root (current-directory))
;; does path have a certain extension
(define/contract (has-ext? path ext)
(path? symbol? . -> . boolean?)
@ -75,14 +79,15 @@
(check-not-equal? (remove-all-ext foo.bar.txt-path) foo.bar-path) ; removes more than one ext
(check-equal? (remove-all-ext foo.bar.txt-path) foo-path))
;; superfluous: use file-name-from-path in racket/path
(define/contract (filename-of path)
#|(define/contract (filename-of path)
(complete-path? . -> . path?)
(define-values (dir filename ignored) (split-path path))
filename)
(module+ test
(check-equal? (filename-of (build-path (current-directory) "pollen-file-tools.rkt")) (->path "pollen-file-tools.rkt")))
(check-equal? (filename-of (build-path (current-directory) "pollen-file-tools.rkt")) (->path "pollen-file-tools.rkt")))|#
(define/contract (preproc-source? x)
@ -129,3 +134,9 @@
(define/contract (make-pollen-source-path thing)
(path? . -> . path?)
(add-ext (remove-ext (->path thing)) POLLEN_SOURCE_EXT))
(define/contract (project-files-with-ext ext)
(symbol? . -> . (listof complete-path?))
(filter (λ(i) (has-ext? i ext)) (directory-list pollen-file-root)))
;; todo: write tests for project-files-with-ext

@ -69,60 +69,37 @@
; helper functions for regenerate functions
(define pollen-file-root (current-directory))
;(define pollen-file-root (current-directory))
; complete pollen path =
;(build-path pollen-file-root f)
;; regenerate with message
(define/contract (regenerate-path/message path)
(complete-path? . -> . void?)
(message "Regenerating: " path)
(regenerate path))
;; regenerate files listed in a pmap file
(define/contract (regenerate-with-pmap pmap)
(pmap? . -> . void?)
(for-each regenerate (all-pages pmap)))
;; todo: write test
;;;;;;;;;;;;;
;; todo next
(define/contract (regenerate-with-pmap/message pmap)
(pmap-source? . -> . void?)
(message "Regenerating pages from pollen map: " (filename-of pmap))
(for-each regenerate-path/message
(all-pages (dynamic-require pmap 'main))))
(define (get-pollen-files-with-ext ext)
(filter (λ(f) (has-ext? f ext)) (directory-list pollen-file-root)))
; burn all files
(define (regenerate-all-files)
(reset-mod-dates)
(define all-preproc-files (get-pollen-files-with-ext POLLEN_PREPROC_EXT))
(for-each regenerate-path/message all-preproc-files)
(define all-pollen-maps (get-pollen-files-with-ext POLLEN_MAP_EXT))
(for-each regenerate-with-pmap/message all-pollen-maps)
(displayln "Completed"))
(define (regenerate path #:force [force #f])
; dispatches path-in to the right place
;; dispatches path to the right place
(define/contract (regenerate path #:force [force #f])
(path? . -> . void?)
(regenerating-message path)
(let ([path (->complete-path path)])
(cond
[(pmap-source? path) (let ([pmap (dynamic-require path 'main)])
(regenerate-with-pmap pmap))]
[(needs-preproc? path) (do-preproc path #:force force)]
[(needs-template? path) (do-template path #:force force)]
[(pmap-source? path) (regenerate-with-pmap/message path)])))
[(needs-template? path) (do-template path #:force force)])))
;; todo: write test
(define (regenerate-message path)
(message "Regenerated:" (->string (file-name-from-path path))))
(define (regenerating-message path)
(message "Regenerating:" (->string (file-name-from-path path))))
(define (do-preproc path #:force [force #f])
; set up preproc-in-path & preproc-out-path values

@ -2,7 +2,6 @@
(define POLLEN_PREPROC_EXT 'pp)
(define POLLEN_SOURCE_EXT 'p)
(define POLLEN_MAP_EXT 'pmap)
(define TEMPLATE_FILE_PREFIX #\-)
(define POLLEN_EXPRESSION_DELIMITER #\◊)
(define TEMPLATE_FIELD_DELIMITER POLLEN_EXPRESSION_DELIMITER)
@ -10,7 +9,9 @@
(define DEFAULT_TEMPLATE "-main.html")
(define TEMPLATE_META_KEY 'template)
(define DEFAULT_MAP "main.pmap")
(define POLLEN_MAP_EXT 'pmap)
(define DEFAULT_POLLEN_MAP "main.pmap")
(define POLLEN_MAP_PARENT_KEY 'parent)
(define MAIN_POLLEN_EXPORT 'body)
;(define META_POLLEN_TAG 'metas)

Loading…
Cancel
Save