forked from MapComplete/MapComplete
Fix tests
This commit is contained in:
parent
e9d18d2337
commit
39376c0012
1 changed files with 31 additions and 11 deletions
|
|
@ -54,6 +54,20 @@ export class ExtractImages extends Conversion<
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static isImageType(metapath: any): boolean {
|
||||||
|
if (metapath.hints.typehint === "icon" ||
|
||||||
|
metapath.hints.typehint === "image") {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
const types = metapath.hints.types?.split(";").map(x => x.trim())
|
||||||
|
if (types?.some(t => t === "icon" || t === "image")) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* const images = new ExtractImages(true, new Set<string>()).convert(<any>{
|
* const images = new ExtractImages(true, new Set<string>()).convert(<any>{
|
||||||
* "layers": [
|
* "layers": [
|
||||||
|
|
@ -102,9 +116,14 @@ export class ExtractImages extends Conversion<
|
||||||
const allFoundImages: { path: string; context: string }[] = []
|
const allFoundImages: { path: string; context: string }[] = []
|
||||||
for (const metapath of ExtractImages.layoutMetaPaths) {
|
for (const metapath of ExtractImages.layoutMetaPaths) {
|
||||||
const mightBeTr = ExtractImages.mightBeTagRendering(<any>metapath)
|
const mightBeTr = ExtractImages.mightBeTagRendering(<any>metapath)
|
||||||
const allRenderedValuesAreImages =
|
|
||||||
metapath.hints.typehint === "icon" || metapath.hints.typehint === "image"
|
const allRenderedValuesAreImages = ExtractImages.isImageType(metapath)
|
||||||
|
|
||||||
const found = Utils.CollectPath(metapath.path, json)
|
const found = Utils.CollectPath(metapath.path, json)
|
||||||
|
if(found.length === 0){
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if (mightBeTr) {
|
if (mightBeTr) {
|
||||||
// We might have tagRenderingConfigs containing icons here
|
// We might have tagRenderingConfigs containing icons here
|
||||||
for (const el of found) {
|
for (const el of found) {
|
||||||
|
|
@ -134,9 +153,9 @@ export class ExtractImages extends Conversion<
|
||||||
// Inspect all the rendered values
|
// Inspect all the rendered values
|
||||||
const fromPath = Utils.CollectPath(trpath.path, foundImage)
|
const fromPath = Utils.CollectPath(trpath.path, foundImage)
|
||||||
const isRendered = trpath.hints.typehint === "rendered"
|
const isRendered = trpath.hints.typehint === "rendered"
|
||||||
const isImage =
|
|
||||||
trpath.hints.typehint === "icon" ||
|
const isImage = ExtractImages.isImageType(trpath)
|
||||||
trpath.hints.typehint === "image"
|
|
||||||
for (const img of fromPath) {
|
for (const img of fromPath) {
|
||||||
if (allRenderedValuesAreImages && isRendered) {
|
if (allRenderedValuesAreImages && isRendered) {
|
||||||
// What we found is an image
|
// What we found is an image
|
||||||
|
|
@ -158,7 +177,7 @@ export class ExtractImages extends Conversion<
|
||||||
} else {
|
} else {
|
||||||
allFoundImages.push({
|
allFoundImages.push({
|
||||||
path: img.leaf,
|
path: img.leaf,
|
||||||
context: context + "." + path,
|
context: context + "." + path
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -172,7 +191,7 @@ export class ExtractImages extends Conversion<
|
||||||
.ExtractImages(false)
|
.ExtractImages(false)
|
||||||
.map((path) => ({
|
.map((path) => ({
|
||||||
path,
|
path,
|
||||||
context: context + "." + path,
|
context: context + "." + path
|
||||||
}))
|
}))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -192,7 +211,7 @@ export class ExtractImages extends Conversion<
|
||||||
}
|
}
|
||||||
allFoundImages.push({
|
allFoundImages.push({
|
||||||
context: context.path.join(".") + "." + foundElement.path.join("."),
|
context: context.path.join(".") + "." + foundElement.path.join("."),
|
||||||
path: foundElement.leaf,
|
path: foundElement.leaf
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -283,7 +302,6 @@ export class FixImages extends DesugaringStep<LayoutConfigJson> {
|
||||||
const absolute = url.protocol + "//" + url.host
|
const absolute = url.protocol + "//" + url.host
|
||||||
let relative = url.protocol + "//" + url.host + url.pathname
|
let relative = url.protocol + "//" + url.host + url.pathname
|
||||||
relative = relative.substring(0, relative.lastIndexOf("/"))
|
relative = relative.substring(0, relative.lastIndexOf("/"))
|
||||||
const self = this
|
|
||||||
|
|
||||||
if (relative.endsWith("assets/generated/themes")) {
|
if (relative.endsWith("assets/generated/themes")) {
|
||||||
context.warn(
|
context.warn(
|
||||||
|
|
@ -292,8 +310,10 @@ export class FixImages extends DesugaringStep<LayoutConfigJson> {
|
||||||
relative = absolute
|
relative = absolute
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const knownImages = this._knownImages
|
||||||
|
|
||||||
function replaceString(leaf: string) {
|
function replaceString(leaf: string) {
|
||||||
if (self._knownImages.has(leaf)) {
|
if (knownImages.has(leaf)) {
|
||||||
return leaf
|
return leaf
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -316,7 +336,7 @@ export class FixImages extends DesugaringStep<LayoutConfigJson> {
|
||||||
json = Utils.Clone(json)
|
json = Utils.Clone(json)
|
||||||
|
|
||||||
for (const metapath of metapaths) {
|
for (const metapath of metapaths) {
|
||||||
if (metapath.hints.typehint !== "image" && metapath.hints.typehint !== "icon") {
|
if (!ExtractImages.isImageType(metapath)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
const mightBeTr = ExtractImages.mightBeTagRendering(<any>metapath)
|
const mightBeTr = ExtractImages.mightBeTagRendering(<any>metapath)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue