Static HTML Template helper#14623
Conversation
| this.win.document.documentElement.classList.add('i-amphtml-ios-embed'); | ||
| const documentElement = this.win.document.documentElement; | ||
| const topClasses = documentElement.className; | ||
| documentElement.className = 'i-amphtml-ios-embed'; |
There was a problem hiding this comment.
Nice clean up.
I'm curious why className was set to an empty value and the classList was added to afterward in the previous code. Is there a subtle behaviour specific to iOS?
There was a problem hiding this comment.
Looks like an oversight from https://github.com/ampproject/amphtml/pull/6276/files#diff-6eedd5ca45df1b5aee7d616b017d360aR1419.
| <img class="i-amphtml-intrinsic-sizer" /> | ||
| </i-amphtml-sizer>`; | ||
| const intrinsicSizer = sizer.firstElementChild; | ||
| intrinsicSizer.setAttribute('src', |
There was a problem hiding this comment.
Perhaps I am missing something. Why can't this attribute be included in the template literal?
There was a problem hiding this comment.
The src requires dynamic height and width, which aren't statically analyzable.
| preload.setAttribute('rel', 'preload'); | ||
| const preload = htmlFor(this.document_)` | ||
| <link rel="preload" referrerpolicy="origin" />`; | ||
| preload.setAttribute('href', url); |
There was a problem hiding this comment.
Same question here, is there a reason the url cannot be included here in the tagged template literal?
There was a problem hiding this comment.
The url is not statically analyzable, so there's not guarantee that it's not malicious.
|
/cc @newmuis @Enriqe @gmajoulet for IMO this should be used instead of Dynamic templating still unsolved. |
|
@alanorozco Thanks to our naive localization approach, pretty much none of our templates are static anymore (translated strings get swapped in at runtime) |
Using the diff --git a/extensions/amp-story/0.1/amp-story.js b/extensions/amp-story/0.1/amp-story.js
--- a/extensions/amp-story/0.1/amp-story.js
+++ b/extensions/amp-story/0.1/amp-story.js
* Container for "pill-style" share widget, rendered on desktop.
* @private @const {!./simple-template.ElementDef}
*/
-const SHARE_WIDGET_PILL_CONTAINER = {
- tag: 'div',
- attrs: dict({'class': 'i-amphtml-story-share-pill'}),
- children: [
- {
- tag: 'span',
- attrs: dict({'class': 'i-amphtml-story-share-pill-label'}),
- localizedStringId:
- LocalizedStringId.AMP_STORY_SYSTEM_LAYER_SHARE_WIDGET_LABEL,
- },
- ],
-};
+const shareWidgetPillContainer = html`
+ <div class="i-amphtml-story-share-pill">
+ <span class="i-amphtml-story-share-pill-label"></span>
+ </div>`
+shareWidgetPillContainer.querySelector('i-amphtml-story-share-pill-label')
+ .innerText = LocalizedStringId.AMP_STORY_SYSTEM_LAYER_SHARE_WIDGET_LABEL; |
b509aed to
5ddba2e
Compare
5ddba2e to
c85d4af
Compare
|
So there's good news and bad news. 👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there. 😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request. Note to project maintainer: This is a terminal state, meaning the |
244d511 to
3c606ba
Compare
|
CLAs look good, thanks! |
0fef4f7 to
14bd80d
Compare
Create static HTML DOM trees using a HTML like syntax. This is **only** available for static trees. **Dynamic variables in the string are not permitted**.
14bd80d to
ed7c01e
Compare
* Static HTML Template helper Create static HTML DOM trees using a HTML like syntax. This is **only** available for static trees. **Dynamic variables in the string are not permitted**. * Typecast * Update fixed position tests * Do not create HTML elements using html helper * Insensitive lint * lint * Add htmlRefs function * Bump max filesize * Tests * Revert changes to eslint-plugin-amphtml-internal version * Lint
Create static HTML DOM trees using a HTML like syntax. Leading/trailing text (including whitespace) is dropped, and only a single root element in the template is supported.
This is only available for static trees. Dynamic variables in the string are not permitted, and will result in linting errors and runtime errors.
Valid uses are:
Or, you can use it directly as the template literal tag:
Closes #14529, jump starts #13906.
/cc @alanorozco, @kristoferbaxter