working mostly

pull/9/head
Matthew Butterick 10 years ago
parent e8fc8db202
commit a7e6bcc73f

@ -7,6 +7,19 @@
(provide (except-out (all-defined-out) decode register-block-tag)) (provide (except-out (all-defined-out) decode register-block-tag))
;; general way of coercing to string
(define (to-string x)
(if (string? x)
x ; fast exit for strings
(with-handlers ([exn:fail? (λ(exn) (error "Can't convert ~a to ~a" x 'string))])
(cond
[(equal? '() x) ""]
[(symbol? x) (symbol->string x)]
[(number? x) (number->string x)]
[(path? x) (path->string x)]
[(char? x) (format "~a" x)]
[else (error)])))) ; put this last so other xexprish things don't get caught
;; add a block tag to the list ;; add a block tag to the list
;; this function is among the predicates because it alters a predicate globally. ;; this function is among the predicates because it alters a predicate globally.

@ -5,6 +5,8 @@
(provide (all-defined-out) (all-from-out racket/contract/region)) (provide (all-defined-out) (all-from-out racket/contract/region))
(define-for-syntax (put-file-in-require-form file) (define-for-syntax (put-file-in-require-form file)
`(file ,(path->string file))) `(file ,(path->string file)))

@ -44,7 +44,6 @@
;; set up the 'main export ;; set up the 'main export
(require pollen/decode) (require pollen/decode)
(require (only-in racket/list filter-not)) (require (only-in racket/list filter-not))
@ -57,8 +56,8 @@
;; 'root is the hook for the decoder function. ;; 'root is the hook for the decoder function.
;; If it's not a defined identifier, it just hits #%top and becomes `(root ,@body ...) ;; If it's not a defined identifier, it just hits #%top and becomes `(root ,@body ...)
[wants-decoder? root] [wants-decoder? root]
;; for preprocessor output, just make a string. Converts x-expressions to HTML. ;; for preprocessor output, just make a string.
[else (λ xs (apply string-append (map (dynamic-require 'xml 'xexpr->string) xs)))]) [else (λ xs (apply string-append (map to-string xs)))])
(cdr main-without-metas))) ;; cdr strips placeholder-root tag (cdr main-without-metas))) ;; cdr strips placeholder-root tag

@ -233,10 +233,12 @@
(list (list
;; path based on template-name ;; path based on template-name
(and template-name (build-path source-dir template-name)) (and template-name (build-path source-dir template-name))
;; path based on metas ;; path based on metas. Need to parameterize a source file for it to find pollen-requires.
;; If you want standard behavior, requires can be declared explicitly.
(parameterize ([current-directory PROJECT_ROOT])
(let ([source-metas (dynamic-require source-path 'metas)]) (let ([source-metas (dynamic-require source-path 'metas)])
(and (TEMPLATE_META_KEY . in? . source-metas) (and (TEMPLATE_META_KEY . in? . source-metas)
(build-path source-dir (get source-metas TEMPLATE_META_KEY)))) (build-path source-dir (get source-metas TEMPLATE_META_KEY)))))
;; path using default template name = ;; path using default template name =
;; "-main" + extension from output path (e.g. foo.xml.p -> -main.xml) ;; "-main" + extension from output path (e.g. foo.xml.p -> -main.xml)
(build-path source-dir (add-ext DEFAULT_TEMPLATE_PREFIX (get-ext (->output-path source-path))))))) (build-path source-dir (add-ext DEFAULT_TEMPLATE_PREFIX (get-ext (->output-path source-path)))))))
@ -278,14 +280,16 @@
;; cache some modules inside this namespace so they can be shared by namespace for eval ;; cache some modules inside this namespace so they can be shared by namespace for eval
;; todo: macrofy this to avoid repeating names ;; todo: macrofy this to avoid repeating names
(require web-server/templates (require web-server/templates
xml/path
racket/port
racket/file
racket/rerequire
racket/contract
racket/list racket/list
xml/path xml/path
pollen/debug pollen/debug
pollen/decode pollen/decode
pollen/file-tools pollen/file-tools
;; commented out so we don't get #%top in this file
; pollen/main-imports
; pollen/main-preproc-imports
pollen/predicates pollen/predicates
pollen/ptree pollen/ptree
sugar sugar
@ -315,15 +319,15 @@
pollen/debug pollen/debug
pollen/decode pollen/decode
pollen/file-tools pollen/file-tools
; pollen/main-imports
; pollen/main-preproc-imports
pollen/predicates pollen/predicates
pollen/ptree pollen/ptree
sugar sugar
pollen/template pollen/template
pollen/tools pollen/tools
pollen/world)) pollen/world
pollen/project-requires))
(namespace-require 'racket/base) ; use namespace-require for FIRST require, then eval after (namespace-require 'racket/base) ; use namespace-require for FIRST require, then eval after
(eval eval-string (current-namespace)))) (eval eval-string (current-namespace))))
(define/contract (render-source-with-template source-path template-path) (define/contract (render-source-with-template source-path template-path)
@ -340,6 +344,8 @@
(define string-to-eval (define string-to-eval
`(begin `(begin
;; enables macrofication
(require (for-syntax racket/base))
;; for include-template (used below) ;; for include-template (used below)
(require web-server/templates) (require web-server/templates)
;; for ptree navigation functions, and template commands ;; for ptree navigation functions, and template commands

Loading…
Cancel
Save