Skip to content

Commit

Permalink
support or condition in theme def
Browse files Browse the repository at this point in the history
  • Loading branch information
farin committed Jan 28, 2021
1 parent 6291a80 commit 7e9123c
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/renderer/plugins/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,24 @@ class Theme {
if (!img.if) {
return true
}
if (img.if[0] === '!') {
const p = img.if.substring(1)
return !params.includes(p)
let conditions
const or = img.if.includes('||')
const and = img.if.includes('&&')
if (or && and) {
throw new Error('both || and && is not allowed in one expression')
}
return params.includes(img.if)
if (and) {
conditions = img.if.split(/\s*&&\s*/)
} else if (or) {
conditions = img.if.split(/\s*\|\|\s*/)
} else {
conditions = [img.if]
}
const values = conditions.map(cond => cond[0] === '!' ? !params.includes(cond.substring(1)) : params.includes(cond))
if (or) {
return values.includes(true)
}
return !values.includes(false)
}

const getFeature = id => {
Expand Down

0 comments on commit 7e9123c

Please sign in to comment.