From a895c0dde1ea14e2362af1f6ea26e6683ec8a390 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Wed, 27 Jan 2016 08:38:26 -0800 Subject: [PATCH] change #:splice to #:splice? in `->html` --- pollen/scribblings/template.scrbl | 12 ++++++------ pollen/template/html.rkt | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/pollen/scribblings/template.scrbl b/pollen/scribblings/template.scrbl index 131de5a..495d2dc 100644 --- a/pollen/scribblings/template.scrbl +++ b/pollen/scribblings/template.scrbl @@ -114,7 +114,7 @@ Note that if @racket[_meta-source] is a relative path or pagenode, it is treated -@section{HTML templates} +@section{HTML} @defmodule[pollen/template/html] @@ -125,7 +125,7 @@ Functions specific to HTML templates. [xexpr-or-xexprs (or/c xexpr? (listof xexpr?))] [#:tag html-tag (or/c #f txexpr-tag?) #f] [#:attrs html-attrs (or/c #f txexpr-attrs?) #f] -[#:splice splice-html? boolean? #f]) +[#:splice? splice-html? boolean? #f]) string?] Convert @racket[_xexpr-or-xexprs] to an HTML string. Similar to @racket[xexpr->string], but consistent with the HTML spec, text that appears within @code{script} or @code{style} blocks will not be escaped. @@ -161,13 +161,13 @@ If the generated HTML has an outer tag, the @racket[_splice-html?] option will s @examples[#:eval my-eval (define tx '(root (p "Chicken nuggets"))) (->html tx) -(->html tx #:splice #t) +(->html tx #:splice? #t) (define x "Fancy sauce") (->html x) (code:comment @#,t{This next one won't do anything}) -(->html x #:splice #t) -(code:comment @#,t{Adds the outer tag, but then #:splice removes it}) -(->html x #:tag 'div #:attrs '((id "doback")) #:splice #t) +(->html x #:splice? #t) +(code:comment @#,t{Adds the outer tag, but then #:splice? removes it}) +(->html x #:tag 'div #:attrs '((id "doback")) #:splice? #t) ] diff --git a/pollen/template/html.rkt b/pollen/template/html.rkt index fe41bbc..0414dbb 100644 --- a/pollen/template/html.rkt +++ b/pollen/template/html.rkt @@ -7,8 +7,8 @@ paren-match) -(define+provide/contract (->html x-arg #:tag [tag #f] #:attrs [attrs #f] #:splice [splice? #f]) - (((or/c txexpr-element? txexpr-elements?)) (#:tag (or/c #f txexpr-tag?) #:attrs (or/c #f txexpr-attrs?) #:splice boolean?) . ->* . string?) +(define+provide/contract (->html x-arg #:tag [tag #f] #:attrs [attrs #f] #:splice? [splice? #f] #:splice [bwc-splice? #f]) + (((or/c txexpr-element? txexpr-elements?)) (#:tag (or/c #f txexpr-tag?) #:attrs (or/c #f txexpr-attrs?) #:splice? boolean? #:splice boolean?) . ->* . string?) (define x (cond [(txexpr? x-arg) x-arg] @@ -24,7 +24,7 @@ (define html-attrs (or attrs (and (txexpr? x) (get-attrs x)) null)) (define html-elements (or (and (txexpr? x) (get-elements x)) (list x))) (define html (xexpr->html (txexpr html-tag html-attrs html-elements))) - (if (or splice? (and (list? x-arg) (not (txexpr? x-arg)) (not tag))) + (if (or splice? bwc-splice? (and (list? x-arg) (not (txexpr? x-arg)) (not tag))) (trim-outer-tag html) html)] [else (xexpr->html x)])) @@ -34,18 +34,18 @@ (check-equal? (->html tx) "

hello

") (check-equal? (->html #:tag 'brennan tx) "

hello

") (check-equal? (->html #:attrs '((id "dale")) tx) "

hello

") - (check-equal? (->html #:splice #t tx) "

hello

") + (check-equal? (->html #:splice? #t tx) "

hello

") (check-equal? (->html #:tag 'brennan #:attrs '((id "dale")) tx) "

hello

") (check-equal? (->html #:tag 'brennan #:attrs '((id "dale")) #:splice #t tx) "

hello

") (define x "hello") (check-equal? (->html x) "hello") (check-equal? (->html #:tag 'brennan x) "hello") (check-exn exn:fail? (λ() (->html #:attrs '((id "dale")) x) "hello")) ;; won't work without tag - (check-equal? (->html #:splice #t x) "hello") + (check-equal? (->html #:splice? #t x) "hello") (check-equal? (->html #:tag 'brennan #:attrs '((id "dale")) x) "hello") - (check-equal? (->html #:tag 'brennan #:attrs '((id "dale")) #:splice #t x) "hello") + (check-equal? (->html #:tag 'brennan #:attrs '((id "dale")) #:splice? #t x) "hello") (define xs '("hello " (em "you") " " 42)) (check-equal? (->html xs) "hello you *") - (check-equal? (->html #:splice #t xs) "hello you *") + (check-equal? (->html #:splice? #t xs) "hello you *") (check-equal? (->html #:tag 'div xs) "
hello you *
"))