From 6e41ca303338f33e4f8be1d32c0fe2936b340623 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Tue, 30 Oct 2018 12:00:50 -0700 Subject: [PATCH] move to external --- pollen/private/{ => external}/doclang-raw.rkt | 0 pollen/private/external/include-template.rkt | 34 +++++++++++++++++++ .../private/{ => external}/manual-history.rkt | 0 .../{ => external}/mode-indentation.rkt | 0 pollen/private/{ => external}/pipe.py | 0 pollen/private/include-template.rkt | 33 ------------------ 6 files changed, 34 insertions(+), 33 deletions(-) rename pollen/private/{ => external}/doclang-raw.rkt (100%) create mode 100644 pollen/private/external/include-template.rkt rename pollen/private/{ => external}/manual-history.rkt (100%) rename pollen/private/{ => external}/mode-indentation.rkt (100%) rename pollen/private/{ => external}/pipe.py (100%) delete mode 100644 pollen/private/include-template.rkt diff --git a/pollen/private/doclang-raw.rkt b/pollen/private/external/doclang-raw.rkt similarity index 100% rename from pollen/private/doclang-raw.rkt rename to pollen/private/external/doclang-raw.rkt diff --git a/pollen/private/external/include-template.rkt b/pollen/private/external/include-template.rkt new file mode 100644 index 0000000..d71bce8 --- /dev/null +++ b/pollen/private/external/include-template.rkt @@ -0,0 +1,34 @@ +#lang racket/base +(require (for-syntax racket/base + racket/list + syntax/parse) + (only-in scribble/text/syntax-utils include/text) + (only-in "output.rkt" output) + racket/match + racket/port) + +(provide include-template) + +;; Adaptation of function in web-server/templates library +;; to check for binary result and pass it through. +;; Actually patches underlying bug in `output`. + +(define (finish result) + (match result + [(? bytes? bs) bs] + ;; list of expressions with byte string in last place. + ;; infer that user is trying to return a binary as the last value in a template, + ;; and treat it as a single binary value. + [(list _ ... (? bytes? bs)) bs] + [_ (with-output-to-string (λ () (output result)))])) + +(define-syntax (include-template stx) + (syntax-parse stx + [(_ (~optional (~seq #:command-char command-char:expr)) src:expr) + (quasisyntax/loc stx + (finish (include/text #,@(if (attribute command-char) + (list #'#:command-char #'command-char) + empty) + src)))])) + + diff --git a/pollen/private/manual-history.rkt b/pollen/private/external/manual-history.rkt similarity index 100% rename from pollen/private/manual-history.rkt rename to pollen/private/external/manual-history.rkt diff --git a/pollen/private/mode-indentation.rkt b/pollen/private/external/mode-indentation.rkt similarity index 100% rename from pollen/private/mode-indentation.rkt rename to pollen/private/external/mode-indentation.rkt diff --git a/pollen/private/pipe.py b/pollen/private/external/pipe.py similarity index 100% rename from pollen/private/pipe.py rename to pollen/private/external/pipe.py diff --git a/pollen/private/include-template.rkt b/pollen/private/include-template.rkt deleted file mode 100644 index 3e6ca77..0000000 --- a/pollen/private/include-template.rkt +++ /dev/null @@ -1,33 +0,0 @@ -#lang racket/base -(require (only-in scribble/text/syntax-utils include/text) - (only-in "output.rkt" output) - racket/list - (for-syntax racket/base - racket/list - syntax/parse) - racket/port) - -;; Adaptation of function in web-server/templates library -;; to check for binary result and pass it through. -;; Actually patches underlying bug in `output`. -(define-syntax (include-template stx) - (syntax-parse stx - [(_ (~optional (~seq #:command-char command-char:expr)) p:expr) - (quasisyntax/loc stx - (let ([result (include/text #,@(if (attribute command-char) - (list #'#:command-char #'command-char) - empty) - p)]) - - (let ([result (cond - [(bytes? result) result] - ;; list of expressions with byte string in last place. - ;; infer that user is trying to return a binary as the last value in a template, - ;; and treat it as a single binary value. - [(and (list? result) (bytes? (last result))) (last result)] - [else result])]) - (if (bytes? result) - (with-output-to-bytes (λ () (write-bytes result))) - (with-output-to-string (λ () (output result)))))))])) - -(provide include-template)