diff --git a/resource/compile-time.rkt b/resource/compile-time.rkt index b1acda7..9a26d6e 100644 --- a/resource/compile-time.rkt +++ b/resource/compile-time.rkt @@ -26,9 +26,14 @@ [munged-path munged-path]) (syntax/loc stx (begin + ;; Compile time code: (begin-for-syntax - (record-resource normal-path munged-path)) + (let* ([this-module + (variable-reference->resolved-module-path + (#%variable-reference))] + [resolved-module-path (resolved-module-path-name this-module)]) + (record-resource resolved-module-path normal-path munged-path))) ;; Run time code (define name (resource normal-path munged-path))))))])) diff --git a/resource/query.rkt b/resource/query.rkt index 5a6b437..03176a9 100644 --- a/resource/query.rkt +++ b/resource/query.rkt @@ -3,18 +3,19 @@ (require racket/contract racket/runtime-path syntax/modresolve + racket/path "structs.rkt") (provide/contract [query (module-path? . -> . (listof resource?))]) (define-runtime-path record.rkt "record.rkt") -(define ns (make-base-empty-namespace)) +(define ns (make-base-namespace)) ;; query: module-path -> (listof record) ;; Given a module, collect all of its resource records (define (query a-module-path) - (let ([resolved-path (resolve-module-path a-module-path #f)]) + (let ([resolved-path (normalize-path (resolve-module-path a-module-path #f))]) (parameterize ([current-namespace ns]) (dynamic-require a-module-path (void)) ;; get the compile-time code running. - ((dynamic-require-for-syntax record.rkt 'get-records))))) + ((dynamic-require-for-syntax record.rkt 'get-records) resolved-path)))) diff --git a/resource/record.rkt b/resource/record.rkt index 17877a5..95c4856 100644 --- a/resource/record.rkt +++ b/resource/record.rkt @@ -9,12 +9,14 @@ (struct resource (path key) #:prefab) -(define records '()) +(define records (make-hash)) -(define (get-records) - records) +(define (get-records a-path) + (hash-ref records a-path '())) -;; record-javascript-implementation!: path a-resource-path -> void -(define (record-resource a-resource-path a-key) - (set! records (cons (resource a-resource-path a-key) - records))) + +;; record-javascript-implementation!: path path a-resource-path -> void +(define (record-resource a-module-path a-resource-path a-key) + (hash-set! records a-module-path + (cons (resource a-resource-path a-key) + (hash-ref records a-module-path '()))))