dlf
This commit is contained in:
parent
6e27cefb48
commit
9d1397715e
@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
|
|
||||||
import com.realnet.OpenAi.Services.HtmlBuilder4;
|
import com.realnet.OpenAi.Services.HtmlBuilder4;
|
||||||
import com.realnet.OpenAi.Services.HtmlGenerTorService;
|
import com.realnet.OpenAi.Services.HtmlGenerTorService;
|
||||||
|
import com.realnet.dlf.Services.HtmlService;
|
||||||
import com.realnet.fnd.response.EntityResponse;
|
import com.realnet.fnd.response.EntityResponse;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@ -47,7 +48,8 @@ public class HtmlGeneratorController {
|
|||||||
return ResponseEntity.badRequest().body("Missing 'jsonStructure' in request.");
|
return ResponseEntity.badRequest().body("Missing 'jsonStructure' in request.");
|
||||||
}
|
}
|
||||||
|
|
||||||
String html = HtmlBuilder4.buildHtml(jsonStructure);
|
// String html = HtmlBuilder4.buildHtml(jsonStructure);
|
||||||
|
String html = HtmlService.buildHtml(jsonStructure);
|
||||||
return ResponseEntity.ok(new EntityResponse(html));
|
return ResponseEntity.ok(new EntityResponse(html));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
@ -255,6 +255,7 @@ public class HtmlBuilder4 {
|
|||||||
TYPE_RENDERERS.put("blog-author-bio", HtmlBuilder4::renderBlogAuthorBio);
|
TYPE_RENDERERS.put("blog-author-bio", HtmlBuilder4::renderBlogAuthorBio);
|
||||||
TYPE_RENDERERS.put("newsletter-signup", HtmlBuilder4::renderNewsletterSignup);
|
TYPE_RENDERERS.put("newsletter-signup", HtmlBuilder4::renderNewsletterSignup);
|
||||||
TYPE_RENDERERS.put("blog-categories", HtmlBuilder4::renderBlogCategories);
|
TYPE_RENDERERS.put("blog-categories", HtmlBuilder4::renderBlogCategories);
|
||||||
|
TYPE_RENDERERS.put("how-to-blog-post", HtmlBuilder4::renderHowToBlogPost);
|
||||||
|
|
||||||
// Media
|
// Media
|
||||||
TYPE_RENDERERS.put("video-section", HtmlBuilder4::renderVideoSection);
|
TYPE_RENDERERS.put("video-section", HtmlBuilder4::renderVideoSection);
|
||||||
@ -928,12 +929,30 @@ public class HtmlBuilder4 {
|
|||||||
String className = get(child, "class");
|
String className = get(child, "class");
|
||||||
|
|
||||||
if ("img".equalsIgnoreCase(type)) {
|
if ("img".equalsIgnoreCase(type)) {
|
||||||
sb.append("<img class=\"feature-image\" src=\"").append(get(child, "src")).append("\" alt=\"")
|
String ref = getString(child, "ref", "");
|
||||||
.append(get(child, "alt")).append("\"/>");
|
String classAttr = getString(child, "class", "");
|
||||||
|
String src = getString(child, "src", "").trim();
|
||||||
|
String alt = getString(child, "alt", "Image");
|
||||||
|
|
||||||
|
if (src.isEmpty()) {
|
||||||
|
src = "/assets/images/place.png";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("feature-image".equalsIgnoreCase(ref) || "feature-image".equalsIgnoreCase(classAttr)) {
|
||||||
|
// ✅ Correct: render actual <img>
|
||||||
|
sb.append("<img class=\"feature-image\" src=\"").append(src).append("\" alt=\"").append(alt)
|
||||||
|
.append("\"");
|
||||||
|
if (!classAttr.isEmpty()) {
|
||||||
|
sb.append(" class=\"").append(classAttr).append("\"");
|
||||||
|
}
|
||||||
|
sb.append(" style=\"width: 100%; height: auto;\"/>");
|
||||||
|
} else {
|
||||||
|
// ✅ fallback icon
|
||||||
|
sb.append(renderImageDiv(child));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ("img".equals(type)) {
|
|
||||||
sb.append(renderImageDiv(child));
|
else if ("div".equals(type) && "placeholder-img".equals(className)) {
|
||||||
} else if ("div".equals(type) && "placeholder-img".equals(className)) {
|
|
||||||
sb.append(renderImageDiv(child));
|
sb.append(renderImageDiv(child));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -969,6 +988,74 @@ public class HtmlBuilder4 {
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String renderFeatureSection(Map<String, Object> node) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append("<section class=\"feature-section\">");
|
||||||
|
|
||||||
|
List<Map<String, Object>> children = getChildren(node);
|
||||||
|
|
||||||
|
for (Map<String, Object> child : children) {
|
||||||
|
String type = getString(child, "type", "");
|
||||||
|
String className = get(child, "class");
|
||||||
|
|
||||||
|
if ("img".equalsIgnoreCase(type)) {
|
||||||
|
String ref = getString(child, "ref", "");
|
||||||
|
String classAttr = getString(child, "class", "");
|
||||||
|
String src = getString(child, "src", "").trim();
|
||||||
|
String alt = getString(child, "alt", "Image");
|
||||||
|
|
||||||
|
if (src.isEmpty()) {
|
||||||
|
src = "/assets/images/place.png";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("feature-image".equalsIgnoreCase(ref) || "feature-image".equalsIgnoreCase(classAttr)) {
|
||||||
|
// ✅ Correct: render actual <img>
|
||||||
|
sb.append("<img src=\"").append(src).append("\" alt=\"").append(alt).append("\"");
|
||||||
|
if (!classAttr.isEmpty()) {
|
||||||
|
sb.append(" class=\"").append(classAttr).append("\"");
|
||||||
|
}
|
||||||
|
sb.append(" style=\"width: 100%; height: auto;\"/>");
|
||||||
|
} else {
|
||||||
|
// ✅ fallback icon
|
||||||
|
sb.append(renderImageDiv(child));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if ("div".equals(type) && "placeholder-img".equals(className)) {
|
||||||
|
sb.append(renderImageDiv(child));
|
||||||
|
}
|
||||||
|
|
||||||
|
else if ("div".equalsIgnoreCase(type)) {
|
||||||
|
sb.append("<div class=\"feature-content\">");
|
||||||
|
|
||||||
|
List<Map<String, Object>> divChildren = getChildren(child);
|
||||||
|
for (Map<String, Object> inner : divChildren) {
|
||||||
|
String innerType = getString(inner, "type", "");
|
||||||
|
|
||||||
|
if ("h2".equalsIgnoreCase(innerType)) {
|
||||||
|
sb.append("<h2 class=\"feature-title\">").append(getString(inner, "content", ""))
|
||||||
|
.append("</h2>");
|
||||||
|
} else if ("p".equalsIgnoreCase(innerType)) {
|
||||||
|
sb.append("<p class=\"feature-description\">").append(getString(inner, "content", ""))
|
||||||
|
.append("</p>");
|
||||||
|
} else if ("ul".equalsIgnoreCase(innerType)) {
|
||||||
|
sb.append("<ul class=\"feature-list\">");
|
||||||
|
List<Map<String, Object>> items = getChildren(inner);
|
||||||
|
for (Map<String, Object> li : items) {
|
||||||
|
sb.append("<li>").append(getString(li, "content", "")).append("</li>");
|
||||||
|
}
|
||||||
|
sb.append("</ul>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.append("</div>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.append("</section>");
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
private static String renderFeatureGrid(Map<String, Object> node) {
|
private static String renderFeatureGrid(Map<String, Object> node) {
|
||||||
return "<section class='feature-grid'>Features</section>";
|
return "<section class='feature-grid'>Features</section>";
|
||||||
}
|
}
|
||||||
@ -3906,74 +3993,86 @@ public class HtmlBuilder4 {
|
|||||||
|
|
||||||
private static String renderBrandGuideline(Map<String, Object> data) {
|
private static String renderBrandGuideline(Map<String, Object> data) {
|
||||||
StringBuilder html = new StringBuilder();
|
StringBuilder html = new StringBuilder();
|
||||||
html.append("<section class=\"brand-guideline\" style=\"font-family: sans-serif; padding: 40px;\">");
|
html.append("<section class=\"brand-guideline\">");
|
||||||
|
|
||||||
// Project Info
|
// Project Info
|
||||||
Map<String, Object> project = (Map<String, Object>) data.get("project");
|
Map<String, Object> project = (Map<String, Object>) data.get("project");
|
||||||
html.append("<div class=\"project-info\" style=\"margin-bottom: 30px;\">")
|
html.append("<div class=\"project-info\">").append("<h2 class=\"brand-title\">")
|
||||||
.append("<h2 style=\"margin-bottom: 10px;\">").append(getString(project, "name", "")).append("</h2>")
|
.append(getString(project, "name", "")).append("</h2>")
|
||||||
.append("<p><strong>Designer:</strong> ").append(getString(project, "designer", "")).append("</p>")
|
.append("<p class=\"brand-meta\"><strong>Designer:</strong> ")
|
||||||
.append("<p><strong>Client:</strong> ").append(getString(project, "client", "")).append("</p>")
|
.append(getString(project, "designer", "")).append("</p>")
|
||||||
.append("<p><strong>Website:</strong> <a href=\"").append(getString(project, "website", "#"))
|
.append("<p class=\"brand-meta\"><strong>Client:</strong> ").append(getString(project, "client", ""))
|
||||||
.append("\">").append(getString(project, "website", "")).append("</a></p>")
|
.append("</p>").append("<p class=\"brand-meta\"><strong>Website:</strong> <a href=\"")
|
||||||
.append("<p><strong>Logo Date:</strong> ").append(getString(project, "logoDate", "")).append("</p>")
|
.append(getString(project, "website", "#")).append("\">").append(getString(project, "website", ""))
|
||||||
.append("</div>");
|
.append("</a></p>").append("<p class=\"brand-meta\"><strong>Logo Date:</strong> ")
|
||||||
|
.append(getString(project, "logoDate", "")).append("</p>").append("</div>");
|
||||||
|
|
||||||
// Logos
|
// Logos
|
||||||
Map<String, Object> logo = (Map<String, Object>) data.get("logo");
|
Map<String, Object> logo = (Map<String, Object>) data.get("logo");
|
||||||
html.append("<div class=\"logo-section\" style=\"margin-bottom: 30px;\">").append("<h3>Logo Variants</h3>");
|
html.append("<div class=\"logo-section\">").append("<h3 class=\"section-heading\">Logo Variants</h3>");
|
||||||
|
|
||||||
html.append("<p>Primary Logo:</p><img src=\"").append(getString(logo, "primary", ""))
|
html.append("<p class=\"logo-label\">Primary Logo:</p><div class=\"logo-img\"><img src=\"")
|
||||||
.append("\" alt=\"Primary Logo\" style=\"height: 60px;\"/><br/><br/>");
|
.append(getOrDefaultImage(logo.get("primary")))
|
||||||
|
.append("\" alt=\"Primary Logo\" class=\"logo-primary\" /></div>");
|
||||||
|
|
||||||
html.append("<p>Icon Logo:</p><img src=\"").append(getString(logo, "icon", ""))
|
html.append("<p class=\"logo-label\">Icon Logo:</p><div class=\"logo-img\"><img src=\"")
|
||||||
.append("\" alt=\"Icon Logo\" style=\"height: 40px;\"/><br/><br/>");
|
.append(getOrDefaultImage(logo.get("icon")))
|
||||||
|
.append("\" alt=\"Icon Logo\" class=\"logo-icon\" /></div>");
|
||||||
|
|
||||||
List<String> mono = (List<String>) logo.get("monochrome");
|
List<String> mono = (List<String>) logo.get("monochrome");
|
||||||
if (mono != null && mono.size() == 2) {
|
if (mono != null && mono.size() == 2) {
|
||||||
html.append("<p>Monochrome Logos:</p>").append("<img src=\"").append(mono.get(0))
|
html.append("<p class=\"logo-label\">Monochrome Logos:</p>").append("<div class=\"logo-mono-group\">")
|
||||||
.append("\" alt=\"Black Logo\" style=\"height: 40px; margin-right: 20px;\"/>").append("<img src=\"")
|
.append("<img src=\"").append(getOrDefaultImage(mono.get(0)))
|
||||||
.append(mono.get(1))
|
.append("\" alt=\"Black Logo\" class=\"logo-mono\" />").append("<img src=\"")
|
||||||
.append("\" alt=\"White Logo\" style=\"height: 40px; background: #ccc; padding: 4px;\"/><br/><br/>");
|
.append(getOrDefaultImage(mono.get(1)))
|
||||||
|
.append("\" alt=\"White Logo\" class=\"logo-mono white-bg\" />").append("</div>");
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Object> social = (Map<String, Object>) logo.get("social");
|
Map<String, Object> social = (Map<String, Object>) logo.get("social");
|
||||||
html.append("<p>Social Logos:</p>").append("<img src=\"").append(getString(social, "square", ""))
|
html.append("<p class=\"logo-label\">Social Logos:</p>").append("<div class=\"logo-social-group\">")
|
||||||
.append("\" alt=\"Social Square\" style=\"height: 40px; margin-right: 10px;\"/>").append("<img src=\"")
|
.append("<img src=\"").append(getOrDefaultImage(social.get("square")))
|
||||||
.append(getString(social, "round", "")).append("\" alt=\"Social Round\" style=\"height: 40px;\"/>")
|
.append("\" alt=\"Social Square\" class=\"logo-social-square\" />").append("<img src=\"")
|
||||||
.append("</div>");
|
.append(getOrDefaultImage(social.get("round")))
|
||||||
|
.append("\" alt=\"Social Round\" class=\"logo-social-round\" />").append("</div>").append("</div>");
|
||||||
|
|
||||||
// Colors
|
// Colors
|
||||||
List<Map<String, Object>> colors = (List<Map<String, Object>>) data.get("colors");
|
List<Map<String, Object>> colors = (List<Map<String, Object>>) data.get("colors");
|
||||||
html.append("<div class=\"brand-colors\" style=\"margin-bottom: 30px;\">").append("<h3>Brand Colors</h3>")
|
html.append("<div class=\"brand-colors\">").append("<h3 class=\"section-heading\">Brand Colors</h3>")
|
||||||
.append("<div style=\"display: flex; gap: 20px; flex-wrap: wrap;\">");
|
.append("<div class=\"color-group\">");
|
||||||
|
|
||||||
for (Map<String, Object> color : colors) {
|
for (Map<String, Object> color : colors) {
|
||||||
String hex = getString(color, "hex", "#000");
|
String hex = getString(color, "hex", "#000");
|
||||||
html.append("<div style=\"width: 120px; text-align: center;\">").append("<div style=\"background: ")
|
String slug = color.get("name").toString().toLowerCase().replaceAll("\\s+", "-");
|
||||||
.append(hex).append("; height: 40px; border: 1px solid #ccc;\"></div>")
|
html.append("<div class=\"color-block ").append(slug).append("\">").append("<p class=\"color-name\">")
|
||||||
.append("<p style=\"margin: 4px 0 0; font-size: 14px;\">").append(getString(color, "name", ""))
|
.append(getString(color, "name", "")).append(" (").append(hex).append(")</p>")
|
||||||
.append("</p>").append("<p style=\"font-size: 12px; color: #666;\">")
|
.append("<p class=\"color-usage\">").append(getString(color, "usage", "")).append("</p>")
|
||||||
.append(getString(color, "usage", "")).append("</p>").append("</div>");
|
.append("</div>");
|
||||||
}
|
}
|
||||||
html.append("</div></div>");
|
html.append("</div></div>");
|
||||||
|
|
||||||
// Typography
|
// Typography
|
||||||
Map<String, Object> typography = (Map<String, Object>) data.get("typography");
|
Map<String, Object> typography = (Map<String, Object>) data.get("typography");
|
||||||
html.append("<div class=\"typography-section\">").append("<h3>Typography</h3>");
|
html.append("<div class=\"typography-section\">").append("<h3 class=\"section-heading\">Typography</h3>");
|
||||||
|
|
||||||
Map<String, Object> headline = (Map<String, Object>) typography.get("headline");
|
Map<String, Object> headline = (Map<String, Object>) typography.get("headline");
|
||||||
html.append("<p><strong>Headline:</strong> ").append(getString(headline, "fontFamily", "")).append(" - ")
|
html.append("<div class=\"font-block\">").append("<p class=\"font-role\">Headline</p>")
|
||||||
.append(getString(headline, "weight", "")).append("</p>");
|
.append("<p class=\"font-family\">").append(getString(headline, "fontFamily", "")).append(" — ")
|
||||||
|
.append(getString(headline, "weight", "")).append("</p>").append("</div>");
|
||||||
|
|
||||||
Map<String, Object> body = (Map<String, Object>) typography.get("body");
|
Map<String, Object> body = (Map<String, Object>) typography.get("body");
|
||||||
html.append("<p><strong>Body:</strong> ").append(getString(body, "fontFamily", "")).append(" - ")
|
html.append("<div class=\"font-block\">").append("<p class=\"font-role\">Body</p>")
|
||||||
.append(getString(body, "weight", "")).append("</p>");
|
.append("<p class=\"font-family\">").append(getString(body, "fontFamily", "")).append(" — ")
|
||||||
|
.append(getString(body, "weight", "")).append("</p>").append("</div>").append("</div>");
|
||||||
|
|
||||||
html.append("</div></section>");
|
html.append("</section>");
|
||||||
return html.toString();
|
return html.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String getOrDefaultImage(Object src) {
|
||||||
|
String s = src == null ? "" : src.toString().trim();
|
||||||
|
return s.isEmpty() ? "/assets/images/placeholder.png" : s;
|
||||||
|
}
|
||||||
|
|
||||||
private static String renderLogoGrid(List<Map<String, Object>> data) {
|
private static String renderLogoGrid(List<Map<String, Object>> data) {
|
||||||
StringBuilder html = new StringBuilder();
|
StringBuilder html = new StringBuilder();
|
||||||
html.append("<section class=\"logo-grid-section\" style=\"padding: 40px; font-family: sans-serif;\">")
|
html.append("<section class=\"logo-grid-section\" style=\"padding: 40px; font-family: sans-serif;\">")
|
||||||
@ -4318,55 +4417,6 @@ public class HtmlBuilder4 {
|
|||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String renderFeatureSection(Map<String, Object> node) {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
sb.append("<section class=\"feature-section\">");
|
|
||||||
|
|
||||||
List<Map<String, Object>> children = getChildren(node);
|
|
||||||
|
|
||||||
for (Map<String, Object> child : children) {
|
|
||||||
String type = getString(child, "type", "");
|
|
||||||
String className = get(child, "class");
|
|
||||||
|
|
||||||
if ("img".equalsIgnoreCase(type)) {
|
|
||||||
sb.append("<img class=\"feature-image\" src=\"").append(getString(child, "src", "")).append("\" alt=\"")
|
|
||||||
.append(getString(child, "alt", "Feature Image")).append("\" />");
|
|
||||||
}
|
|
||||||
if ("img".equals(type)) {
|
|
||||||
sb.append(renderImageDiv(child));
|
|
||||||
} else if ("div".equals(type) && "placeholder-img".equals(className)) {
|
|
||||||
sb.append(renderImageDiv(child));
|
|
||||||
} else if ("div".equalsIgnoreCase(type)) {
|
|
||||||
sb.append("<div class=\"feature-content\">");
|
|
||||||
|
|
||||||
List<Map<String, Object>> divChildren = getChildren(child);
|
|
||||||
for (Map<String, Object> inner : divChildren) {
|
|
||||||
String innerType = getString(inner, "type", "");
|
|
||||||
|
|
||||||
if ("h2".equalsIgnoreCase(innerType)) {
|
|
||||||
sb.append("<h2 class=\"feature-title\">").append(getString(inner, "content", ""))
|
|
||||||
.append("</h2>");
|
|
||||||
} else if ("p".equalsIgnoreCase(innerType)) {
|
|
||||||
sb.append("<p class=\"feature-description\">").append(getString(inner, "content", ""))
|
|
||||||
.append("</p>");
|
|
||||||
} else if ("ul".equalsIgnoreCase(innerType)) {
|
|
||||||
sb.append("<ul class=\"feature-list\">");
|
|
||||||
List<Map<String, Object>> items = getChildren(inner);
|
|
||||||
for (Map<String, Object> li : items) {
|
|
||||||
sb.append("<li>").append(getString(li, "content", "")).append("</li>");
|
|
||||||
}
|
|
||||||
sb.append("</ul>");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.append("</div>");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.append("</section>");
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String renderHeroCenteredHeadingSplit(Map<String, Object> section) {
|
private static String renderHeroCenteredHeadingSplit(Map<String, Object> section) {
|
||||||
StringBuilder html = new StringBuilder();
|
StringBuilder html = new StringBuilder();
|
||||||
html.append("<section class=\"hero-centered\">");
|
html.append("<section class=\"hero-centered\">");
|
||||||
@ -4571,13 +4621,13 @@ public class HtmlBuilder4 {
|
|||||||
// Get attributes from JSON
|
// Get attributes from JSON
|
||||||
// String className = getString(data, "class", "placeholder-img");
|
// String className = getString(data, "class", "placeholder-img");
|
||||||
String className = "placeholder-img";
|
String className = "placeholder-img";
|
||||||
String src = getString(data, "src", "/src/assets/images/placeholder.png");
|
String src = getString(data, "src", "/src/assets/images/place.png");
|
||||||
String width = getString(data, "width", ""); // optional
|
String width = getString(data, "width", ""); // optional
|
||||||
String height = getString(data, "height", ""); // optional
|
String height = getString(data, "height", ""); // optional
|
||||||
|
|
||||||
// Fallback to default image if src is missing or blank
|
// Fallback to default image if src is missing or blank
|
||||||
if (src.isEmpty()) {
|
if (src.isEmpty()) {
|
||||||
src = "/src/assets/images/placeholder.png";
|
src = "/src/assets/images/place.png";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build style
|
// Build style
|
||||||
|
|||||||
@ -0,0 +1,31 @@
|
|||||||
|
package com.realnet.dlf.Builders;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class HtmlBuilder {
|
||||||
|
|
||||||
|
public static final Map<String, Function<Map<String, Object>, String>> TYPE_RENDERERS = new HashMap<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
// Blog Related
|
||||||
|
|
||||||
|
// TYPE_RENDERERS.put("cta-block", HtmlBuilder::renderCtaBlock);
|
||||||
|
|
||||||
|
//<TYPE_RENDER>
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//<METHOD_RENDER>
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,5 +1,6 @@
|
|||||||
package com.realnet.dlf.Controllers;
|
package com.realnet.dlf.Controllers;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -97,4 +98,10 @@ public class Design_lbraryController {
|
|||||||
return ResponseEntity.ok(htmlWithCss);
|
return ResponseEntity.ok(htmlWithCss);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/Design_lbrary/build")
|
||||||
|
public void buildFiles() throws IOException {
|
||||||
|
designLibraryService.build();
|
||||||
|
System.out.println(" all files build..");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1,8 +1,16 @@
|
|||||||
package com.realnet.dlf.Services;
|
package com.realnet.dlf.Services;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@ -17,6 +25,9 @@ import com.realnet.users.service1.AppUserServiceImpl;
|
|||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class Design_lbraryService {
|
public class Design_lbraryService {
|
||||||
|
|
||||||
|
@Value("${projectPath}")
|
||||||
|
private String projectPath;
|
||||||
@Autowired
|
@Autowired
|
||||||
private Design_lbraryRepository designLibraryRepository;
|
private Design_lbraryRepository designLibraryRepository;
|
||||||
@Autowired
|
@Autowired
|
||||||
@ -92,6 +103,98 @@ public class Design_lbraryService {
|
|||||||
return finalHtml;
|
return finalHtml;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void build() throws IOException {
|
||||||
|
List<Design_lbrary> dls = designLibraryRepository.findAll();
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
for (Design_lbrary design_lbrary : dls) {
|
||||||
|
|
||||||
|
String name = design_lbrary.getName();
|
||||||
|
String javacode = design_lbrary.getJavacode();
|
||||||
|
String method = javacode.substring(javacode.indexOf("static String"), javacode.indexOf("("));
|
||||||
|
|
||||||
|
System.out.println(name + " building start .... ");
|
||||||
|
|
||||||
|
String typeRender = "TYPE_RENDERERS.put(" + "\"" + name + "\", HtmlBuilder::" + method + ");";
|
||||||
|
|
||||||
|
buildfront2("//<TYPE_RENDER>", typeRender);
|
||||||
|
|
||||||
|
buildfront2("//<METHOD_RENDER>", javacode);
|
||||||
|
|
||||||
|
i++;
|
||||||
|
|
||||||
|
System.out.println(name + " build ");
|
||||||
|
System.out.println("total build " + i);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void buildfront2(String keyword, String replaceString) throws IOException {
|
||||||
|
|
||||||
|
String fileName = "HtmlBuilder.java";
|
||||||
|
StringBuilder frontend = new StringBuilder();
|
||||||
|
|
||||||
|
// CEATE PACKAGE
|
||||||
|
|
||||||
|
String directoryName;
|
||||||
|
|
||||||
|
directoryName = projectPath + "/src/main/java/com/realnet/dlf/Builders";
|
||||||
|
|
||||||
|
String filePath = directoryName + File.separator + fileName;
|
||||||
|
System.out.println("routing path is " + filePath);
|
||||||
|
|
||||||
|
String str = replaceString;
|
||||||
|
|
||||||
|
int length = str.length();
|
||||||
|
|
||||||
|
// CEATE PACKAGE
|
||||||
|
|
||||||
|
File file = null;
|
||||||
|
|
||||||
|
file = new File(filePath);
|
||||||
|
|
||||||
|
FileReader fr = new FileReader(file);
|
||||||
|
BufferedReader br = new BufferedReader(fr);
|
||||||
|
String line;
|
||||||
|
|
||||||
|
while ((line = br.readLine()) != null) {
|
||||||
|
|
||||||
|
if (line.trim().equalsIgnoreCase(str.trim())) {
|
||||||
|
str = "";
|
||||||
|
}
|
||||||
|
frontend.append(line + "\n");
|
||||||
|
// System.out.println(line);
|
||||||
|
}
|
||||||
|
fr.close();
|
||||||
|
br.close();
|
||||||
|
System.out.println(frontend.length());
|
||||||
|
|
||||||
|
String back = keyword;
|
||||||
|
int back_l = back.length();
|
||||||
|
|
||||||
|
int ord = StringUtils.ordinalIndexOf(frontend.toString(), back, 1);
|
||||||
|
|
||||||
|
String front = frontend.substring(0, ord + back_l) + "\n" + str + "\n"
|
||||||
|
+ frontend.substring(ord + back_l, frontend.length());
|
||||||
|
|
||||||
|
String codee = front.substring(0, front.lastIndexOf("\n")); // remove last line break
|
||||||
|
|
||||||
|
// creating files
|
||||||
|
File file1 = new File(filePath);
|
||||||
|
|
||||||
|
// Writing files
|
||||||
|
|
||||||
|
FileWriter fr1 = new FileWriter(file1.getAbsoluteFile());
|
||||||
|
BufferedWriter br1 = new BufferedWriter(fr1);
|
||||||
|
// PrintWriter out = new PrintWriter(br1);
|
||||||
|
// out.println(r_import);
|
||||||
|
|
||||||
|
br1.write(codee.toString());
|
||||||
|
br1.close();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public AppUser getUser() {
|
public AppUser getUser() {
|
||||||
AppUser user = userService.getLoggedInUser();
|
AppUser user = userService.getLoggedInUser();
|
||||||
return user;
|
return user;
|
||||||
|
|||||||
@ -0,0 +1,461 @@
|
|||||||
|
package com.realnet.dlf.Services;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import com.realnet.dlf.Builders.HtmlBuilder;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class HtmlService {
|
||||||
|
|
||||||
|
public static String buildHtml(Object node) {
|
||||||
|
if (node instanceof Map) {
|
||||||
|
Map<String, Object> map = (Map<String, Object>) node;
|
||||||
|
|
||||||
|
// Handle raw section container
|
||||||
|
|
||||||
|
// Check if a universal TYPE_RENDERER exists for this block
|
||||||
|
String type = getString(map, "type", "");
|
||||||
|
if (HtmlBuilder.TYPE_RENDERERS.containsKey(type.toLowerCase())) {
|
||||||
|
return HtmlBuilder.TYPE_RENDERERS.get(type.toLowerCase()).apply(map);
|
||||||
|
}
|
||||||
|
// Normal map block
|
||||||
|
return renderFromMap(map);
|
||||||
|
} else if (node instanceof List) {
|
||||||
|
return renderFromList((List<Object>) node);
|
||||||
|
} else if (node != null) {
|
||||||
|
return node.toString();
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Map<String, String> TYPE_TAG_MAP = new HashMap<>();
|
||||||
|
static {
|
||||||
|
TYPE_TAG_MAP.put("navbar", "nav");
|
||||||
|
TYPE_TAG_MAP.put("footer", "footer");
|
||||||
|
TYPE_TAG_MAP.put("article", "article");
|
||||||
|
TYPE_TAG_MAP.put("header", "header");
|
||||||
|
TYPE_TAG_MAP.put("logo", "div");
|
||||||
|
TYPE_TAG_MAP.put("nav", "nav");
|
||||||
|
TYPE_TAG_MAP.put("link", "a");
|
||||||
|
TYPE_TAG_MAP.put("button", "button");
|
||||||
|
TYPE_TAG_MAP.put("span", "span");
|
||||||
|
TYPE_TAG_MAP.put("img", "img"); // already supported as self-closing
|
||||||
|
TYPE_TAG_MAP.put("social-icons", "div");
|
||||||
|
TYPE_TAG_MAP.put("icon", "div");
|
||||||
|
TYPE_TAG_MAP.put("text", "span"); // or "p" depending on your choice
|
||||||
|
|
||||||
|
// add more if needed
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getString(Map<String, Object> map, String key, String defaultValue) {
|
||||||
|
Object val = map.get(key);
|
||||||
|
return val instanceof String ? (String) val : defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String renderFromMap(Map<String, Object> node) {
|
||||||
|
StringBuilder html = new StringBuilder();
|
||||||
|
|
||||||
|
// Get tag from 'tag' or fallback to 'type'
|
||||||
|
String type = getString(node, "type", "div");
|
||||||
|
String rawTag = getString(node, "tag", "");
|
||||||
|
String tag = !rawTag.isEmpty() ? rawTag : TYPE_TAG_MAP.getOrDefault(type.toLowerCase(), type);
|
||||||
|
|
||||||
|
html.append("<").append(tag);
|
||||||
|
|
||||||
|
// Add class and id if present
|
||||||
|
String className = getString(node, "class", getString(node, "ref", ""));
|
||||||
|
String id = getString(node, "id", "");
|
||||||
|
|
||||||
|
if (!className.isEmpty())
|
||||||
|
html.append(" class=\"").append(className).append("\"");
|
||||||
|
if (!id.isEmpty())
|
||||||
|
html.append(" id=\"").append(id).append("\"");
|
||||||
|
|
||||||
|
// Add other attributes (like src, alt for img)
|
||||||
|
for (Map.Entry<String, Object> entry : node.entrySet()) {
|
||||||
|
String key = entry.getKey();
|
||||||
|
Object value = entry.getValue();
|
||||||
|
if (!Arrays.asList("type", "tag", "class", "id", "content", "children", "menu", "actions", "buttons")
|
||||||
|
.contains(key) && !(value instanceof Map || value instanceof List)) {
|
||||||
|
html.append(" ").append(key).append("=\"").append(value).append("\"");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Self-closing tag support (like img)
|
||||||
|
// Self-closing tag like <img />
|
||||||
|
if ("img".equalsIgnoreCase(tag)) {
|
||||||
|
html.append(" src=\"").append(getString(node, "src", "")).append("\"");
|
||||||
|
html.append(" alt=\"").append(getString(node, "alt", "")).append("\"");
|
||||||
|
html.append(" />");
|
||||||
|
return html.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Content rendering
|
||||||
|
if (node.containsKey("content")) {
|
||||||
|
html.append(node.get("content"));
|
||||||
|
}
|
||||||
|
|
||||||
|
html.append(">");
|
||||||
|
|
||||||
|
// Render inline content if present
|
||||||
|
|
||||||
|
// Special short-circuit rendering for link and button
|
||||||
|
if ("link".equalsIgnoreCase(type)) {
|
||||||
|
html.append("<a href=\"#\">").append(node.get("content")).append("</a>");
|
||||||
|
return html.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("text".equalsIgnoreCase(type)) {
|
||||||
|
html.append(getString(node, "content", ""));
|
||||||
|
return html.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("logo".equalsIgnoreCase(type)) {
|
||||||
|
html.append("<div class=\"").append(className).append("\">").append(getString(node, "content", "Logo"))
|
||||||
|
.append("</div>");
|
||||||
|
return html.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("icon".equalsIgnoreCase(type)) {
|
||||||
|
String label = getString(node, "content", "");
|
||||||
|
String emoji = getIconEmoji(label);
|
||||||
|
html.append("<div>").append(emoji).append(" ").append(label).append("</div>");
|
||||||
|
return html.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("a".equalsIgnoreCase(type)) {
|
||||||
|
String href = getString(node, "href", "#");
|
||||||
|
html.append("<a href=\"").append(href).append("\">").append(getString(node, "content", "")).append("</a>");
|
||||||
|
return html.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("button".equalsIgnoreCase(type)) {
|
||||||
|
html.append("<button class=\"").append(className).append("\">").append(node.get("content"))
|
||||||
|
.append("</button>");
|
||||||
|
return html.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.containsKey("content")) {
|
||||||
|
html.append(node.get("content"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle structured known patterns
|
||||||
|
if (node.containsKey("logo")) {
|
||||||
|
html.append("<div class=\"logo-1\">").append(node.get("logo")).append("</div>");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.containsKey("heading")) {
|
||||||
|
html.append("<h1>").append(node.get("heading")).append("</h1>");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.containsKey("subheading")) {
|
||||||
|
html.append("<p>").append(node.get("subheading")).append("</p>");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.containsKey("text")) {
|
||||||
|
html.append("<p>").append(node.get("text")).append("</p>");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.containsKey("menu")) {
|
||||||
|
html.append(renderMenu(node.get("menu")));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.containsKey("actions")) {
|
||||||
|
html.append(renderActions(node.get("actions")));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.containsKey("buttons")) {
|
||||||
|
html.append(renderButtons(node.get("buttons")));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.containsKey("columns")) {
|
||||||
|
html.append(renderColumns(node.get("columns")));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.containsKey("children")) {
|
||||||
|
html.append(buildHtml(node.get("children")));
|
||||||
|
}
|
||||||
|
|
||||||
|
html.append("</").append(tag).append(">");
|
||||||
|
return html.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String renderFromList(List<Object> list) {
|
||||||
|
StringBuilder html = new StringBuilder();
|
||||||
|
for (Object item : list) {
|
||||||
|
html.append(buildHtml(item));
|
||||||
|
}
|
||||||
|
return html.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String renderButtons(Object obj) {
|
||||||
|
StringBuilder html = new StringBuilder();
|
||||||
|
|
||||||
|
// Case 1: Simple list of string labels
|
||||||
|
if (obj instanceof List) {
|
||||||
|
List<Object> btns = (List<Object>) obj;
|
||||||
|
html.append("<div class=\"cta-buttons\">");
|
||||||
|
for (Object item : btns) {
|
||||||
|
if (item instanceof String) {
|
||||||
|
html.append("<button>").append(item).append("</button>");
|
||||||
|
} else if (item instanceof Map) {
|
||||||
|
html.append(renderSingleButton((Map<String, Object>) item));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
html.append("</div>");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Case 2: Object with "items" list and optional class
|
||||||
|
else if (obj instanceof Map) {
|
||||||
|
Map<String, Object> btnMap = (Map<String, Object>) obj;
|
||||||
|
List<Object> items = (List<Object>) btnMap.get("items");
|
||||||
|
String btnClass = getString(btnMap, "class", "cta-buttons");
|
||||||
|
|
||||||
|
html.append("<div class=\"").append(btnClass).append("\">");
|
||||||
|
if (items != null) {
|
||||||
|
for (Object btn : items) {
|
||||||
|
if (btn instanceof String) {
|
||||||
|
html.append("<button>").append(btn).append("</button>");
|
||||||
|
} else if (btn instanceof Map) {
|
||||||
|
html.append(renderSingleButton((Map<String, Object>) btn));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
html.append("</div>");
|
||||||
|
}
|
||||||
|
|
||||||
|
return html.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String renderSingleButton(Map<String, Object> btn) {
|
||||||
|
String label = getString(btn, "label", "Button");
|
||||||
|
String href = getString(btn, "action", "#");
|
||||||
|
String style = getString(btn, "style", "filled");
|
||||||
|
String bg = getString(btn, "backgroundColor", style.equals("outlined") ? "white" : "black");
|
||||||
|
String color = getString(btn, "textColor", style.equals("outlined") ? "black" : "white");
|
||||||
|
String border = style.equals("outlined") ? "1px solid " + getString(btn, "borderColor", "#000") : "none";
|
||||||
|
|
||||||
|
return new StringBuilder().append("<a href=\"").append(href).append("\" style=\"").append("background:")
|
||||||
|
.append(bg).append("; ").append("color:").append(color).append("; ")
|
||||||
|
.append("padding:10px 20px; border-radius:4px; text-decoration:none; ").append("border:").append(border)
|
||||||
|
.append("; margin-right:10px; display:inline-block;\">").append(label).append("</a>").toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String renderColumns(Object obj) {
|
||||||
|
StringBuilder html = new StringBuilder();
|
||||||
|
html.append("<div class=\"blog-layout\">");
|
||||||
|
|
||||||
|
List<Map<String, Object>> columns = (List<Map<String, Object>>) obj;
|
||||||
|
for (Map<String, Object> col : columns) {
|
||||||
|
String type = getString(col, "type", "");
|
||||||
|
if ("main".equalsIgnoreCase(type)) {
|
||||||
|
html.append("<main class=\"main-column\">");
|
||||||
|
if (col.containsKey("contentBlocks")) {
|
||||||
|
List<Map<String, Object>> blocks = (List<Map<String, Object>>) col.get("contentBlocks");
|
||||||
|
for (Map<String, Object> block : blocks) {
|
||||||
|
html.append("<div class=\"content-block\">").append("<h2>")
|
||||||
|
.append(getString(block, "heading", "")).append("</h2>").append("<p>")
|
||||||
|
.append(getString(block, "text", "")).append("</p>").append("</div>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
html.append("</main>");
|
||||||
|
} else if ("sidebar".equalsIgnoreCase(type)) {
|
||||||
|
html.append("<aside class=\"sidebar-column\">");
|
||||||
|
List<String> widgets = (List<String>) col.get("widgets");
|
||||||
|
for (String widget : widgets) {
|
||||||
|
html.append("<div class=\"widget\">").append(getWidgetIcon(widget)).append(" ").append(widget)
|
||||||
|
.append("</div>");
|
||||||
|
}
|
||||||
|
html.append("</aside>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
html.append("</div>");
|
||||||
|
return html.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String renderMenu(Object obj) {
|
||||||
|
StringBuilder html = new StringBuilder("<ul class=\"nav-1\">");
|
||||||
|
|
||||||
|
List<Object> menu = (List<Object>) obj;
|
||||||
|
for (Object item : menu) {
|
||||||
|
if (item instanceof String) {
|
||||||
|
html.append("<li><a href=\"#\">").append(item).append("</a></li>");
|
||||||
|
} else if (item instanceof Map) {
|
||||||
|
Map<String, Object> dropdownItem = (Map<String, Object>) item;
|
||||||
|
html.append("<li class=\"dropdown\">");
|
||||||
|
html.append("<a href=\"#\">").append(dropdownItem.get("title")).append("</a>");
|
||||||
|
|
||||||
|
if (dropdownItem.containsKey("dropdown")) {
|
||||||
|
html.append(renderDropdown(dropdownItem.get("dropdown")));
|
||||||
|
}
|
||||||
|
html.append("</li>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
html.append("</ul>");
|
||||||
|
return html.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String renderDropdown(Object obj) {
|
||||||
|
StringBuilder html = new StringBuilder("<div class=\"dropdown-content\"><div class=\"dropdown-columns\">");
|
||||||
|
|
||||||
|
Map<String, Object> dropdown = (Map<String, Object>) obj;
|
||||||
|
List<Map<String, Object>> columns = (List<Map<String, Object>>) dropdown.get("columns");
|
||||||
|
|
||||||
|
for (Map<String, Object> column : columns) {
|
||||||
|
html.append("<div class=\"column\">");
|
||||||
|
html.append("<h4>").append(column.get("title")).append("</h4>");
|
||||||
|
html.append("<ul>");
|
||||||
|
|
||||||
|
if (column.containsKey("items")) {
|
||||||
|
List<Map<String, Object>> items = (List<Map<String, Object>>) column.get("items");
|
||||||
|
for (Map<String, Object> item : items) {
|
||||||
|
html.append("<li><span>").append(item.get("icon")).append("</span>").append("<strong>")
|
||||||
|
.append(item.get("title")).append("</strong>").append("<p>").append(item.get("description"))
|
||||||
|
.append("</p>").append("</li>");
|
||||||
|
}
|
||||||
|
} else if (column.containsKey("blogs")) {
|
||||||
|
List<Map<String, Object>> blogs = (List<Map<String, Object>>) column.get("blogs");
|
||||||
|
for (Map<String, Object> blog : blogs) {
|
||||||
|
html.append("<li><strong>").append(blog.get("title")).append("</strong>").append("<p>")
|
||||||
|
.append(blog.get("description")).append("</p>").append("<a href=\"#\">")
|
||||||
|
.append(blog.get("cta")).append("</a></li>");
|
||||||
|
}
|
||||||
|
if (column.containsKey("footerLink")) {
|
||||||
|
html.append("<div class=\"footer-link\"><a href=\"#\">").append(column.get("footerLink"))
|
||||||
|
.append("</a></div>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
html.append("</ul></div>");
|
||||||
|
}
|
||||||
|
|
||||||
|
html.append("</div></div>");
|
||||||
|
return html.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String renderActions(Object obj) {
|
||||||
|
StringBuilder html = new StringBuilder("<div class=\"navbar-actions\">");
|
||||||
|
|
||||||
|
List<Map<String, Object>> actions = (List<Map<String, Object>>) obj;
|
||||||
|
for (Map<String, Object> action : actions) {
|
||||||
|
String label = getString(action, "label", "Button");
|
||||||
|
String variant = getString(action, "variant", "");
|
||||||
|
String btnClass = "join-btn";
|
||||||
|
if (!variant.isEmpty()) {
|
||||||
|
btnClass += " " + variant;
|
||||||
|
}
|
||||||
|
html.append("<button class=\"").append(btnClass).append("\">").append(label).append("</button>");
|
||||||
|
}
|
||||||
|
|
||||||
|
html.append("</div>");
|
||||||
|
return html.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String renderNavbarBlock(Map<String, Object> nav) {
|
||||||
|
StringBuilder html = new StringBuilder();
|
||||||
|
|
||||||
|
// Inline styles
|
||||||
|
StringBuilder style = new StringBuilder();
|
||||||
|
if (nav.containsKey("style")) {
|
||||||
|
Map<String, Object> styleMap = (Map<String, Object>) nav.get("style");
|
||||||
|
for (Map.Entry<String, Object> s : styleMap.entrySet()) {
|
||||||
|
appendStyle(style, s.getKey(), s.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
html.append("<nav style=\"").append(style).append("\">");
|
||||||
|
|
||||||
|
// Logo
|
||||||
|
if (nav.containsKey("Logo")) {
|
||||||
|
Map<String, Object> logo = (Map<String, Object>) nav.get("Logo");
|
||||||
|
String type = getString(logo, "type", "text");
|
||||||
|
if ("image".equalsIgnoreCase(type)) {
|
||||||
|
html.append("<img src=\"").append(logo.get("src")).append("\" alt=\"").append(logo.get("alt"))
|
||||||
|
.append("\" width=\"").append(logo.get("width")).append("\" height=\"")
|
||||||
|
.append(logo.get("height")).append("\" />");
|
||||||
|
} else if ("text".equalsIgnoreCase(type)) {
|
||||||
|
html.append("<div style=\"font-weight:").append(getString(logo, "fontWeight", "normal"))
|
||||||
|
.append("; font-size:").append(getString(logo, "fontSize", "16px")).append(";\">")
|
||||||
|
.append(getString(logo, "text", "Logo")).append("</div>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Links
|
||||||
|
if (nav.containsKey("Links")) {
|
||||||
|
List<Map<String, Object>> links = (List<Map<String, Object>>) nav.get("Links");
|
||||||
|
html.append("<ul style=\"display:flex; gap:20px; list-style:none\">");
|
||||||
|
for (Map<String, Object> link : links) {
|
||||||
|
html.append("<li><a href=\"").append(link.get("href")).append("\">")
|
||||||
|
.append(getString(link, "label", "")).append("</a></li>");
|
||||||
|
}
|
||||||
|
html.append("</ul>");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Buttons
|
||||||
|
if (nav.containsKey("Buttons")) {
|
||||||
|
List<Map<String, Object>> buttons = (List<Map<String, Object>>) nav.get("Buttons");
|
||||||
|
for (Map<String, Object> btn : buttons) {
|
||||||
|
String bg = getString(btn, "background", "white");
|
||||||
|
String color = getString(btn, "textColor", "black");
|
||||||
|
String border = getString(btn, "border", "none");
|
||||||
|
|
||||||
|
html.append("<a href=\"").append(getString(btn, "action", "#")).append("\" style=\"")
|
||||||
|
.append("background:").append(bg).append(";").append("color:").append(color).append(";")
|
||||||
|
.append("padding:8px 16px;").append("border:").append(border).append(";")
|
||||||
|
.append("text-decoration:none; margin-left:10px;").append("\">")
|
||||||
|
.append(getString(btn, "label", "Button")).append("</a>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
html.append("</nav>");
|
||||||
|
return html.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void appendStyle(StringBuilder style, String key, Object value) {
|
||||||
|
if (value != null) {
|
||||||
|
style.append(key).append(":").append(value).append("; ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getIconEmoji(String label) {
|
||||||
|
label = label.toLowerCase();
|
||||||
|
if (label.contains("facebook"))
|
||||||
|
return "📘";
|
||||||
|
if (label.contains("instagram"))
|
||||||
|
return "📷";
|
||||||
|
if (label.equals("x"))
|
||||||
|
return "𝕏";
|
||||||
|
if (label.contains("search"))
|
||||||
|
return "🔍";
|
||||||
|
if (label.contains("profile"))
|
||||||
|
return "👤";
|
||||||
|
if (label.contains("twitter"))
|
||||||
|
return "🐦";
|
||||||
|
|
||||||
|
if (label.contains("linkedin"))
|
||||||
|
return "🔗";
|
||||||
|
if (label.contains("youtube"))
|
||||||
|
return "▶️";
|
||||||
|
return "📦";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getWidgetIcon(String widget) {
|
||||||
|
widget = widget.toLowerCase();
|
||||||
|
if (widget.contains("search"))
|
||||||
|
return "🔍";
|
||||||
|
if (widget.contains("recent"))
|
||||||
|
return "📝";
|
||||||
|
if (widget.contains("newsletter"))
|
||||||
|
return "📬";
|
||||||
|
return "📦";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user