From 2e507f08e57466fc08071615483cb28e6fe9696c Mon Sep 17 00:00:00 2001 From: Nicolas Peltier Date: Fri, 11 Sep 2020 17:06:00 +0200 Subject: [PATCH] GH-24 inline bg & color --- .../dx/structure/components/flex/flex.html | 10 +- .../adobe/dx/structure/flex/FlexModel.java | 2 +- .../java/com/adobe/dx/img/ImageModel.java | 34 ----- .../dx/{style => inlinestyle}/Constants.java | 2 +- .../InlineStyleService.java | 2 +- .../{style => inlinestyle}/StyleWorker.java | 2 +- .../dx/inlinestyle/internal/Background.java | 122 ++++++++++++++++++ .../internal/Border.java | 14 +- .../internal/Color.java | 10 +- .../internal/InlineStyleServiceImpl.java | 8 +- .../internal/Shadow.java | 6 +- .../{style => inlinestyle}/package-info.java | 2 +- .../adobe/dx/style/internal/Background.java | 70 ---------- .../com/adobe/dx/styleguide/StyleGuide.java | 36 ++++++ .../adobe/dx/styleguide/StyleGuideItem.java | 41 ++++++ .../adobe/dx/styleguide/StyleGuideUtil.java | 68 ++++++++++ .../com/adobe/dx/styleguide/package-info.java | 20 +++ .../internal/AbstractStyleWorkerTest.java | 81 ++++++++++++ .../inlinestyle/internal/BackgroundTest.java | 81 ++++++++++++ .../internal/BorderTest.java | 4 +- .../internal/ColorTest.java | 10 +- .../internal/InlineStyleServiceImplTest.java | 4 +- .../internal/ShadowTest.java | 4 +- .../internal/AbstractStyleWorkerTest.java | 58 --------- .../dx/style/internal/BackgroundTest.java | 56 -------- 25 files changed, 493 insertions(+), 254 deletions(-) delete mode 100644 bundles/core/src/main/java/com/adobe/dx/img/ImageModel.java rename bundles/core/src/main/java/com/adobe/dx/{style => inlinestyle}/Constants.java (97%) rename bundles/core/src/main/java/com/adobe/dx/{style => inlinestyle}/InlineStyleService.java (97%) rename bundles/core/src/main/java/com/adobe/dx/{style => inlinestyle}/StyleWorker.java (98%) create mode 100644 bundles/core/src/main/java/com/adobe/dx/inlinestyle/internal/Background.java rename bundles/core/src/main/java/com/adobe/dx/{style => inlinestyle}/internal/Border.java (94%) rename bundles/core/src/main/java/com/adobe/dx/{style => inlinestyle}/internal/Color.java (83%) rename bundles/core/src/main/java/com/adobe/dx/{style => inlinestyle}/internal/InlineStyleServiceImpl.java (96%) rename bundles/core/src/main/java/com/adobe/dx/{style => inlinestyle}/internal/Shadow.java (95%) rename bundles/core/src/main/java/com/adobe/dx/{style => inlinestyle}/package-info.java (95%) delete mode 100644 bundles/core/src/main/java/com/adobe/dx/style/internal/Background.java create mode 100644 bundles/core/src/main/java/com/adobe/dx/styleguide/StyleGuide.java create mode 100644 bundles/core/src/main/java/com/adobe/dx/styleguide/StyleGuideItem.java create mode 100644 bundles/core/src/main/java/com/adobe/dx/styleguide/StyleGuideUtil.java create mode 100644 bundles/core/src/main/java/com/adobe/dx/styleguide/package-info.java create mode 100644 bundles/core/src/test/java/com/adobe/dx/inlinestyle/internal/AbstractStyleWorkerTest.java create mode 100644 bundles/core/src/test/java/com/adobe/dx/inlinestyle/internal/BackgroundTest.java rename bundles/core/src/test/java/com/adobe/dx/{style => inlinestyle}/internal/BorderTest.java (97%) rename bundles/core/src/test/java/com/adobe/dx/{style => inlinestyle}/internal/ColorTest.java (84%) rename bundles/core/src/test/java/com/adobe/dx/{style => inlinestyle}/internal/InlineStyleServiceImplTest.java (98%) rename bundles/core/src/test/java/com/adobe/dx/{style => inlinestyle}/internal/ShadowTest.java (94%) delete mode 100644 bundles/core/src/test/java/com/adobe/dx/style/internal/AbstractStyleWorkerTest.java delete mode 100644 bundles/core/src/test/java/com/adobe/dx/style/internal/BackgroundTest.java diff --git a/apps/structure/app/jcr_root/apps/dx/structure/components/flex/flex.html b/apps/structure/app/jcr_root/apps/dx/structure/components/flex/flex.html index 43dd629b..29abc024 100644 --- a/apps/structure/app/jcr_root/apps/dx/structure/components/flex/flex.html +++ b/apps/structure/app/jcr_root/apps/dx/structure/components/flex/flex.html @@ -26,17 +26,19 @@ ${'#{0}' @ format=model.id, context='styleString'} > .dx-flex-items > * {${model.gap[bp] @ context = 'styleString'}} - ${'#{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} } - } - ${model.style @ context='styleString'}
-
+
\ No newline at end of file diff --git a/apps/structure/core/src/main/java/com/adobe/dx/structure/flex/FlexModel.java b/apps/structure/core/src/main/java/com/adobe/dx/structure/flex/FlexModel.java index bfcb4741..0a2064a8 100644 --- a/apps/structure/core/src/main/java/com/adobe/dx/structure/flex/FlexModel.java +++ b/apps/structure/core/src/main/java/com/adobe/dx/structure/flex/FlexModel.java @@ -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; diff --git a/bundles/core/src/main/java/com/adobe/dx/img/ImageModel.java b/bundles/core/src/main/java/com/adobe/dx/img/ImageModel.java deleted file mode 100644 index 1797af1c..00000000 --- a/bundles/core/src/main/java/com/adobe/dx/img/ImageModel.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * - * ADOBE CONFIDENTIAL - * __________________ - * - * Copyright 2019 Adobe - * All Rights Reserved. - * - * NOTICE: All information contained herein is, and remains - * the property of Adobe and its suppliers, if any. The intellectual - * and technical concepts contained herein are proprietary to Adobe - * and its suppliers and are protected by all applicable intellectual - * property laws, including trade secret and copyright laws. - * Dissemination of this information or reproduction of this material - * is strictly forbidden unless prior written permission is obtained - * from Adobe. - ******************************************************************************/ - -package com.adobe.dx.img; - -import java.util.Map; - -import org.apache.sling.api.SlingHttpServletRequest; -import org.apache.sling.models.annotations.Model; -import org.apache.sling.models.annotations.injectorspecific.ScriptVariable; - -@Model(adaptables = SlingHttpServletRequest.class) -public class ImageModel { - - @ScriptVariable - Map resprops; - - -} diff --git a/bundles/core/src/main/java/com/adobe/dx/style/Constants.java b/bundles/core/src/main/java/com/adobe/dx/inlinestyle/Constants.java similarity index 97% rename from bundles/core/src/main/java/com/adobe/dx/style/Constants.java rename to bundles/core/src/main/java/com/adobe/dx/inlinestyle/Constants.java index 41118eeb..ee08d56c 100644 --- a/bundles/core/src/main/java/com/adobe/dx/style/Constants.java +++ b/bundles/core/src/main/java/com/adobe/dx/inlinestyle/Constants.java @@ -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() { diff --git a/bundles/core/src/main/java/com/adobe/dx/style/InlineStyleService.java b/bundles/core/src/main/java/com/adobe/dx/inlinestyle/InlineStyleService.java similarity index 97% rename from bundles/core/src/main/java/com/adobe/dx/style/InlineStyleService.java rename to bundles/core/src/main/java/com/adobe/dx/inlinestyle/InlineStyleService.java index 82ac8080..4dc32ab5 100644 --- a/bundles/core/src/main/java/com/adobe/dx/style/InlineStyleService.java +++ b/bundles/core/src/main/java/com/adobe/dx/inlinestyle/InlineStyleService.java @@ -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; diff --git a/bundles/core/src/main/java/com/adobe/dx/style/StyleWorker.java b/bundles/core/src/main/java/com/adobe/dx/inlinestyle/StyleWorker.java similarity index 98% rename from bundles/core/src/main/java/com/adobe/dx/style/StyleWorker.java rename to bundles/core/src/main/java/com/adobe/dx/inlinestyle/StyleWorker.java index 72d146fb..2eb171bb 100644 --- a/bundles/core/src/main/java/com/adobe/dx/style/StyleWorker.java +++ b/bundles/core/src/main/java/com/adobe/dx/inlinestyle/StyleWorker.java @@ -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; diff --git a/bundles/core/src/main/java/com/adobe/dx/inlinestyle/internal/Background.java b/bundles/core/src/main/java/com/adobe/dx/inlinestyle/internal/Background.java new file mode 100644 index 00000000..16419620 --- /dev/null +++ b/bundles/core/src/main/java/com/adobe/dx/inlinestyle/internal/Background.java @@ -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 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; + } +} diff --git a/bundles/core/src/main/java/com/adobe/dx/style/internal/Border.java b/bundles/core/src/main/java/com/adobe/dx/inlinestyle/internal/Border.java similarity index 94% rename from bundles/core/src/main/java/com/adobe/dx/style/internal/Border.java rename to bundles/core/src/main/java/com/adobe/dx/inlinestyle/internal/Border.java index 4035d713..7dbb5168 100644 --- a/bundles/core/src/main/java/com/adobe/dx/style/internal/Border.java +++ b/bundles/core/src/main/java/com/adobe/dx/inlinestyle/internal/Border.java @@ -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; diff --git a/bundles/core/src/main/java/com/adobe/dx/style/internal/Color.java b/bundles/core/src/main/java/com/adobe/dx/inlinestyle/internal/Color.java similarity index 83% rename from bundles/core/src/main/java/com/adobe/dx/style/internal/Color.java rename to bundles/core/src/main/java/com/adobe/dx/inlinestyle/internal/Color.java index faf01bf4..f0051702 100644 --- a/bundles/core/src/main/java/com/adobe/dx/style/internal/Color.java +++ b/bundles/core/src/main/java/com/adobe/dx/inlinestyle/internal/Color.java @@ -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; @@ -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); } diff --git a/bundles/core/src/main/java/com/adobe/dx/style/internal/InlineStyleServiceImpl.java b/bundles/core/src/main/java/com/adobe/dx/inlinestyle/internal/InlineStyleServiceImpl.java similarity index 96% rename from bundles/core/src/main/java/com/adobe/dx/style/internal/InlineStyleServiceImpl.java rename to bundles/core/src/main/java/com/adobe/dx/inlinestyle/internal/InlineStyleServiceImpl.java index 1a875075..5d8cc3e7 100644 --- a/bundles/core/src/main/java/com/adobe/dx/style/internal/InlineStyleServiceImpl.java +++ b/bundles/core/src/main/java/com/adobe/dx/inlinestyle/internal/InlineStyleServiceImpl.java @@ -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; diff --git a/bundles/core/src/main/java/com/adobe/dx/style/internal/Shadow.java b/bundles/core/src/main/java/com/adobe/dx/inlinestyle/internal/Shadow.java similarity index 95% rename from bundles/core/src/main/java/com/adobe/dx/style/internal/Shadow.java rename to bundles/core/src/main/java/com/adobe/dx/inlinestyle/internal/Shadow.java index 9de3d46f..72718965 100644 --- a/bundles/core/src/main/java/com/adobe/dx/style/internal/Shadow.java +++ b/bundles/core/src/main/java/com/adobe/dx/inlinestyle/internal/Shadow.java @@ -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; diff --git a/bundles/core/src/main/java/com/adobe/dx/style/package-info.java b/bundles/core/src/main/java/com/adobe/dx/inlinestyle/package-info.java similarity index 95% rename from bundles/core/src/main/java/com/adobe/dx/style/package-info.java rename to bundles/core/src/main/java/com/adobe/dx/inlinestyle/package-info.java index 0128bc09..221abadd 100644 --- a/bundles/core/src/main/java/com/adobe/dx/style/package-info.java +++ b/bundles/core/src/main/java/com/adobe/dx/inlinestyle/package-info.java @@ -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; \ No newline at end of file diff --git a/bundles/core/src/main/java/com/adobe/dx/style/internal/Background.java b/bundles/core/src/main/java/com/adobe/dx/style/internal/Background.java deleted file mode 100644 index 9e3cba4c..00000000 --- a/bundles/core/src/main/java/com/adobe/dx/style/internal/Background.java +++ /dev/null @@ -1,70 +0,0 @@ -/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ~ 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.style.internal; - -import static com.adobe.dx.utils.RequestUtil.getFromRespProps; - -import com.adobe.dx.responsive.Breakpoint; -import com.adobe.dx.style.StyleWorker; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.commons.lang.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"; - - @Override - public String getKey() { - return KEY; - } - - @Override - public @Nullable String getDeclaration(@Nullable Breakpoint breakpoint, SlingHttpServletRequest request) { - String bgColor = getFromRespProps(request, breakpoint, PN_BACKGROUNDCOLOR, String.class); - String gradient = getFromRespProps(request, breakpoint, PN_GRADIENT, String.class); - String backgroundImage = getFromRespProps(request, breakpoint, PN_IMAGE, String.class); - if (bgColor != null || gradient != null || backgroundImage != null) { - List declarations = new ArrayList<>(); - if (StringUtils.isNotBlank(bgColor)) { - declarations.add(COLOR_FORMAT.format(bgColor)); - } - if (StringUtils.isNotBlank(gradient)) { - - } - - } - return null; - } - - @Override - public @Nullable String getRule(@Nullable Breakpoint breakpoint, @Nullable String id, - SlingHttpServletRequest request) { - return null; - } -} diff --git a/bundles/core/src/main/java/com/adobe/dx/styleguide/StyleGuide.java b/bundles/core/src/main/java/com/adobe/dx/styleguide/StyleGuide.java new file mode 100644 index 00000000..bec3c217 --- /dev/null +++ b/bundles/core/src/main/java/com/adobe/dx/styleguide/StyleGuide.java @@ -0,0 +1,36 @@ +/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~ 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.styleguide; + +import com.adobe.dx.domtagging.internal.IDTaggerImpl; + +import org.apache.sling.caconfig.annotation.Configuration; +import org.apache.sling.caconfig.annotation.Property; + +@Configuration(description = "holds all style guide configurations") +public @interface StyleGuide { + /** + * @return all gradients configured + */ + @Property(label="gradients", description = "get all gradients configured") + StyleGuideItem[] gradients(); + + /** + * @return all colors configured + */ + @Property(label="colors", description = "get all colors configured") + StyleGuideItem[] colors(); +} diff --git a/bundles/core/src/main/java/com/adobe/dx/styleguide/StyleGuideItem.java b/bundles/core/src/main/java/com/adobe/dx/styleguide/StyleGuideItem.java new file mode 100644 index 00000000..5599f6e5 --- /dev/null +++ b/bundles/core/src/main/java/com/adobe/dx/styleguide/StyleGuideItem.java @@ -0,0 +1,41 @@ +/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~ 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.styleguide; + +import org.apache.sling.caconfig.annotation.Configuration; +import org.apache.sling.caconfig.annotation.Property; + +@Configuration(label="Style item", description = "holds configuration for one style type", collection = true) +public @interface StyleGuideItem { + + /** + * @return key used to match that style item with its consumers' usage + */ + @Property(label="Key", description = "key used to match that style item with its consumers' usage") + String key(); + + /** + * @return value we do use in style + */ + @Property(label="Value", description = "value we do use in style") + String value(); + + /** + * @return label presented to user interfaces + */ + @Property(label="Label", description = "Label to be used in user interfaces") + String label(); +} diff --git a/bundles/core/src/main/java/com/adobe/dx/styleguide/StyleGuideUtil.java b/bundles/core/src/main/java/com/adobe/dx/styleguide/StyleGuideUtil.java new file mode 100644 index 00000000..ecb4c4f9 --- /dev/null +++ b/bundles/core/src/main/java/com/adobe/dx/styleguide/StyleGuideUtil.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * + * ADOBE CONFIDENTIAL + * __________________ + * + * Copyright 2019 Adobe + * All Rights Reserved. + * + * NOTICE: All information contained herein is, and remains + * the property of Adobe and its suppliers, if any. The intellectual + * and technical concepts contained herein are proprietary to Adobe + * and its suppliers and are protected by all applicable intellectual + * property laws, including trade secret and copyright laws. + * Dissemination of this information or reproduction of this material + * is strictly forbidden unless prior written permission is obtained + * from Adobe. + ******************************************************************************/ + +package com.adobe.dx.styleguide; + +import org.apache.commons.lang.StringUtils; +import org.apache.sling.api.SlingHttpServletRequest; +import org.apache.sling.caconfig.ConfigurationBuilder; + +public class StyleGuideUtil { + private StyleGuideUtil() { + + } + + private static StyleGuideItem get(StyleGuideItem[] items, String key) { + if (items != null && StringUtils.isNotBlank(key)) { + for (StyleGuideItem item : items) { + if (key.equals(item.key())) { + return item; + } + } + } + return null; + } + + private static String getValue(StyleGuideItem[] items, String key) { + StyleGuideItem item = get(items, key); + if (item != null) { + return item.value(); + } + return null; + } + + private static StyleGuide getGuide(SlingHttpServletRequest request) { + return request.getResource().adaptTo(ConfigurationBuilder.class).as(StyleGuide.class); + } + + public static String getColor(SlingHttpServletRequest request, String key) { + StyleGuide guide = getGuide(request); + if (guide != null) { + return getValue(guide.colors(), key); + } + return null; + } + + public static String getGradient(SlingHttpServletRequest request, String key) { + StyleGuide guide = getGuide(request); + if (guide != null) { + return getValue(guide.gradients(), key); + } + return null; + } +} diff --git a/bundles/core/src/main/java/com/adobe/dx/styleguide/package-info.java b/bundles/core/src/main/java/com/adobe/dx/styleguide/package-info.java new file mode 100644 index 00000000..ca8c5352 --- /dev/null +++ b/bundles/core/src/main/java/com/adobe/dx/styleguide/package-info.java @@ -0,0 +1,20 @@ +/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~ 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. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ + @Version("0.0.1") + package com.adobe.dx.styleguide; + + import org.osgi.annotation.versioning.Version; + \ No newline at end of file diff --git a/bundles/core/src/test/java/com/adobe/dx/inlinestyle/internal/AbstractStyleWorkerTest.java b/bundles/core/src/test/java/com/adobe/dx/inlinestyle/internal/AbstractStyleWorkerTest.java new file mode 100644 index 00000000..f47a63a3 --- /dev/null +++ b/bundles/core/src/test/java/com/adobe/dx/inlinestyle/internal/AbstractStyleWorkerTest.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * + * ADOBE CONFIDENTIAL + * __________________ + * + * Copyright 2019 Adobe + * All Rights Reserved. + * + * NOTICE: All information contained herein is, and remains + * the property of Adobe and its suppliers, if any. The intellectual + * and technical concepts contained herein are proprietary to Adobe + * and its suppliers and are protected by all applicable intellectual + * property laws, including trade secret and copyright laws. + * Dissemination of this information or reproduction of this material + * is strictly forbidden unless prior written permission is obtained + * from Adobe. + ******************************************************************************/ + +package com.adobe.dx.inlinestyle.internal; + +import com.adobe.dx.bindings.internal.DxBindingsValueProvider; +import com.adobe.dx.responsive.Breakpoint; +import com.adobe.dx.responsive.ResponsiveConfiguration; +import com.adobe.dx.responsive.internal.ResponsivePropertiesImpl; +import com.adobe.dx.responsive.internal.ResponsivePropertiesImplTest; +import com.adobe.dx.inlinestyle.StyleWorker; +import com.adobe.dx.styleguide.StyleGuide; +import com.adobe.dx.styleguide.StyleGuideItem; +import com.adobe.dx.testing.AbstractTest; +import com.adobe.dx.utils.RequestUtil; + +import org.apache.commons.lang.StringUtils; +import org.apache.sling.api.scripting.SlingBindings; +import org.apache.sling.testing.mock.caconfig.MockContextAwareConfig; + +public abstract class AbstractStyleWorkerTest extends AbstractTest { + + abstract StyleWorker getWorker(); + + String getDeclaration() { + return getDeclaration(null); + } + + void setStyleGuide() { + String confRoot = CONF_ROOT + "/sling:configs/" + StyleGuide.class.getName() + "/"; + context.build().resource(confRoot + "colors") + .siblingsMode() + .resource("1","key", "red", "value", "#FF0000") + .resource("2", "key", "white", "value", "#FFFFFF"); + context.build().resource(confRoot + "gradients") + .siblingsMode() + .resource("1","label", "Adobe Red", "key", "red", "value", "linear-gradient(180deg, rgba(0, 0, 0, 0.5) 36.8%,rgba(255, 0, 0, 0.78) 95.0%)") + .resource("2", "label", "Fade to black", "key", "wb", "value", "linear-gradient(180deg, rgba(0, 0, 0, 0.5) 50.0%,rgba(0, 0, 0, 1) 95.0%)") + .resource("3", "label", "Rainbow bars", "key", "rainbow", "value", "linear-gradient(90deg, rgba(255, 0, 0, 0.41) 20.0%,rgba(255, 165, 0, 0.41) 20.0%,rgba(255, 165, 0, 0.41) 40.0%,rgba(255, 255, 0, 0.41) 40.0%,rgba(255, 255, 0, 0.41) 60.0%,rgba(0, 128, 0, 0.41) 60.0%,rgba(0, 128, 0, 0.41) 80.0%,rgba(0, 0, 255, 0.4) 80.0%)"); + MockContextAwareConfig.registerAnnotationClasses(context, StyleGuide.class); + MockContextAwareConfig.registerAnnotationClasses(context, StyleGuideItem.class); + } + + void setBreakpoints() { + SlingBindings bindings = (SlingBindings)context.request().getAttribute(SlingBindings.class.getName()); + ResponsiveConfiguration configuration = ResponsivePropertiesImplTest.initResponsiveConfiguration(context); + ResponsivePropertiesImpl responsiveProperties = new ResponsivePropertiesImpl(configuration, getVM(CONTENT_ROOT)); + bindings.put(DxBindingsValueProvider.RESP_PROPS_KEY, responsiveProperties); + bindings.put(DxBindingsValueProvider.BP_KEY, configuration.breakpoints()); + } + + String getDeclaration(String breakpointKey) { + SlingBindings bindings = (SlingBindings)context.request().getAttribute(SlingBindings.class.getName()); + bindings.put(DxBindingsValueProvider.POLICY_KEY, getVM(CONTENT_ROOT)); + Breakpoint breakpoint = null; + if (StringUtils.isNotBlank(breakpointKey)) { + for (Breakpoint candidate : RequestUtil.getBreakpoints(context.request())) { + if (candidate.key().equals(breakpointKey)) { + breakpoint = candidate; + break; + } + } + } + return getWorker().getDeclaration(breakpoint, context.request()); + } +} diff --git a/bundles/core/src/test/java/com/adobe/dx/inlinestyle/internal/BackgroundTest.java b/bundles/core/src/test/java/com/adobe/dx/inlinestyle/internal/BackgroundTest.java new file mode 100644 index 00000000..bb854b4c --- /dev/null +++ b/bundles/core/src/test/java/com/adobe/dx/inlinestyle/internal/BackgroundTest.java @@ -0,0 +1,81 @@ +/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~ 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 org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import com.adobe.dx.inlinestyle.StyleWorker; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class BackgroundTest extends AbstractStyleWorkerTest{ + + @Override + StyleWorker getWorker() { + return new Background(); + } + + @BeforeEach + void setup(){ + setStyleGuide(); + setBreakpoints(); + context.currentResource(CONTENT_ROOT); + } + + @Test + void getBackgroundImage() { + context.build().resource(CONTENT_ROOT, + "fileReferenceMobile", "/content/dam/mobile.jpg", + "fileReferenceTablet", "/content/dam/tablet.jpg", + "fileReferenceDesktop", "/content/dam/desktop.jpg", + "focusXMobile", 30, + "focusYMobile", 30); + assertEquals("background-image: url(%2fcontent%2fdam%2fmobile.jpg); background-size: cover; background-position: 30% 30% ", getDeclaration("mobile")); + assertEquals("background-image: url(%2fcontent%2fdam%2fdesktop.jpg); background-size: cover", getDeclaration("desktop")); + } + + @Test + void getBackgroundColor() { + context.build().resource(CONTENT_ROOT, + "backgroundColorDesktop", "white"); + assertEquals("background-color: #FFFFFF", getDeclaration("desktop")); + assertNull(getDeclaration("mobile")); + assertNull(getDeclaration("tablet")); + } + + @Test + void getBackgroundGradient() { + context.build().resource(CONTENT_ROOT, + "gradientTablet", "red"); + assertEquals("background-image: linear-gradient(180deg, rgba(0, 0, 0, 0.5) 36.8%,rgba(255, 0, 0, 0.78) 95.0%)", getDeclaration("tablet")); + assertNull(getDeclaration("mobile")); + assertNull(getDeclaration("desktop")); + } + + @Test + void getBackgroundCumulate() { + context.build().resource(CONTENT_ROOT, + "fileReferenceMobile", "/content/dam/mobile.jpg", + "focusXMobile", 30, + "focusYMobile", 30, + "backgroundColorMobile", "white", + "gradientMobile", "red"); + assertEquals("background-color: #FFFFFF; background-image: linear-gradient(180deg, rgba(0, 0, 0, 0.5) 36.8%,rgba(255, 0, 0, 0.78) 95.0%),url(%2fcontent%2fdam%2fmobile.jpg); background-size: cover; background-position: 30% 30% ", + getDeclaration("mobile")); + } +} \ No newline at end of file diff --git a/bundles/core/src/test/java/com/adobe/dx/style/internal/BorderTest.java b/bundles/core/src/test/java/com/adobe/dx/inlinestyle/internal/BorderTest.java similarity index 97% rename from bundles/core/src/test/java/com/adobe/dx/style/internal/BorderTest.java rename to bundles/core/src/test/java/com/adobe/dx/inlinestyle/internal/BorderTest.java index 1e52730e..eb700bb9 100644 --- a/bundles/core/src/test/java/com/adobe/dx/style/internal/BorderTest.java +++ b/bundles/core/src/test/java/com/adobe/dx/inlinestyle/internal/BorderTest.java @@ -13,12 +13,12 @@ ~ 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 org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; -import com.adobe.dx.style.StyleWorker; +import com.adobe.dx.inlinestyle.StyleWorker; import org.junit.jupiter.api.Test; diff --git a/bundles/core/src/test/java/com/adobe/dx/style/internal/ColorTest.java b/bundles/core/src/test/java/com/adobe/dx/inlinestyle/internal/ColorTest.java similarity index 84% rename from bundles/core/src/test/java/com/adobe/dx/style/internal/ColorTest.java rename to bundles/core/src/test/java/com/adobe/dx/inlinestyle/internal/ColorTest.java index 7bf147f7..916aef0d 100644 --- a/bundles/core/src/test/java/com/adobe/dx/style/internal/ColorTest.java +++ b/bundles/core/src/test/java/com/adobe/dx/inlinestyle/internal/ColorTest.java @@ -13,12 +13,12 @@ ~ 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 org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; -import com.adobe.dx.style.StyleWorker; +import com.adobe.dx.inlinestyle.StyleWorker; import org.junit.jupiter.api.Test; @@ -31,9 +31,11 @@ StyleWorker getWorker() { @Test void getColor() { context.build().resource(CONTENT_ROOT, - "foregroundColorDesktop", "#FFFFFF"); + "foregroundColorDesktop", "white"); + setStyleGuide(); + setBreakpoints(); + context.currentResource(CONTENT_ROOT); assertEquals("color: #FFFFFF", getDeclaration("desktop")); assertNull(getDeclaration("mobile")); } - } diff --git a/bundles/core/src/test/java/com/adobe/dx/style/internal/InlineStyleServiceImplTest.java b/bundles/core/src/test/java/com/adobe/dx/inlinestyle/internal/InlineStyleServiceImplTest.java similarity index 98% rename from bundles/core/src/test/java/com/adobe/dx/style/internal/InlineStyleServiceImplTest.java rename to bundles/core/src/test/java/com/adobe/dx/inlinestyle/internal/InlineStyleServiceImplTest.java index 74867b3f..ab977388 100644 --- a/bundles/core/src/test/java/com/adobe/dx/style/internal/InlineStyleServiceImplTest.java +++ b/bundles/core/src/test/java/com/adobe/dx/inlinestyle/internal/InlineStyleServiceImplTest.java @@ -13,7 +13,7 @@ ~ 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 org.junit.jupiter.api.Assertions.*; @@ -22,7 +22,7 @@ import com.adobe.dx.responsive.ResponsiveConfiguration; import com.adobe.dx.responsive.internal.ResponsivePropertiesImpl; import com.adobe.dx.responsive.internal.ResponsivePropertiesImplTest; -import com.adobe.dx.style.StyleWorker; +import com.adobe.dx.inlinestyle.StyleWorker; import com.adobe.dx.testing.AbstractTest; import com.adobe.dx.utils.RequestUtil; diff --git a/bundles/core/src/test/java/com/adobe/dx/style/internal/ShadowTest.java b/bundles/core/src/test/java/com/adobe/dx/inlinestyle/internal/ShadowTest.java similarity index 94% rename from bundles/core/src/test/java/com/adobe/dx/style/internal/ShadowTest.java rename to bundles/core/src/test/java/com/adobe/dx/inlinestyle/internal/ShadowTest.java index cfb51690..b75b1ea8 100644 --- a/bundles/core/src/test/java/com/adobe/dx/style/internal/ShadowTest.java +++ b/bundles/core/src/test/java/com/adobe/dx/inlinestyle/internal/ShadowTest.java @@ -13,11 +13,11 @@ ~ 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 org.junit.jupiter.api.Assertions.assertEquals; -import com.adobe.dx.style.StyleWorker; +import com.adobe.dx.inlinestyle.StyleWorker; import org.junit.jupiter.api.Test; diff --git a/bundles/core/src/test/java/com/adobe/dx/style/internal/AbstractStyleWorkerTest.java b/bundles/core/src/test/java/com/adobe/dx/style/internal/AbstractStyleWorkerTest.java deleted file mode 100644 index c39c14d1..00000000 --- a/bundles/core/src/test/java/com/adobe/dx/style/internal/AbstractStyleWorkerTest.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * - * ADOBE CONFIDENTIAL - * __________________ - * - * Copyright 2019 Adobe - * All Rights Reserved. - * - * NOTICE: All information contained herein is, and remains - * the property of Adobe and its suppliers, if any. The intellectual - * and technical concepts contained herein are proprietary to Adobe - * and its suppliers and are protected by all applicable intellectual - * property laws, including trade secret and copyright laws. - * Dissemination of this information or reproduction of this material - * is strictly forbidden unless prior written permission is obtained - * from Adobe. - ******************************************************************************/ - -package com.adobe.dx.style.internal; - -import com.adobe.dx.bindings.internal.DxBindingsValueProvider; -import com.adobe.dx.responsive.Breakpoint; -import com.adobe.dx.responsive.ResponsiveConfiguration; -import com.adobe.dx.responsive.internal.ResponsivePropertiesImpl; -import com.adobe.dx.responsive.internal.ResponsivePropertiesImplTest; -import com.adobe.dx.style.StyleWorker; -import com.adobe.dx.testing.AbstractTest; - -import org.apache.commons.lang.StringUtils; -import org.apache.sling.api.scripting.SlingBindings; - -public abstract class AbstractStyleWorkerTest extends AbstractTest { - - abstract StyleWorker getWorker(); - - String getDeclaration() { - return getDeclaration(null); - } - - String getDeclaration(String breakpointKey) { - SlingBindings bindings = (SlingBindings)context.request().getAttribute(SlingBindings.class.getName()); - bindings.put(DxBindingsValueProvider.POLICY_KEY, getVM(CONTENT_ROOT)); - Breakpoint breakpoint = null; - if (StringUtils.isNotBlank(breakpointKey)) { - ResponsiveConfiguration configuration = ResponsivePropertiesImplTest.initResponsiveConfiguration(context); - ResponsivePropertiesImpl responsiveProperties = new ResponsivePropertiesImpl(configuration, getVM(CONTENT_ROOT)); - bindings.put(DxBindingsValueProvider.RESP_PROPS_KEY, responsiveProperties); - bindings.put(DxBindingsValueProvider.BP_KEY, configuration.breakpoints()); - for (Breakpoint candidate : configuration.breakpoints()) { - if (candidate.key().equals(breakpointKey)) { - breakpoint = candidate; - break; - } - } - } - return getWorker().getDeclaration(breakpoint, context.request()); - } -} diff --git a/bundles/core/src/test/java/com/adobe/dx/style/internal/BackgroundTest.java b/bundles/core/src/test/java/com/adobe/dx/style/internal/BackgroundTest.java deleted file mode 100644 index 12c56787..00000000 --- a/bundles/core/src/test/java/com/adobe/dx/style/internal/BackgroundTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ~ 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.style.internal; - -import static org.junit.jupiter.api.Assertions.*; - -import com.adobe.dx.style.StyleWorker; - -import org.junit.jupiter.api.Test; - -class BackgroundTest extends AbstractStyleWorkerTest{ - - @Override - StyleWorker getWorker() { - return new Background(); - } - - @Test - void getBackgroundImage() { - context.build().resource(CONTENT_ROOT, - "fileReferenceMobile", "/content/dam/mobile.jpg", - "fileReferenceTablet", "/content/dam/tablet.jpg", - "fileReferenceDesktop", "/content/dam/desktop.jpg", - "focusXMobile", 30, - "focusYMobile", 30); - assertEquals("background-image:url(\\2f content\\2f dam\\2f mobile.jpg); background-size: cover; background-position: 30% 30%; ", getDeclaration("mobile")); - assertEquals("background-image:url(\\2f content\\2f dam\\2f desktop.jpg); background-size: cover; ", getDeclaration("desktop")); - } - - @Test - void getBackgroundColor() { - context.build().resource(CONTENT_ROOT, - "backgroundColorDesktop", " #FFFFFF"); - assertEquals("background-color : #FFFFFF", getDeclaration("desktop")); - } - - @Test - void getBackgroundGradient() { - context.build().resource(CONTENT_ROOT, - "backgroundColorDesktop", " #FFFFFF"); - assertEquals("background-color : #FFFFFF", getDeclaration("desktop")); - } -} \ No newline at end of file