diff --git a/pollen/private/main-base.rkt b/pollen/private/main-base.rkt index 51fa099..59a7d0a 100644 --- a/pollen/private/main-base.rkt +++ b/pollen/private/main-base.rkt @@ -1,6 +1,6 @@ #lang racket/base (require (for-syntax racket/base syntax/strip-context racket/syntax "../world.rkt" "split-metas.rkt") - "to-string.rkt" "../pagetree.rkt" "../world.rkt") ; need world here to resolve PARSER-MODE-ARG later + "to-string.rkt" "../pagetree.rkt" "splice.rkt" "../world.rkt") ; need world here to resolve PARSER-MODE-ARG (provide (all-defined-out)) (define-syntax-rule (define+provide-module-begin-in-mode PARSER-MODE-ARG) @@ -10,7 +10,7 @@ (define-syntax (pollen-module-begin stx) (syntax-case stx () [(_ EXPR (... ...)) - (let-values ([(meta-keys meta-values expr-without-metas) (split-metas (syntax->datum #'(EXPR (... ...))) (world:current-define-meta-name))]) + (let*-values ([(meta-keys meta-values expr-without-metas) (split-metas (syntax->datum #'(EXPR (... ...))) (world:current-define-meta-name))]) (with-syntax ([(EXPR-WITHOUT-METAS (... ...)) (datum->syntax #'(EXPR (... ...)) expr-without-metas)] [(KEY (... ...)) (datum->syntax #'(EXPR (... ...)) meta-keys)] [(VALUE (... ...)) (datum->syntax #'(EXPR (... ...)) meta-values)] @@ -21,6 +21,7 @@ [MODE-PAGETREE (datum->syntax #'(EXPR (... ...)) world:mode-pagetree)] [MODE-MARKUP (datum->syntax #'(EXPR (... ...)) world:mode-markup)] [MODE-MARKDOWN (datum->syntax #'(EXPR (... ...)) world:mode-markdown)] + [SPLICING_TAG (datum->syntax #'(EXPR (... ...)) (world:current-splicing-tag))] [DOC (format-id #'(EXPR (... ...)) "~a" (world:current-main-export))] [DOC-RAW (generate-temporary)]); prevents conflicts with other imported Pollen sources (replace-context #'(EXPR (... ...)) @@ -48,7 +49,8 @@ (λ(xs) (apply ROOT ((dynamic-require 'markdown 'parse-markdown) (apply string-append (map to-string xs)))))] [else (λ(xs) (apply string-append (map to-string xs)))])] ; string output for preprocessor ;; drop leading newlines, as they're often the result of `defines` and `requires` - [doc-elements (or (memf (λ(ln) (not (equal? ln NEWLINE))) DOC-RAW) null)]) - (proc doc-elements))) + [doc-elements (or (memf (λ(ln) (not (equal? ln NEWLINE))) DOC-RAW) null)] + [doc-elements-spliced (splice doc-elements 'SPLICING_TAG)]) + (proc doc-elements-spliced))) (provide DOC METAS (except-out (all-from-out 'inner) DOC-RAW #%top))))))])))) ; hide internal exports \ No newline at end of file diff --git a/pollen/private/project-server-routes.rkt b/pollen/private/project-server-routes.rkt index 64dfe3a..b8d0c17 100644 --- a/pollen/private/project-server-routes.rkt +++ b/pollen/private/project-server-routes.rkt @@ -83,9 +83,10 @@ `(div (p "filename =" ,(->string relative-path)) (p "size = " ,(bytecount->string (file-size path))) - ,@(when/splice (not (equal? (get-ext path) "svg")) - `(p "width = " ,(->string (image-width img)) " " - "height = " ,(->string (image-height img)))) + ,@(if (not (equal? (get-ext path) "svg")) + `(p "width = " ,(->string (image-width img)) " " + "height = " ,(->string (image-height img))) + "") (a ((href ,img-url)) (img ((style "width:100%;border:1px solid #eee")(src ,img-url)))))) (require file/unzip) @@ -186,8 +187,8 @@ (cond [(string? cell-content) (string-append indent-string cell-content)] [(txexpr? cell-content) - ;; indent link text by depth in pagetree - `(,(get-tag cell-content) ,(cons '(class "indented-link") (get-attrs cell-content)) ,indent-string (span ((class "indented-link-text")) ,@(get-elements cell-content)))] + ;; indent link text by depth in pagetree + `(,(get-tag cell-content) ,(cons '(class "indented-link") (get-attrs cell-content)) ,indent-string (span ((class "indented-link-text")) ,@(get-elements cell-content)))] [else (error 'make-path-row (format "mysterious cell data: ~v" cell-content))])))) (cond ; 'in' cell diff --git a/pollen/private/splice.rkt b/pollen/private/splice.rkt new file mode 100644 index 0000000..357fbad --- /dev/null +++ b/pollen/private/splice.rkt @@ -0,0 +1,20 @@ +#lang racket/base +(provide (all-defined-out)) + +(define (splice x [splicing-tag '@]) + (let loop ([x x]) + (if (list? x) + (apply append + (map (λ(xi) (let ([proc (if (and (pair? xi) (eq? (car xi) splicing-tag)) + cdr ; expose elements + list)]) ; wrap in list + (proc (loop xi)))) x)) + x))) + +(module+ test + (require rackunit) + (check-equal? (splice '(@ 1 (@ 2 (@ 3 (div 4 (@ 5))) 6) 7)) + '(@ 1 2 3 (div 4 5) 6 7)) + (check-equal? (splice '((@ "foo" "bar"))) '("foo" "bar")) + (check-equal? (splice '(@ "foo" "bar")) '(@ "foo" "bar")) ; this is correct, for composable behavior + (check-equal? (splice null) null)) \ No newline at end of file diff --git a/pollen/private/split-metas.rkt b/pollen/private/split-metas.rkt index 533f6a2..e455fde 100644 --- a/pollen/private/split-metas.rkt +++ b/pollen/private/split-metas.rkt @@ -6,16 +6,16 @@ (define (meta? x) ; meta has form (define-meta key value) (and (list? x) (>= (length x) 3) (eq? (car x) meta-key))) - + (define (non-meta?/gather x) (or (not (meta? x)) (and (set! matches (cons x matches)) #f))) - + (define rest (let loop ([x (if (list? tree) tree (list tree))]) (if (list? x) (map loop (filter non-meta?/gather x)) x))) - + (let ([meta-key cadr][meta-value caddr]) - (values (map meta-key matches) (map meta-value matches) rest))) + (values (map meta-key matches) (map meta-value matches) rest))) \ No newline at end of file diff --git a/pollen/scribblings/mb-tools.rkt b/pollen/scribblings/mb-tools.rkt index 44a7b4f..43c9f43 100644 --- a/pollen/scribblings/mb-tools.rkt +++ b/pollen/scribblings/mb-tools.rkt @@ -64,8 +64,7 @@ (syntax-case stx () [(_ name predicate? desc ...) (with-syntax ([world:name (format-id stx "world:~a" #'name)] - [world:current-name (format-id stx "world:current-~a" #'name)] - [local:name (format-id stx "local:~a" #'name)]) + [world:current-name (format-id stx "world:current-~a" #'name)]) #'(deftogether ((defthing world:name predicate?) (defproc (world:current-name) predicate?)) desc ...))])) diff --git a/pollen/scribblings/template.scrbl b/pollen/scribblings/template.scrbl index 495d2dc..c9ad3f1 100644 --- a/pollen/scribblings/template.scrbl +++ b/pollen/scribblings/template.scrbl @@ -112,6 +112,15 @@ Note that if @racket[_meta-source] is a relative path or pagenode, it is treated ] +@defform[(when/splice condition pollen-args)] +If @racket[_condition] is true, put the @racket[_pollen-args] into the document. Within a template file, usually invoked like so: + +@verbatim{◊when/splice[@racketvarfont{condition}]{The text to insert.}} + +The inserted text can contain its own nested Pollen commands. + +@racket[when/splice] can be more convenient than @racket[when], because @racket[when] will only use the last argument between the curly braces. @racket[when/splice], by contrast, treats everything between the curly braces as a block. + @section{HTML} diff --git a/pollen/scribblings/third-tutorial-files/template.html b/pollen/scribblings/third-tutorial-files/template.html index 092a5eb..b05fb02 100644 --- a/pollen/scribblings/third-tutorial-files/template.html +++ b/pollen/scribblings/third-tutorial-files/template.html @@ -6,10 +6,10 @@
◊->html[doc] ◊(define prev-page (previous here)) -◊when/block[prev-page]{ +◊when/splice[prev-page]{ } ◊(define next-page (next here)) -◊when/block[next-page]{ +◊when/splice[next-page]{ }