(sigil resources)
(sigil resources) - Unified resource resolution for Sigil
Provides access to library, documentation, and asset files with automatic resolution across project builds, bundled archives, and filesystem.
Resolution order:
- Project build output (if package.sgl found in cwd or parents)
- Bundled archive (if running from a bundled executable)
- Executable-relative (assets/ folder next to binary, for 'assets only)
- Filesystem (library-paths for 'lib only)
Resource categories determine the base path:
- 'lib -> project: build/dev/lib/ | bundle: lib/ | system: library-paths
- 'docs -> project: docs/ | bundle: docs/
- 'assets -> project: assets/ | bundle: assets/ | exe-relative: assets/
Example:
(import (sigil resources)) ;; Read module JSON docs (read-resource 'lib "sigil/string.json") ;; Read language reference markdown (read-resource 'docs "reference/language/syntax.md") ;; Read an asset file (read-resource-bytes 'assets "images/logo.png")
Exports
clear-resource-cacheprocedureClear the resource resolution cache.
Resets the cached project root so the next resource lookup re-scans the filesystem. Call this after changing the working directory or modifying the project layout.
(clear-resource-cache)project-rootprocedureGet the project root directory, or #f if not in a project.
A project is detected by finding package.sgl in the current directory or any parent directory. The result is cached; call clear-resource-cache to reset.
(project-root) ; => "/home/user/my-project" or #fin-project?procedureCheck if currently running within a Sigil project.
Returns #t if package.sgl is found in the current directory or any parent directory.
(in-project?) ; => #tresource-contextprocedureGet the current resource resolution context.
Returns a symbol indicating where resources are resolved from:
project— loaded from a project build directorybundle— loaded from a bundled executable archivesystem— loaded from filesystem library paths
(resource-context) ; => projectresource-exists?procedureCheck if a resource exists.
Category is one of: 'lib, 'docs, 'assets. Path is relative within that category (e.g., "sigil/string.json").
(resource-exists? 'lib "sigil/string.json") ; => #tread-resourceprocedureRead a resource as a string.
Returns the file contents as a string, or #f if not found. Category is one of: 'lib, 'docs, 'assets.
(read-resource 'docs "reference/language/syntax.md")
; => "# Syntax\n..."read-resource-bytesprocedureRead a resource as a bytevector.
Returns the file contents as a bytevector, or #f if not found. Useful for binary assets like images.
(read-resource-bytes 'assets "images/logo.png")
; => #u8(137 80 78 71 ...)