Skip to content

Commit

Permalink
adobeGH-24 background draft
Browse files Browse the repository at this point in the history
  • Loading branch information
npeltier committed Sep 14, 2020
1 parent fd3dbdf commit af5f5e0
Show file tree
Hide file tree
Showing 18 changed files with 344 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
jcr:primaryType="cq:Component"
componentGroup="DX"
jcr:title="Flex"
styleWorkers="[shadow,border]"/>
styleWorkers="[background,color,shadow,border]"/>
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,6 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/-->
<template data-sly-template.background="${ @ id}">
<sly data-sly-repeat.bp="${breakpoints}">
<sly data-sly-test="${resprops.backgroundColor[bp.key] || resprops.gradient[bp.key]}">
<sly data-sly-test="${bp.mediaQuery}">${bp.mediaQuery}{</sly>
${'#{0}' @ format=id, context='styleString'} {
<sly data-sly-test="${resprops.backgroundColor[bp.key]}">
${'background-color: {0}; ' @ format=resprops.backgroundColor[bp.key], context='styleString'}
</sly>
<sly data-sly-test="${resprops.gradient[bp.key]}">
${'background-image: {0};' @ format=[resprops.gradient[bp.key]], context='styleString'}
</sly>}<sly data-sly-test="${bp.mediaQuery}">}</sly>
</sly>
</sly>
</template>
<template data-sly-template.foreground="${ @ id}">
<sly data-sly-repeat.bp="${breakpoints}"
data-sly-test="${resprops.foregroundColor[bp.key]}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,6 @@
<sly data-sly-test="${bp.mediaQuery}">}</sly>
</sly>
</sly>
<sly data-sly-use.colorTpl="color.html" data-sly-call="${colorTpl.background @ id = model.id}"></sly>
<!--/* Background Image (Must be set after Background Colors to override background-image) */-->
<sly data-sly-test="${imageModel.src}" data-sly-use.backgroundTpl="background.html"
data-sly-call="${backgroundTpl.styles @ colorModel = colorModel, imageModel = imageModel, idGeneratorModel = idGeneratorModel}"></sly>
<sly data-sly-test="${colorModel.foreground}"
data-sly-use.colorTpl="${rtPro.componentPath}/color.html"
data-sly-call="${colorTpl.foreground @ colorModel = colorModel, imageModel = imageModel, idGeneratorModel = idGeneratorModel}"></sly>
<!--/* Border */-->
<sly data-sly-test="${model.border || model.borderRadius}"
data-sly-use.borderTpl="${rtPro.componentPath}/border.html"
data-sly-call="${borderTpl.border @ idGeneratorModel = idGeneratorModel, position = model}">
</sly>
<!--/* Shadow & Border */-->
<sly data-sly-test="${model.style}">${model.style @ context='styleString'}</sly>
</style>
<div id="${model.id}" class="dx-flex">
Expand Down
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.StyleService;
import com.adobe.dx.style.InlineStyleService;
import com.day.cq.wcm.api.policies.ContentPolicy;
import com.day.cq.wcm.api.policies.ContentPolicyManager;

Expand Down Expand Up @@ -51,7 +51,7 @@ public class FlexModel {
IDTagger idTagger;

@OSGiService
StyleService styleService;
InlineStyleService styleService;

@ScriptVariable
Breakpoint[] breakpoints;
Expand All @@ -72,7 +72,7 @@ void init() {
}
}
if (styleService != null) {
style = styleService.getLocalStyle(getId(), request);
style = styleService.getInlineStyle(getId(), request);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import static com.day.cq.wcm.scripting.WCMBindingsConstants.NAME_CURRENT_CONTENT_POLICY;

import com.adobe.dx.responsive.ResponsiveConfiguration;
import com.adobe.dx.responsive.internal.ResponsiveProperties;
import com.adobe.dx.responsive.internal.ResponsivePropertiesImpl;
import com.day.cq.wcm.api.policies.ContentPolicy;

import javax.script.Bindings;
Expand All @@ -33,7 +33,6 @@
import org.osgi.framework.Constants;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Reference;

@Component(service = BindingsValuesProvider.class,
property = {
Expand Down Expand Up @@ -69,7 +68,7 @@ public void addBindings(@NotNull Bindings bindings) {
.adaptTo(ConfigurationBuilder.class)
.as(ResponsiveConfiguration.class);
bindings.put(BP_KEY, configuration.breakpoints());
bindings.put(RESP_PROPS_KEY, new ResponsiveProperties(configuration, dxPolicy));
bindings.put(RESP_PROPS_KEY, new ResponsivePropertiesImpl(configuration, dxPolicy));
}
}
}
Expand Down
34 changes: 34 additions & 0 deletions bundles/core/src/main/java/com/adobe/dx/img/ImageModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*******************************************************************************
*
* 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<String, Object> resprops;


}
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
* simply check for get operation the required property with and ordered list of
* suffix. Allowing several properties
*/
public class ResponsiveProperties implements Map<String, Object> {
public class ResponsivePropertiesImpl implements Map<String, LinkedHashMap<String, Object>> {

private final Breakpoint[] breakpoints;
private ValueMap properties;

public ResponsiveProperties(final ResponsiveConfiguration configuration, ValueMap properties) {
public ResponsivePropertiesImpl(final ResponsiveConfiguration configuration, ValueMap properties) {
breakpoints = configuration.breakpoints();
this.properties = properties;
}
Expand All @@ -48,10 +48,10 @@ private String computeResponsiveResourceName(String name, Breakpoint breakpoint)
}

@Override
public Object get(Object key) {
public LinkedHashMap<String, Object> get(Object key) {
if (key != null) {
boolean empty = true;
LinkedHashMap<String,String> breakpointValues = new LinkedHashMap<>();
LinkedHashMap<String, Object> breakpointValues = new LinkedHashMap<>();
for (Breakpoint breakpoint : breakpoints) {
String respKey = computeResponsiveResourceName(key.toString(), breakpoint);
String value = properties.get(respKey, String.class);
Expand Down Expand Up @@ -87,17 +87,17 @@ public boolean containsValue(Object value) {

@Nullable
@Override
public Object put(String key, Object value) {
public LinkedHashMap<String, Object> put(String key, LinkedHashMap<String, Object> value) {
throw new UnsupportedOperationException();
}

@Override
public Object remove(Object key) {
public LinkedHashMap<String, Object> remove(Object key) {
throw new UnsupportedOperationException();
}

@Override
public void putAll(@NotNull Map<? extends String, ?> m) {
public void putAll(@NotNull Map<? extends String, ? extends LinkedHashMap<String, Object>> m) {
throw new UnsupportedOperationException();
}

Expand All @@ -114,13 +114,13 @@ public Set<String> keySet() {

@NotNull
@Override
public Collection<Object> values() {
public Collection<LinkedHashMap<String, Object>> values() {
throw new UnsupportedOperationException();
}

@NotNull
@Override
public Set<Entry<String, Object>> entrySet() {
public Set<Entry<String, LinkedHashMap<String, Object>>> entrySet() {
throw new UnsupportedOperationException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.apache.sling.api.SlingHttpServletRequest;
import org.jetbrains.annotations.Nullable;

public interface StyleService {
public interface InlineStyleService {

/**
* Computes a list of CSS declarations relatives of the given request. If an id is provided,
Expand All @@ -28,5 +28,5 @@ public interface StyleService {
* @param request current request
* @return declaration set, or local rule
*/
String getLocalStyle(@Nullable String id, SlingHttpServletRequest request);
String getInlineStyle(@Nullable String id, SlingHttpServletRequest request);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ 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<String> 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;
}
}
56 changes: 56 additions & 0 deletions bundles/core/src/main/java/com/adobe/dx/style/internal/Color.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ 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 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 Color implements StyleWorker {
private final static String KEY = "color";

private final static String PN_COLOR = "foregroundColor";
private final static String FORMAT = "color: %s";

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

@Override
public @Nullable String getDeclaration(@Nullable Breakpoint breakpoint, SlingHttpServletRequest request) {
String color = getFromRespProps(request, breakpoint, PN_COLOR, String.class);
if (StringUtils.isNotBlank(color)) {
return String.format(FORMAT, color);
}
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 @@ -22,7 +22,7 @@

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

import java.util.ArrayList;
Expand All @@ -45,7 +45,7 @@
import org.slf4j.LoggerFactory;

@Component(configurationPolicy = ConfigurationPolicy.REQUIRE)
public class StyleServiceImpl implements StyleService {
public class InlineStyleServiceImpl implements InlineStyleService {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private static final String FORMAT_ID = "#%s {%s}";
private static final String FORMAT_BP = "\n%s {\n%s\n}";
Expand Down Expand Up @@ -84,7 +84,7 @@ String getStylePerBreakpoint(String id, Breakpoint breakpoint, String[] keys, Sl
}

@Override
public String getLocalStyle(String id, SlingHttpServletRequest request) {
public String getInlineStyle(String id, SlingHttpServletRequest request) {
Resource resource = request.getResource();
String[] keys = getWorkerKeys(resource);
if (keys.length > 0) {
Expand Down
Loading

0 comments on commit af5f5e0

Please sign in to comment.