@ez-aem/policies
Version:
Easily Manage AEM Policies and Style System with EZ-AEM Policies.
81 lines (80 loc) • 3.8 kB
JavaScript
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ComponentPolicy = void 0;
var jcrPrimaryType = { "jcr:primaryType": "nt:unstructured" };
var ComponentPolicy = (function () {
function ComponentPolicy(settings) {
this.policy = settings === null || settings === void 0 ? void 0 : settings.policy;
this.title = settings === null || settings === void 0 ? void 0 : settings.title;
this.description = (settings === null || settings === void 0 ? void 0 : settings.description) || null;
this.styles = (settings === null || settings === void 0 ? void 0 : settings.styles) || null;
this.component = settings === null || settings === void 0 ? void 0 : settings.component;
this.attributes = settings === null || settings === void 0 ? void 0 : settings.attributes;
this.configurations = settings === null || settings === void 0 ? void 0 : settings.configurations;
}
ComponentPolicy.prototype.format = function (includeResourceType, theme) {
var _a, _b;
if (includeResourceType === void 0) { includeResourceType = true; }
var policy = (_a = {},
_a[this.policy] = __assign(__assign({ attributes: __assign(__assign(__assign({}, jcrPrimaryType), { "sling:resourceType": "wcm/core/components/policy/policy", "jcr:title": this.title, "jcr:description": this.description }), this.formatAttributes()), "jcr:content": {
attributes: jcrPrimaryType,
} }, this.formatStyleGroups(theme)), this.formatConfigurations(this.configurations)),
_a);
if (includeResourceType)
return _b = {}, _b[this.component] = policy, _b;
else
return policy;
};
ComponentPolicy.prototype.formatAttributes = function () {
for (var key in this.attributes) {
var value = this.attributes[key];
switch (typeof this.attributes[key]) {
case "object":
if (Array.isArray(this.attributes[key])) {
this.attributes[key] = "[".concat(value.join(","), "]");
}
break;
default:
this.attributes[key] = value.toString();
break;
}
}
return this.attributes;
};
ComponentPolicy.prototype.formatStyleGroups = function (theme) {
if (this.styles === null)
return false;
return {
"cq:styleGroups": __assign({ attributes: jcrPrimaryType }, this.styles.format("xml", theme))
};
};
ComponentPolicy.prototype.formatConfigurations = function (configuration) {
for (var key in configuration) {
if (typeof configuration[key] === "object" && key !== "attributes") {
if (configuration[key].attributes) {
if (!configuration[key].attributes["jcr:primaryType"]) {
configuration[key].attributes["jcr:primaryType"] = "nt:unstructured";
}
}
else {
configuration[key].attributes = { "jcr:primaryType": "nt:unstructured" };
}
this.formatConfigurations(configuration[key]);
}
}
return configuration;
};
return ComponentPolicy;
}());
exports.ComponentPolicy = ComponentPolicy;