Skip to content

Commit

Permalink
feat(linkResolver): as argument to Prismic::Dom
Browse files Browse the repository at this point in the history
  • Loading branch information
mrloop committed Jan 28, 2021
1 parent 3e5987c commit 77cf510
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 9 deletions.
6 changes: 5 additions & 1 deletion addon/components/prismic/children.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{{~#each @node.children as |child|~}}
<Prismic::Element @node={{child}} @onUnknownTag={{@onUnknownTag}} />
<Prismic::Element
@linkResolver={{@linkResolver}}
@node={{child}}
@onUnknownTag={{@onUnknownTag}}
/>
{{~else~}}
{{~@node.element.text~}}
{{~/each~}}
6 changes: 5 additions & 1 deletion addon/components/prismic/dom.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
{{@nodes}}
{{~else~}}
{{~#each this.tree.children as |child|~}}
<Prismic::Element @node={{child}} @onUnknownTag={{@onUnknownTag}} />
<Prismic::Element
@linkResolver={{@linkResolver}}
@node={{child}}
@onUnknownTag={{@onUnknownTag}}
/>
{{~/each~}}
{{~/if~}}
</div>
26 changes: 19 additions & 7 deletions addon/components/prismic/element.hbs
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
{{~#if (eq @node.type "image")~}}
{{~#if (eq @node.type 'image')~}}
<Prismic::Image @node={{@node}} />
{{~else if (eq @node.type "span")~}}
<Prismic::Children @node={{@node}} @onUnknownTag={{@onUnknownTag}} />
{{~else if (eq @node.type "hyperlink")~}}
{{~else if (eq @node.type 'span')~}}
<Prismic::Children
@linkResolver={{@linkResolver}}
@node={{@node}}
@onUnknownTag={{@onUnknownTag}}
/>
{{~else if (eq @node.type 'hyperlink')~}}
<a
href={{this.linkHref}}
rel="noreferrer noopener"
rel='noreferrer noopener'
target={{this.target}}
><Prismic::Children @node={{@node}} @onUnknownTag={{@onUnknownTag}} /></a>
><Prismic::Children
@linkResolver={{@linkResolver}}
@node={{@node}}
@onUnknownTag={{@onUnknownTag}}
/></a>
{{~else~}}
{{~#let (element this.tagName) as |Tag|~}}
<Tag><Prismic::Children @node={{@node}} @onUnknownTag={{@onUnknownTag}} /></Tag>
<Tag><Prismic::Children
@linkResolver={{@linkResolver}}
@node={{@node}}
@onUnknownTag={{@onUnknownTag}}
/></Tag>
{{~/let~}}
{{~/if~}}
34 changes: 34 additions & 0 deletions tests/integration/components/prismic/dom-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,40 @@ module('Integration | Component | prismic/dom', function (hooks) {
});

module('complex combinations', function () {
test('doc hyperlink with linkResolver', async function (assert) {
this.nodes = [
{
type: 'paragraph',
text: 'A link to another doc',
spans: [
{
start: 18,
end: 21,
type: 'hyperlink',
data: {
id: 'YAlUbREAACIAEKtG',
type: 'faq_article',
tags: ['transaction_helper_cards'],
slug: 'processing-card-transaction',
lang: 'en-us',
link_type: 'Document',
isBroken: false,
},
},
],
},
];
this.linkResolver = ({ uid }) => `https://qonto.com/${uid}`;

await render(
hbs`<Prismic::Dom @linkResolver={{this.linkResolver}} @nodes={{this.nodes}} />`
);

assert
.dom('a')
.hasProperty('href', 'https://qonto.com/processing-card-transaction');
});

test('list', async function (assert) {
this.nodes = [
{ type: 'o-list-item', text: 'one', spans: [] },
Expand Down

0 comments on commit 77cf510

Please sign in to comment.