[ofbiz-framework] branch trunk updated: Improved: Show border and file name for content rendered from ftl (OFBIZ-12002)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[ofbiz-framework] branch trunk updated: Improved: Show border and file name for content rendered from ftl (OFBIZ-12002)

James Yong-2
This is an automated email from the ASF dual-hosted git repository.

jamesyong pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 347c905  Improved: Show border and file name for content rendered from ftl (OFBIZ-12002)
347c905 is described below

commit 347c9056743b63c7898f5e5dc52cd31193b55258
Author: James Yong <[hidden email]>
AuthorDate: Fri Sep 18 14:37:36 2020 +0800

    Improved: Show border and file name for content rendered from ftl (OFBIZ-12002)
   
    New property “widget.dev.namedBorder” to control the display of the named border
   
    Thanks Michael for review
---
 framework/widget/config/widget.properties                |  3 +++
 .../java/org/apache/ofbiz/widget/model/HtmlWidget.java   |  7 +++++++
 .../java/org/apache/ofbiz/widget/model/ModelWidget.java  |  8 ++++++++
 .../ofbiz/widget/renderer/html/HtmlWidgetRenderer.java   | 16 +++++++---------
 4 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/framework/widget/config/widget.properties b/framework/widget/config/widget.properties
index 9a83b79..306fb31 100644
--- a/framework/widget/config/widget.properties
+++ b/framework/widget/config/widget.properties
@@ -27,6 +27,9 @@
 # boundary comments.
 widget.verbose=true
 
+# Enable widget named border for development
+widget.dev.namedBorder=true
+
 # Default number of items to be displayed per page in a list form
 widget.form.defaultViewSize=20
 
diff --git a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/HtmlWidget.java b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/HtmlWidget.java
index 4bae38a..800f812 100644
--- a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/HtmlWidget.java
+++ b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/HtmlWidget.java
@@ -167,6 +167,10 @@ public class HtmlWidget extends ModelScreenWidget {
                 if (insertWidgetBoundaryComments) {
                     writer.append(HtmlWidgetRenderer.buildBoundaryComment("Begin", "Template", location));
                 }
+                boolean insertWidgetNamedBorder = ModelWidget.widgetNamedBorderEnabled();
+                if (insertWidgetNamedBorder) {
+                    writer.append(HtmlWidgetRenderer.buildNamedBorder("Begin", "Template", location));
+                }
 
                 Template template = null;
                 if (location.endsWith(".fo.ftl")) { // FOP can't render correctly escaped characters
@@ -176,6 +180,9 @@ public class HtmlWidget extends ModelScreenWidget {
                 }
                 FreeMarkerWorker.renderTemplate(template, context, writer);
 
+                if (insertWidgetNamedBorder) {
+                    writer.append(HtmlWidgetRenderer.buildNamedBorder("End", "Template", location));
+                }
                 if (insertWidgetBoundaryComments) {
                     writer.append(HtmlWidgetRenderer.buildBoundaryComment("End", "Template", location));
                 }
diff --git a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelWidget.java b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelWidget.java
index 3d1dcec..8630fd1 100644
--- a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelWidget.java
+++ b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelWidget.java
@@ -150,4 +150,12 @@ public abstract class ModelWidget implements Serializable {
         }
         return result;
     }
+
+    /**
+     * Returns <code>true</code> if showing filename and border on the rendered part of the template.
+     * @return true if <code>widget.dev.namedBorder</code> is set to <code>true</code>
+     */
+    public static boolean widgetNamedBorderEnabled() {
+        return "true".equals(UtilProperties.getPropertyValue("widget", "widget.dev.namedBorder"));
+    }
 }
diff --git a/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlWidgetRenderer.java b/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlWidgetRenderer.java
index 781e099..0b89029 100644
--- a/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlWidgetRenderer.java
+++ b/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlWidgetRenderer.java
@@ -22,7 +22,6 @@ import java.io.File;
 import java.io.IOException;
 import java.util.List;
 
-import org.apache.ofbiz.base.util.Debug;
 import org.apache.ofbiz.base.util.UtilHtml;
 import org.apache.ofbiz.base.util.UtilHttp;
 import org.apache.ofbiz.widget.model.ModelWidget;
@@ -73,10 +72,10 @@ public class HtmlWidgetRenderer {
      * @param widgetName The widget name
      */
     public static String buildBoundaryComment(String boundaryType, String widgetType, String widgetName) {
-        String boundaryComment = "<!-- " + boundaryType + " " + widgetType + " " + widgetName + " -->" + WHITE_SPACE;
-        if (!Debug.verboseOn()) {
-            return boundaryComment;
-        }
+        return "<!-- " + boundaryType + " " + widgetType + " " + widgetName + " -->" + WHITE_SPACE;
+    }
+
+    public static String buildNamedBorder(String boundaryType, String widgetType, String widgetName) {
         List<String> themeBasePathsToExempt = UtilHtml.getVisualThemeFolderNamesToExempt();
         if (!themeBasePathsToExempt.stream().anyMatch(widgetName::contains)) {
             // add additional visual label for non-theme ftl
@@ -85,13 +84,12 @@ public class HtmlWidgetRenderer {
                 String fileName = widgetName.substring(widgetName.lastIndexOf(File.separator) + 1);
                 return "</div><div class='info-overlay'><span class='info-overlay-item'>"
                         + fileName
-                        + "</span></div></div>" + boundaryComment;
+                        + "</span></div></div>";
             default:
-                return boundaryComment + "<div class='info-container'><div class='info-content'>";
+                return "<div class='info-container'><div class='info-content'>";
             }
-        } else {
-            return boundaryComment;
         }
+        return "";
     }
 
     public static String formatBoundaryJsComment(String boundaryType, String widgetType, String widgetName) {