working on regenerate

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

@ -9,9 +9,9 @@
(case arg (case arg
[("serve") `(require "server.rkt")] [("serve") `(require "server.rkt")]
[("regenerate") `(begin [("regenerate") `(begin
(displayln "Regenerate all...") (displayln "Regenerate preproc & pmap files ...")
(require "regenerate.rkt") (require "regenerate.rkt" "pollen-file-tools.rkt")
(regenerate-all-files))] (map regenerate (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))

@ -7,7 +7,7 @@
(provide (all-defined-out)) (provide (all-defined-out))
; get the values out of the file, or make them up ; 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) (define pmap-main empty)
@ -35,12 +35,12 @@
;; xexpr with tag as name, parent as attr, children as elements with tag as next parent ;; 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)))] (make-tagged-xexpr tag attr (map (λ(c) (add-parents c tag)) children)))]
;; single map entry: convert to xexpr with parent ;; 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 (module+ test
(define test-pmap-main `(pmap-main "foo" "bar" (one (two "three")))) (define test-pmap-main `(pmap-main "foo" "bar" (one (two "three"))))
(check-equal? (main->pmap test-pmap-main) (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 (module+ test
(check-equal? (remove-parents (check-equal? (remove-parents
'(pmap-main ((parent "")) (foo ((parent ""))) (bar ((parent ""))) `(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")))))))
(one ((parent "")) (two ((parent "one")) (three ((parent "two")))))))
'(pmap-main (foo) (bar) (one (two (three)))))) '(pmap-main (foo) (bar) (one (two (three))))))
(module+ test (module+ test
(let ([sample-main `(pmap-root "foo" "bar" (one (two "three")))]) (let ([sample-main `(pmap-root "foo" "bar" (one (two "three")))])
(check-equal? (main->pmap sample-main) (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)) (module+ test (require rackunit))
; helper functions for regenerate functions
(define pollen-file-root (current-directory))
;; does path have a certain extension ;; does path have a certain extension
(define/contract (has-ext? path ext) (define/contract (has-ext? path ext)
(path? symbol? . -> . boolean?) (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-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)) (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?) (complete-path? . -> . path?)
(define-values (dir filename ignored) (split-path path)) (define-values (dir filename ignored) (split-path path))
filename) filename)
(module+ test (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) (define/contract (preproc-source? x)
@ -129,3 +134,9 @@
(define/contract (make-pollen-source-path thing) (define/contract (make-pollen-source-path thing)
(path? . -> . path?) (path? . -> . path?)
(add-ext (remove-ext (->path thing)) POLLEN_SOURCE_EXT)) (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 ; helper functions for regenerate functions
(define pollen-file-root (current-directory)) ;(define pollen-file-root (current-directory))
; complete pollen path = ; complete pollen path =
;(build-path pollen-file-root f) ;(build-path pollen-file-root f)
;; regenerate with message ;; regenerate files listed in a pmap file
(define/contract (regenerate-path/message path) (define/contract (regenerate-with-pmap pmap)
(complete-path? . -> . void?) (pmap? . -> . void?)
(message "Regenerating: " path) (for-each regenerate (all-pages pmap)))
(regenerate path))
;; todo: write test ;; todo: write test
;;;;;;;;;;;;;
;; todo next
(define/contract (regenerate-with-pmap/message pmap) ;; dispatches path to the right place
(pmap-source? . -> . void?) (define/contract (regenerate path #:force [force #f])
(message "Regenerating pages from pollen map: " (filename-of pmap)) (path? . -> . void?)
(for-each regenerate-path/message (regenerating-message path)
(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
(let ([path (->complete-path path)]) (let ([path (->complete-path path)])
(cond (cond
[(pmap-source? path) (let ([pmap (dynamic-require path 'main)])
(regenerate-with-pmap pmap))]
[(needs-preproc? path) (do-preproc path #:force force)] [(needs-preproc? path) (do-preproc path #:force force)]
[(needs-template? path) (do-template path #:force force)] [(needs-template? path) (do-template path #:force force)])))
[(pmap-source? path) (regenerate-with-pmap/message path)])))
;; todo: write test
(define (regenerate-message path) (define (regenerating-message path)
(message "Regenerated:" (->string (file-name-from-path path)))) (message "Regenerating:" (->string (file-name-from-path path))))
(define (do-preproc path #:force [force #f]) (define (do-preproc path #:force [force #f])
; set up preproc-in-path & preproc-out-path values ; set up preproc-in-path & preproc-out-path values

@ -2,7 +2,6 @@
(define POLLEN_PREPROC_EXT 'pp) (define POLLEN_PREPROC_EXT 'pp)
(define POLLEN_SOURCE_EXT 'p) (define POLLEN_SOURCE_EXT 'p)
(define POLLEN_MAP_EXT 'pmap)
(define TEMPLATE_FILE_PREFIX #\-) (define TEMPLATE_FILE_PREFIX #\-)
(define POLLEN_EXPRESSION_DELIMITER #\◊) (define POLLEN_EXPRESSION_DELIMITER #\◊)
(define TEMPLATE_FIELD_DELIMITER POLLEN_EXPRESSION_DELIMITER) (define TEMPLATE_FIELD_DELIMITER POLLEN_EXPRESSION_DELIMITER)
@ -10,7 +9,9 @@
(define DEFAULT_TEMPLATE "-main.html") (define DEFAULT_TEMPLATE "-main.html")
(define TEMPLATE_META_KEY 'template) (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 MAIN_POLLEN_EXPORT 'body)
;(define META_POLLEN_TAG 'metas) ;(define META_POLLEN_TAG 'metas)

Loading…
Cancel
Save