Make AMP Layouts first class in the validator. #1143
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This implements the logic in src/custom-element.js, applyLayout_.
validator.proto:
When added, AmpLayout takes over responsibility for
validating the four style attributes width,height,layout,sizes.
defines_default_width and defines_default_height.
This is efficient, and has sufficient expressive power for
the validation needs. E.g., if only defines_default_height is set,
that means the width will be auto.
validator.protoascii:
in github to see how they override isLayoutSupported. E.g.,
see here for amp-img.js: builtins/amp-img.js
isLayoutSizeDefined is a predicate covering fixed,
fixed-height, responsive, and fill, and in addition,
nodisplay is always allowed. This, along with the whitelist
from layout.js for hasNaturalDimensions is what then makes
up a tag spec.
validator.js is implemented in the same way:
consideration has the amp_layout field set), then the four
layout tags are added as optional via a taglist, $AMP_LAYOUT_ATTRS,
to disable the usual attribute checks.
for width and height that we deal with. I made this into a
constructor so that I can return four named values. This thing
supports 'auto', based on a constructor argument.
width, height), CalculateWidth, CalculateHeight, and
CalculateLayout compute the effective layout spec of the element.
This is where the defaults get implemented, and the logic is
intended to produce the same results as the original.
tag, based on the specification from the protoascii
(AmpLayout::supported_layouts). In the runtime, this is
done via the isLayoutSupported hook I mentioned above.
values, e.g., FIXED_HEIGHT requires that the width field is
set to 'auto'. I kept those errors short in our usual style.
Thanks to @dvoytenko and @Gregable for advice and review
(and catching bugs!).