repair handling of source files without extensions (fixes #130)

pull/131/head
Matthew Butterick 8 years ago
parent 45300dbef6
commit a633eac8df

@ -1 +1 @@
1475977524
1475981471

@ -120,7 +120,10 @@
(define template-path (or maybe-template-path (get-template-for source-path output-path)))
(message (format "rendering: /~a as /~a" (find-relative-path (current-project-root) source-path)
(find-relative-path (current-project-root) output-path)))
(define render-result (parameterize ([current-poly-target (->symbol (get-ext output-path))])
;; output-path and template-path may not have an extension, so check them in order with fallback
(define render-result (parameterize ([current-poly-target (->symbol (or (get-ext output-path)
(and template-path (get-ext template-path))
(current-poly-target)))])
(apply render-proc (list source-path template-path output-path))))
;; wait till last possible moment to store mod dates, because render-proc may also trigger its own subrenders
;; e.g., of a template.
@ -210,7 +213,7 @@
(define (get-template)
(define source-dir (dirname source-path))
(define output-path (or maybe-output-path (->output-path source-path)))
(define output-path-ext (get-ext output-path))
(define output-path-ext (or (get-ext output-path) (current-poly-target))) ; output-path may not have an extension
(define (get-template-from-metas)
(with-handlers ([exn:fail:contract? (λ _ #f)]) ; in case source-path doesn't work with cached-require
(parameterize ([current-directory (current-project-root)])

@ -0,0 +1,4 @@
#lang pollen
test
====

@ -0,0 +1,4 @@
#lang pollen
test
====

@ -1,5 +1,10 @@
#lang at-exp racket/base
(require rackunit racket/port racket/system racket/runtime-path compiler/find-exe)
(require rackunit
racket/port
racket/system
racket/runtime-path
compiler/find-exe
pollen/render)
(module test-default pollen
"hello world")
@ -38,6 +43,8 @@
(define-runtime-path test.html.pmd "data/test.html.pmd")
(define-runtime-path test.html.pp "data/test.html.pp")
(define-runtime-path test.no-ext "data/test.no-ext")
(define-runtime-path test.pp "data/test.pp")
(define-runtime-path test.pm "data/test.pm")
;; `find-exe` avoids reliance on $PATH of the host system
@ -51,4 +58,11 @@
(check-equal? (run test-import.html.pm) @string-append{'(root "test" "\n" "====" "\n" (root "This is sample 01."))})
(check-equal? (run test.html.pmd) "'(root (h1 ((id \"test\")) \"test\"))")
(check-equal? (run test.html.pp) "test\n====")
(check-equal? (run test.no-ext) "test\n===="))
(check-equal? (run test.no-ext) "test\n====")
(check-equal? (run test.pm) "'(root \"test\" \"\\n\" \"====\")")
(check-equal? (run test.pp) "test\n====")
(check-equal? (render test.html.pm) "<html><head><meta charset=\"UTF-8\"/></head><body><root>test\n====</root></body></html>")
(check-equal? (render test.html.pmd) "<html><head><meta charset=\"UTF-8\"/></head><body><root><h1 id=\"test\">test</h1></root></body></html>")
(check-equal? (render test.html.pp) "test\n====")
(check-equal? (render test.pm) "<html><head><meta charset=\"UTF-8\"/></head><body><root>test\n====</root></body></html>")
(check-equal? (render test.pp) "test\n===="))

Loading…
Cancel
Save