Skip to content

feat: WritableFS, LocalFS, MemFS, and fs.FS-backed FileSystemLoader#2

Merged
panyam merged 2 commits into
mainfrom
feat/writable-fs
Apr 3, 2026
Merged

feat: WritableFS, LocalFS, MemFS, and fs.FS-backed FileSystemLoader#2
panyam merged 2 commits into
mainfrom
feat/writable-fs

Conversation

@panyam

@panyam panyam commented Apr 3, 2026

Copy link
Copy Markdown
Owner

Summary

Adds portable filesystem abstractions to Templar, enabling template storage beyond the local disk (S3, IndexedDB/WASM, in-memory for tests).

New types

Type What it is
WritableFS Interface: fs.FS + WriteFile/MkdirAll/Remove/Rename
LocalFS WritableFS backed by local OS filesystem (relative to root dir)
MemFS WritableFS backed by in-memory map (testing, WASM)

FileSystemLoader enhancement

New FileSystems []fs.FS field where FileSystems[i] backs Folders[i]:

// Old way (unchanged, backward compatible):
loader := NewFileSystemLoader("/usr/share/templates")

// New way (portable):
loader := &FileSystemLoader{
    Folders:     []string{"templates", "layouts"},
    FileSystems: []fs.FS{myMemFS, myS3FS},
    Extensions:  []string{"html"},
}

When FileSystems[i] is nil (or the slice is shorter), falls back to OS filesystem — fully backward compatible.

Motivation

Slyds (presentation toolkit) needs to store decks on various backends. Rather than invent a separate filesystem abstraction, we're adding it to Templar where the template loader can use it directly. This benefits any Templar user who wants templates from non-OS sources.

Tests

19 new tests covering LocalFS, MemFS (including write isolation, directory inference), FileSystemLoader with MemFS, mixed FS+OS, backward compatibility.

All existing tests pass unchanged.

panyam added 2 commits April 3, 2026 14:18
…emLoader

Adds portable filesystem abstractions for template storage:

WritableFS interface:
- Extends fs.FS with WriteFile, MkdirAll, Remove, Rename
- Enables template storage on local disk, S3, IndexedDB (WASM), in-memory

LocalFS:
- WritableFS backed by local OS filesystem
- All paths relative to a root directory

MemFS:
- WritableFS backed by in-memory map
- Full fs.FS compliance (Open, ReadFile, ReadDir, Stat with directory inference)
- Write isolation (copies on write to prevent aliasing)
- Useful for testing and WASM environments

FileSystemLoader fs.FS support:
- New FileSystems []fs.FS field: FileSystems[i] backs Folders[i]
- nil entry = OS filesystem (backward compatible)
- Existing code using only Folders works unchanged

19 new tests covering:
- LocalFS: write/read roundtrip, mkdir, remove, rename, readdir
- MemFS: write/read, open, remove, rename, readdir, stat, isolation, dir inference
- FileSystemLoader: MemFS-backed loading, mixed FS+OS, backward compat, not-found
@panyam panyam merged commit 77f39b8 into main Apr 3, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant