testing
0.0.10
+
+ com.adobe.dx
+ core
+ 0.0.13-SNAPSHOT
+
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 d6c199a3..b929142e 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
@@ -16,21 +16,38 @@
package com.adobe.dx.structure.flex;
+import com.adobe.dx.domtagging.IDTagger;
+
+import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.SlingHttpServletRequest;
-import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.Model;
+import org.apache.sling.models.annotations.injectorspecific.OSGiService;
import org.apache.sling.models.annotations.injectorspecific.SlingObject;
import org.apache.sling.models.annotations.DefaultInjectionStrategy;
-@Model(adaptables = { SlingHttpServletRequest.class,
- Resource.class }, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
+@Model(adaptables = SlingHttpServletRequest.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class FlexModel {
@SlingObject
- protected Resource resource;
+ protected SlingHttpServletRequest request;
+
+ @OSGiService
+ protected IDTagger idTagger;
+
+ String id;
public String getHello() {
return "Hello";
}
+ public boolean isStyleNeeded() {
+ return true;
+ }
+
+ public String getId() {
+ if (StringUtils.isBlank(id) && idTagger != null) {
+ id = idTagger.computeComponentId(request, null);
+ }
+ return id;
+ }
}
diff --git a/bundles/core/pom.xml b/bundles/core/pom.xml
index 9563e291..bed7fc74 100644
--- a/bundles/core/pom.xml
+++ b/bundles/core/pom.xml
@@ -116,6 +116,12 @@ Bundle-DocURL:
org.jetbrains
annotations
+
+ org.apache.sling
+ org.apache.sling.api
+ 2.18.4
+ test
+
com.adobe.dx
testing
diff --git a/bundles/core/src/main/java/com/adobe/dx/bindings/internal/DxBindingsValueProvider.java b/bundles/core/src/main/java/com/adobe/dx/bindings/internal/DxBindingsValueProvider.java
index 6ace9341..b34ab9e0 100644
--- a/bundles/core/src/main/java/com/adobe/dx/bindings/internal/DxBindingsValueProvider.java
+++ b/bundles/core/src/main/java/com/adobe/dx/bindings/internal/DxBindingsValueProvider.java
@@ -50,7 +50,9 @@ public class DxBindingsValueProvider implements BindingsValuesProvider {
private static final String POLICY_KEY = "dxPolicy";
- private static final String RESP_PROPS_KEY = "respProperties";
+ private static final String RESP_PROPS_KEY = "resprops";
+
+ private static final String BP_KEY = "breakpoints";
@Override
public void addBindings(@NotNull Bindings bindings) {
@@ -66,6 +68,7 @@ public void addBindings(@NotNull Bindings bindings) {
ResponsiveConfiguration configuration = resource
.adaptTo(ConfigurationBuilder.class)
.as(ResponsiveConfiguration.class);
+ bindings.put(BP_KEY, configuration.breakpoints());
bindings.put(RESP_PROPS_KEY, new ResponsiveProperties(configuration, dxPolicy));
}
}
diff --git a/bundles/core/src/main/java/com/adobe/dx/domtagging/internal/IDTaggerImpl.java b/bundles/core/src/main/java/com/adobe/dx/domtagging/internal/IDTaggerImpl.java
index 068b3c34..44759501 100644
--- a/bundles/core/src/main/java/com/adobe/dx/domtagging/internal/IDTaggerImpl.java
+++ b/bundles/core/src/main/java/com/adobe/dx/domtagging/internal/IDTaggerImpl.java
@@ -426,7 +426,7 @@ public Resource next() {
+ "for resource types that should be tagged with an id"
)
@SuppressWarnings("squid:S00100")
- String[] acceptedTypes() default { "dx/components/structure/.*" };
+ String[] acceptedTypes() default { "dx/structure/components/.*" };
@AttributeDefinition(
name = "Reference type",
diff --git a/bundles/core/src/main/java/com/adobe/dx/responsive/Breakpoint.java b/bundles/core/src/main/java/com/adobe/dx/responsive/Breakpoint.java
new file mode 100644
index 00000000..d365f2f6
--- /dev/null
+++ b/bundles/core/src/main/java/com/adobe/dx/responsive/Breakpoint.java
@@ -0,0 +1,40 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ 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.responsive;
+
+import org.apache.sling.caconfig.annotation.Configuration;
+import org.apache.sling.caconfig.annotation.Property;
+
+@Configuration(collection = true)
+public @interface Breakpoint {
+ @Property(label = "name")
+ String getLabel();
+
+ @Property(label = "property suffix", description = "suffix to append to a property to get the responsive version of it")
+ String propertySuffix();
+
+ @Property(label = "map key", description = "key from where a value will be available")
+ String key();
+
+ @Property(label = "media Query", description = "media query that defines this breakpoint")
+ String mediaQuery();
+
+ @Property(label = "start", description = "screen width from which this breakpoint is set")
+ int start();
+
+ @Property(label = "end", description = "screen width to which this breakpoint is set")
+ int end();
+}
diff --git a/bundles/core/src/main/java/com/adobe/dx/responsive/ResponsiveConfiguration.java b/bundles/core/src/main/java/com/adobe/dx/responsive/ResponsiveConfiguration.java
index 8e5d9763..4887aa28 100644
--- a/bundles/core/src/main/java/com/adobe/dx/responsive/ResponsiveConfiguration.java
+++ b/bundles/core/src/main/java/com/adobe/dx/responsive/ResponsiveConfiguration.java
@@ -1,9 +1,23 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ 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.responsive;
import org.apache.sling.caconfig.annotation.Configuration;
@Configuration(label="Responsive Configuration", description = "sets the responsive behaviour")
public @interface ResponsiveConfiguration {
-
- String[] breakpoints() default {"Mobile", "Tablet", "Desktop"};
+ Breakpoint[] breakpoints();
}
diff --git a/bundles/core/src/main/java/com/adobe/dx/responsive/internal/ResponsiveProperties.java b/bundles/core/src/main/java/com/adobe/dx/responsive/internal/ResponsiveProperties.java
index 699b273d..d15da27a 100644
--- a/bundles/core/src/main/java/com/adobe/dx/responsive/internal/ResponsiveProperties.java
+++ b/bundles/core/src/main/java/com/adobe/dx/responsive/internal/ResponsiveProperties.java
@@ -16,6 +16,7 @@
package com.adobe.dx.responsive.internal;
+import com.adobe.dx.responsive.Breakpoint;
import com.adobe.dx.responsive.ResponsiveConfiguration;
import java.util.Collection;
@@ -34,11 +35,11 @@
*/
public class ResponsiveProperties implements Map {
- private final String[] breakpoints;
+ private final Breakpoint[] breakpoints;
private ValueMap properties;
public ResponsiveProperties(final ResponsiveConfiguration configuration, ValueMap properties) {
- this.breakpoints = configuration.breakpoints();
+ breakpoints = configuration.breakpoints();
this.properties = properties;
}
@@ -47,11 +48,11 @@ public Object get(Object key) {
if (key != null) {
boolean empty = true;
LinkedHashMap breakpointValues = new LinkedHashMap<>();
- for (String breakpoint : breakpoints) {
- String respKey = key + breakpoint;
+ for (Breakpoint breakpoint : breakpoints) {
+ String respKey = key + breakpoint.propertySuffix();
String value = properties.get(respKey, String.class);
empty &= StringUtils.isBlank(value);
- breakpointValues.put(breakpoint.toLowerCase(), value);
+ breakpointValues.put(breakpoint.key(), value);
}
if (!empty) {
return breakpointValues;
diff --git a/bundles/core/src/main/java/com/adobe/dx/responsive/package-info.java b/bundles/core/src/main/java/com/adobe/dx/responsive/package-info.java
index 633aa3d3..0a1b62dc 100644
--- a/bundles/core/src/main/java/com/adobe/dx/responsive/package-info.java
+++ b/bundles/core/src/main/java/com/adobe/dx/responsive/package-info.java
@@ -13,7 +13,7 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- @Version("0.1.0")
+ @Version("0.2.0")
package com.adobe.dx.responsive;
import org.osgi.annotation.versioning.Version;
diff --git a/bundles/core/src/test/java/com/adobe/dx/responsive/internal/ResponsivePropertiesTest.java b/bundles/core/src/test/java/com/adobe/dx/responsive/internal/ResponsivePropertiesTest.java
index e62b873b..6f5f20d6 100644
--- a/bundles/core/src/test/java/com/adobe/dx/responsive/internal/ResponsivePropertiesTest.java
+++ b/bundles/core/src/test/java/com/adobe/dx/responsive/internal/ResponsivePropertiesTest.java
@@ -17,6 +17,7 @@
import static org.junit.jupiter.api.Assertions.*;
+import com.adobe.dx.responsive.Breakpoint;
import com.adobe.dx.responsive.ResponsiveConfiguration;
import com.adobe.dx.testing.AbstractTest;
@@ -37,17 +38,23 @@
public class ResponsivePropertiesTest extends AbstractTest {
- public final static String[] BREAKPOINTS = new String[] {"Mobile", "Tablet", "Desktop"};
ResponsiveConfiguration configuration;
public static ResponsiveConfiguration initResponsiveConfiguration(AemContext context) {
- context.create().resource(CONTENT_ROOT, "sling:configRef", CONF_ROOT);
+ 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.writeConfiguration(context, CONTENT_ROOT, ResponsiveConfiguration.class,"breakpoints", BREAKPOINTS);
- return context.resourceResolver()
+ MockContextAwareConfig.registerAnnotationClasses(context, Breakpoint.class);
+ context.create().resource(CONTENT_ROOT, "sling:configRef", CONF_ROOT);
+ ResponsiveConfiguration configuration = context.resourceResolver()
.getResource(CONTENT_ROOT)
.adaptTo(ConfigurationBuilder.class)
.as(ResponsiveConfiguration.class);
+ assertEquals( 3, configuration.breakpoints().length, "we should have 3 breakpoints configured");
+ return configuration;
}
@BeforeEach