Commit d7e21e4b authored by Enrique Alcantara's avatar Enrique Alcantara

Code review feedback

- Identify attribute definition HTML comment
- Rename renderUtils.canRender to willAlwaysRender
- Do not display attribute definitions in a tooltip
parent 0342d1cd
......@@ -2,6 +2,6 @@ import { isAttributeDefinition } from './render_utils';
const canRender = ({ literal }) => isAttributeDefinition(literal);
const render = () => ({ type: 'html', content: '<!-- -->' });
const render = () => ({ type: 'html', content: '<!-- sse-attribute-definition -->' });
export default { canRender, render };
import { renderWithAttributeDefinitions as render, canRender } from './render_utils';
import {
renderWithAttributeDefinitions as render,
willAlwaysRender as canRender,
} from './render_utils';
export default { render, canRender };
import { renderWithAttributeDefinitions as render, canRender } from './render_utils';
import {
renderWithAttributeDefinitions as render,
willAlwaysRender as canRender,
} from './render_utils';
export default { render, canRender };
......@@ -4,13 +4,13 @@ import {
buildUneditableCloseToken,
} from './build_uneditable_token';
const attributeDefinitionRegexp = /(^{:.+}$)/;
export const renderUneditableLeaf = (_, { origin }) => buildUneditableBlockTokens(origin());
export const renderUneditableBranch = (_, { entering, origin }) =>
entering ? buildUneditableOpenTokens(origin()) : buildUneditableCloseToken();
const attributeDefinitionRegexp = /(^{:.+}$)/;
export const isAttributeDefinition = text => attributeDefinitionRegexp.test(text);
const findAttributeDefinition = node => {
......@@ -20,22 +20,19 @@ const findAttributeDefinition = node => {
return isAttributeDefinition(literal) ? literal : null;
};
export const renderWithAttributeDefinitions = (node, context) => {
export const renderWithAttributeDefinitions = (node, { origin }) => {
const attributes = findAttributeDefinition(node);
const origin = context.origin();
const token = origin();
if (origin.type === 'openTag' && attributes) {
Object.assign(origin, {
if (token.type === 'openTag' && attributes) {
Object.assign(token, {
attributes: {
'data-attribute-definition': attributes,
'data-toggle': 'tooltip',
'data-placement': 'left',
title: attributes,
},
});
}
return origin;
return token;
};
export const canRender = () => true;
export const willAlwaysRender = () => true;
......@@ -16,7 +16,10 @@ describe('rich_content_editor/renderers/render_attribute_definition', () => {
describe('render', () => {
it('returns an empty HTML comment', () => {
expect(renderer.render()).toEqual({ type: 'html', content: '<!-- -->' });
expect(renderer.render()).toEqual({
type: 'html',
content: '<!-- sse-attribute-definition -->',
});
});
});
});
......@@ -2,8 +2,8 @@ import renderer from '~/vue_shared/components/rich_content_editor/services/rende
import * as renderUtils from '~/vue_shared/components/rich_content_editor/services/renderers/render_utils';
describe('rich_content_editor/renderers/render_heading', () => {
it('canRender delegates to renderUtils.canRender', () => {
expect(renderer.canRender).toBe(renderUtils.canRender);
it('canRender delegates to renderUtils.willAlwaysRender', () => {
expect(renderer.canRender).toBe(renderUtils.willAlwaysRender);
});
it('render delegates to renderUtils.renderWithAttributeDefinitions', () => {
......
......@@ -2,8 +2,8 @@ import renderer from '~/vue_shared/components/rich_content_editor/services/rende
import * as renderUtils from '~/vue_shared/components/rich_content_editor/services/renderers/render_utils';
describe('rich_content_editor/renderers/render_list_item', () => {
it('canRender delegates to renderUtils.canRender', () => {
expect(renderer.canRender).toBe(renderUtils.canRender);
it('canRender delegates to renderUtils.willAlwaysRender', () => {
expect(renderer.canRender).toBe(renderUtils.willAlwaysRender);
});
it('render delegates to renderUtils.renderWithAttributeDefinitions', () => {
......
......@@ -2,6 +2,7 @@ import {
renderUneditableLeaf,
renderUneditableBranch,
renderWithAttributeDefinitions,
willAlwaysRender,
} from '~/vue_shared/components/rich_content_editor/services/renderers/render_utils';
import {
......@@ -43,15 +44,18 @@ describe('rich_content_editor/renderers/render_utils', () => {
});
});
describe('willAlwaysRender', () => {
it('always returns true', () => {
expect(willAlwaysRender()).toBe(true);
});
});
describe('renderWithAttributeDefinitions', () => {
let openTagToken;
let closeTagToken;
let node;
const attributes = {
'data-attribute-definition': attributeDefinition,
title: attributeDefinition,
'data-toggle': 'tooltip',
'data-placement': 'left',
};
beforeEach(() => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment