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

OCRVS 6085: Configurable handlebars #763

Merged
merged 2 commits into from
Oct 20, 2023
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"@graphql-codegen/typescript-operations": "^3.0.4",
"@types/bcryptjs": "^2.4.2",
"@types/google-libphonenumber": "^7.4.23",
"@types/handlebars": "^4.1.0",
"@types/hapi__inert": "^5.2.3",
"@types/jsonwebtoken": "^8.5.8",
"@types/react-intl": "^3.0.0",
Expand Down Expand Up @@ -162,4 +163,4 @@
"minimist": "^1.2.2",
"acorn": "^6.4.1"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as Handlebars from 'handlebars'

export const loud: Handlebars.HelperDelegate = function (
this: any,
value: string
) {
return value.toUpperCase()
}
Comment on lines +3 to +8
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export const loud: Handlebars.HelperDelegate = function (
this: any,
value: string
) {
return value.toUpperCase()
}
export const loud: Handlebars.HelperDelegate = (intl: IntlShape) => {
return function (
this: any,
value: string
) {
return value.toUpperCase()
}
}


export const quiet: Handlebars.HelperDelegate = function (
this: any,
value: string
) {
return value.toLowerCase()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { buildTypeScriptToJavaScript } from '@countryconfig/utils'
import * as Hapi from '@hapi/hapi'
import { join } from 'path'

export async function handlebarsHandler(
request: Hapi.Request,
h: Hapi.ResponseToolkit
) {
return h
.response(
await buildTypeScriptToJavaScript(join(__dirname, 'custom-handlebars.ts'))
)
.type('text/javascript')
}
12 changes: 12 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { applicationConfigHandler } from './api/application/handler'
import { validatorsHandler } from './form/common/custom-validation-conditionals/validators-handler'
import { conditionalsHandler } from './form/common/custom-validation-conditionals/conditionals-handler'
import { COUNTRY_WIDE_CRUDE_DEATH_RATE } from './api/application/application-config-default'
import { handlebarsHandler } from './form/common/custom-validation-conditionals/handlebars-handler'

export interface ITokenPayload {
sub: string
Expand Down Expand Up @@ -302,6 +303,17 @@ export async function createServer() {
}
})

server.route({
method: 'GET',
path: '/handlebars.js',
handler: handlebarsHandler,
options: {
auth: false,
tags: ['api'],
description: 'Serves handlebars as JS'
}
})

server.route({
method: 'GET',
path: '/content/{application}',
Expand Down
21 changes: 20 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3211,6 +3211,13 @@
dependencies:
"@types/node" "*"

"@types/handlebars@^4.1.0":
version "4.1.0"
resolved "https://registry.yarnpkg.com/@types/handlebars/-/handlebars-4.1.0.tgz#3fcce9bf88f85fe73dc932240ab3fb682c624850"
integrity sha512-gq9YweFKNNB1uFK71eRqsd4niVkXrxHugqWFQkeLRJvGjnxsLr16bYtcsG4tOFwmYi0Bax+wCkbf1reUfdl4kA==
dependencies:
handlebars "*"

"@types/hapi-pino@^6.3.0":
version "6.4.0"
resolved "https://registry.yarnpkg.com/@types/hapi-pino/-/hapi-pino-6.4.0.tgz#3e1103918812d8bd8d4f189b68d08c086eafe74c"
Expand Down Expand Up @@ -6020,6 +6027,18 @@ growly@^1.3.0:
resolved "https://registry.yarnpkg.com/growly/-/growly-1.3.0.tgz#f10748cbe76af964b7c96c93c6bcc28af120c081"
integrity sha512-+xGQY0YyAWCnqy7Cd++hc2JqMYzlm0dG30Jd0beaA64sROr8C4nt8Yc9V5Ro3avlSUDTN0ulqP/VBKi1/lLygw==

handlebars@*:
version "4.7.8"
resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.7.8.tgz#41c42c18b1be2365439188c77c6afae71c0cd9e9"
integrity sha512-vafaFqs8MZkRrSX7sFVUdo3ap/eNiLnb4IakshzvP56X5Nr1iGKAIqdX6tMlm6HcNRIkr6AxO5jFEoJzzpT8aQ==
dependencies:
minimist "^1.2.5"
neo-async "^2.6.2"
source-map "^0.6.1"
wordwrap "^1.0.0"
optionalDependencies:
uglify-js "^3.1.4"

handlebars@^4.7.7:
version "4.7.7"
resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.7.7.tgz#9ce33416aad02dbd6c8fafa8240d5d98004945a1"
Expand Down Expand Up @@ -7899,7 +7918,7 @@ ndjson@^1.4.0:
split2 "^2.1.0"
through2 "^2.0.3"

neo-async@^2.6.0:
neo-async@^2.6.0, neo-async@^2.6.2:
version "2.6.2"
resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.2.tgz#b4aafb93e3aeb2d8174ca53cf163ab7d7308305f"
integrity sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==
Expand Down
Loading