prevent caching of ptrees used as dashbaords

pull/9/head
Matthew Butterick 11 years ago
parent 91ff86327d
commit 5bb2e5bc19

@ -211,13 +211,6 @@
; or a file (e.g., html) that has a pollen source file ; or a file (e.g., html) that has a pollen source file
(ormap (λ(proc) (proc (->path x))) (list pollen-source? has-pollen-source?))) (ormap (λ(proc) (proc (->path x))) (list pollen-source? has-pollen-source?)))
(define/contract (ptree-source? x)
(any/c . -> . boolean?)
(has-ext? x PTREE_SOURCE_EXT))
(module+ test
(check-true (ptree-source? "foo.ptree"))
(check-false (ptree-source? "ptree.bar")))
(define/contract (pollen-source? x) (define/contract (pollen-source? x)

@ -1,10 +1,18 @@
#lang racket/base #lang racket/base
(require racket/contract racket/match xml/path racket/bool) (require racket/contract racket/match xml/path racket/bool racket/rerequire)
(require "tools.rkt" "world.rkt" "debug.rkt" "decode.rkt") (require "tools.rkt" "world.rkt" "debug.rkt" "decode.rkt")
(module+ test (require rackunit)) (module+ test (require rackunit))
(provide pnode? ptree? parent children previous next pnode->url ptree-source-decode path->pnode ptree->list file->ptree make-project-ptree current-ptree current-url-context) (provide pnode? ptree? ptree-source? parent children previous next pnode->url ptree-source-decode path->pnode ptree->list file->ptree make-project-ptree current-ptree current-url-context)
(define/contract (ptree-source? x)
(any/c . -> . boolean?)
((->path x) . has-ext? . PTREE_SOURCE_EXT))
(module+ test
(check-true (ptree-source? (format "foo.~a" PTREE_SOURCE_EXT)))
(check-false (ptree-source? (format "~a.foo" PTREE_SOURCE_EXT))))
(define/contract (pnode? x) (define/contract (pnode? x)
(any/c . -> . boolean?) (any/c . -> . boolean?)
@ -48,6 +56,7 @@
(pathish? . -> . ptree?) (pathish? . -> . ptree?)
(define path (->path p)) (define path (->path p))
(message "Loading ptree file" (->string (file-name-from-path path))) (message "Loading ptree file" (->string (file-name-from-path path)))
(dynamic-rerequire path)
(dynamic-require path MAIN_POLLEN_EXPORT)) (dynamic-require path MAIN_POLLEN_EXPORT))
(define/contract (directory->ptree dir) (define/contract (directory->ptree dir)

@ -116,7 +116,7 @@
;; and files without extension that correspond to p files ;; and files without extension that correspond to p files
[(needs-template? path) (render-with-template path #:force force)] [(needs-template? path) (render-with-template path #:force force)]
;; this will catch ptree files ;; this will catch ptree files
[(ptree-source? path) (let ([ptree (dynamic-require path 'main)]) [(report (ptree-source? path)) (let ([ptree (dynamic-require path 'main)])
(render-files-in-ptree ptree #:force force))] (render-files-in-ptree ptree #:force force))]
[(equal? FALLBACK_TEMPLATE (->string (file-name-from-path path))) [(equal? FALLBACK_TEMPLATE (->string (file-name-from-path path)))
(message "Render: using fallback template")] (message "Render: using fallback template")]
@ -363,7 +363,7 @@
(define/contract (render-files-in-ptree ptree #:force [force #f]) (define/contract (render-files-in-ptree ptree #:force [force #f])
((ptree?) (#:force boolean?) . ->* . void?) ((ptree?) (#:force boolean?) . ->* . void?)
;; pass force parameter through ;; pass force parameter through
(for-each (λ(i) (render i #:force force)) (for-each (λ(i) (render (report i) #:force force))
;; use dynamic-require to avoid requiring ptree.rkt every time render.rkt is required ;; use dynamic-require to avoid requiring ptree.rkt every time render.rkt is required
((dynamic-require "ptree.rkt" 'all-pages) ptree))) ((dynamic-require "ptree.rkt" 'all-pages) ptree)))

@ -18,10 +18,10 @@
(define (body-wrapper content-xexpr) (define (body-wrapper content-xexpr)
`(html `(html
(head (head
(meta ((charset "UTF-8"))) (meta ([charset "UTF-8"]))
(link ((rel "stylesheet") (link ([rel "stylesheet"]
(type "text/css") [type "text/css"]
(href ,(format "/~a" DASHBOARD_CSS))))) [href ,(format "/~a" DASHBOARD_CSS)])))
(body (body
,content-xexpr (div ((id "pollen-logo")))))) ,content-xexpr (div ((id "pollen-logo"))))))
@ -174,12 +174,12 @@
(cond ; in cell (cond ; in cell
[source (cons (format "in/~a" source) "in")] [source (cons (format "in/~a" source) "in")]
[(or (has-ext? filename PTREE_SOURCE_EXT) (sourceish? filename)) (cons (format "in/~a" filename) "in")] [(or (ptree-source? filename) (sourceish? filename)) (cons (format "in/~a" filename) "in")]
[else empty-cell]) [else empty-cell])
(cond ; out cell (cond ; out cell
[(directory-exists? (build-path dir filename)) (cons #f #f)] [(directory-exists? (build-path dir filename)) (cons #f #f)]
[(has-ext? filename PTREE_SOURCE_EXT) empty-cell] [(ptree-source? filename) empty-cell]
[else (cons (format "out/~a" filename) "out")])))))) [else (cons (format "out/~a" filename) "out")]))))))
(define (ineligible-path? x) (or (not (visible? x)) (member x RESERVED_PATHS))) (define (ineligible-path? x) (or (not (visible? x)) (member x RESERVED_PATHS)))
@ -188,12 +188,14 @@
(define output-paths (map ->output-path xs)) (define output-paths (map ->output-path xs))
(define (unique-members xs) (set->list (list->set xs))) (define (unique-members xs) (set->list (list->set xs)))
(define all-paths (unique-members output-paths)) (define all-paths (unique-members output-paths))
(define built-directory-exists? (λ(f) (directory-exists? (build-path dir f)))) (define path-is-directory? (λ(f) (directory-exists? (build-path dir f))))
(define subdirectories (filter built-directory-exists? all-paths)) (define subdirectories (filter path-is-directory? all-paths))
(define files (filter-not built-directory-exists? all-paths)) (define files (filter-not path-is-directory? all-paths))
(define ptree-sources (filter ptree-source? files))
(define other-files (filter-not ptree-source? files))
(define (sort-names xs) (sort xs #:key ->string string<?)) (define (sort-names xs) (sort xs #:key ->string string<?))
;; put subdirs in list ahead of files (so they appear at the top) ;; put subdirs in list ahead of files (so they appear at the top)
(append (sort-names subdirectories) (sort-names files))) (append (sort-names subdirectories) (sort-names ptree-sources) (sort-names other-files)))
(define project-paths (filter-not ineligible-path? (if (file-exists? dashfile) (define project-paths (filter-not ineligible-path? (if (file-exists? dashfile)
(map ->path (ptree->list (file->ptree dashfile))) (map ->path (ptree->list (file->ptree dashfile)))

Loading…
Cancel
Save