Libraryless. Click here for Pure Java version (5981L/35K).
sclass HTMLFramer1 { S title; bool titleIsHTML; new L<NavItem> navItems; new L<O> contents; // items will be evaluated to strings upon rendering new LinkedHashSet<S> headElements; // automatically avoid duplication bool navBeforeTitle; new L<Runnable> willRender; srecord NavItem(S link, S html) { bool targetBlank; } public S get() { ret render(); } swappable S render() { callFAll(willRender); ret hhtml(hhead(htitle(titleIsHTML ? hTitleClean(title) : title) + lines(headElements)) + hbody( (navBeforeTitle ? renderNav() + renderTitle() : renderTitle() + renderNav()) + nemptyLines(contents))); } swappable S renderTitle() { ret h1(encodedTitle()); } S encodedTitle() { //printVars_str encodedTitle(+title, +titleIsHTML); ret titleIsHTML ? title : htmlEncode2(title); } swappable S renderNav() { if (empty(navItems)) ret ""; ret div_vbar(map renderNavItem(navItems), style := "margin-bottom: 0.5em"); } S renderNavItem(NavItem ni) { ret ahref_possiblyTargetBlank(ni.link, ni.html, ni.targetBlank); } void addNavItem(S html) { navItems.add(new NavItem(null, html)); } void addNavItems(Iterable<S> htmls) { forEach addNavItem(htmls); } void addNavItem(S link, S html, O... _) { navItems.add(setAll(new NavItem(link, html), filterParams(_, 'targetBlank))); } void addInHead aka addInHEAD(O html) { headElements.add(str(html)); } // legacy signature for binary compatibility void add(S html) { add((O) html); } // convenience signature for lambdas void add(IF0<O> html) { add(lambdaToToString(html)); } // add contents: TODO move things to head automatically void add(O html) { if (notNullOrEmptyString(html)) contents.add(html); } void addAll(Cl<S> l) { forEach add(l); } void clearNavItems { navItems.clear(); } selfType setTitle(S title) { this.title = title; this; } S htmlTitle(S title) { this.title = title; titleIsHTML = true; ret title; } Cl<S> headElements() { ret headElements; } }
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1029581 |
Snippet name: | HTMLFramer1 |
Eternal ID of this version: | #1029581/36 |
Text MD5: | bed4f935759c177b1f38be02ae3108b4 |
Transpilation MD5: | 7eb4b61f9993e23ad606f1ed25b3e142 |
Author: | stefan |
Category: | javax / web |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-09-24 23:33:50 |
Source code size: | 2243 bytes / 90 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 350 / 765 |
Version history: | 35 change(s) |
Referenced in: | [show references] |