From 2131032cb305b08bf244c341d27c97da0aa06596 Mon Sep 17 00:00:00 2001 From: Julian Gonggrijp Date: Tue, 25 May 2021 15:07:34 +0200 Subject: [PATCH] Factor out common hbs partial for the SPARQL preamble (#455) --- frontend/src/global/hbsPartials.ts | 5 +++++ frontend/src/main.ts | 1 + .../src/sparql/query-templates/items-for-source-template.hbs | 4 +--- frontend/src/sparql/query-templates/preamble-template.hbs | 3 +++ frontend/src/test-util.ts | 1 + 5 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 frontend/src/global/hbsPartials.ts create mode 100644 frontend/src/sparql/query-templates/preamble-template.hbs diff --git a/frontend/src/global/hbsPartials.ts b/frontend/src/global/hbsPartials.ts new file mode 100644 index 000000000..6fe5815cd --- /dev/null +++ b/frontend/src/global/hbsPartials.ts @@ -0,0 +1,5 @@ +import Handlebars from 'handlebars/dist/handlebars.runtime'; + +import sparqlPreamble from '../sparql/query-templates/preamble-template'; + +Handlebars.registerPartial('sparqlPreamble', sparqlPreamble); diff --git a/frontend/src/main.ts b/frontend/src/main.ts index 976668923..5e48ff2d2 100644 --- a/frontend/src/main.ts +++ b/frontend/src/main.ts @@ -7,6 +7,7 @@ import './global/scroll-easings'; import { i18nPromise } from './global/i18n'; import './global/internalLinks'; import './global/hbsHelpers'; +import './global/hbsPartials'; import user from './global/user'; import { prefetch } from './global/ld-store'; import './global/item-cache'; diff --git a/frontend/src/sparql/query-templates/items-for-source-template.hbs b/frontend/src/sparql/query-templates/items-for-source-template.hbs index a9ee06416..4310b4349 100644 --- a/frontend/src/sparql/query-templates/items-for-source-template.hbs +++ b/frontend/src/sparql/query-templates/items-for-source-template.hbs @@ -1,6 +1,4 @@ -{{#each namespaces}} -PREFIX {{label}}: <{{prefix}}> -{{/each}} +{{>sparqlPreamble}} PREFIX schema: PREFIX oa: CONSTRUCT { diff --git a/frontend/src/sparql/query-templates/preamble-template.hbs b/frontend/src/sparql/query-templates/preamble-template.hbs new file mode 100644 index 000000000..20cdbc82e --- /dev/null +++ b/frontend/src/sparql/query-templates/preamble-template.hbs @@ -0,0 +1,3 @@ +{{#each namespaces}} +PREFIX {{label}}: <{{prefix}}> +{{/each}} diff --git a/frontend/src/test-util.ts b/frontend/src/test-util.ts index afbc8bdb5..5f0ca6bdf 100644 --- a/frontend/src/test-util.ts +++ b/frontend/src/test-util.ts @@ -6,6 +6,7 @@ import { Events } from 'backbone'; import Store from './common-rdf/store'; import './global/hbsHelpers'; +import './global/hbsPartials'; import { i18nPromise } from './global/i18n'; /**