fixing the resource querying so it's per module
This commit is contained in:
parent
e6547a9aa2
commit
8e03f3dc28
|
@ -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))))))]))
|
||||
|
|
|
@ -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))))
|
||||
|
|
|
@ -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 '()))))
|
||||
|
|
Loading…
Reference in New Issue
Block a user