-
Notifications
You must be signed in to change notification settings - Fork 3
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
Allow glob pattern to specify files #18
Comments
API idea: @EmbedStr('xml/*.xml') // A glob pattern
const files = _$files; // Map<String, String>
@EmbedBinary('images/*.png')
const images = _$images; // Map<String, List<int>>
// Generated code
const _$files = {
'xml/basic.xml': "...",
'xml/river.xml': "...",
};
const _$images = {
'png/foo.png': [10, ...],
'png/bar.png' : [8, ...],
} |
Glob is a good idea. I do wonder if you need a different annotation than the standard one, to perhaps avoid confusion / unexpected behaviour when you try and embed a single file that happens to include glob character. |
Maybe we could avoid this problem by explicitly typing annotated variables depending on the expected output types. ( // Default output type depends on the result of glob search
@EmbedStr('xml/*.xml')
const basic = _$basic;
// Expects a single output
@EmbedStr('xml/basic.xml')
const String basic = _$basic;
// Expects multiple outputs
@EmbedStr('xml/*.xml')
const Map<String, String> files = _$files; One good thing about this approach is that the Dart compiler would warn us if a file path unexpectedly contains a glob pattern. // Compile error: Cannot assign a Map to a String variable
@EmbedStr('xml/*.xml')
const String basic = _$basic; @bramp, what do you think? Is it still confusing? |
Still could be error prone, but seems reasonable enough. I think my concern is a minor one, and I guess either way it'll hopefully be caught early. I'm happy with whichever approach. |
Today I have to write
Instead I would love to write
The text was updated successfully, but these errors were encountered: