implement lang-wide splicing with `current-splicing-tag`; reimplement `when/block` as `when/splice`
parent
a895c0dde1
commit
02cdc44a4f
@ -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))
|
@ -0,0 +1,20 @@
|
||||
#lang racket/base
|
||||
(require rackunit)
|
||||
|
||||
(module markup pollen/markup
|
||||
(require pollen/template)
|
||||
"Hello" (when #t (@ "Splice")) (when/splice #t "Splice") "World")
|
||||
(require (prefix-in markup: 'markup))
|
||||
(check-equal? markup:doc '(root "Hello" "Splice" "Splice" "World"))
|
||||
|
||||
(module pre pollen/pre
|
||||
(require pollen/template)
|
||||
"Hello" (when #t (@ "Splice")) (when/splice #t "Splice") "World")
|
||||
(require (prefix-in pre: 'pre))
|
||||
(check-equal? pre:doc "HelloSpliceSpliceWorld")
|
||||
|
||||
(module markdown pollen/markdown
|
||||
(require pollen/template)
|
||||
"Hello" (when #t (@ "Splice")) (when/splice #t "Splice") "World")
|
||||
(require (prefix-in markdown: 'markdown))
|
||||
(check-equal? markdown:doc '(root (p () "HelloSpliceSpliceWorld")))
|
@ -1,8 +0,0 @@
|
||||
#lang racket/base
|
||||
(require pollen/private/main-base)
|
||||
|
||||
(define+provide-module-begin-in-mode world:mode-template)
|
||||
|
||||
(module reader racket/base
|
||||
(require pollen/private/reader-base)
|
||||
(define+provide-reader-in-mode world:mode-template))
|
Loading…
Reference in New Issue