(define-module (ldp path) #:use-module (oop goops) #:use-module (web uri)) (define-class () (components-rev #:init-keyword #:components-rev #:getter path-components-rev)) (export ) (define-public (is-root? x) (equal? (path-components-rev x) '())) (define-public (path->filename x) (if (is-root? x) "." (string-append "./" (encode-and-join-uri-path (map (lambda (x) (string-append "r_" x)) (reverse (path-components-rev x))))))) (define-public (path->uri x) (let* ((components (reverse (path-components-rev x))) (relative-to-root (encode-and-join-uri-path components)) (path (string-append "/" relative-to-root))) (build-uri-reference #:path path))) (define-public (path->string x) (uri-path (path->uri x))) (define-public (uri->path x) (make #:components-rev (reverse (split-and-decode-uri-path (uri-path x))))) (define-public (string->path x) (uri->path (build-uri-reference #:path x))) (define-public (path? x) (is-a? x )) (define-public (the-path x) (unless (path? x) (scm-error 'wrong-type-arg "the-path" "Expected a path from (ldp path)." '() (list x))) x) (define-public (path-parent x) (make #:components-rev (cdr (path-components-rev x)))) (define-public (path-cons container slug) (make #:components-rev (cons slug (path-components-rev container)))) (define-public (path-slug x) (car (path-components-rev x))) (define-public (path-equal? x y) (equal? (path-components-rev x) (path-components-rev y)))