Skip to content

Read templates from fs.FS to allow for embedding #22

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

Merged
merged 1 commit into from
Dec 4, 2024

Conversation

gaqzi
Copy link
Contributor

@gaqzi gaqzi commented Nov 24, 2024

To allow for embedding all the assets into the binary I want to be able
to configure the filesystem html/template reads from.

I'm not sure how to add tests for this since component.go have no direct
tests. To test out the behavior I used replace in the go.mod for the
render example to see that it still worked as expected.

The new embedfs example shows the same example by swapping out the FS
to the embedded one so there's something to show how it's used. :)

I'm happy to add more tests to make it fit the project as this is a bit of a drive by PR since I wanted to solve a problem for me, and hacked it together to test if it could work :D


require github.com/donseba/go-htmx v1.11.3

replace github.com/donseba/go-htmx => ./../../
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since there's no tagged version I did this to show what it looks like, would have to remove and set to the correct version if this looks good :)

To allow for embedding all the assets into the binary I want to be able
to configure the filesystem html/template reads from.
@gaqzi gaqzi force-pushed the use-fs-for-looking-up-templates branch from 93a6e20 to f203f24 Compare November 24, 2024 14:39
@donseba
Copy link
Owner

donseba commented Nov 25, 2024

Hey thanks, for the addition . maybe it should have a switch to check if .fs is nil, and not assign a value by default.

that said I have been working on something in parallel that might interest you. https://github.com/donseba/go-partial and more specifically have a look at this PR : donseba/go-partial#14 which is still open.

it also does support the custom filesystem you are looking for.

its basically the components in this htmx repo but with many additions which felt wrong to add to this repo since the main focus of this repo should be just htmx.

@SergeAx
Copy link

SergeAx commented Nov 30, 2024

Wow, I was about to ask for embedded FS support! I wanted to go directly to issues but decided to take a look at PRs first, and here we go :) I would really appreciate merging this!

@donseba
Copy link
Owner

donseba commented Nov 30, 2024

Ok. Let me make a few changes and I'll add it.

@donseba donseba merged commit dfb38ca into donseba:main Dec 4, 2024
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.

3 participants