Skip to content

Commit

Permalink
Merge 49c882b into 2eae3b6
Browse files Browse the repository at this point in the history
  • Loading branch information
cea2aj committed Oct 13, 2021
2 parents 2eae3b6 + 49c882b commit 468a72f
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 32 deletions.
27 changes: 5 additions & 22 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,19 @@ commands:
# Download and cache dependencies
- restore_cache:
keys:
- v2-dependencies-{{ checksum "package-lock.json" }}
# fallback to using the latest cache if no exact match is found
- v2-dependencies-
- v3-node-14-{{ checksum "package-lock.json" }}
# fallback to use the latest cache from the same node version if no exact match is found
- v3-node-14-
- run: npm install
- save_cache:
paths:
- node_modules
key: v2-dependencies-{{ checksum "package-lock.json" }}
key: v3-node-14-{{ checksum "package-lock.json" }}
deploy-to-aws:
description: "Deploys the dist directory to a given subdirectory of the answers bucket"
parameters:
subdirectory:
type: string
default: ''
cache-control:
type: string
default: "no-cache"
Expand Down Expand Up @@ -151,13 +150,6 @@ jobs:
command: |
sudo apt-get install -qq gettext
./.circleci/run_translation_verification.sh
# deploy to S3 in the root folder, overwriting the existing latest version
deploy_latest:
docker:
- image: circleci/python:2.7
working_directory: ~/answers
steps:
- deploy-to-aws
# deploys assets to an uncached folder in the S3 bucket named by branch
deploy_branch:
docker:
Expand Down Expand Up @@ -311,8 +303,7 @@ workflows:
tags:
only: /^v.*/
branches:
only:
- master
ignore: /.*/
- unit_test:
filters:
tags:
Expand Down Expand Up @@ -354,18 +345,10 @@ workflows:
- useragent_acceptance_test
- headless_acceptance_test
- translation_test
- deploy_latest:
filters:
branches:
only: master
requires:
- hold
- deploy_version:
filters:
tags:
only: /^v.*/
branches:
ignore: /.*/
requires:
- hold
build_and_deploy_search_bar:
Expand Down
44 changes: 42 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
- [Custom Data Transforms](#custom-data-transforms)
- [Using a Custom Template for a Component](#using-a-custom-template-for-a-component)
- [Creating Custom Components](#creating-custom-components)
6. [Template Helpers](#template-helpers)
6. [Extending the Built-in Renderer](#extending-the-built-in-renderer)
- [Custom Partials](#custom-partials)
- [Template Helpers](#template-helpers)
7. [Analytics](#analytics)
- [Custom Analytics Using JavaScript](#custom-analytics-using-javascript)
- [Custom Analytics Using Data Attributes](#custom-analytics-using-data-attributes)
Expand Down Expand Up @@ -2319,7 +2321,45 @@ ANSWERS.addComponent('MyCustomComponent', {
});
```
# Template Helpers
# Extending the Built-in Renderer
## Custom Partials
[Handlebars partials](https://handlebarsjs.com/guide/partials.html) use the
same handlebars syntax as templates, but they can be reused and be called
directly from templates or other partials. The ANSWERS object offers an
`ANSWERS.registerPartial` function for custom partials. This will map a partial
string to an entry in the Answers handlebars renderer.
```js
/**
* Add a partial
* @param {string} partialName The unique name for the partial
* @param {string} partial The handlebars partial string
*/
registerPartial (partialName, partial)
```
The default handlebars renderer uses a mapping from partial name strings to
handlebars partial strings. Once registered, this custom partial can be called
from other partials or templates.
For example,
```js
// create custom partial
ANSWERS.registerPartial(
'thank-you-message',
'<div class="thanks">Thank you!</div>'
);

// use new partial in a template
ANSWERS.registerTemplate(
'cards/custom',
'<p>Main information</p> {{> thank-you-message }}'
);
```
## Template Helpers
When using handlebars templates, Answers ships with a bunch of pre-built template helpers that you can use. You can learn more about them [here](https://github.com/jonschlinkert/template-helpers).
Expand Down
4 changes: 2 additions & 2 deletions THIRD-PARTY-NOTICES
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ MIT License

The following NPM package may be included in this product:

- @yext/answers-core@1.3.0
- @yext/answers-core@1.3.2

This package contains the following license and notice below:

Expand Down Expand Up @@ -342,7 +342,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The following NPM packages may be included in this product:

- @yext/answers-search-ui@1.10.0
- @yext/answers-search-ui@1.11.0
- @yext/answers-storage@1.1.0

These packages each contain the following license and notice below:
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@yext/answers-search-ui",
"version": "1.10.0",
"version": "1.11.0",
"description": "Javascript Answers Programming Interface",
"main": "dist/answers-umd.js",
"repository": {
Expand All @@ -24,7 +24,7 @@
],
"dependencies": {
"@mapbox/mapbox-gl-language": "^0.10.1",
"@yext/answers-core": "^1.3.0",
"@yext/answers-core": "^1.3.2",
"@yext/answers-storage": "^1.1.0",
"@yext/rtf-converter": "^1.5.0",
"cross-fetch": "^3.1.4",
Expand Down
7 changes: 7 additions & 0 deletions src/answers-search-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,13 @@ class AnswersSearchBar {
return this;
}

/**
* @returns {boolean} Whether analytics events are opted in or out
*/
getAnalyticsOptIn () {
return this._analyticsReporterService?.getAnalyticsOptIn();
}

/**
* Opt in or out of analytic events
* @param {boolean} analyticsEventsEnabled
Expand Down
16 changes: 16 additions & 0 deletions src/answers-umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,22 @@ class Answers {
this.renderer.registerTemplate(templateName, template);
}

/**
* Add a partial to the current renderer
* @param {string} partialName The unique name for the partial
* @param {string} partial The handlebars partial string
*/
registerPartial (partialName, partial) {
this.renderer.registerPartial(partialName, partial);
}

/**
* @returns {boolean} Whether analytics events are opted in or out
*/
getAnalyticsOptIn () {
return this._analyticsReporterService?.getAnalyticsOptIn();
}

/**
* Opt in or out of analytic events
* @param {boolean} analyticsEventsEnabled
Expand Down
7 changes: 7 additions & 0 deletions src/core/analytics/analyticsreporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ export default class AnalyticsReporter {
this._globalOptions.queryId = queryId;
}

/**
* @returns {boolean} Whether analytics events are opted in or out
*/
getAnalyticsOptIn () {
return this._analyticsEventsEnabled;
}

/**
* Opt in or out of analytics click events
* @param {boolean} analyticsEventsEnabled
Expand Down
9 changes: 9 additions & 0 deletions src/ui/rendering/handlebarsrenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ export default class HandlebarsRenderer extends Renderer {
this._handlebars.registerHelper(name, cb);
}

/**
* Register a partial to the internal Handlebars compiler
* @param {string} partialName The unique name for the partial
* @param {string} partial The handlebars partial string
*/
registerPartial (partialName, partial) {
this._handlebars.registerPartial(partialName, partial);
}

/**
* SafeString is a public interface for external dependencies to
* mark a string as 'safe'. Handlebars will not escape a SafeString
Expand Down
4 changes: 4 additions & 0 deletions src/ui/rendering/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export default class Renderer {

}

registerPartial (partialName, partial) {

}

compile (template) {

}
Expand Down
5 changes: 5 additions & 0 deletions tests/core/analytics/analyticsreporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,9 @@ describe('reporting events', () => {
expect.anything(),
expect.objectContaining({ data: expect.not.objectContaining({ queryId: '123' }) }));
});

it('Set and get analytics opt in', async () => {
analyticsReporter.setAnalyticsOptIn(true);
expect(analyticsReporter.getAnalyticsOptIn()).toEqual(true);
});
});

0 comments on commit 468a72f

Please sign in to comment.