improvements

pull/9/head
Matthew Butterick 11 years ago
parent 7c138d2915
commit 41178c8587

@ -1,7 +1,7 @@
#lang racket/base #lang racket/base
(require (for-syntax racket/base)) (require (for-syntax racket/base))
(require racket/port racket/file racket/rerequire racket/path) (require racket/port racket/file racket/rerequire racket/path racket/list racket/match)
(require sugar) (require sugar "file-tools.rkt" "cache.rkt" "world.rkt" "debug.rkt" "ptree.rkt" "project-requires.rkt")
(module+ test (require rackunit)) (module+ test (require rackunit))
@ -203,36 +203,39 @@
(let ([ft-path (build-path source-dir world:fallback-template)]) ; delete fallback template if needed (let ([ft-path (build-path source-dir world:fallback-template)]) ; delete fallback template if needed
(when (file-exists? ft-path) (delete-file ft-path)))) (when (file-exists? ft-path) (delete-file ft-path))))
;; cache some modules inside this namespace so they can be shared by namespace for eval ;; cache some modules inside a separate namespace
;; todo: macrofy this to avoid repeating names ;; to speed up for eval
(require web-server/templates
xml (module my-module-cache racket/base
racket/port (require web-server/templates
racket/file xml
racket/rerequire racket/port
racket/contract racket/file
racket/list racket/rerequire
racket/match racket/contract
pollen/debug racket/list
pollen/decode racket/match
;; pollen/file-tools pollen/debug
;; not pollen/main, because it brings in pollen/top pollen/decode
pollen/lang/inner-lang-helper pollen/file-tools
pollen/predicates ;; exports file-tools pollen/main
pollen/ptree pollen/lang/inner-lang-helper
pollen/cache pollen/predicates
sugar pollen/ptree
txexpr pollen/cache
pollen/template sugar
pollen/tools txexpr
;; not pollen/top, because we don't want it in the current ns pollen/template
pollen/world pollen/tools
pollen/project-requires) pollen/world
;; cache project requires in this ns. pollen/project-requires)
;; This means changes to project requires require server restart. (require-project-require-files)
;; But this seems mandatory anyhow because no dynamic-rerequire for whole module. (define-namespace-anchor my-module-cache-ns-anchor)
(require-project-require-files) (provide my-module-cache-ns-anchor))
(define original-ns (current-namespace))
(require 'my-module-cache)
(define cache-ns (namespace-anchor->namespace my-module-cache-ns-anchor))
(define (render-through-eval base-dir eval-string) (define (render-through-eval base-dir eval-string)
(parameterize ([current-namespace (make-base-namespace)] (parameterize ([current-namespace (make-base-namespace)]
@ -240,7 +243,7 @@
[current-output-port (current-error-port)] [current-output-port (current-error-port)]
[current-ptree (make-project-ptree (world:current-project-root))] [current-ptree (make-project-ptree (world:current-project-root))]
[current-url-context (world:current-project-root)]) [current-url-context (world:current-project-root)])
(for-each (λ(mod-name) (namespace-attach-module original-ns mod-name)) (for-each (λ(mod-name) (namespace-attach-module cache-ns mod-name))
`(web-server/templates `(web-server/templates
xml xml
racket/port racket/port
@ -297,10 +300,10 @@
(render (render
(string->path "/Users/mb/git/bpt/test.html.pm") (string->path "/Users/mb/git/bpt/test.html.pm")
))) )))
|# |#
(define (render-files-in-ptree ptree #:force [force #f]) (define (render-files-in-ptree ptree #:force [force #f])
(for-each (λ(i) (render i #:force force)) (for-each (λ(i) (render i #:force force))
((cached-require "ptree.rkt" 'all-pages) ptree))) ((cached-require "ptree.rkt" 'all-pages) ptree)))

Loading…
Cancel
Save