myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lof...@apache.org
Subject [myfaces-tobago] branch master updated: TOBAGO-1903: new attribute keepLineBreaks: tc:out should be usable without rendering a <br> for a \n
Date Wed, 06 Jun 2018 11:35:21 GMT
This is an automated email from the ASF dual-hosted git repository.

lofwyr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git


The following commit(s) were added to refs/heads/master by this push:
     new 685d1a0  TOBAGO-1903: new attribute keepLineBreaks: tc:out should be usable without
rendering a <br> for a \n
685d1a0 is described below

commit 685d1a0e09d208f9e73fd41e013aeba3520312c0
Author: Udo Schnurpfeil <lofwyr@apache.org>
AuthorDate: Wed Jun 6 13:33:16 2018 +0200

    TOBAGO-1903: new attribute keepLineBreaks: tc:out should be usable without rendering a
<br> for a \n
---
 .../apache/myfaces/tobago/component/Attributes.java |  1 +
 .../tobago/internal/component/AbstractUIOut.java    |  2 ++
 .../internal/renderkit/renderer/OutRenderer.java    | 21 +++++++++++++--------
 .../taglib/component/OutTagDeclaration.java         |  9 +++++++++
 .../tobago-example-demo/src/main/webapp/main.xhtml  |  2 +-
 5 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Attributes.java
b/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Attributes.java
index f6cd215..4e2139d 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Attributes.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Attributes.java
@@ -127,6 +127,7 @@ public enum Attributes {
   itemImage,
   itemValue,
   justifyContent,
+  keepLineBreaks,
   label,
   labelLayout,
   labelPosition,
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIOut.java
b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIOut.java
index 989e9dc..e1f38b9 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIOut.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIOut.java
@@ -33,6 +33,8 @@ public abstract class AbstractUIOut extends UIOutput implements SupportsLabelLay
 
   public abstract boolean isEscape();
 
+  public abstract boolean isKeepLineBreaks();
+
   public abstract boolean isCreateSpan();
 
   public abstract boolean isCompact();
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/OutRenderer.java
b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/OutRenderer.java
index 6224fba..9cc0e0e 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/OutRenderer.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/OutRenderer.java
@@ -46,7 +46,7 @@ public class OutRenderer extends MessageLayoutRendererBase {
   @Override
   public void encodeBeginField(final FacesContext facesContext, final UIComponent component)
throws IOException {
 
-    final AbstractUIOut out = (UIOut) component;
+    final AbstractUIOut out = (AbstractUIOut) component;
 
     String text = RenderUtils.currentValue(out);
     if (text == null) {
@@ -56,6 +56,7 @@ public class OutRenderer extends MessageLayoutRendererBase {
     final TobagoResponseWriter writer = getResponseWriter(facesContext);
 
     final boolean escape = out.isEscape();
+    final boolean keepLineBreaks = out.isKeepLineBreaks();
     final boolean compact = out.isCompact() || !out.isCreateSpan();
     final Markup markup = out.getMarkup();
 
@@ -78,14 +79,18 @@ public class OutRenderer extends MessageLayoutRendererBase {
       }
     }
     if (escape) {
-      final StringTokenizer tokenizer = new StringTokenizer(text, "\r\n");
-      while (tokenizer.hasMoreTokens()) {
-        final String token = tokenizer.nextToken();
-        writer.writeText(token);
-        if (tokenizer.hasMoreTokens()) {
-          writer.startElement(HtmlElements.BR);
-          writer.endElement(HtmlElements.BR);
+      if (keepLineBreaks) {
+        final StringTokenizer tokenizer = new StringTokenizer(text, "\r\n");
+        while (tokenizer.hasMoreTokens()) {
+          final String token = tokenizer.nextToken();
+          writer.writeText(token);
+          if (tokenizer.hasMoreTokens()) {
+            writer.startElement(HtmlElements.BR);
+            writer.endElement(HtmlElements.BR);
+          }
         }
+      } else {
+        writer.writeText(text);
       }
     } else { // escape="false"
       writer.writeText("", null); // to ensure the closing > of the <span> start
tag.
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/OutTagDeclaration.java
b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/OutTagDeclaration.java
index a21fe84..45b166d 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/OutTagDeclaration.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/OutTagDeclaration.java
@@ -67,6 +67,15 @@ public interface OutTagDeclaration
   void setEscape(String escape);
 
   /**
+   * Flag indicating that new-line characters will be converted to HTML &lt;br&gt;.
+   * This is useful for pre-formatted plain text.
+   * This has only an effect, with escape="true".
+   */
+  @TagAttribute
+  @UIComponentTagAttribute(type = "boolean", defaultValue = "true")
+  void setKeepLineBreaks(String keepLineBreaks);
+
+  /**
    * Indicates that the renderer should create an element in the output language
    * (e. g. an span or div tag around the output text).
    * Use true, if you enable the possibility to apply styles to the output.
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/main.xhtml b/tobago-example/tobago-example-demo/src/main/webapp/main.xhtml
index fe60a8a..07f11c1 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/main.xhtml
+++ b/tobago-example/tobago-example-demo/src/main/webapp/main.xhtml
@@ -59,7 +59,7 @@
 
         <tc:panel rendered="#{navigationState.viewSource}">
           <pre><code class="language-markup" id="demo-view-source">
-            <tc:out value="#{navigationTree.source}"/>
+            <tc:out keepLineBreaks="false" value="#{navigationTree.source}"/>
           </code></pre>
         </tc:panel>
       </tc:segmentLayout>

-- 
To stop receiving notification emails like this one, please contact
lofwyr@apache.org.

Mime
View raw message