2
0
mirror of https://github.com/tenrok/vue-meta.git synced 2026-06-15 11:22:25 +03:00

refactor: extract applyTemplate method and make it more generic

This commit is contained in:
pimlie
2019-03-08 12:59:16 +01:00
committed by Alexander Lichter
parent 15eb9ccfd1
commit fa90902fc7
+24
View File
@@ -0,0 +1,24 @@
import { isUndefined, isFunction } from './typeof'
export default function applyTemplate({ component, metaTemplateKeyName, contentKeyName }, headObject, template, chunk) {
if (isUndefined(template)) {
template = headObject[metaTemplateKeyName]
delete headObject[metaTemplateKeyName]
}
// return early if no template defined
if (!template) {
return false
}
if (isUndefined(chunk)) {
chunk = headObject[contentKeyName]
}
if (isFunction(template)) {
headObject[contentKeyName] = template.call(component, chunk)
} else {
headObject[contentKeyName] = template.replace(/%s/g, chunk)
}
return true
}