forked from adobe/adobe-dx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adobeGH-24 introduces StyleService with shadow & border
- StyleService checks for current component's type styleWorker property, and registered workers, and computes one style for all, - Shadow worker + UT - Border worker + UT
- Loading branch information
Showing
23 changed files
with
840 additions
and
46 deletions.
There are no files selected for viewing
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
apps/structure/core/src/test/java/com/adobe/dx/structure/AbstractStructureModelTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/******************************************************************************* | ||
* | ||
* 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.structure; | ||
|
||
import com.adobe.dx.bindings.internal.DxBindingsValueProvider; | ||
import com.adobe.dx.responsive.Breakpoint; | ||
import com.adobe.dx.responsive.ResponsiveConfiguration; | ||
import com.adobe.dx.testing.AbstractRequestModelTest; | ||
|
||
import java.util.Map; | ||
|
||
import javax.script.Bindings; | ||
import javax.script.SimpleBindings; | ||
|
||
import org.apache.sling.api.scripting.SlingBindings; | ||
import org.apache.sling.testing.mock.caconfig.MockContextAwareConfig; | ||
import org.junit.jupiter.api.BeforeEach; | ||
|
||
import io.wcm.testing.mock.aem.junit5.AemContext; | ||
|
||
public class AbstractStructureModelTest extends AbstractRequestModelTest { | ||
|
||
protected SlingBindings getBindings(AemContext context) { | ||
return (SlingBindings) context.request().getAttribute(SlingBindings.class.getName()); | ||
} | ||
|
||
protected static final String MODEL_PATH = CONTENT_ROOT + "/model"; | ||
|
||
@BeforeEach | ||
public void beforeEach() { | ||
context.build().resource(CONF_ROOT + "/sling:configs/" + ResponsiveConfiguration.class.getName() + "/breakpoints") | ||
.siblingsMode() | ||
.resource("1", "propertySuffix", "Mobile", "key", "mobile") | ||
.resource("2", "propertySuffix", "Tablet", "key", "tablet") | ||
.resource("3", "propertySuffix", "Desktop", "key", "desktop"); | ||
MockContextAwareConfig.registerAnnotationClasses(context, ResponsiveConfiguration.class); | ||
MockContextAwareConfig.registerAnnotationClasses(context, Breakpoint.class); | ||
context.create().resource(CONTENT_ROOT, "sling:configRef", CONF_ROOT); | ||
} | ||
|
||
@Override | ||
protected <T> T getModel(Class<T> type) { | ||
DxBindingsValueProvider provider = new DxBindingsValueProvider(); | ||
Bindings bindings = new SimpleBindings(); | ||
for (Map.Entry<String, Object> entry : getBindings(context).entrySet()) { | ||
bindings.put(entry.getKey(), entry.getValue()); | ||
} | ||
bindings.put(SlingBindings.RESOURCE, context.currentResource()); | ||
provider.addBindings(bindings); | ||
SlingBindings slingBindings = getBindings(context); | ||
slingBindings.put(DxBindingsValueProvider.POLICY_KEY, bindings.get(DxBindingsValueProvider.POLICY_KEY)); | ||
slingBindings.put(DxBindingsValueProvider.BP_KEY, bindings.get(DxBindingsValueProvider.BP_KEY)); | ||
slingBindings.put(DxBindingsValueProvider.RESP_PROPS_KEY, bindings.get(DxBindingsValueProvider.RESP_PROPS_KEY)); | ||
return super.getModel(type); | ||
} | ||
|
||
@Override | ||
protected <T> T getModel(Class<T> type, String path) { | ||
context.currentResource(path); | ||
return getModel(type); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
bundles/core/src/main/java/com/adobe/dx/style/Constants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
~ 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; | ||
|
||
public class Constants { | ||
private Constants() { | ||
} | ||
public static final String DECLARATION_DELIMITER = ";"; | ||
public static final String DECLARATION = ": "; | ||
public static final String SPACE = " "; | ||
public static final String PX = "px"; | ||
public static final String PX_SPACE = PX + SPACE; | ||
public static final String DEL_SPACE = DECLARATION_DELIMITER + SPACE; | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
bundles/core/src/main/java/com/adobe/dx/style/StyleService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
~ 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; | ||
|
||
import org.apache.sling.api.SlingHttpServletRequest; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public interface StyleService { | ||
|
||
/** | ||
* Computes a list of CSS declarations relatives of the given request. If an id is provided, | ||
* encapsulate those declarations in that id rule (for nested usage). | ||
* | ||
* @param id optional ID to encapsulate declarations with | ||
* @param request current request | ||
* @return declaration set, or local rule | ||
*/ | ||
String getLocalStyle(@Nullable String id, SlingHttpServletRequest request); | ||
} |
41 changes: 41 additions & 0 deletions
41
bundles/core/src/main/java/com/adobe/dx/style/StyleWorker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.style; | ||
|
||
import org.apache.sling.api.resource.Resource; | ||
import org.apache.sling.api.resource.ValueMap; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* Single CSS rule generator, for very specific usage in a style tag, modified by the component itself | ||
*/ | ||
public interface StyleWorker { | ||
|
||
/** | ||
* @return key with which the worker can be identified | ||
*/ | ||
String getKey(); | ||
|
||
/** | ||
* Generates a declaration specific to that generator, for an upper rule | ||
* | ||
* @param resource current component resource, | ||
* @param dxPolicy policy, could be obtained from above resource, but in the signature for practical reason, | ||
* @return single or several declarations split by ';', or null if not necessary or able to generate some | ||
*/ | ||
@Nullable String getDeclaration(Resource resource, ValueMap dxPolicy); | ||
|
||
} |
Oops, something went wrong.