Skip to content

Commit

Permalink
set baseUrl from PCI's
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcelh1983 committed Aug 28, 2024
1 parent 50bd1db commit dadc30f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ The build-in functions that can be chained are:
- `stripStylesheets(): QtiTransformAPI`: Remove all stylesheet references from the XML.
- `changeAssetLocation(getNewUrl: (oldUrl: string) => string, srcAttribute?: string[], skipBase64 = true): QtiTransformAPI`: Helper function to change the asset location of media files. Url can be changed in the callback function. By default the following attributes are checked for references: `['src', 'href', 'data', 'primary-path', 'fallback-path', 'template-location']` but that can be overriden. Also by default you won't get a callback for base64 urls.
- `changeAssetLocationAsync(getNewUrl: (oldUrl: string) => Promise<string>, srcAttribute?: string[], skipBase64 = true): QtiTransformAPI`: Async function of changeAssetLocation
- `configurePciAsync(getModuleResolutionConfig: (url: string) => Promise<ModuleResolutionConfig>): Promise<QtiTransformAPI>`: makes sure custom-interaction-type-identifier are unique per item, and adds /modules/module_resolution.js and /modules/fallback_module_resolution.js to the qti-interaction-modules tag of the item qti.
- `configurePciAsync(baseUrl: string, getModuleResolutionConfig: (url: string) => Promise<ModuleResolutionConfig>): Promise<QtiTransformAPI>`: makes sure custom-interaction-type-identifier are unique per item, adds /modules/module_resolution.js and /modules/fallback_module_resolution.js to the qti-interaction-modules tag of the item qti and sets a baseUrl to be able to get the full path of the modules.
- `customTypes(): QtiTransformAPI`: Apply custom type transformations to the XML. Can be used override default web-components. E.g. `<qti-choice-interaction class="type:custom">` will result in `<qti-choice-interaction-custom>` so you can create your own web-component to render choice interactions.
- `customInteraction(baseRef: string, baseItem: string)` Transforms qti-custom-interactions that contain an object tag. Object tag will be removed and attributes will be merged in the qti-custom-interactions tag.
- `stripMaterialInfo(): QtiTransformAPI`: Remove unnecessary material information from the XML
Expand Down
8 changes: 6 additions & 2 deletions src/lib/qti-transformer/qti-transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ interface QtiTransformAPI {
skipBase64?: boolean
): Promise<QtiTransformAPI>;
configurePciAsync(
baseUrl: string,
getModuleResolutionConfig: (url: string) => Promise<ModuleResolutionConfig>
): Promise<QtiTransformAPI>;
stripStylesheets(): QtiTransformAPI;
Expand Down Expand Up @@ -144,8 +145,11 @@ export const qtiTransform = (xmlValue: string): QtiTransformAPI => {
await changeAssetLocationAsync($, getNewUrlAsync, srcAttribute, skipBase64);
return api;
},
async configurePciAsync(getModuleResolutionConfig: (url: string) => Promise<ModuleResolutionConfig>) {
await configurePciAsync($, getModuleResolutionConfig);
async configurePciAsync(
baseUrl: string,
getModuleResolutionConfig: (url: string) => Promise<ModuleResolutionConfig>
) {
await configurePciAsync($, baseUrl, getModuleResolutionConfig);
return api;
},
stripStylesheets() {
Expand Down
6 changes: 5 additions & 1 deletion src/lib/qti-transformer/transformers/configure-pci/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ export interface ModuleResolutionConfig {

export async function configurePciAsync(
$: cheerio.CheerioAPI,
baseUrl: string,
getModuleResolutionConfig: (url: string) => Promise<ModuleResolutionConfig>
) {
await configurePCI($, getModuleResolutionConfig);
await configurePCI($, baseUrl, getModuleResolutionConfig);
return $;
}

Expand All @@ -28,6 +29,7 @@ export async function configurePciAsync(
// Also, if there are multiple pci's with the same custom-interaction-type-identifier we'll make them unique.
async function configurePCI(
$: cheerio.CheerioAPI,
baseUrl: string,
getModuleResolutionConfig: (url: string) => Promise<ModuleResolutionConfig>
) {
const customInteractionTypeIdentifiers: string[] = [];
Expand All @@ -36,6 +38,8 @@ async function configurePCI(
const moduleResolutionFallbackConfig = await getModuleResolutionConfig('/modules/fallback_module_resolution.js');
if (portableCustomInteractions.length > 0) {
for (const interaction of portableCustomInteractions) {
// set data-base-url
$(interaction).attr('data-base-url', baseUrl);
let customInteractionTypeIdentifier = $(interaction).attr('custom-interaction-type-identifier');
if (customInteractionTypeIdentifiers.includes(customInteractionTypeIdentifier)) {
customInteractionTypeIdentifier = customInteractionTypeIdentifier + customInteractionTypeIdentifiers.length;
Expand Down

0 comments on commit dadc30f

Please sign in to comment.