studying reload, better

pull/9/head
Matthew Butterick 11 years ago
parent 455f52083b
commit 1d2d1cd416

@ -69,11 +69,23 @@
(file-proc source-or-output-path)) (file-proc source-or-output-path))
(define (project-requires-changed?)
(define changed? (ormap file-needs-rerequire? (get-project-require-files)))
(when changed?
(begin
(message "render: project requires have changed, resetting cache")
(current-cache (make-cache))
;; also need to dirty up the mod-dates table so existing files are deemed invalid
(reset-modification-dates)))
changed?)
(define/contract (render-needed? source-path template-path output-path) (define/contract (render-needed? source-path template-path output-path)
(complete-path? (or/c #f complete-path?) complete-path? . -> . boolean?) (complete-path? (or/c #f complete-path?) complete-path? . -> . boolean?)
(or (not (file-exists? output-path)) (or (not (file-exists? output-path))
(modification-date-expired? source-path template-path) (report (modification-date-expired? source-path template-path))
(and (not (null-source? source-path)) (source-needs-rerequire? source-path)))) (and (not (null-source? source-path)) (file-needs-rerequire? source-path))
(project-requires-changed?)))
(define/contract+provide (render-to-file-if-needed source-or-output-path #:force [force #f]) (define/contract+provide (render-to-file-if-needed source-or-output-path #:force [force #f])
@ -124,6 +136,7 @@
(define template-path (or maybe-template-path (get-template-for source-path))) (define template-path (or maybe-template-path (get-template-for source-path)))
(render-for-dev-server template-path) ; because template might have its own preprocessor source (render-for-dev-server template-path) ; because template might have its own preprocessor source
(define expr-to-eval (define expr-to-eval
`(begin `(begin
(require (for-syntax racket/base)) (require (for-syntax racket/base))
@ -161,7 +174,7 @@
(build-path (world:current-server-extras-path) world:fallback-template)))) ; fallback template (build-path (world:current-server-extras-path) world:fallback-template)))) ; fallback template
(define/contract (source-needs-rerequire? source-path) (define/contract (file-needs-rerequire? source-path)
(complete-path? . -> . boolean?) (complete-path? . -> . boolean?)
(define-values (source-dir source-name _) (split-path source-path)) (define-values (source-dir source-name _) (split-path source-path))
;; use dynamic-rerequire now to force render for cached-require later, ;; use dynamic-rerequire now to force render for cached-require later,
@ -177,6 +190,8 @@
;; cache some modules to speed up eval. ;; cache some modules to speed up eval.
;; Do it in separate module so as not to pollute this one. ;; Do it in separate module so as not to pollute this one.
;; todo: macrofy these lists of modules ;; todo: macrofy these lists of modules
;; Don't, however, put the project-requires here,
;; because they will no longer be subject to rerequire.
(module my-module-cache racket/base (module my-module-cache racket/base
(require web-server/templates (require web-server/templates
xml xml
@ -200,7 +215,6 @@
pollen/tools pollen/tools
pollen/world pollen/world
pollen/project-requires) pollen/project-requires)
(require-project-require-files)
(define-namespace-anchor my-module-cache-ns-anchor) (define-namespace-anchor my-module-cache-ns-anchor)
(provide my-module-cache-ns-anchor)) (provide my-module-cache-ns-anchor))
@ -235,6 +249,5 @@
pollen/template pollen/template
pollen/tools pollen/tools
pollen/world pollen/world
pollen/project-requires pollen/project-requires))
,@(get-project-require-files)))
(string->bytes/utf-8 (eval expr-to-eval (current-namespace))))) (string->bytes/utf-8 (eval expr-to-eval (current-namespace)))))
Loading…
Cancel
Save