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

Release amp-mustache from experimental #1161

Merged
merged 1 commit into from
Jan 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions extensions/amp-mustache/0.1/amp-mustache.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,10 @@
* limitations under the License.
*/

import {isExperimentOn} from '../../../src/experiments';
import {log} from '../../../src/log';
import {parse as mustacheParse, render as mustacheRender,
setUnescapedSanitizier} from '../../../third_party/mustache/mustache';
import {sanitizeHtml, sanitizeFormattingHtml} from '../../../src/sanitizer';

/** @const */
const EXPERIMENT = 'mustache';

/** @const */
const TAG = 'AmpMustache';


// Configure inline sanitizer for unescaped values.
setUnescapedSanitizier(sanitizeFormattingHtml);

Expand All @@ -39,34 +30,15 @@ setUnescapedSanitizier(sanitizeFormattingHtml);
*/
export class AmpMustache extends AMP.BaseTemplate {

/**
* @return {boolean}
* @private
*/
isExperimentOn_() {
return isExperimentOn(this.getWin(), EXPERIMENT);
}

/** @override */
compileCallback() {
if (!this.isExperimentOn_()) {
return;
}
/** @private @const {string} */
this.template_ = this.element./*OK*/innerHTML;
mustacheParse(this.template_);
}

/** @override */
render(data) {
if (!this.isExperimentOn_()) {
const m = `Experiment "${EXPERIMENT}" disabled`;
log.warn(TAG, m, this.element);
const fallback = document.createElement('div');
fallback.textContent = m;
return fallback;
}

const html = mustacheRender(this.template_, data);
const sanitized = sanitizeHtml(html);
const root = this.getWin().document.createElement('div');
Expand Down
14 changes: 1 addition & 13 deletions extensions/amp-mustache/0.1/test/test-amp-mustache.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,10 @@ import {AmpMustache}

describe('amp-mustache template', () => {

it('should be blocked by the experiment', () => {
const templateElement = document.createElement('div');
const template = new AmpMustache(templateElement);
template.isExperimentOn_ = () => false;
const result = template.render({});
expect(result./*OK*/innerHTML).to.equal('Experiment "mustache" disabled');
});

it('should render with the experiment', () => {
it('should render', () => {
const templateElement = document.createElement('div');
templateElement.textContent = 'value = {{value}}';
const template = new AmpMustache(templateElement);
template.isExperimentOn_ = () => true;
template.compileCallback();
const result = template.render({value: 'abc'});
expect(result./*OK*/innerHTML).to.equal('value = abc');
Expand All @@ -41,7 +32,6 @@ describe('amp-mustache template', () => {
const templateElement = document.createElement('div');
templateElement./*OK*/innerHTML = 'value = <a href="{{value}}">abc</a>';
const template = new AmpMustache(templateElement);
template.isExperimentOn_ = () => true;
template.compileCallback();
const result = template.render({
value: /*eslint no-script-url: 0*/ 'javascript:alert();'
Expand All @@ -53,7 +43,6 @@ describe('amp-mustache template', () => {
const templateElement = document.createElement('div');
templateElement.textContent = 'value = {{{value}}}';
const template = new AmpMustache(templateElement);
template.isExperimentOn_ = () => true;
template.compileCallback();
const result = template.render({value: '<b>abc</b><img><div>def</div>'});
expect(result./*OK*/innerHTML).to.equal('value = <b>abc</b>');
Expand All @@ -63,7 +52,6 @@ describe('amp-mustache template', () => {
const templateElement = document.createElement('div');
templateElement./*OK*/innerHTML = '<a>abc</a>';
const template = new AmpMustache(templateElement);
template.isExperimentOn_ = () => true;
template.compileCallback();
const result = template.render({});
expect(result.tagName).to.equal('A');
Expand Down
8 changes: 0 additions & 8 deletions tools/experiments/experiments.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,6 @@ const EXPERIMENTS = [
'DEVELOPING.md#amp-dev-channel-experimental',
},

// Mustache
{
id: 'mustache',
name: 'Mustache templates (amp-mustache)',
spec: 'https://github.com/ampproject/amphtml/blob/master/extensions/' +
'amp-mustache/amp-mustache.md',
},

// AMP Analytics
{
id: 'amp-analytics',
Expand Down