-
Notifications
You must be signed in to change notification settings - Fork 5
/
render.rkt
129 lines (105 loc) · 3.73 KB
/
render.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#lang racket/base
;; Helper functions for documenting syntax-parse examples
(provide
(except-out
(all-from-out scribble/doclang scribble/example scribble/manual) #%module-begin)
(for-syntax
(all-from-out racket/base syntax/parse))
(rename-out [module-begin #%module-begin])
tech/guide
;; Usage: @tech/guide{text}
;; where `text` refers to a technical definition.
;; Short for @tech[#:doc ....]{text},
;; where the `....` is the module path for The Racket Guide
tech/reference
;; Usage: @tech/reference{text}
;; where `text` refers to a technical definition.
;; Short for @tech[#:doc ....]{text},
;; where the `....` is the module path for The Racket Reference
;; (If the name is too long for you, `rename-in` to something shorter.)
tech/syntax
;; Usage: @tech/syntax{text}
;; where `text` refers to a definition from the `syntax` lib.
racketfile
;; Usage: @racketfile{filename}
;; where `filename` is a string representing a Racket file
;; Renders the contents of `filename` as if they were copy/pasted into
;; a `racketblock`
stxbee2021
;; Usage @stxbee2021[user issue]
;; Renders a thank-you note for a Syntax Bee 2021 submission
adapted-from
;; Usage @adapted-from[#:what [kind #f] name url]
stxbee2021-issue
)
(require
scribble/doclang
scribble/example
scribble/manual
(only-in racket/format ~a)
(for-syntax
racket/runtime-path
racket/path
racket/base
syntax/location
syntax/parse
(only-in racket/file file->list)))
;; =============================================================================
(define-syntax (module-begin stx)
(syntax-parse stx
[(_ id . body)
(syntax/loc stx
(#%module-begin id values () . body))]))
(define-syntax (racketfile stx)
(syntax-parse stx
[(_ file-name:str)
#:with (str* ...)
(file->list (let* ([fn (syntax-e #'file-name)]
[dir (syntax-source-directory stx)])
(cond
[(complete-path? fn)
fn]
[dir
(build-path dir fn)]
[else
(raise-argument-error 'racketfile "cannot find source for '~a'" fn)]))
(lambda (p)
(let ([v (read-line p)])
(if (eof-object? v) v (string-append v "\n")))))
(with-syntax ((ctx (syntax/loc stx #'file-name)))
(syntax/loc stx
(typeset-code
#:context ctx
(quote str*) ...)))]))
(define (tech/guide . text)
(apply tech text #:doc '(lib "scribblings/guide/guide.scrbl")))
(define (tech/reference . text)
(apply tech text #:doc '(lib "scribblings/reference/reference.scrbl")))
(define (tech/syntax . text)
(apply tech text #:doc '(lib "syntax/scribblings/syntax.scrbl")))
(define (github-user usr)
(hyperlink (format "https://github.com/~a" usr) (tt usr)))
(define (github-issue owner repo item)
(hyperlink (format "https://github.com/~a/~a/issues/~a" owner repo item) (tt "#" item)))
(define (stxbee2021-issue item)
(github-issue "syntax-objects" "Summer2021" item))
(define (nested-inset content)
(nested #:style 'inset content))
(define (stxbee2021 user issue)
(nested-inset
(emph "Contributed by "
(github-user user)
" ("
(stxbee2021-issue (~a issue))
") during the 2021 Syntax Parse Bee."
)))
(define (adapted-from #:what [what-type #f] name url)
(define-values [what-pre what-post]
(if what-type
(values " the " (string-append " " what-type))
(values " " "")))
(nested-inset
(emph "Adapted from"
what-pre
(hyperlink url name)
what-post ".")))