UNPKG

@rr0/cms

Version:

RR0 Content Management System (CMS)

35 lines (34 loc) 1.69 kB
import path from "path"; import { TimeElementFactory, TimeRenderer, TimeService, TimeTextBuilder, TimeUrlBuilder } from "../time/index.js"; import { cmsTestUtil } from "../test/index.js"; export class TimeTestUtil { constructor(cmsTestUtil) { this.timeOptions = { rootDir: "time", files: [] }; this.urlBuilder = new TimeUrlBuilder(this.timeOptions); Object.assign(this.urlBuilder, { ...this.urlBuilder.options, rootDir: cmsTestUtil.filePath(this.timeOptions.rootDir) }); console.log(this.urlBuilder.options); this.timeTextBuilder = new TimeTextBuilder(cmsTestUtil.intlOptions); this.fullRoot = path.join(cmsTestUtil.rootDir, this.timeOptions.rootDir); this.timeRenderer = new TimeRenderer(this.urlBuilder, this.timeTextBuilder); } newHtmlContext(inputFileName, contents, locale = "fr") { return cmsTestUtil.newHtmlContext(this.filePath(inputFileName), contents, locale); } filePath(inputFileName) { return path.join(this.timeOptions.rootDir, inputFileName); } url(inputFileName) { return path.join("/", this.filePath(inputFileName)); } getService(options = this.timeOptions) { if (!this.timeService || this.timeOptions.rootDir !== options.rootDir || JSON.stringify(this.timeService.files) !== JSON.stringify(options.files)) { this.timeOptions = options; Object.assign(this.urlBuilder.options, options); this.timeService = new TimeService(cmsTestUtil.dataService, options); this.timeElementFactory = new TimeElementFactory(this.timeRenderer); } return this.timeService; } }