aoc2020/scripts/make-day

28 lines
828 B
Plaintext
Raw Normal View History

2020-12-01 21:33:57 +00:00
#!/usr/bin/env racket
#lang racket
(require racket/runtime-path
scribble/text (rename-in scribble/text/output [output scribble-output]))
(define-runtime-path template "template.rktrkt")
(define (eval-template file vars [port (current-output-port)])
(define cs (current-namespace))
(define output-exp
(parameterize ([current-namespace (make-base-namespace)])
(for ([mod (in-list '(scribble/text))])
(namespace-attach-module cs mod)
(namespace-require mod))
(hash-for-each vars namespace-set-variable-value!)
(eval `(include/text (file ,file)))))
(scribble-output output-exp port))
(command-line
2020-12-01 23:14:54 +00:00
#:program "make-day"
2020-12-01 21:33:57 +00:00
#:args (day)
(call-with-output-file
(format "~a.rkt" day)
(lambda (out)
(eval-template (path->string template) (hash 'day day) out))))