Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed ##include-string and resource-readers for http and ipfs #88

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/lib/resource/http.scm
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,17 @@
(##define-resource-reader
http
(lambda (resource-path)
(shell-cmd (string-append "curl --silent http://" resource-path))))
(let ((resource-path-real
(if (string-prefix? "http:/" resource-path)
(string-append "http://" (substring resource-path (string-length "http:/") (string-length resource-path)))
(string-append "http://" resource-path))))
(open-input-string (pipe-through (string-append "curl --silent " resource-path-real) "")))))

(##define-resource-reader
https
(lambda (resource-path)
(let ((resource-path-real
(if (string-prefix? "https:/" resource-path)
(string-append "https://" (substring resource-path (string-length "https:/") (string-length resource-path)))
(string-append "https://" resource-path))))
(open-input-string (pipe-through (string-append "curl --silent " resource-path-real) "")))))
2 changes: 1 addition & 1 deletion src/lib/resource/ipfs.scm
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
(##define-resource-reader
ipfs
(lambda (resource-path)
(shell-cmd (string-append "ipfs cat " resource-path))))
(open-input-string (pipe-through (string-append "ipfs cat " resource-path) ""))))
2 changes: 2 additions & 0 deletions src/lib/resource/macros.scm
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
(##include-once (ribbit "define-macro"))

(define-macro
(##define-resource-reader name reader)
(add-resource-str-reader!
Expand Down
11 changes: 10 additions & 1 deletion src/rsc.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1828,7 +1828,7 @@
mtx)
#f))))

((eqv? first '##include-str)
((eqv? first '##include-string)
(expand-expr (read-str-resource (parse-resource (cadr expr))) mtx))

(else
Expand Down Expand Up @@ -2140,6 +2140,15 @@
((cadr reader) resource-path)
(error "No resource reader found for resource-type:" (resource-type resource)))))

(define (read-char-list input-port)
(let loop ((c (read-char input-port)))
(cond
((eof-object? c) '())
(else (cons c (loop (read-char input-port)))))))

(define (read-str-resource resource)
(list->string (read-char-list (get-resource-port resource))))

(define (expand-resource resource mtx)
(let ((old-current-resource current-resource))
(set! current-resource resource)
Expand Down
Loading