@ez-aem/policies
Version:
Easily Manage AEM Policies and Style System with EZ-AEM Policies.
104 lines (103 loc) • 4.69 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 ComponentPolicy = (function () {
function ComponentPolicy(settings) {
var _this = this;
this["@jcr:primaryType"] = "nt:unstructured";
this.policyName = settings.policyName || "content";
Object.keys(settings).filter(function (key) { return key.startsWith("@"); }).map(function (key) { return _this[key] = settings[key]; });
this["@sling:resourceType"] = settings["@sling:resourceType"];
this["@jcr:title"] = settings["@jcr:title"];
this["@jcr:description"] = settings["@jcr:description"] || null;
this["@cq:styleDefaultClasses"] = settings["@cq:styleDefaultClasses"] || null;
if (settings["@columns"])
this["@columns"] = settings["@columns"];
if (settings["@mainContentSelector"])
this["@mainContentSelector"] = settings["@mainContentSelector"];
if (settings["@components"])
this["@components"] = settings["@components"] || [];
if (settings["@clientlibs"])
this["@clientlibs"] = settings["@clientlibs"] || [];
this["cq:authoring"] = settings["cq:authoring"] || null;
this["cq:styleGroups"] = settings["cq:styleGroups"] || null;
this["@backgroundImageEnabled"] = settings["@backgroundImageEnabled"] || null;
this["children"] = settings["children"] || null;
this.formatAttributes();
}
ComponentPolicy.prototype.addCQStyleGroups = function (cqStyleGroups) {
this["cq:styleGroups"] = cqStyleGroups;
};
ComponentPolicy.prototype.addCQAuthoring = function (cqAuthoring) {
this["cq:authoring"] = cqAuthoring;
};
ComponentPolicy.prototype.format = function (includeResourceType, theme) {
var _a, _b;
if (includeResourceType === void 0) { includeResourceType = true; }
var policy = (_a = {},
_a[this.policyName] = __assign(__assign(__assign(__assign(__assign({ "@jcr:primaryType": this["@jcr:primaryType"], "@sling:resourceType": "wcm/core/components/policy/policy", "@jcr:title": this["@jcr:title"] }, this.formatAttributes()), { "jcr:content": {
"@jcr:primaryType": this["@jcr:primaryType"],
} }), this.formatCQAuthoring()), this.formatStyleGroups(theme)), this.formatChildren()),
_a);
if (includeResourceType)
return _b = {}, _b[this["@sling:resourceType"]] = policy, _b;
else
return policy;
};
ComponentPolicy.prototype.formatCQAuthoring = function () {
if (this["cq:authoring"] === null)
return false;
return {
"cq:authoring": __assign({ "@jcr:primaryType": this["@jcr:primaryType"] }, this["cq:authoring"])
};
};
ComponentPolicy.prototype.formatChildren = function () {
if (this["children"])
return __assign({}, this["children"]);
};
ComponentPolicy.prototype.formatStyleGroups = function (theme) {
if (this["cq:styleGroups"] === null)
return false;
return {
"cq:styleGroups": __assign({ "@jcr:primaryType": this["@jcr:primaryType"] }, this["cq:styleGroups"].format("xml", theme))
};
};
ComponentPolicy.prototype.formatAttributes = function () {
var attributes = {};
for (var key in this) {
if (key.startsWith("@") && key !== "@sling:resourceType") {
var value = this[key];
switch (typeof this[key]) {
case "string":
attributes[key] = value;
break;
case "object":
if (Array.isArray(this[key])) {
attributes[key] = "[".concat(value.join(","), "]");
}
break;
case "boolean":
attributes[key] = value;
break;
default:
attributes[key] = value.toString();
break;
}
}
}
return attributes;
};
return ComponentPolicy;
}());
exports.ComponentPolicy = ComponentPolicy;