Local Yarn Code

Artifact Content

Artifact 08620f02590778467436f02578fd9b57c7f99879f4d53a1047aac50563908f28:


     1  #lang racket/base
     2  
3 ;; Licensed under the Local Yarn License 1.0.0. You may not use this 4 ;; file except in compliance with that license. A copy of the license 5 ;; is included with this source code, in the file β€œLICENSE.md”. 6 ;; 7 ;; Maintainer contact information: 8 ;; Joel Dueck (joel@jdueck.net) 9 ;; https://joeldueck.com 10 ;; -------------------------------------------------------------------------
11 12 ;; Functions for tags and template content used in all Pollen source files and templates. 13 14 (require (for-syntax racket/base 15 racket/syntax 16 syntax/parse 17 pollen/setup)) 18 19 (require pollen/tag 20 pollen/setup 21 racket/function 22 "tags-html.rkt" 23 "snippets-html.rkt" 24 "crystalize.rkt") 25 26 (provide (all-defined-out) 27 (all-from-out "crystalize.rkt" "snippets-html.rkt")) 28 29 (module setup racket/base 30 (require syntax/modresolve pollen/setup) 31 (provide (all-defined-out)) 32 (define poly-targets '(html)) 33 (define block-tags (cons 'title default-block-tags)) 34 (define cache-watchlist 35 (map resolve-module-path '("tags-html.rkt" 36 "snippets-html.rkt" 37 "dust.rkt" 38 "crystalize.rkt")))) 39 40 ;; Macro for defining tag functions that automatically branch based on the 41 ;; current output format and the list of poly-targets in the setup module. 42 ;; Use this macro when you know you will need keyword arguments. 43 ;; 44 (define-syntax (poly-branch-kwargs-tag stx) 45 (syntax-parse stx 46 [(_ TAG:id) 47 (with-syntax ([((POLY-TARGET POLY-FUNC) ...) 48 (for/list ([target (in-list (setup:poly-targets))]) 49 (list target (format-id stx "~a-~a" target #'TAG)))] 50 [DEFAULT-FUNC (format-id stx "html-~a" #'TAG)]) 51 #'(define-tag-function (TAG attributes elems) 52 (case (current-poly-target) 53 [(POLY-TARGET) (POLY-FUNC attributes elems)] ... 54 [else (DEFAULT-FUNC attributes elems)])))])) 55 56 ;; Like above, but uses `define` instead of `define-tag-function`. 57 ;; Use this when you know you will not need keyword arguments. 58 ;; 59 (define-syntax (poly-branch-tag stx) 60 (syntax-parse stx 61 [(_ TAG:id) 62 (with-syntax ([((POLY-TARGET POLY-FUNC) ...) 63 (for/list ([target (in-list (setup:poly-targets))]) 64 (list target (format-id stx "~a-~a" target #'TAG)))] 65 [DEFAULT-FUNC (format-id stx "html-~a" #'TAG)]) 66 #'(define (TAG . args) 67 (case (current-poly-target) 68 [(POLY-TARGET) (apply POLY-FUNC args)] ... 69 [else (apply DEFAULT-FUNC args)])))])) 70 71 ;; Define all the tag functions 72 (poly-branch-tag root) 73 74 (poly-branch-tag p) 75 (poly-branch-tag i) 76 (poly-branch-tag em) 77 (poly-branch-tag b) 78 (poly-branch-tag strong) 79 (poly-branch-tag strike) 80 ;(poly-branch-tag color) 81 (poly-branch-tag ol) 82 (poly-branch-tag ul) 83 (poly-branch-tag item) 84 (poly-branch-tag sup) 85 (poly-branch-tag blockquote) 86 (poly-branch-tag newthought) 87 (poly-branch-tag smallcaps) 88 (poly-branch-tag center) 89 (poly-branch-tag section) 90 (poly-branch-tag subsection) 91 (poly-branch-tag code) 92 (poly-branch-kwargs-tag blockcode) 93 (poly-branch-kwargs-tag verse) ; [#:title ""] [#:italic "no"] 94 95 (poly-branch-tag link) 96 (poly-branch-tag url) 97 (poly-branch-tag fn) 98 (poly-branch-tag fndef) 99 100 (poly-branch-kwargs-tag note) 101 102 ;; Not yet implemented 103 ; (poly-branch-tag table) ; #:columns "" 104 ; (poly-branch-tag inline-math) 105 ; (poly-branch-tag margin-note) 106 ; (poly-branch-tag noun) 107 ; (poly-branch-func index-entry entry) 108 ; (poly-branch-tag figure) ; #:src "img--sans-path.png" [#:has-print-version? "yes"] 109 ; (poly-branch-tag spot-illustration) ; #:src "img--sans-path.png" [#:has-print-version? "yes"] 110 111 ;; My pet shortcut for for/splice. Greatly cuts down on parentheses for the 112 ;; most common use case (looping through a single list). 113 (define-syntax (for/s stx) 114 (syntax-case stx () 115 [(_ thing listofthings result-expr ...) 116 #'(for/splice ([thing (in-list listofthings)]) result-expr ...)]))