diff --git a/decode.rkt b/decode.rkt index bd79554..4ee6f59 100644 --- a/decode.rkt +++ b/decode.rkt @@ -3,6 +3,7 @@ (require "debug.rkt" "world.rkt") +(define (symbols? x) (and (list? x) (andmap symbol? x))) (define+provide (to-string x) (if (string? x) @@ -42,7 +43,7 @@ #:symbol-proc (symbol? . -> . xexpr?) #:valid-char-proc (valid-char? . -> . xexpr?) #:cdata-proc (cdata? . -> . xexpr?) - #:exclude-tags (listof symbol?) ) . ->* . txexpr?) + #:exclude-tags symbols?) . ->* . txexpr?) (let loop ([x txexpr]) @@ -88,7 +89,7 @@ #:symbol-proc (symbol? . -> . xexpr?) #:valid-char-proc (valid-char? . -> . xexpr?) #:cdata-proc (cdata? . -> . xexpr?) - #:exclude-tags (listof symbol?) ) . ->* . txexpr-elements?) + #:exclude-tags symbols?) . ->* . txexpr-elements?) (define temp-tag (gensym "temp-tag")) (define decode-result (decode `(temp-tag ,@elements) diff --git a/file.rkt b/file.rkt index b4d47e3..7022133 100644 --- a/file.rkt +++ b/file.rkt @@ -28,9 +28,11 @@ (coerce/path? . -> . coerce/boolean?) (not ((->string path) . starts-with? . "."))) +(define (paths? x) (and (list? x) (andmap path? x))) +(define (complete-paths? x) (and (list? x) (andmap complete-path? x))) (define+provide/contract (visible-files dir) - (pathish? . -> . (listof path?)) + (pathish? . -> . paths?) (filter visible? (map (λ(p) (find-relative-path dir p)) (filter file-exists? @@ -108,7 +110,7 @@ (define+provide/contract (project-files-with-ext ext) - (coerce/symbol? . -> . (listof complete-path?)) + (coerce/symbol? . -> . complete-paths?) (map ->complete-path (filter (λ(i) (has-ext? i ext)) (directory-list (world:current-project-root))))) diff --git a/pagetree.rkt b/pagetree.rkt index d5ca241..296d5d8 100644 --- a/pagetree.rkt +++ b/pagetree.rkt @@ -10,6 +10,9 @@ (->boolean (and (symbol? x) (with-handlers ([exn:fail? (λ(e) #f)]) (not (whitespace/nbsp? (->string x))))))) +(define+provide (pagenodes? x) + (and (list? x) (andmap pagenode? x))) + (define+provide (pagenodeish? x) (with-handlers ([exn:fail? (λ(e) #f)]) @@ -78,7 +81,7 @@ (define+provide/contract (children p [pt (current-pagetree)]) - (((or/c #f pagenodeish?)) (pagetree?) . ->* . (or/c #f (listof pagenode?))) + (((or/c #f pagenodeish?)) (pagetree?) . ->* . (or/c #f pagenodes?)) (and pt p (let ([pagenode (->pagenode p)]) (if (equal? pagenode (car pt)) @@ -87,19 +90,18 @@ (define+provide/contract (siblings pnish [pt (current-pagetree)]) - (((or/c #f pagenodeish?)) (pagetree?) . ->* . (or/c #f (listof pagenode?))) + (((or/c #f pagenodeish?)) (pagetree?) . ->* . (or/c #f pagenodes?)) (children (parent pnish pt) pt)) ;; flatten tree to sequence (define+provide/contract (pagetree->list pt) - (pagetree? . -> . (listof pagenode?)) + (pagetree? . -> . pagenodes?) ; use cdr to get rid of root tag at front (cdr (flatten pt))) (define (adjacents side pnish [pt (current-pagetree)]) - ; ((symbol? (or/c #f pagenodeish?)) (pagetree?) . ->* . (or/c #f (listof pagenode?))) (and pt pnish (let* ([pagenode (->pagenode pnish)] [proc (if (equal? side 'left) takef takef-right)] @@ -108,12 +110,12 @@ (define+provide/contract (previous* pnish [pt (current-pagetree)]) - (((or/c #f pagenodeish?)) (pagetree?) . ->* . (or/c #f (listof pagenode?))) + (((or/c #f pagenodeish?)) (pagetree?) . ->* . (or/c #f pagenodes?)) (adjacents 'left pnish pt)) (define+provide/contract (next* pnish [pt (current-pagetree)]) - (((or/c #f pagenodeish?)) (pagetree?) . ->* . (or/c #f (listof pagenode?))) + (((or/c #f pagenodeish?)) (pagetree?) . ->* . (or/c #f pagenodes?)) (adjacents 'right pnish pt)) diff --git a/project.rkt b/project.rkt index da85d17..9b381e0 100644 --- a/project.rkt +++ b/project.rkt @@ -1,9 +1,10 @@ #lang racket/base (require "world.rkt" sugar/define sugar/coerce) +(define (paths? x) (and (list? x) (andmap path? x))) (define/contract+provide (get-directory-require-files source-path) ; keep contract local to ensure coercion - (coerce/path? . -> . (or/c #f (listof path?))) + (coerce/path? . -> . (or/c #f paths?)) (define possible-requires (list (simplify-path (build-path source-path 'up world:directory-require)))) (and (andmap file-exists? possible-requires) possible-requires)) diff --git a/render.rkt b/render.rkt index 5ea0aa4..a62ae61 100644 --- a/render.rkt +++ b/render.rkt @@ -16,8 +16,17 @@ ;; using internal contracts to provide some extra safety (negligible performance hit) +(define/contract (valid-path-arg? x) + (any/c . -> . boolean?) + (or (equal? #f x) (complete-path? x))) + +(define/contract (valid-path-args? x) + (any/c . -> . boolean?) + (and (list? x) (andmap valid-path-arg? x))) + + (define/contract (make-mod-dates-key paths) - ((listof (or/c #f complete-path?)) . -> . (listof (or/c #f complete-path?))) + (valid-path-args? . -> . valid-path-args?) paths) ; for now, this does nothing; maybe later, it will do more @@ -27,20 +36,21 @@ (define/contract (store-render-in-modification-dates . rest-paths) - (() #:rest (listof (or/c #f complete-path?)) . ->* . void?) + (() #:rest valid-path-args? . ->* . void?) (define key (make-mod-dates-key rest-paths)) (hash-set! modification-date-hash key (map path->mod-date-value key))) (define/contract (modification-date-expired? . rest-paths) - (() #:rest (listof (or/c #f complete-path?)) . ->* . boolean?) + (() #:rest valid-path-args? . ->* . boolean?) (define key (make-mod-dates-key rest-paths)) (or (not (key . in? . modification-date-hash)) ; no stored mod date (not (equal? (map path->mod-date-value key) (get modification-date-hash key))))) ; data has changed +(define (list-of-pathish? x) (and (list? x) (andmap pathish? x))) (define/contract+provide (render-batch . xs) - (() #:rest (listof pathish?) . ->* . void?) + (() #:rest list-of-pathish? . ->* . void?) ;; Why not just (map render ...)? ;; Because certain files will pass through multiple times (e.g., templates) ;; And with render, they would be rendered repeatedly. diff --git a/tag.rkt b/tag.rkt index 17f9e6d..1a8abda 100644 --- a/tag.rkt +++ b/tag.rkt @@ -2,7 +2,7 @@ (require txexpr sugar/define) (define/contract+provide (make-default-tag-function . ids) - (() #:rest (listof txexpr-tag?) . ->* . procedure?) + (() #:rest txexpr-tags? . ->* . procedure?) (define (make-one-tag id) (λ x (define reversed-pieces ; list of attribute pairs, and last element holds a list of everything else, then reversed diff --git a/template.rkt b/template.rkt index d709635..e1b25d6 100644 --- a/template.rkt +++ b/template.rkt @@ -24,7 +24,7 @@ (define+provide/contract (select* key value-source) - (coerce/symbol? (or/c hash? txexpr? pagenode? pathish?) . -> . (or/c #f (listof txexpr-element?))) + (coerce/symbol? (or/c hash? txexpr? pagenode? pathish?) . -> . (or/c #f txexpr-elements?)) (define metas-result (and (not (txexpr? value-source)) (select-from-metas key value-source))) (define doc-result (select-from-doc key value-source)) (define result (append (or (and metas-result (list metas-result)) null) (or doc-result null))) @@ -40,7 +40,7 @@ (define+provide/contract (select-from-doc key doc-source) - (coerce/symbol? (or/c txexpr? pagenode? pathish?) . -> . (or/c #f (listof txexpr-element?))) + (coerce/symbol? (or/c txexpr? pagenode? pathish?) . -> . (or/c #f txexpr-elements?)) (define doc (cond [(txexpr? doc-source) doc-source] [else (get-doc doc-source)]))