You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
At the moment one can use source: auto in the template resource to search for the matching file somewhere under the templates dir in the directory of the file. These two are different operations:
Search in subdirectories
Search for a file with the matching name
but in the current implementation they are tied together, so it's "all or nothing": one can search in the subdirectories, but only if the file name matches. Sometimes it's inconvenient:
In this case I use the same source file for a bunch of different destination files, so it cannot be automatically matched. So I have to specify the full path to the source file.
It would be great if there was an option to explicitly specify a name of the source file, but still let the code search the file for you in the subdirectories.
I see few possible approaches here:
Treat source "./templates/foo" as a specific path, but source "foo" as an autosearch path (so it must start with ./ to be specific). This could be the best option, but it will break existing code (just like in my snippet above), so I doubt it's viable.
Extend source to accept a new type. For example, a two-elements array like source: [:auto, "foo.erb"], where the second argument is the filename to search for.
Add a new attribute to the template, something like source_filename, defaulting to nil.
So it could look like this:
# current code, searches for "bar" inside the "templates" and its subdirectoriestemplate"foo/bar"# current code, doesn't search but uses the specific pathtemplate"foo/bar"dosource"templates/one/two/three/four.erb"end# proposed approach #2, searches for "four.erb" inside the "templates" and its subdirectoriestemplate"foo/bar"dosource[:auto,"four.erb"]end# proposed approach #3, searches for "four.erb" inside the "templates" and its subdirectoriestemplate"foo/bar"dosource_filename"four.erb"end
If this proposal makes sense for you, I'll create a pull request.
The text was updated successfully, but these errors were encountered:
At the moment one can use
source: auto
in thetemplate
resource to search for the matching file somewhere under thetemplates
dir in the directory of the file. These two are different operations:but in the current implementation they are tied together, so it's "all or nothing": one can search in the subdirectories, but only if the file name matches. Sometimes it's inconvenient:
In this case I use the same source file for a bunch of different destination files, so it cannot be automatically matched. So I have to specify the full path to the source file.
It would be great if there was an option to explicitly specify a name of the source file, but still let the code search the file for you in the subdirectories.
I see few possible approaches here:
source "./templates/foo"
as a specific path, butsource "foo"
as an autosearch path (so it must start with./
to be specific). This could be the best option, but it will break existing code (just like in my snippet above), so I doubt it's viable.source
to accept a new type. For example, a two-elements array likesource: [:auto, "foo.erb"]
, where the second argument is the filename to search for.template
, something likesource_filename
, defaulting tonil
.So it could look like this:
If this proposal makes sense for you, I'll create a pull request.
The text was updated successfully, but these errors were encountered: