You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by hn...@apache.org on 2021/11/17 14:40:18 UTC
[myfaces-tobago] branch tobago-5.x updated: feature: FontAwesome5 support
This is an automated email from the ASF dual-hosted git repository.
hnoeth pushed a commit to branch tobago-5.x
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git
The following commit(s) were added to refs/heads/tobago-5.x by this push:
new 959608b feature: FontAwesome5 support
959608b is described below
commit 959608b03c3fe6a74df58c6b450850bb6edee342
Author: Henning Noeth <hn...@apache.org>
AuthorDate: Wed Nov 17 14:02:02 2021 +0100
feature: FontAwesome5 support
Issue: Tobago-2101
---
.../apache/myfaces/tobago/renderkit/css/Icons.java | 10 ++-
.../renderkit/renderer/ButtonRendererUnitTest.java | 59 ++++++++++++++++
.../src/test/resources/renderer/button/iconBi.html | 18 +++++
.../test/resources/renderer/button/iconBiJpg.html | 18 +++++
.../src/test/resources/renderer/button/iconFa.html | 18 +++++
.../test/resources/renderer/button/iconFar.html | 18 +++++
.../src/test/resources/renderer/button/iconFx.html | 18 +++++
.../tobago/renderkit/css/IconsUnitTest.java | 80 ++++++++++++++++++++++
8 files changed, 236 insertions(+), 3 deletions(-)
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/css/Icons.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/css/Icons.java
index 27aa9b0..e200793 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/css/Icons.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/css/Icons.java
@@ -53,9 +53,10 @@ public enum Icons implements CssItem {
private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
- private static final Pattern PATTERN = Pattern.compile("^((fa|bi)(-[a-z]+)+)$");
- private static final Pattern PATTERN_BI = Pattern.compile("^(bi(-[a-z]+)+)$");
- private static final Pattern PATTERN_FA = Pattern.compile("^(fa(-[a-z]+)+)$");
+ private static final Pattern PATTERN = Pattern.compile("^(bi|fa|(fas|far|fal|fad)\\sfa)-[\\w\\d]+$");
+ private static final Pattern PATTERN_BI = Pattern.compile("^bi-[\\w\\d]+$");
+ private static final Pattern PATTERN_FA = Pattern.compile("^fa-[\\w\\d]+$");
+ private static final Pattern PATTERN_FA5 = Pattern.compile("^(fas|far|fal|fad)\\sfa-[\\w\\d]+$");
private final String clazz;
@@ -87,6 +88,9 @@ public enum Icons implements CssItem {
if (PATTERN_FA.matcher(name).matches()) {
return "fa " + name;
}
+ if (PATTERN_FA5.matcher(name).matches()) {
+ return name;
+ }
LOG.warn("Unknown icon format for name: '" + name + "'");
return null;
}
diff --git a/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/renderkit/renderer/ButtonRendererUnitTest.java b/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/renderkit/renderer/ButtonRendererUnitTest.java
index 2204b99..0a21820 100644
--- a/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/renderkit/renderer/ButtonRendererUnitTest.java
+++ b/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/renderkit/renderer/ButtonRendererUnitTest.java
@@ -41,4 +41,63 @@ public class ButtonRendererUnitTest extends RendererTestBase {
Assertions.assertEquals(loadHtml("renderer/button/button.html"), formattedResult());
}
+ @Test
+ public void iconBi() throws IOException {
+ final UIButton b = (UIButton) ComponentUtils.createComponent(
+ facesContext, Tags.button.componentType(), RendererTypes.Button, "id");
+ b.setLabel("button");
+ b.setImage("bi-code");
+
+ b.encodeAll(facesContext);
+
+ Assertions.assertEquals(loadHtml("renderer/button/iconBi.html"), formattedResult());
+ }
+
+ @Test
+ public void iconBiJpg() throws IOException {
+ final UIButton b = (UIButton) ComponentUtils.createComponent(
+ facesContext, Tags.button.componentType(), RendererTypes.Button, "id");
+ b.setLabel("button");
+ b.setImage("bi-code.jpg");
+
+ b.encodeAll(facesContext);
+
+ Assertions.assertEquals(loadHtml("renderer/button/iconBiJpg.html"), formattedResult());
+ }
+
+ @Test
+ public void iconFa() throws IOException {
+ final UIButton b = (UIButton) ComponentUtils.createComponent(
+ facesContext, Tags.button.componentType(), RendererTypes.Button, "id");
+ b.setLabel("button");
+ b.setImage("fa-code");
+
+ b.encodeAll(facesContext);
+
+ Assertions.assertEquals(loadHtml("renderer/button/iconFa.html"), formattedResult());
+ }
+
+ @Test
+ public void iconFx() throws IOException {
+ final UIButton b = (UIButton) ComponentUtils.createComponent(
+ facesContext, Tags.button.componentType(), RendererTypes.Button, "id");
+ b.setLabel("button");
+ b.setImage("fx-code");
+
+ b.encodeAll(facesContext);
+
+ Assertions.assertEquals(loadHtml("renderer/button/iconFx.html"), formattedResult());
+ }
+
+ @Test
+ public void iconFar() throws IOException {
+ final UIButton b = (UIButton) ComponentUtils.createComponent(
+ facesContext, Tags.button.componentType(), RendererTypes.Button, "id");
+ b.setLabel("button");
+ b.setImage("far fa-code");
+
+ b.encodeAll(facesContext);
+
+ Assertions.assertEquals(loadHtml("renderer/button/iconFar.html"), formattedResult());
+ }
}
diff --git a/tobago-core/src/test/resources/renderer/button/iconBi.html b/tobago-core/src/test/resources/renderer/button/iconBi.html
new file mode 100644
index 0000000..e4991e1
--- /dev/null
+++ b/tobago-core/src/test/resources/renderer/button/iconBi.html
@@ -0,0 +1,18 @@
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+-->
+
+<button type='button' id='id' name='id' class='tobago-button btn btn-secondary tobago-auto-spacing'><tobago-behavior event='click' client-id='id'></tobago-behavior><i class='bi-code'></i><span>button</span></button>
\ No newline at end of file
diff --git a/tobago-core/src/test/resources/renderer/button/iconBiJpg.html b/tobago-core/src/test/resources/renderer/button/iconBiJpg.html
new file mode 100644
index 0000000..e9d06c3
--- /dev/null
+++ b/tobago-core/src/test/resources/renderer/button/iconBiJpg.html
@@ -0,0 +1,18 @@
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+-->
+
+<button type='button' id='id' name='id' class='tobago-button btn btn-secondary tobago-auto-spacing'><tobago-behavior event='click' client-id='id'></tobago-behavior><img src='bi-code.jpg' alt=''><span>button</span></button>
\ No newline at end of file
diff --git a/tobago-core/src/test/resources/renderer/button/iconFa.html b/tobago-core/src/test/resources/renderer/button/iconFa.html
new file mode 100644
index 0000000..46a13d6
--- /dev/null
+++ b/tobago-core/src/test/resources/renderer/button/iconFa.html
@@ -0,0 +1,18 @@
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+-->
+
+<button type='button' id='id' name='id' class='tobago-button btn btn-secondary tobago-auto-spacing'><tobago-behavior event='click' client-id='id'></tobago-behavior><i class='fa fa-code'></i><span>button</span></button>
\ No newline at end of file
diff --git a/tobago-core/src/test/resources/renderer/button/iconFar.html b/tobago-core/src/test/resources/renderer/button/iconFar.html
new file mode 100644
index 0000000..5a8370a
--- /dev/null
+++ b/tobago-core/src/test/resources/renderer/button/iconFar.html
@@ -0,0 +1,18 @@
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+-->
+
+<button type='button' id='id' name='id' class='tobago-button btn btn-secondary tobago-auto-spacing'><tobago-behavior event='click' client-id='id'></tobago-behavior><i class='far fa-code'></i><span>button</span></button>
\ No newline at end of file
diff --git a/tobago-core/src/test/resources/renderer/button/iconFx.html b/tobago-core/src/test/resources/renderer/button/iconFx.html
new file mode 100644
index 0000000..e18bf79
--- /dev/null
+++ b/tobago-core/src/test/resources/renderer/button/iconFx.html
@@ -0,0 +1,18 @@
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+-->
+
+<button type='button' id='id' name='id' class='tobago-button btn btn-secondary tobago-auto-spacing'><tobago-behavior event='click' client-id='id'></tobago-behavior><img src='fx-code' alt=''><span>button</span></button>
\ No newline at end of file
diff --git a/tobago-theme/tobago-theme-standard/src/test/java/org/apache/myfaces/tobago/renderkit/css/IconsUnitTest.java b/tobago-theme/tobago-theme-standard/src/test/java/org/apache/myfaces/tobago/renderkit/css/IconsUnitTest.java
new file mode 100644
index 0000000..31aacf9
--- /dev/null
+++ b/tobago-theme/tobago-theme-standard/src/test/java/org/apache/myfaces/tobago/renderkit/css/IconsUnitTest.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.myfaces.tobago.renderkit.css;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class IconsUnitTest {
+
+ @Test
+ public void iconBi() {
+ Assertions.assertTrue(Icons.matches("bi-code"));
+ Assertions.assertEquals("bi-code", Icons.custom("bi-code").getName());
+ }
+
+ @Test
+ public void iconBiJpg() {
+ Assertions.assertFalse(Icons.matches("bi-code.jpg"));
+ Assertions.assertNull(Icons.custom("bi-code.jpg").getName());
+ }
+
+ @Test
+ public void iconFa() {
+ Assertions.assertTrue(Icons.matches("fa-code"));
+ Assertions.assertEquals("fa fa-code", Icons.custom("fa-code").getName());
+ }
+
+ @Test
+ public void iconFx() {
+ Assertions.assertFalse(Icons.matches("fx-code"));
+ Assertions.assertNull(Icons.custom("fx-code").getName());
+ }
+
+ @Test
+ public void iconFas() {
+ Assertions.assertTrue(Icons.matches("fas fa-code"));
+ Assertions.assertEquals("fas fa-code", Icons.custom("fas fa-code").getName());
+ }
+
+ @Test
+ public void iconFar() {
+ Assertions.assertTrue(Icons.matches("far fa-code"));
+ Assertions.assertEquals("far fa-code", Icons.custom("far fa-code").getName());
+ }
+
+ @Test
+ public void iconFal() {
+ Assertions.assertTrue(Icons.matches("fal fa-code"));
+ Assertions.assertEquals("fal fa-code", Icons.custom("fal fa-code").getName());
+ }
+
+ @Test
+ public void iconFad() {
+ Assertions.assertTrue(Icons.matches("fad fa-code"));
+ Assertions.assertEquals("fad fa-code", Icons.custom("fad fa-code").getName());
+ }
+
+ @Test
+ public void iconFax() {
+ Assertions.assertFalse(Icons.matches("fax fa-code"));
+ Assertions.assertNull(Icons.custom("fax fa-code").getName());
+ }
+}