Skip to content

Commit

Permalink
adobeGH-24 inline bg & color
Browse files Browse the repository at this point in the history
  • Loading branch information
npeltier committed Sep 14, 2020
1 parent af5f5e0 commit 2e507f0
Show file tree
Hide file tree
Showing 25 changed files with 493 additions and 254 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,19 @@
${'#{0}' @ format=model.id, context='styleString'} > .dx-flex-items > * {${model.gap[bp] @ context = 'styleString'}}
</sly>
<sly data-sly-repeat.definition="${model.definitions[bp]}">
${'#{0}' @ format=model.id, context='styleString'} > .dx-flex-items > *:nth-child(${model.definitions[bp].size @ context='unsafe' }) {
${'#{0}' @ format=model.id, context='styleString'} > .dx-flex-items > *:nth-child(${definition.count @ context='unsafe' }) {
${definition.width}
${definition.minHeight}
${definition.order}
}
</sly>
<sly data-sly-test="${bp.mediaQuery}">}</sly>
</sly>
</sly>
<sly data-sly-test="${model.style}">${model.style @ context='styleString'}</sly>
</style>
<div id="${model.id}" class="dx-flex">
<div class="dx-flex-items" data-sly-resource="${'./items' @ resourceType='dx/structure/components/parlite'}"></div>
<div data-sly-element="${dxPolicy.elementName}"
aria-label="${dxPolicy.ariaLabel}"
role="${(!dxPolicy.elementName || dxPolicy.elementName == 'div') && dxPolicy.ariaLandmarkRole}"
class="dx-flex-items"
data-sly-resource="${'./items' @ resourceType='dx/structure/components/parlite'}"></div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import com.adobe.dx.domtagging.IDTagger;
import com.adobe.dx.responsive.Breakpoint;
import com.adobe.dx.style.InlineStyleService;
import com.adobe.dx.inlinestyle.InlineStyleService;
import com.day.cq.wcm.api.policies.ContentPolicy;
import com.day.cq.wcm.api.policies.ContentPolicyManager;

Expand Down
34 changes: 0 additions & 34 deletions bundles/core/src/main/java/com/adobe/dx/img/ImageModel.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
package com.adobe.dx.style;
package com.adobe.dx.inlinestyle;

public class Constants {
private Constants() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
package com.adobe.dx.style;
package com.adobe.dx.inlinestyle;

import org.apache.sling.api.SlingHttpServletRequest;
import org.jetbrains.annotations.Nullable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
package com.adobe.dx.style;
package com.adobe.dx.inlinestyle;

import com.adobe.dx.responsive.Breakpoint;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ Copyright 2020 Adobe
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
package com.adobe.dx.inlinestyle.internal;

import static com.adobe.dx.inlinestyle.Constants.DEL_SPACE;
import static com.adobe.dx.utils.RequestUtil.getFromRespProps;

import com.adobe.dx.responsive.Breakpoint;
import com.adobe.dx.inlinestyle.StyleWorker;
import com.adobe.dx.styleguide.StyleGuideUtil;
import com.day.text.Text;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.SlingHttpServletRequest;
import org.jetbrains.annotations.Nullable;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;

@Component(configurationPolicy = ConfigurationPolicy.REQUIRE)
public class Background implements StyleWorker {
private static final String KEY = "background";
private static final String PN_BACKGROUNDCOLOR = "backgroundColor";
private static final String PN_GRADIENT = "gradient";
private static final String PN_IMAGE = "fileReference";
private static final String PN_FOCUSX = "focusX";
private static final String PN_FOCUSY = "focusY";
private static final String COLOR_FORMAT = "background-color: %s";
private static final String IMAGE_FORMAT = "background-image: %s";
private static final String BG_SIZE = "background-size: cover";
private static final String POSITION_PREFIX = "background-position: ";
private static final String POSITION_UNIT = "% ";
private static final String IMAGE_DECLARATION = "url(%s)";
private static final String IMG_DECLARATION_DELIMITER = ",";

@Override
public String getKey() {
return KEY;
}


private String generateColorDeclaration(String bgColor) {
if (StringUtils.isNotBlank(bgColor)) {
return String.format(COLOR_FORMAT, bgColor);
}
return null;
}

private String generateImageDeclaration(String gradient, String image) {
if (StringUtils.isNotBlank(gradient) || StringUtils.isNotBlank(image)) {
String imageDeclaration = null;
if (StringUtils.isNotBlank(image)) {
imageDeclaration = String.format(IMAGE_DECLARATION, Text.escape(image));
}
return String.format(IMAGE_FORMAT, Arrays.asList(gradient, imageDeclaration).stream()
.filter(StringUtils::isNotBlank)
.collect(Collectors.joining(IMG_DECLARATION_DELIMITER)));
}
return null;
}

private String generateSize(String image) {
if (StringUtils.isNotBlank(image)) {
return BG_SIZE;
}
return null;
}

private String generatePosition(String image, @Nullable Breakpoint breakpoint, SlingHttpServletRequest request) {
if (StringUtils.isNotBlank(image)) {
String focusX = getFromRespProps(request, breakpoint, PN_FOCUSX, String.class);
String focusY = getFromRespProps(request, breakpoint, PN_FOCUSY, String.class);
if (focusX != null && focusY != null) {
return POSITION_PREFIX + focusX + POSITION_UNIT + focusY + POSITION_UNIT;
}
}
return null;
}

@Override
public @Nullable String getDeclaration(@Nullable Breakpoint breakpoint, SlingHttpServletRequest request) {
String bgColorKey = getFromRespProps(request, breakpoint, PN_BACKGROUNDCOLOR, String.class);
String bgColor = StyleGuideUtil.getColor(request, bgColorKey);
String gradientKey = getFromRespProps(request, breakpoint, PN_GRADIENT, String.class);
String gradient = StyleGuideUtil.getGradient(request, gradientKey);
String image = getFromRespProps(request, breakpoint, PN_IMAGE, String.class);
if (bgColor != null || gradient != null || image != null) {
List<String> declarations = new ArrayList<>();
declarations.add(generateColorDeclaration(bgColor));
declarations.add(generateImageDeclaration(gradient, image));
declarations.add(generateSize(image));
declarations.add(generatePosition(image, breakpoint, request));
return declarations.stream()
.filter(StringUtils::isNotBlank)
.collect(Collectors.joining(DEL_SPACE));
}
return null;
}

@Override
public @Nullable String getRule(@Nullable Breakpoint breakpoint, @Nullable String id,
SlingHttpServletRequest request) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
package com.adobe.dx.style.internal;
package com.adobe.dx.inlinestyle.internal;

import static com.adobe.dx.style.Constants.DECLARATION;
import static com.adobe.dx.style.Constants.DEL_SPACE;
import static com.adobe.dx.style.Constants.PX;
import static com.adobe.dx.style.Constants.PX_SPACE;
import static com.adobe.dx.style.Constants.SPACE;
import static com.adobe.dx.inlinestyle.Constants.DECLARATION;
import static com.adobe.dx.inlinestyle.Constants.DEL_SPACE;
import static com.adobe.dx.inlinestyle.Constants.PX;
import static com.adobe.dx.inlinestyle.Constants.PX_SPACE;
import static com.adobe.dx.inlinestyle.Constants.SPACE;
import static com.adobe.dx.utils.RequestUtil.getPolicy;

import com.adobe.dx.responsive.Breakpoint;
import com.adobe.dx.style.StyleWorker;
import com.adobe.dx.inlinestyle.StyleWorker;

import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@
~ limitations under the License.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

package com.adobe.dx.style.internal;
package com.adobe.dx.inlinestyle.internal;

import static com.adobe.dx.utils.RequestUtil.getFromRespProps;

import com.adobe.dx.responsive.Breakpoint;
import com.adobe.dx.style.StyleWorker;
import com.adobe.dx.inlinestyle.StyleWorker;
import com.adobe.dx.styleguide.StyleGuide;
import com.adobe.dx.styleguide.StyleGuideUtil;

import org.apache.commons.lang.StringUtils;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.caconfig.ConfigurationBuilder;
import org.jetbrains.annotations.Nullable;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
Expand All @@ -41,7 +44,8 @@ public String getKey() {

@Override
public @Nullable String getDeclaration(@Nullable Breakpoint breakpoint, SlingHttpServletRequest request) {
String color = getFromRespProps(request, breakpoint, PN_COLOR, String.class);
String colorKey = getFromRespProps(request, breakpoint, PN_COLOR, String.class);
String color = StyleGuideUtil.getColor(request, colorKey);
if (StringUtils.isNotBlank(color)) {
return String.format(FORMAT, color);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
~ limitations under the License.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

package com.adobe.dx.style.internal;
package com.adobe.dx.inlinestyle.internal;

import static com.adobe.dx.style.Constants.DECLARATION_DELIMITER;
import static com.adobe.dx.inlinestyle.Constants.DECLARATION_DELIMITER;
import static com.day.cq.wcm.commons.Constants.EMPTY_STRING_ARRAY;
import static org.apache.commons.lang3.StringUtils.EMPTY;

import com.adobe.dx.responsive.Breakpoint;
import com.adobe.dx.style.StyleWorker;
import com.adobe.dx.style.InlineStyleService;
import com.adobe.dx.inlinestyle.StyleWorker;
import com.adobe.dx.inlinestyle.InlineStyleService;
import com.adobe.dx.utils.RequestUtil;

import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
package com.adobe.dx.style.internal;
package com.adobe.dx.inlinestyle.internal;

import static com.adobe.dx.style.Constants.PX_SPACE;
import static com.adobe.dx.inlinestyle.Constants.PX_SPACE;
import static com.adobe.dx.utils.RequestUtil.getPolicy;

import com.adobe.dx.responsive.Breakpoint;
import com.adobe.dx.style.StyleWorker;
import com.adobe.dx.inlinestyle.StyleWorker;

import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.ValueMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
~ limitations under the License.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
@Version("0.0.1")
package com.adobe.dx.style;
package com.adobe.dx.inlinestyle;

import org.osgi.annotation.versioning.Version;

This file was deleted.

Loading

0 comments on commit 2e507f0

Please sign in to comment.