Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ private Node processResponsiveGrid(Node root) throws RepositoryException {

do {
child = siblings.nextNode();
if (isColumnNode(child)) {
if (isStartNode(child)) {
child.remove();
break;
}
Expand All @@ -228,7 +228,7 @@ private Node processResponsiveGrid(Node root) throws RepositoryException {
addResponsive(node, c, newline, offset);
order.add(node.getName());
child = siblings.nextNode();
if (isColumnNode(child)) {
if (isBreakNode(child) || isEndNode(child)) {
child.remove();
siblings.nextNode();
}
Expand All @@ -240,9 +240,13 @@ private Node processResponsiveGrid(Node root) throws RepositoryException {
// Move remaining non column content to the end, preserve the order.
while (siblings.hasNext()) {
child = siblings.nextNode();
if (isColumnNode(child)) {
child.remove();
continue;
if (isStartNode(child)) {
// Recursively process the newly found column control
processResponsiveGrid(root);
continue;
} else if (isBreakNode(child) || isEndNode(child)) {
child.remove();
continue;
}
order.add(child.getName());
}
Expand Down Expand Up @@ -305,7 +309,7 @@ private List<Queue<String>> getColumnContent(Node root) throws RepositoryExcepti
columnContents.add(nodeNames);
while (siblings.hasNext()) {
Node node = siblings.nextNode();
if (StringUtils.equals(columnControlResourceType, node.getProperty(SLING_RESOURCE_TYPE_PROPERTY).getString())) {
if (isBreakNode(node) || isEndNode(node)) {
// Node is now the next column break;
break;
}
Expand All @@ -316,12 +320,30 @@ private List<Queue<String>> getColumnContent(Node root) throws RepositoryExcepti
return columnContents;
}

private boolean isColumnNode(Node node) throws RepositoryException {
if (!node.hasProperty(SLING_RESOURCE_TYPE_PROPERTY)) {
return false;
// Check if the node is a column control node.
private boolean isStartNode(Node node) throws RepositoryException {
if (!node.hasProperty(SLING_RESOURCE_TYPE_PROPERTY)) {
return false;
}
return StringUtils.equals(columnControlResourceType,
node.getProperty(SLING_RESOURCE_TYPE_PROPERTY).getString());
}
// Check if the node is a break node of controlType 'break'
private boolean isBreakNode(Node node) throws RepositoryException {
if (!node.hasProperty(SLING_RESOURCE_TYPE_PROPERTY)) {
return false;
}
return node.hasProperty("controlType")
&& StringUtils.equals("break", node.getProperty("controlType").getString());
}
// Check if the node is an end node of controlType 'end'
private boolean isEndNode(Node node) throws RepositoryException {
if (!node.hasProperty(SLING_RESOURCE_TYPE_PROPERTY)) {
return false;
}
return node.hasProperty("controlType")
&& StringUtils.equals("end", node.getProperty("controlType").getString());
}
return StringUtils.equals(columnControlResourceType, node.getProperty(SLING_RESOURCE_TYPE_PROPERTY).getString());
}

private void addResponsive(Node node, int index, boolean isNewline, boolean isOffset) throws RepositoryException {
Node responsive = node.addNode(NN_RESPONSIVE_CONFIG, NT_UNSTRUCTURED);
Expand Down Expand Up @@ -416,8 +438,8 @@ protected void activate(ComponentContext context, Config config) throws Configur
columnControlResourceType = PROP_RESOURCE_TYPE_DEFAULT;
}

// String type = config.grid_type();
isResponsive = false; // !StringUtils.equals(PROP_CONTAINER_TYPE, type);
String type = config.grid_type();
isResponsive = !StringUtils.equals(PROP_CONTAINER_TYPE, type);

containerResourceType = config.container_resourceType();
if (!isResponsive) {
Expand Down Expand Up @@ -475,15 +497,15 @@ protected void activate(ComponentContext context, Config config) throws Configur
)
String column_control_resourceType() default PROP_RESOURCE_TYPE_DEFAULT;

// @AttributeDefinition(
// name = "Conversion Type",
// description = "Type of structure to convert to: RESPONSIVE will arrange column contents in parent responsive grid. CONTAINER will replace each column with a container.",
// options = {
// @Option(label = "Responsive", value = PROP_RESPONSIVE_TYPE),
// @Option(label = "Container", value = PROP_CONTAINER_TYPE),
// }
// )
// String grid_type() default PROP_RESPONSIVE_TYPE;
@AttributeDefinition(
name = "Conversion Type",
description = "Type of structure to convert to: RESPONSIVE will arrange column contents in parent responsive grid. CONTAINER will replace each column with a container.",
options = {
@Option(label = "Responsive", value = PROP_RESPONSIVE_TYPE),
@Option(label = "Container", value = PROP_CONTAINER_TYPE),
}
)
String grid_type() default PROP_RESPONSIVE_TYPE;

@AttributeDefinition(
name = "Container ResourceType",
Expand Down