working on polcom render

pull/9/head
Matthew Butterick 11 years ago
parent 9d90846b96
commit cd614ce11e

@ -9,6 +9,20 @@ render renders all files in project directory
clone copies rendered files to desktop
[filename] renders individual file"))
(define (handle-render dir-or-path [port #f])
`(begin
(require pollen/render pollen/world pollen/file sugar)
(parameterize ([current-directory (world:current-project-root)])
(define dir-or-path ,dir-or-path)
(apply render-batch (map ->complete-path (if (not (directory-exists? dir-or-path))
(begin
(displayln (format "Rendering ~a" dir-or-path))
(list dir-or-path))
(begin
(displayln (format "Rendering preproc & pagetree files in directory ~a" dir-or-path)
(apply append (map (λ(proc) (filter proc (directory-list dir-or-path))) (list preproc-source? pagetree-source?)))))))))))
(define (handle-start directory [port #f])
(if (not (directory-exists? directory))
(error (format "~a is not a directory" directory))

@ -25,6 +25,7 @@
(case arg-command-name
[(#f "help") (handle-help)]
[("start") (handle-start arg-project-directory arg-server-port)]
[("render") (handle-render (vector-ref args 1))]
[else (handle-else arg-command-name)])))
(select-syntax-for-command)

@ -46,7 +46,9 @@
;; And with render, they would be rendered repeatedly.
;; Using reset-modification-dates is sort of like session control.
(reset-modification-dates)
(for-each render-to-file-if-needed xs))
(for-each (λ(x) ((if (pagetree-source? x)
render-pagetree
render-to-file-if-needed) x)) xs))
(define/contract+provide (render-pagetree pagetree-or-path)
@ -54,10 +56,11 @@
(define pagetree (if (pagetree? pagetree-or-path)
pagetree-or-path
(cached-require pagetree-or-path world:main-pollen-export)))
(apply render-batch (pagetree->list pagetree)))
(parameterize ([current-directory (world:current-project-root)])
(for-each render-from-source-or-output-path (map ->complete-path (pagetree->list pagetree)))))
(define/contract+provide (render-for-dev-server so-pathish #:force [force #f])
(define/contract+provide (render-from-source-or-output-path so-pathish #:force [force #f])
((pathish?) (#:force boolean?) . ->* . void?)
(let ([so-path (->complete-path so-pathish)]) ; so-path = source or output path (could be either)
(cond
@ -155,7 +158,7 @@
((complete-path?) ((or/c #f complete-path?)) . ->* . bytes?)
(match-define-values (source-dir _ _) (split-path 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-from-source-or-output-path template-path) ; because template might have its own preprocessor source
(define expr-to-eval
`(begin
(require (for-syntax racket/base))

@ -55,7 +55,7 @@
;; extract main xexpr from a path
(define/contract (file->xexpr path #:render [wants-render #t])
((complete-path?) (#:render boolean?) . ->* . txexpr?)
(when wants-render (render-for-dev-server path))
(when wants-render (render-from-source-or-output-path path))
(dynamic-rerequire path) ; stores module mod date; reloads if it's changed
(dynamic-require path world:main-pollen-export))
@ -67,7 +67,7 @@
;; just file->string with a render option
(define/contract (slurp path #:render [wants-render #t])
((complete-path?) (#:render boolean?) . ->* . string?)
(when wants-render (render-for-dev-server path))
(when wants-render (render-from-source-or-output-path path))
(file->string path))
@ -226,7 +226,7 @@
(define (route-default req)
(logger req)
(define force (equal? (get-query-value (request-uri req) 'force) "true"))
(render-for-dev-server (req->path req) #:force force)
(render-from-source-or-output-path (req->path req) #:force force)
(next-dispatcher))

Loading…
Cancel
Save