Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

hotfix: fixed go:embed directive to include partials for resources #57

Merged
merged 4 commits into from Nov 27, 2021

Conversation

sio4
Copy link
Member

@sio4 sio4 commented Nov 27, 2021

Fixed go:embed directive to include partials (starting with _) in the resource directories also included successfully.

fixes #55 along with gobuffalo/buffalo#2178

@sio4 sio4 changed the title hotfix: fixed go:embed directive to include partials in resource directory hotfix: fixed go:embed directive to include partials for resources Nov 27, 2021
@fasmat
Copy link
Member

fasmat commented Nov 27, 2021

lgtm

@paganotoni paganotoni merged commit 98b5bea into gobuffalo:main Nov 27, 2021
@sio4 sio4 mentioned this pull request Nov 29, 2021
14 tasks
@saurori
Copy link
Contributor

saurori commented Nov 29, 2021

The */* does not work for me (on Go 1.17.2). I have a directory templates/content/shared with a few partials that have file names starting with _. In development I get the following error:

templates/embed.go:8:14: pattern */*: cannot embed directory content/shared: contains no embeddable files

I believe this is a known issue, see: golang/go#43854 . Looks like it will be fixed in a future go release, but maybe not until 1.18 :/

@fasmat
Copy link
Member

fasmat commented Nov 29, 2021

@saurori Files starting with _ or . are ignored by the //go:embed directive. The only way to have them included is to either include them explicitly with //go:embed templates/content/shared/_myfile.html or to include their parent folder with a wildcard: //go:embed templates/content/shared/*

The automatically generated files cannot account for all subfolders of the directory, since embed uses filepath.Glob to find files and this function does not support ** (see also here)

Fortunately you can add as many //go:embed directives above the variable as you wish to include all the files you need in your application.

@sio4
Copy link
Member Author

sio4 commented Nov 29, 2021

Yeah, @saurori, as you mentioned the issue on golang, it is a limitation of golang 1.16 and 1.17 and not easy to handle it automatically since your files are not in the standard directory created by generators. I think once we document it, it could be helpful but currently, we just started supporting them, and are still not clearly documented.

@saurori
Copy link
Contributor

saurori commented Nov 29, 2021

I'm aware of the limitations as pointed out in the Golang issue. I was more pointing out that using //go:embed * */* in the embed template will break for some users once they add other partials. For now I've resorted to running a find **/_* in the templates/ dir to enumerate all the partials for go:embed until something like //go:embed all:_ is supported.

EDIT: @sio4 yeah I think some documentation or a comment would be helpful 👍

@sio4
Copy link
Member Author

sio4 commented Nov 29, 2021

Yeah, I know you exactly mentioned that and linked the issue on golang repo. Thanks for pointing out that issue too!

By the way, The current implementation does not break users who just use generated templates within standard paths such as templates itself and templates/resource. To make it smoother, we are working on supporting those cases like your subdirectory pattern under the resource directory. It is coming around the corner! Stay tuned!

@sio4 sio4 deleted the hotfix-template-embedding branch March 12, 2022 02:29
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New application with buffalo 0.18: could not find templates errors
4 participants