-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreveal.rkt
181 lines (155 loc) · 5.73 KB
/
reveal.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#lang at-exp racket
(provide
slide-group slide gslide
L t C CB ~
url image fragment color th* td* simple-table
;; comment
reveal)
(require
scribble/html
net/url
(for-syntax syntax/parse))
;; http://docs.racket-lang.org/scribble/extra-style.html
;; Reveal and new html stuff
(define/provide-elements/not-empty section video) ; more tags here
;; Register sections (but only at the top-level)
(define-values [get-sections register-section]
(let ([sections '()])
(values (λ () (reverse sections))
(λ (section) (set! sections (cons section sections))))))
(define section-toplevel? (make-parameter #t))
(define-syntax-rule (slide (options ...) stuff ...)
(do-slide (list options ...) (λ () (list stuff ...))))
(define (do-slide options thunk)
(let ((toplevel? (section-toplevel?)))
(parameterize ([section-toplevel? #f])
(let ((section (apply section (append options (thunk)))))
(if toplevel?
(register-section section)
section)))))
(define group-title (make-parameter #f))
(define-syntax-rule (slide-group title stuff ...)
(do-slide-group title (λ () (list stuff ...))))
(define (do-slide-group title thunk)
(slide ()
(slide () @(h1 title))
(parameterize ([group-title title])
(thunk))))
(define (do-group-title)
(when (group-title)
(p align: 'right valign: 'top (font size: 4 (b (group-title))))))
(define-syntax-rule (gslide (options ...) stuff ...)
(slide (options ...) (do-group-title) stuff ...))
(define-syntax-rule (when-not condition body ...)
(when (not condition) body ...))
(define (reveal-url . text)
;; (cons "http://cdn.jsdelivr.net/reveal.js/3.0.0/" text)
(cons "resources/reveal/" text))
;; Quick helpers
(define-syntax-rule (defcodes lang ...)
(begin (define (lang . text) (pre (code class: 'lang text)))
...))
(defcodes scheme javascript haskell)
(define (pic-url name url)
(let ((file (string-append "resources/pic/" name)))
(unless (file-exists? file)
(define out (open-output-file file #:exists 'truncate))
(call/input-url (string->url url)
get-pure-port
(λ (in) (copy-port in out)))
(close-output-port out))
file))
(define (L . x) (apply div align: 'left x))
(define (t . x) x)
(define (C . x) (apply div align: 'center x))
(define (CB . x) (C (apply b x)))
(define (url x) (a href: x (tt x)))
;;(define (comment . x) '())
(define (image name url . size)
(img src: (pic-url name url) alt: name height: (if (empty? size) "75%" size)))
(define (fragment #:index (index 1) . body)
(apply span class: 'fragment data-fragment-index: index body))
(define *white* "#ffffff")
(define *gray* "#7f7f7f")
(define *blue* "#0000ff")
(define *light-blue* "#b4b4ff")
(define *red* "#ff0000")
(define *light-red* "#ffb4b4")
(define *green* "#00ff00")
(define *light-green* "#b4ffb4")
(define ~ @p{ })
(define (spacing* l (space (br)))
(cond
((null? l) (list space))
((pair? l) (append (list space)
(if (pair? (car l)) (car l) (list (car l)))
(spacing* (cdr l))))
(else (error 'spacing*))))
(define (spacing l)
(if (list? l)
(cdr (spacing* (filter-not null? l)))
l))
(define (color text #:fg (fgcolor #f) #:bg (bgcolor #f))
(if (or fgcolor bgcolor)
(span style: (list (if fgcolor (list "color:" fgcolor ";") '())
(if bgcolor (list "background-color:" bgcolor ";") '()))
text)
text))
(define (gray . text) (color text #:fg *gray*))
(define (bg-slide text fgcolor bgcolor)
(λ x
(gslide (data-background: bgcolor)
(spacing x)
(div align: 'right valign: 'bottom (color #:fg fgcolor text)))))
(define-syntax-rule (x-slide (options ...) x ...)
(gslide (options ...) (spacing (list x ...))))
;;(define th-width "4%")
;;(define td-width "48%")
;;(define table-width "114%")
(define th-width "8%")
(define td-width "46%")
(define table-width "104%")
(define (th* name)
(if name (th width: th-width (font size: "6" (color name #:fg *white*))) (td)))
(define (td* x) (td (color x #:fg *white*)))
(define (row name left right
#:left-bg (left-bg #f) #:right-bg (right-bg #f) #:fragment? (fragment? #f))
(tr
(th* name)
(td
width: td-width (when left-bg bgcolor:) (when left-bg left-bg)
(spacing left))
(if right
(td
width: td-width bgcolor: right-bg
(when fragment? class:) (when fragment? 'fragment)
(when fragment? data-fragment-index:) (when fragment? 1)
(spacing right))
(td width: td-width))))
(define (simple-table contents)
(letrec ((line (lambda (th . tds) (cons (th* th) (map td* tds))))
(lines (lambda (titles . xss)
(apply table align: 'right width: "100%"
(tr (map th* titles))
(map (lambda (xs) (apply tr (apply line xs))) xss)))))
(apply lines contents)))
(define (reveal)
(output-xml
@html{
@head{
@meta[http-equiv: "Content-Type" content: "text/html; charset=utf-8"]
@link[rel: 'stylesheet href: "resources/my.css"]
@link[rel: 'stylesheet href: @reveal-url{css/reveal.css}]
@link[rel: 'stylesheet href: @reveal-url{css/theme/black.css}]
@link[rel: 'stylesheet href: @reveal-url{lib/css/zenburn.css}]
@link[rel: 'stylesheet href: "resources/my.css"]}
@body{
@div[class: 'reveal]{@div[class: 'slides]{@get-sections}}
@script[src: @reveal-url{lib/js/head.min.js}]
@script[src: @reveal-url{js/reveal.min.js}]
@script/inline{
Reveal.initialize({
dependencies: [
{src: "@reveal-url{plugin/highlight/highlight.js}",
async: true, callback: () => hljs.initHighlightingOnLoad()}],
controls: false})}}}))