-
Notifications
You must be signed in to change notification settings - Fork 54
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
Added alt-function to support RetinaJS libraries. #21
Conversation
Continuing discussion from #15 Neat! One bug and one API suggestion. Bug: We must calculate the hash of the group of files. If I change one image or the other, the hash should change. API suggestion: In my opinion, calculating a groupwise hash on files with the “@\dx” or “_\dx” suffix should be the default. Files will not likely get named as such by coincidence. Hence, I think the only option we need to add is a pattern, that when matched and eliminated, maps to some “root” filename. Given this:
The following filenames:
…will map to this “root” filename:
All files in the group should then get hashed together to produce:
|
Good points. I'll add these changes. |
I'll add an option to turn of handling of alternates. |
I purposely used globs in stead of regexp, because I thought it would be easier for most. But the solution would be easier just using regexp. I'm kind of for simplifying the solution. Cons:
Pros:
|
The implementation is now using regexp for matching in stead of globs. This makes the config simpler. Files are grouped and each group of files gets a hash based on the content of all files in the group. Removed dependency on glob-to-regexp and underscore.strings.
Check the new implementation. Works as to your specs. |
Cool. If it were me, I'd still have alternatesPattern: /[@_]\d+x/ // Default
alternatesPattern: [/-hover/, /-active/] // An array of patterns
alternatesPattern: null // Turn alternate matching off Again, just so everyone's clear, the role of the pattern is to produce a match which, when removed from the filename, produces some ‘base’ filename that a group of alternates share in common. Those member files then get hashed as a group and the same hash gets applied to all of the files in the group. So…
…would all produce the base filename |
Added tests for _default_ case
I've removed The reset worked already. Added test to show default case. There are not tests for array. Note that |
Probably should have been a major, 1.0.0, since it adds both new features and breaks backward functionality.
Neat. Now we just need to get @CBas' opinion. |
Come to think of it. In the current implementation the array option is seen as patterns describing separate groups alternates - different schemes you could say:
Where as:
Will would describe only one pattern of alternates. A more practical use of array would be:
The current implementation fails if two patterns matches the same file. An example
In real life I guess your pattern would be:
|
Just to let you know. We are using this problem free in production now.@CBas @steveluscher |
👍 |
👍 I'd love to see it merged in and released as a new version... What we are waiting for? @CBas @steveluscher @mblarsen |
I'm down, but I don't have write access to this repo. If this PR looks good to @CBas, it looks good to me! |
@CBas is not merging it, so for who wants to use it, replace
|
This pull requests implements an alt(ernative) option. This options will allow to map the hash prefix from an original file - say
logo.png
=>ab47.logo.png
- onto alternative versions of that file - saylogo@2x.png
=>ab47.logo@2x.png
.This is useful when you are working with retina images, that require the files to named identically except for some part of the filename, for example
@2x
.Request included passing unit tests.