-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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
resources: Create a ResourceFinder interface #9063
Conversation
0e38e16
to
cca66a8
Compare
So, this is the common interface: // ResourceFinder provides methods to find Resources.
type ResourceFinder interface {
// Get locates the Resource with the given name in the current context (e.g. in .Page.Resources).
//
// It returns nil if no Resource could found.
Get(name interface{}) Resource
// GetMatch finds the first Resource matching the given pattern, or nil if none found.
//
// See Match for a more complete explanation about the rules used.
//
// It returns nil if no Resource could found, panics if pattern is invalid.
GetMatch(pattern interface{}) Resource
// Match gets all resources matching the given base path prefix, e.g
// "*.png" will match all png files. The "*" does not match path delimiters (/),
// so if you organize your resources in sub-folders, you need to be explicit about it, e.g.:
// "images/*.png". To match any PNG image anywhere in the bundle you can do "**.png", and
// to match all PNG images below the images folder, use "images/**.jpg".
//
// The matching is case insensitive.
//
// Match matches by using a relative pathwith Unix style slashes (/) and no
// leading slash, e.g. "images/logo.png".
//
// See https://github.com/gobwas/glob for the full rules set.
//
// It looks for files in the assets file system.
//
// See Match for a more complete explanation about the rules used.
//
// It returns nil if no Resources could found, panics if pattern is invalid.
Match(pattern interface{}) Resources
// ByType returns resources of a given resource type (e.g. "image").
// It returns nil if no Resources could found, panics if tp is invalid.
ByType(tp interface{}) Resources
} |
f599b6d
to
9aa6ae8
Compare
@jmooring I totally forgot about this branch. I have now rebased it against master. Note the absence of // ResourceFinder provides methods to find Resources.
// Note that GetRemote (as found in resources.GetRemote) is
// not covered by this interface, as this is only available as a global template function.
type ResourceFinder interface {
// Get locates the Resource with the given name in the current context (e.g. in .Page.Resources).
//
// It returns nil if no Resource could found, panics if name is invalid.
Get(name any) Resource
// GetMatch finds the first Resource matching the given pattern, or nil if none found.
//
// See Match for a more complete explanation about the rules used.
//
// It returns nil if no Resource could found, panics if pattern is invalid.
GetMatch(pattern any) Resource
// Match gets all resources matching the given base path prefix, e.g
// "*.png" will match all png files. The "*" does not match path delimiters (/),
// so if you organize your resources in sub-folders, you need to be explicit about it, e.g.:
// "images/*.png". To match any PNG image anywhere in the bundle you can do "**.png", and
// to match all PNG images below the images folder, use "images/**.jpg".
//
// The matching is case insensitive.
//
// Match matches by using a relative pathwith Unix style slashes (/) and no
// leading slash, e.g. "images/logo.png".
//
// See https://github.com/gobwas/glob for the full rules set.
//
// See Match for a more complete explanation about the rules used.
//
// It returns nil if no Resources could found, panics if pattern is invalid.
Match(pattern any) Resources
// ByType returns resources of a given resource type (e.g. "image").
// It returns nil if no Resources could found, panics if typ is invalid.
ByType(typ any) Resources
} |
aca7eee
to
3345c36
Compare
I vote no. I updated the image processing docs recently, and the separation between page and global resources made sense, at least to me: https://gohugo.io/content-management/image-processing/#image-resources
|
@jmooring OK, looking at the above, I will take another take on the interface to get rid of the |
And make both .Resources and resources implement it. This gets us 2 new methods/functions, so you can now also do: * .Resources.Get * resources.ByType Note that GetRemote is not covered by this interface, as that is only available as a global template function. Fixes gohugoio#8653
3345c36
to
8adb8ca
Compare
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
And make both .Resources and resources implement it.
Note that GetRemote is not covered by this interface, as that is only available as a global template function.
Fixes #8653