From a633eac8dfd3d5f9161ac4db0bcb738d266d09a7 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Sat, 8 Oct 2016 19:51:11 -0700 Subject: [PATCH] repair handling of source files without extensions (fixes #130) --- pollen/private/ts.rktd | 2 +- pollen/render.rkt | 7 +++++-- pollen/test/data/test.pm | 4 ++++ pollen/test/data/test.pp | 4 ++++ pollen/test/test-langs.rkt | 18 ++++++++++++++++-- 5 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 pollen/test/data/test.pm create mode 100644 pollen/test/data/test.pp diff --git a/pollen/private/ts.rktd b/pollen/private/ts.rktd index 0bb44fa..44d437e 100644 --- a/pollen/private/ts.rktd +++ b/pollen/private/ts.rktd @@ -1 +1 @@ -1475977524 +1475981471 diff --git a/pollen/render.rkt b/pollen/render.rkt index cc0af7c..b12f5c4 100644 --- a/pollen/render.rkt +++ b/pollen/render.rkt @@ -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)]) diff --git a/pollen/test/data/test.pm b/pollen/test/data/test.pm new file mode 100644 index 0000000..4cec105 --- /dev/null +++ b/pollen/test/data/test.pm @@ -0,0 +1,4 @@ +#lang pollen + +test +==== \ No newline at end of file diff --git a/pollen/test/data/test.pp b/pollen/test/data/test.pp new file mode 100644 index 0000000..4cec105 --- /dev/null +++ b/pollen/test/data/test.pp @@ -0,0 +1,4 @@ +#lang pollen + +test +==== \ No newline at end of file diff --git a/pollen/test/test-langs.rkt b/pollen/test/test-langs.rkt index ada1e48..e1c22ef 100644 --- a/pollen/test/test-langs.rkt +++ b/pollen/test/test-langs.rkt @@ -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) "test\n====") + (check-equal? (render test.html.pmd) "

test

") + (check-equal? (render test.html.pp) "test\n====") + (check-equal? (render test.pm) "test\n====") + (check-equal? (render test.pp) "test\n===="))