chore(plugin-annotations): Migrate banner
This commit is contained in:
parent
c598fe7fe6
commit
f33f652e44
2 changed files with 70 additions and 21 deletions
|
@ -1,23 +1,63 @@
|
||||||
// Export macros
|
import { getIds } from './utils.mjs'
|
||||||
export const bannerMacros = {
|
|
||||||
banner: function (so) {
|
|
||||||
// Mix defaults with settings object
|
|
||||||
so = {
|
|
||||||
text: '',
|
|
||||||
dy: -1,
|
|
||||||
spaces: 12,
|
|
||||||
repeat: 10,
|
|
||||||
className: '',
|
|
||||||
...so,
|
|
||||||
}
|
|
||||||
so.path.attr('data-text-dy', so.dy).attr('data-text-class', `${so.className} center`)
|
|
||||||
const spacer = ' '.repeat(so.spaces)
|
|
||||||
|
|
||||||
for (let i = 0; i < so.repeat; i++) {
|
/*
|
||||||
so.path.attr('data-text', spacer)
|
* Defaults for the bannner macro
|
||||||
so.path.attr('data-text', so.text)
|
*/
|
||||||
}
|
const macroDefaults = {
|
||||||
|
classes: 'center',
|
||||||
so.path.attr('data-text', spacer)
|
dy: -1,
|
||||||
},
|
force: false,
|
||||||
|
id: 'banner',
|
||||||
|
repeat: 10,
|
||||||
|
spaces: 12,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The rmbanner macro
|
||||||
|
*/
|
||||||
|
const rmbanner = function (id = macroDefaults.id, { paths, store, part }) {
|
||||||
|
for (const pid of Object.values(
|
||||||
|
store.get(['parts', part.name, 'macros', 'banner', 'ids', id, 'paths'], {})
|
||||||
|
))
|
||||||
|
delete paths[pid]
|
||||||
|
}
|
||||||
|
|
||||||
|
const banner = function (config, { part, paths, store, log, complete }) {
|
||||||
|
/*
|
||||||
|
* Don't add a banne when complete is false, unless force is true
|
||||||
|
*/
|
||||||
|
if (!complete && !config.force) return
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Merge macro defaults with user-provided config to create the macro config (mc)
|
||||||
|
*/
|
||||||
|
const mc = { ...macroDefaults, ...config }
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get the list of IDs
|
||||||
|
*/
|
||||||
|
const ids = getIds(['banner'], mc.id, 'banner')
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Prepare the path to hold the banner text
|
||||||
|
*/
|
||||||
|
paths[ids.banner] = mc.path
|
||||||
|
.clone()
|
||||||
|
.setClass('hidden')
|
||||||
|
.attr('data-text-dy', mc.dy)
|
||||||
|
.attr('data-text-class', mc.classes)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Construct the text string piece by piece so it gets translated
|
||||||
|
*/
|
||||||
|
const spacer = ' '.repeat(mc.spaces)
|
||||||
|
for (let i = 0; i < mc.repeat; i++) paths[ids.banner].addText(spacer).addText(mc.text)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Store all IDs in the store so we can remove this macro with rmbanner
|
||||||
|
*/
|
||||||
|
store.set(['parts', part.name, 'macros', 'banner', 'ids', mc.id, 'paths'], ids)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Export macros
|
||||||
|
export const bannerMacros = { banner, rmbanner }
|
||||||
|
|
9
plugins/plugin-annotations/src/utils.mjs
Normal file
9
plugins/plugin-annotations/src/utils.mjs
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
/*
|
||||||
|
* Helper method to get the various IDs for a macro
|
||||||
|
*/
|
||||||
|
export const getIds = (keys, id, macroName) => {
|
||||||
|
const ids = {}
|
||||||
|
for (const key of keys) ids[key] = `__macro_${macroName}_${id}_${key}`
|
||||||
|
|
||||||
|
return ids
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue