From c6a0a7c41d3874f27e1230a58678a17aa3de655e Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Thu, 6 Feb 2014 17:47:28 -0800 Subject: [PATCH] Revert "Revert "prevent caching of ptrees used as dashbaords"" This reverts commit b972f262d037fd410267bdf9334e501b9de769eb. --- file-tools.rkt | 7 ------- ptree.rkt | 13 +++++++++++-- render.rkt | 4 ++-- server-routes.rkt | 22 ++++++++++++---------- 4 files changed, 25 insertions(+), 21 deletions(-) diff --git a/file-tools.rkt b/file-tools.rkt index c1b663e..74fa7a5 100644 --- a/file-tools.rkt +++ b/file-tools.rkt @@ -211,13 +211,6 @@ ; or a file (e.g., html) that has a pollen source file (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) diff --git a/ptree.rkt b/ptree.rkt index 27c2b51..471ab9a 100644 --- a/ptree.rkt +++ b/ptree.rkt @@ -1,10 +1,18 @@ #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") (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) (any/c . -> . boolean?) @@ -48,6 +56,7 @@ (pathish? . -> . ptree?) (define path (->path p)) (message "Loading ptree file" (->string (file-name-from-path path))) + (dynamic-rerequire path) (dynamic-require path MAIN_POLLEN_EXPORT)) (define/contract (directory->ptree dir) diff --git a/render.rkt b/render.rkt index 4decf7f..fc96907 100644 --- a/render.rkt +++ b/render.rkt @@ -116,7 +116,7 @@ ;; and files without extension that correspond to p files [(needs-template? path) (render-with-template path #:force force)] ;; 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))] [(equal? FALLBACK_TEMPLATE (->string (file-name-from-path path))) (message "Render: using fallback template")] @@ -363,7 +363,7 @@ (define/contract (render-files-in-ptree ptree #:force [force #f]) ((ptree?) (#:force boolean?) . ->* . void?) ;; 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 ((dynamic-require "ptree.rkt" 'all-pages) ptree))) diff --git a/server-routes.rkt b/server-routes.rkt index 4a12535..25a61d1 100644 --- a/server-routes.rkt +++ b/server-routes.rkt @@ -18,10 +18,10 @@ (define (body-wrapper content-xexpr) `(html (head - (meta ((charset "UTF-8"))) - (link ((rel "stylesheet") - (type "text/css") - (href ,(format "/~a" DASHBOARD_CSS))))) + (meta ([charset "UTF-8"])) + (link ([rel "stylesheet"] + [type "text/css"] + [href ,(format "/~a" DASHBOARD_CSS)]))) (body ,content-xexpr (div ((id "pollen-logo")))))) @@ -174,12 +174,12 @@ (cond ; in cell [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]) (cond ; out cell [(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")])))))) (define (ineligible-path? x) (or (not (visible? x)) (member x RESERVED_PATHS))) @@ -188,12 +188,14 @@ (define output-paths (map ->output-path xs)) (define (unique-members xs) (set->list (list->set xs))) (define all-paths (unique-members output-paths)) - (define built-directory-exists? (λ(f) (directory-exists? (build-path dir f)))) - (define subdirectories (filter built-directory-exists? all-paths)) - (define files (filter-not built-directory-exists? all-paths)) + (define path-is-directory? (λ(f) (directory-exists? (build-path dir f)))) + (define subdirectories (filter path-is-directory? 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 stringpath (ptree->list (file->ptree dashfile)))