Skip to content

Commit

Permalink
refactor: remove string templates (#495)
Browse files Browse the repository at this point in the history
  • Loading branch information
shaejaz authored Oct 8, 2024
1 parent 81a45c0 commit 5057297
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 78 deletions.
6 changes: 3 additions & 3 deletions instantsearch.js/autocomplete-results-page/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ search.addWidgets([
instantsearch.widgets.hits({
container: '#hits',
templates: {
item: `
item: (hit, { html, components }) => html`
<div>
<header class="hit-name">
{{#helpers.highlight}}{ "attribute": "name" }{{/helpers.highlight}}
${components.Highlight({ hit, attribute: 'name' })}
</header>
<p class="hit-description">
{{#helpers.highlight}}{ "attribute": "description" }{{/helpers.highlight}}
${components.Highlight({ hit, attribute: 'description' })}
</p>
</div>
`,
Expand Down
12 changes: 5 additions & 7 deletions instantsearch.js/conditional-request/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,13 @@ search.addWidgets([
instantsearch.widgets.hits({
container: '#hits',
templates: {
empty: `
{{#query}}
No results for <q>{{query}}</q>
{{/query}}
empty: ({ query }, { html }) => html`
No results for <q>${query}</q>
`,
item: `
item: (hit, { html, components }) => html`
<article>
<h1>{{#helpers.highlight}}{ "attribute": "name" }{{/helpers.highlight}}</h1>
<p>{{#helpers.highlight}}{ "attribute": "description" }{{/helpers.highlight}}</p>
<h1>${components.Highlight({ hit, attribute: 'name' })}</h1>
<p>${components.Highlight({ hit, attribute: 'description' })}</p>
</article>
`,
},
Expand Down
6 changes: 3 additions & 3 deletions instantsearch.js/facet-dropdown/src/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function createDropdown(
const makeWidget = instantsearch.widgets.panel({
cssClasses,
templates: {
header: options => {
header: (options, { html }) => {
const { widgetParams } = options;

let text;
Expand Down Expand Up @@ -67,13 +67,13 @@ export function createDropdown(
classNames.push(cssClasses.buttonRefined);
}

return `
return html`
<button type="button" class="${cx(...classNames)}">
${text}
</button>
`;
},
footer: `<button type="button" class="${cssClasses.closeButton}">Apply</button>`,
footer: (_, { html }) => html`<button type="button" class="${cssClasses.closeButton}">Apply</button>`,
},
})(baseWidget);

Expand Down
6 changes: 3 additions & 3 deletions instantsearch.js/facet-dropdown/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ search.addWidgets([
instantsearch.widgets.hits({
container: '#hits',
templates: {
item: `
item: (hit, { html, components }) => html`
<article>
<h1>{{#helpers.highlight}}{ "attribute": "name" }{{/helpers.highlight}}</h1>
<p>{{#helpers.highlight}}{ "attribute": "description" }{{/helpers.highlight}}</p>
<h1>${components.Highlight({ hit, attribute: 'name' })}</h1>
<p>${components.Highlight({ hit, attribute: 'description' })}</p>
</article>
`,
},
Expand Down
4 changes: 2 additions & 2 deletions instantsearch.js/geo-search-custom-marker/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ injectScript(
container: '#maps',
googleReference: window.google,
templates: {
HTMLMarker: `
HTMLMarker: (hit, { html }) => html`
<span class="marker">
{{ city }} - {{ airport_id }}
${hit.city} - ${hit.airport_id}
</span>
`,
},
Expand Down
34 changes: 17 additions & 17 deletions instantsearch.js/geo-search-tourism/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,23 @@ $script(
instantsearch.widgets.hits({
container: '#hits',
templates: {
item:
'<div class="hit col-sm-3">' +
'<div class="pictures-wrapper">' +
'<img class="picture" src="{{picture_url}}" />' +
'<img class="profile" src="{{user.user.thumbnail_url}}" />' +
'</div>' +
'<div class="infos">' +
'<h4 class="media-heading">{{#helpers.highlight}}{ "attribute": "name" }{{/helpers.highlight}}</h4>' +
'<p>' +
'{{room_type}} - ' +
'{{#helpers.highlight}}{ "attribute": "city" }{{/helpers.highlight}},' +
'{{#helpers.highlight}}{ "attribute": "country" }{{/helpers.highlight}}' +
'</p>' +
'</div>' +
'</div>',
empty:
'<div class="text-center">No results found matching <strong>{{query}}</strong>.</div>',
item: (hit, { html, components }) => html`
<div class="hit col-sm-3">
<div class="pictures-wrapper">
<img class="picture" src=${hit.picture_url} />
<img class="profile" src=${hit.user.user.thumbnail_url} />
</div>
<div class="infos">
<h4 class="media-heading">${components.Highlight({ hit, attribute: 'name' })}</h4>
<p>
${hit.room_type} - ${components.Highlight({ hit, attribute: 'city' })}, ${components.Highlight({ hit, attribute: 'country' })}
</p>
</div>
</div>'
`,
empty: ({ query }, { html }) => html`
<div class="text-center">No results found matching <strong>${query}</strong>.</div>
`
},
}),

Expand Down
6 changes: 2 additions & 4 deletions instantsearch.js/multi-index-hits/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ search.addWidgets([
instantsearch.widgets.hits({
container: '#hits-instant-search',
templates: {
item:
'{{#helpers.highlight}}{ "attribute": "name" }{{/helpers.highlight}}',
item: (hit, { components }) => components.Highlight({ hit, attribute: 'name' })
},
}),
instantsearch.widgets
Expand All @@ -34,8 +33,7 @@ search.addWidgets([
instantsearch.widgets.hits({
container: '#hits-instant-search-price-desc',
templates: {
item:
'{{#helpers.highlight}}{ "attribute": "name" }{{/helpers.highlight}}',
item: (hit, { components }) => components.Highlight({ hit, attribute: 'name' })
},
}),
]),
Expand Down
6 changes: 3 additions & 3 deletions instantsearch.js/query-suggestions/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ search.addWidgets([
instantsearch.widgets.hits({
container: '#hits',
templates: {
item: `
item: (hit, { html, components }) => html`
<div>
<header class="hit-name">
{{#helpers.highlight}}{ "attribute": "name" }{{/helpers.highlight}}
${components.Highlight({ hit, attribute: 'name' })}
</header>
<p class="hit-description">
{{#helpers.highlight}}{ "attribute": "description" }{{/helpers.highlight}}
${components.Highlight({ hit, attribute: 'description' })}
</p>
</div>
`,
Expand Down
10 changes: 5 additions & 5 deletions instantsearch.js/refresh-cache-periodically/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ search.addWidgets([
instantsearch.widgets.hits({
container: '#hits',
templates: {
item: `
item: (hit, { html, components }) => html`
<div>
<header class="hit-name">
{{#helpers.highlight}}{ "attribute": "name" }{{/helpers.highlight}}
${components.Highlight({ hit, attribute: 'name' })}
</header>
<img src="{{image}}" align="left" />
<img src="${hit.image}" align="left" />
<p class="hit-description">
{{#helpers.highlight}}{ "attribute": "description" }{{/helpers.highlight}}
${components.Highlight({ hit, attribute: 'description' })}
</p>
<p class="hit-price">\${{price}}</p>
<p class="hit-price">\$${hit.price}</p>
</div>
`,
},
Expand Down
22 changes: 11 additions & 11 deletions instantsearch.js/refresh-cache-user-action/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ search.addWidgets([
instantsearch.widgets.hits({
container: '#hits',
templates: {
item: `
<div>
<header class="hit-name">
{{#helpers.highlight}}{ "attribute": "name" }{{/helpers.highlight}}
</header>
<img src="{{image}}" align="left" />
<p class="hit-description">
{{#helpers.highlight}}{ "attribute": "description" }{{/helpers.highlight}}
</p>
<p class="hit-price">\${{price}}</p>
</div>
item: (hit, { html, components }) => html`
<div>
<header class="hit-name">
${components.Highlight({ hit, attribute: 'name' })}
</header>
<img src="${hit.image}" align="left" />
<p class="hit-description">
${components.Highlight({ hit, attribute: 'description' })}
</p>
<p class="hit-price">\$${hit.price}</p>
</div>
`,
},
}),
Expand Down
4 changes: 2 additions & 2 deletions instantsearch.js/routing-basic/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ search.addWidgets([
instantsearch.widgets.hits({
container: '#hits',
templates: {
item: `
item: (hit, { html, components }) => html`
<div>
{{#helpers.highlight}}{ "attribute": "name" }{{/helpers.highlight}}
${components.Highlight({ hit, attribute: 'name' })}
</div>
`,
},
Expand Down
4 changes: 2 additions & 2 deletions instantsearch.js/routing-seo-friendly/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ search.addWidgets([
instantsearch.widgets.hits({
container: '#hits',
templates: {
item: `
item: (hit, { html, components }) => html`
<div>
{{#helpers.highlight}}{ "attribute": "name" }{{/helpers.highlight}}
${components.Highlight({ hit, attribute: 'name' })}
</div>
`,
},
Expand Down
10 changes: 5 additions & 5 deletions instantsearch.js/secured-api-keys/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ search.addWidgets([
instantsearch.widgets.hits({
container: '#hits',
templates: {
item: `
item: (hit, { html, components }) => html`
<div>
<header class="hit-name">
{{#helpers.highlight}}{ "attribute": "name" }{{/helpers.highlight}}
${components.Highlight({ hit, attribute: 'name' })}
</header>
<img src="{{image}}" align="left" />
<img src="${hit.image}" align="left" />
<p class="hit-description">
{{#helpers.highlight}}{ "attribute": "description" }{{/helpers.highlight}}
${components.Highlight({ hit, attribute: 'description' })}
</p>
<p class="hit-price">\${{price}}</p>
<p class="hit-price">\$${hit.price}</p>
</div>
`,
},
Expand Down
19 changes: 8 additions & 11 deletions instantsearch.js/segment-connector/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,24 @@ search.addWidgets([
hits({
container: '#hits',
templates: {
item: (hit, bindEvent) => {
const result = `
item: (hit, { html, components, sendEvent }) => html`
<article>
<h1>${instantsearch.highlight({ attribute: 'name', hit })}</h1>
<p>${instantsearch.highlight({ attribute: 'description', hit })}</p>
<button type="button" ${bindEvent('view', hit, 'View')}>
<h1>${components.Highlight({ hit, attribute: 'name' })}</h1>
<p>${components.Highlight({ hit, attribute: 'description' })}</p>
<button type="button" onClick="${() => sendEvent('view', hit, 'View')}">
View Product
</button>
<button type="button" ${bindEvent('click', hit, 'Favorite')}>
<button type="button" onClick="${() => sendEvent('click', hit, 'Favorite')}">
Favorite
</button>
<button type="button" ${bindEvent('conversion', hit, 'Add to Cart')}>
<button type="button" onClick="${() => sendEvent('conversion', hit, 'Add to Cart')}">
Add to Cart
</button>
<button type="button" ${bindEvent('conversion', hit, 'Order')}>
<button type="button" onClick="${() => sendEvent('conversion', hit, 'Order')}">
Order Now
</button>
</article>
`;
return result;
},
`
},
}),
refinementList({
Expand Down

0 comments on commit 5057297

Please sign in to comment.