Sitemap code generation: Quote colors (#1887)

The sitemap syntax requires colors in icon, label and valuecolors to be strings and have quotes around the values.
This is currently not respected, therefore the generated code could not be used without correction when copied into a sitemap file.

This fixes that bug.

Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
pull/1892/head
Mark Herwege 2023-05-09 20:33:28 +02:00 committed by GitHub
parent 3d8348aca9
commit 54ed5fee15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View File

@ -162,7 +162,7 @@ describe('dslUtil', () => {
]
})
const sitemap = dslUtil.toDsl(component).split('\n')
expect(sitemap[1]).toEqual(' Text item=Temperature valuecolor=[Last_Update==Uninitialized=gray,>=25=orange,==15=green,0=white,blue]')
expect(sitemap[1]).toEqual(' Text item=Temperature valuecolor=[Last_Update==Uninitialized="gray",>=25="orange",==15="green",0="white","blue"]')
})
it('renders widget with valuecolor and text condition correctly', () => {
@ -176,6 +176,6 @@ describe('dslUtil', () => {
]
})
const sitemap = dslUtil.toDsl(component).split('\n')
expect(sitemap[1]).toEqual(' Text item=Temperature valuecolor=[Heat_Warning=="It is hot"=gray]')
expect(sitemap[1]).toEqual(' Text item=Temperature valuecolor=[Heat_Warning=="It is hot"="gray"]')
})
})

View File

@ -42,7 +42,7 @@ function writeWidget (widget, indent) {
dsl += widget.config[key].filter(Boolean).map(color => {
let index = color.lastIndexOf('=') + 1
let colorvalue = color.substring(index)
if (/^[^"'].*\W.*[^"']$/.test(colorvalue)) {
if (!/^(".*")|('.*')$/.test(colorvalue)) {
colorvalue = '"' + colorvalue + '"'
}
colorvalue = (index > 0 ? '=' + colorvalue : colorvalue)