Skip to content
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

feat: custom srcset #55

Merged
merged 4 commits into from
May 4, 2020
Merged

feat: custom srcset #55

merged 4 commits into from
May 4, 2020

Conversation

ericdeansanchez
Copy link
Contributor

@ericdeansanchez ericdeansanchez commented Apr 29, 2020

This PR introduces custom srcsets. Target widths functionality has been
extended to support $start, $stop, and $tol. These values define
where the array of target widths start, stop, and how much variation
is tolerated between each subsequent width.

This functionality is accessed via the createSrcSet function which
has also been extended to support the above functionality.

Now when source set pairs are constructed they are constructed either
with default target widths or by a custom target widths array generated
if $start, $stop, and/or $tol deviates from the defaults.

This PR aims to test the new functionality in a simple manner. By
leveraging php's string literal conventions, integration tests are
performed on the entire output srcset string. I chose this route
to keep the tests easy to reason about (i.e. tried to avoid complicated
setup and string/array manipulation).

Food for thought, we discussed whether we should impl this feature
with default arguments or by passing an options=array(). I've chosen
to move ahead with default args, but am happy to impl another solution.

I could also add some constants here, namely for 8192, 100, but
I figured this could be done if/when $INCREMENT_PERCENTAGE is
normalized to $SRCSET_WIDTH_TOLERANCE.

@ericdeansanchez ericdeansanchez marked this pull request as ready for review April 30, 2020 22:55
Copy link
Contributor

@sherwinski sherwinski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍, just one syntax question before we merge:

@@ -65,65 +74,96 @@ public function createURL($path, $params=array()) {
return $uh->getURL();
}

public function createSrcSet($path, $params=array()) {
public function createSrcSet($path, $params=array(), $start=100, $stop=8192, $tol=8, $disable_variable_quality=false) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have disable_variable_quality written in camelCase? [1]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Yes! It should be disableVariableQuality, thank you! I will make this change right now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I have updated and camel-cased the flag: disableVariableQuality

@ericdeansanchez ericdeansanchez merged commit 8019f1b into master May 4, 2020
@ericdeansanchez ericdeansanchez deleted the custom-srcset branch May 4, 2020 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants