racket/collects/meta/web/common/utils.rkt
Eli Barzilay 82221a51db Make the scribble/html' layout mimic the one for scribble/text'.
Ie, the difference between using it as a language and as a module is now
the same in both.  Also, improve `scribble/html' (and
`scribble/html/htmllang') by reproviding most of the corresponding text
modules.

Change `meta/web' accordingly, and improve code by making a new langugae
(`#lang meta/web').  This language is similar to `scribble/html' except
that it uses the plain scribble reader (not the `-inside' one), it
doesn't use the customized module-begin feature (that uses
`output-xml'), and it adds all the relevant bits of `meta/web/common'.
(Also, "meta/web/common.rkt" is gone, since it's used only as a language
now.)

This commit has lots of details and binding games, so it's tricky, and
potentially caused some problems.  (Took me a while to track many
breakages, so I won't be surprised if there are more.)
2010-10-26 15:36:29 -04:00

43 lines
1.5 KiB
Racket

#lang at-exp racket/base
(require scribble/html (for-syntax scheme/base))
(provide in-here)
(define-syntax (in-here stx)
(syntax-case stx ()
[(_ path paths ...)
(let ([src (let-values ([(dir name dir?)
(split-path (syntax-source stx))])
(or dir (raise-syntax-error
'in-here "missing source information" stx)))])
#`(build-path '#,src path paths ...))]))
(define ((make-path-resourcer file-op)
source [target #f] [referrer values] #:dir [dir #f])
(let ([target (or target (let-values ([(base file dir?) (split-path source)])
(path->string file)))])
(resource (if (eq? void file-op)
(void) (if dir (web-path dir target) target))
(lambda (file) (file-op source file)) referrer)))
(define (write-to-file text file)
(with-output-to-file file (lambda () (write-string text))))
(provide copyfile-resource symlink-resource content-resource)
(define copyfile-resource (make-path-resourcer copy-file))
(define symlink-resource (make-path-resourcer make-file-or-directory-link))
(define content-resource (make-path-resourcer write-to-file))
(provide web-path)
(define (web-path . xs)
(string-join xs "/"))
(provide ->string)
(define (->string x)
(cond [(string? x) x]
[(path? x) (path->string x)]
[(bytes? x) (bytes->string/utf-8 x)]
[(symbol? x) (symbol->string x)]
[(number? x) (number->string x)]
[else (error '->string "don't know what to do with ~e" x)]))