fixing the resource querying so it's per module

This commit is contained in:
Danny Yoo 2011-08-15 13:28:20 -04:00
parent e6547a9aa2
commit 8e03f3dc28
3 changed files with 19 additions and 11 deletions

View File

@ -26,9 +26,14 @@
[munged-path munged-path]) [munged-path munged-path])
(syntax/loc stx (syntax/loc stx
(begin (begin
;; Compile time code: ;; Compile time code:
(begin-for-syntax (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 ;; Run time code
(define name (resource normal-path munged-path))))))])) (define name (resource normal-path munged-path))))))]))

View File

@ -3,18 +3,19 @@
(require racket/contract (require racket/contract
racket/runtime-path racket/runtime-path
syntax/modresolve syntax/modresolve
racket/path
"structs.rkt") "structs.rkt")
(provide/contract [query (module-path? . -> . (listof resource?))]) (provide/contract [query (module-path? . -> . (listof resource?))])
(define-runtime-path record.rkt "record.rkt") (define-runtime-path record.rkt "record.rkt")
(define ns (make-base-empty-namespace)) (define ns (make-base-namespace))
;; query: module-path -> (listof record) ;; query: module-path -> (listof record)
;; Given a module, collect all of its resource records ;; Given a module, collect all of its resource records
(define (query a-module-path) (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]) (parameterize ([current-namespace ns])
(dynamic-require a-module-path (void)) ;; get the compile-time code running. (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))))

View File

@ -9,12 +9,14 @@
(struct resource (path key) #:prefab) (struct resource (path key) #:prefab)
(define records '()) (define records (make-hash))
(define (get-records) (define (get-records a-path)
records) (hash-ref records a-path '()))
;; record-javascript-implementation!: path a-resource-path -> void
(define (record-resource a-resource-path a-key) ;; record-javascript-implementation!: path path a-resource-path -> void
(set! records (cons (resource a-resource-path a-key) (define (record-resource a-module-path a-resource-path a-key)
records))) (hash-set! records a-module-path
(cons (resource a-resource-path a-key)
(hash-ref records a-module-path '()))))