├── .gitignore ├── LICENSE ├── README.md ├── doc └── components.jpg ├── pom.xml └── src ├── main ├── java │ └── io │ │ └── github │ │ └── thymeleaf │ │ └── ui │ │ ├── Attrs.java │ │ ├── Component.java │ │ ├── Components.java │ │ ├── Element.java │ │ ├── HasHtmlAttributes.java │ │ ├── HasStatus.java │ │ ├── Renderable.java │ │ ├── components │ │ ├── Alert.java │ │ ├── Badge.java │ │ ├── Breadcrumb.java │ │ ├── Button.java │ │ ├── ButtonGroup.java │ │ ├── Card.java │ │ ├── Carousel.java │ │ ├── Dropdown.java │ │ ├── ElementCollection.java │ │ ├── Figure.java │ │ ├── Nav.java │ │ ├── Navigation.java │ │ ├── NavigationHeader.java │ │ └── Sidebar.java │ │ ├── dialect │ │ ├── ComponentTemplateResolver.java │ │ ├── IsThemeConfigured.java │ │ ├── UiDialect.java │ │ ├── UiDialectAutoconfiguration.java │ │ ├── UiExpressionObjectFactory.java │ │ └── tags │ │ │ ├── AbstractTagProcessor.java │ │ │ ├── AlertAttributeTagProcessor.java │ │ │ ├── BadgeAttributeTagProcessor.java │ │ │ ├── BreadcrumbAttributeTagProcessor.java │ │ │ ├── ButtonAttributeTagProcessor.java │ │ │ ├── ButtonGroupAttributeTagProcessor.java │ │ │ ├── CardAttributeTagProcessor.java │ │ │ ├── CarouselAttributeTagProcessor.java │ │ │ ├── CopyTagAttributesTagProcessor.java │ │ │ ├── DropdownAttributeTagProcessor.java │ │ │ ├── FigureAttributeTagProcessor.java │ │ │ ├── NavigationAttributeTagProcessor.java │ │ │ ├── NavigationHeaderAttributeTagProcessor.java │ │ │ ├── RenderAttributeTagProcessor.java │ │ │ └── SidebarAttributeTagProcessor.java │ │ ├── elements │ │ ├── Image.java │ │ └── Link.java │ │ └── internal │ │ ├── Checks.java │ │ ├── Reflection.java │ │ ├── Strings.java │ │ ├── Urls.java │ │ └── package.java └── resources │ ├── META-INF │ └── spring.factories │ └── templates │ └── ui │ └── themes │ ├── Readme │ └── default │ ├── alert-component.html │ ├── badge-component.html │ ├── breadcrumb-component.html │ ├── button-component.html │ ├── button-group-component.html │ ├── card-component.html │ ├── carousel-component.html │ ├── dropdown-component.html │ ├── figure-component.html │ ├── navigation-component.html │ ├── navigation-header-component.html │ └── sidebar-component.html └── test ├── java └── io │ └── github │ └── thymeleaf │ └── ui │ ├── ComponentsTest.java │ └── dialect │ └── DialectBenchmarkTest.java └── resources └── test.html /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | .settings 4 | .classpath 5 | .project 6 | 7 | .DS_Store 8 | # Log file 9 | *.log 10 | 11 | # BlueJ files 12 | *.ctxt 13 | 14 | # Mobile Tools for Java (J2ME) 15 | .mtj.tmp/ 16 | 17 | # Package Files # 18 | *.jar 19 | *.war 20 | *.nar 21 | *.ear 22 | *.zip 23 | *.tar.gz 24 | *.rar 25 | 26 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 27 | hs_err_pid* 28 | /target/ 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Thymeleaf UI Dialect 2 | Thymeleaf dialect to create interface components, provides a simple way to define reusable components and some html attributes to render user interface (html) components. 3 | 4 | See demo project: https://github.com/jpenren/thymeleaf-ui-dialect-demo 5 | 6 | Usage 7 | ----- 8 | 9 | Add the Maven dependency to your project: 10 | ```xml 11 | 12 | io.github.jpenren 13 | thymeleaf-ui-dialect 14 | 1.1.0 15 | 16 | ``` 17 | 18 | This library uses Spring Boot autoconfiguration feature, if required you can define this dialect manually: 19 | ```java 20 | templateEngine.addDialect(new UiDialect()); 21 | String theme = "default"; 22 | templateEngine.addTemplateResolver(new ComponentTemplateResolver(theme)); 23 | ``` 24 | 25 | Components 26 | ----- 27 | 28 | Enabling this dialect will introduce the `ui` namespace and a new set of attribute processors for available components: 29 | 30 | **Alert** 31 | 32 | Template: 33 | ```html 34 |
35 | ``` 36 | Output: 37 | ```html 38 | 44 | ``` 45 | 46 | **Badge** 47 | 48 | Template: 49 | ```html 50 | 51 | ``` 52 | Output: 53 | ```html 54 | value 55 | ``` 56 | Template: 57 | ```html 58 | 59 | ``` 60 | Output: 61 | ```html 62 | value 63 | ``` 64 | 65 | **Breadcrumb** 66 | 67 | Template: 68 | ```html 69 |
70 | ``` 71 | Output: 72 | ```html 73 | 83 | ``` 84 | 85 | **Button** 86 | 87 | Template: 88 | ```html 89 | 90 | ``` 91 | Output: 92 | ```html 93 | 94 | ``` 95 | 96 | **Card** 97 | 98 | Template: 99 | ```html 100 |
101 | ``` 102 | Output: 103 | ```html 104 |
105 |
Header
106 | alt text 107 |
108 |
109 | 110 |
111 | ``` 112 | 113 | **Carousel** 114 | 115 | Template: 116 | ```html 117 |
118 | ``` 119 | Output: 120 | ```html 121 | 144 | ``` 145 | 146 | **Dropdown** 147 | 148 | Template: 149 | ```html 150 |
151 | ``` 152 | Output: 153 | ```html 154 | 163 | ``` 164 | 165 | **Figure** 166 | 167 | Template: 168 | ```html 169 |
170 | ``` 171 | Output: 172 | ```html 173 |
174 | 175 |
Caption text
176 |
177 | ``` 178 | 179 | **Navigation** 180 | 181 | Template: 182 | ```html 183 |
184 | ``` 185 | Output: 186 | ```html 187 | 195 | ``` 196 | 197 | **Navigation header** 198 | 199 | Template: 200 | ```html 201 | 202 | ``` 203 | Output: 204 | ```html 205 | 218 | ``` 219 | 220 | Example with Java code: 221 | ```Java 222 | import static io.github.thymeleaf.ui.Components.*; 223 | ... 224 | @ControllerAdvice 225 | public class UiControllerAdvice { 226 | 227 | @ModelAttribute 228 | public NavigationHeader addNavigationHeader() { 229 | NavigationHeader header = navigationHeader("#", "navheader", link("#", "text")); 230 | Dropdown dropdown = dropdown("toggle", "t1"); 231 | dropdown.add(link("#", "text")); 232 | dropdown.add(link("#", "text")); 233 | dropdown.divider(); 234 | dropdown.add(link("#", "text")); 235 | header.add(dropdown); 236 | 237 | return header; 238 | } 239 | } 240 | ``` 241 | Template: 242 | ```html 243 | 244 | ``` 245 | Output: 246 | ```html 247 | 272 | ``` 273 | 274 | **Sidebar** 275 | 276 | Template: 277 | ```html 278 | 279 | ``` 280 | Output: 281 | ```html 282 | 293 | ``` 294 | 295 | Exmple with Java code: 296 | ```Java 297 | import static io.github.thymeleaf.ui.Components.*; 298 | ... 299 | @ControllerAdvice 300 | public class UiControllerAdvice { 301 | 302 | @ModelAttribute 303 | public Sidebar addSidebar() { 304 | Sidebar sidebar = sidebar("Header", link("#", "text"), link("#", "text")); 305 | sidebar.add(submenu("Menu", link("#", "text"), link("#", "text"))); 306 | 307 | return sidebar; 308 | } 309 | } 310 | ``` 311 | Template 312 | ```html 313 | 314 | ``` 315 | Output: 316 | ```html 317 | 339 | ``` 340 | 341 | 342 | Create UI components in Java 343 | -------- 344 | 345 | Spring MVC @Controller: 346 | 347 | ```java 348 | import static io.github.thymeleaf.ui.Components.*; 349 | ... 350 | 351 | @GetMapping("/index") 352 | public String index(ModelMap model){ 353 | 354 | // Alert 355 | model.addAttribute("alert", alert("This is an alert")); 356 | 357 | //Badge 358 | model.addAttribute("badge", badge("4")); 359 | model.addAttribute("badge2", badge("5")); 360 | 361 | //Breadcrumb 362 | Breadcrumb breadcrumb = breadcrumb(location("/", "home"), location("/", "admin"), location("current-page")); 363 | model.addAttribute(breadcrumb); 364 | 365 | //Card 366 | Card card = card("http://[image-location]", "Image alt"); 367 | card.setHeader("Card header"); 368 | card.setTitle("Card title"); 369 | card.setText("Some quick example text"); 370 | card.addLink("#", "Launch"); 371 | model.addAttribute(card); 372 | 373 | //Carousel 374 | Carousel carousel = carousel("demoCarousel", slide("http://[img-location]"), slide("http://img-location")); 375 | carousel.setShowControls(true); 376 | carousel.setShowIndicators(true); 377 | model.addAttribute(carousel); 378 | 379 | //Dropdown 380 | Dropdown dropdown = dropdown("Toggle"); 381 | dropdown.add(link("#", "First Link")); 382 | dropdown.setHeader("My header"); 383 | model.addAttribute(dropdown); 384 | 385 | return "index"; 386 | } 387 | ``` 388 | 389 | Application html template: 390 | 391 | ```html 392 | 393 | 394 | 395 |
396 | 397 | 398 | 399 |
400 |
401 |
402 | 403 | 404 | ``` 405 | 406 | Note: the ui:render tag is able to render any Renderable object. Using ui:render="${alert}" produces the same output as ui:alert="${alert}" 407 | 408 | 409 | 410 | 411 | Themes 412 | -------- 413 | 414 | Any component has an html template with some Thymeleaf logic, these templates are located under `templates/ui/themes/[theme]/[class-name]-component.html`. 415 | 416 | The default theme is `default` based on Bootstrap 4. 417 | 418 | 419 | Custom components 420 | ------- 421 | 422 | Define your custom components just extending `io.github.thymeleaf.ui.Component` and create the html template, an example of a new component: 423 | 424 | ```java 425 | public class CustomComponent extends Component { 426 | private final String message; 427 | 428 | public CustomComponent(String message) { 429 | this.message = message; 430 | } 431 | 432 | public String getMessage() { 433 | return message; 434 | } 435 | } 436 | ``` 437 | 438 | Template file for this component `src/main/resources/templates/ui/themes/[theme]/custom-component-component.html`: 439 | ```html 440 |
441 | 442 |
443 | ``` 444 | 445 | Spring MVC @Controller 446 | 447 | ```java 448 | @GetMapping("/index") 449 | public String index(ModelMap model) { 450 | model.addAttribute(new CustomComponent("Hello world!")); 451 | 452 | return "index"; 453 | } 454 | ``` 455 | 456 | Application html template: 457 | 458 | ```html 459 | 460 | 461 | 462 |
463 | 464 | 465 | ``` 466 | -------------------------------------------------------------------------------- /doc/components.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpenren/thymeleaf-ui-dialect/10edac115bcf21b754975f729c955f43044ed7a8/doc/components.jpg -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | io.github.jpenren 6 | thymeleaf-ui-dialect 7 | 1.1.0 8 | 9 | Thymeleaf UI Dialect 10 | Thymeleaf dialect for reusable interface components 11 | https://github.com/jpenren/thymeleaf-ui-dialect 12 | 2019 13 | 14 | 15 | 16 | Apache License, Version 2.0 17 | https://www.apache.org/licenses/LICENSE-2.0.txt 18 | 19 | 20 | 21 | 22 | 23 | Javier Pena 24 | javiprendo@gmail.com 25 | https://github.com/jpenren 26 | 27 | 28 | 29 | 30 | scm:git:git://github.com/jpenren/thymeleaf-ui-dialect.git 31 | scm:git:git@github.com:jpenren/thymeleaf-ui-dialect.git 32 | git@github.com:jpenren/thymeleaf-ui-dialect.git 33 | 34 | 35 | 36 | UTF-8 37 | UTF-8 38 | 1.7 39 | 1.7 40 | 41 | 42 | 43 | 44 | 45 | org.apache.maven.plugins 46 | maven-source-plugin 47 | 3.0.1 48 | 49 | 50 | attach-sources 51 | 52 | jar 53 | 54 | 55 | 56 | 57 | 58 | org.apache.maven.plugins 59 | maven-javadoc-plugin 60 | 3.0.1 61 | 62 | 63 | attach-javadocs 64 | 65 | jar 66 | 67 | 68 | 69 | 70 | 71 | org.apache.maven.plugins 72 | maven-gpg-plugin 73 | 1.6 74 | 75 | 76 | sign-artifacts 77 | verify 78 | 79 | sign 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | org.springframework 90 | spring-context 91 | 4.0.0.RELEASE 92 | 93 | 94 | 95 | org.thymeleaf 96 | thymeleaf 97 | 3.0.0.RELEASE 98 | 99 | 100 | 101 | org.slf4j 102 | slf4j-api 103 | 1.7.25 104 | 105 | 106 | 107 | org.projectlombok 108 | lombok 109 | 1.18.4 110 | provided 111 | true 112 | 113 | 114 | 115 | javax.servlet 116 | javax.servlet-api 117 | 3.0.1 118 | provided 119 | 120 | 121 | 122 | junit 123 | junit 124 | 4.12 125 | test 126 | 127 | 128 | org.slf4j 129 | slf4j-simple 130 | 1.7.25 131 | test 132 | 133 | 134 | org.thymeleaf 135 | thymeleaf-spring4 136 | 3.0.0.RELEASE 137 | test 138 | 139 | 140 | 141 | 142 | -------------------------------------------------------------------------------- /src/main/java/io/github/thymeleaf/ui/Attrs.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.github.thymeleaf.ui; 18 | 19 | public final class Attrs { 20 | 21 | public static final String ID = "id"; 22 | public static final String CLASS ="class"; 23 | 24 | private Attrs() { 25 | // utilities 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/io/github/thymeleaf/ui/Component.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.github.thymeleaf.ui; 18 | 19 | import io.github.thymeleaf.ui.internal.Strings; 20 | import lombok.Getter; 21 | import lombok.Setter; 22 | 23 | /** 24 | * Any HTML element with template 25 | */ 26 | @Getter 27 | @Setter 28 | public abstract class Component extends Element implements Renderable { 29 | private static final String SUFFIX = "-component"; 30 | private String template = defaultTemplate(); 31 | 32 | // Default template name: ClassName to dash + '-component' 33 | private String defaultTemplate() { 34 | final String simpleName = getClass().getSimpleName(); 35 | final boolean isAnonimous = Strings.isEmpty(simpleName); 36 | final String className = isAnonimous ? getClass().getSuperclass().getSimpleName() : simpleName; 37 | 38 | return Strings.dash(className) + SUFFIX; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/io/github/thymeleaf/ui/Components.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.github.thymeleaf.ui; 18 | 19 | import io.github.thymeleaf.ui.components.Alert; 20 | import io.github.thymeleaf.ui.components.Badge; 21 | import io.github.thymeleaf.ui.components.Breadcrumb; 22 | import io.github.thymeleaf.ui.components.Button; 23 | import io.github.thymeleaf.ui.components.ButtonGroup; 24 | import io.github.thymeleaf.ui.components.Card; 25 | import io.github.thymeleaf.ui.components.Carousel; 26 | import io.github.thymeleaf.ui.components.Dropdown; 27 | import io.github.thymeleaf.ui.components.Figure; 28 | import io.github.thymeleaf.ui.components.Navigation; 29 | import io.github.thymeleaf.ui.components.NavigationHeader; 30 | import io.github.thymeleaf.ui.components.Sidebar; 31 | import io.github.thymeleaf.ui.components.Breadcrumb.Location; 32 | import io.github.thymeleaf.ui.components.Carousel.Slide; 33 | import io.github.thymeleaf.ui.components.Dropdown.Toggle; 34 | import io.github.thymeleaf.ui.components.Sidebar.Submenu; 35 | import io.github.thymeleaf.ui.elements.Image; 36 | import io.github.thymeleaf.ui.elements.Link; 37 | import io.github.thymeleaf.ui.internal.Strings; 38 | 39 | /** 40 | * A set of methods useful for create components. These methods can be used directly: 41 | * Components.alert(...), however, they read better if they 42 | * are referenced through static import: 43 | * 44 | *
 45 |  * import static io.github.thymeleaf.ui.Components.*;
 46 |  *    ...
 47 |  *    alert(...);
 48 |  * 
49 | * 50 | * @author jpenren 51 | * 52 | */ 53 | public final class Components { 54 | 55 | private Components() { 56 | // Utility 57 | } 58 | 59 | public static Alert alert(String message) { 60 | return new Alert(message); 61 | } 62 | 63 | public static Alert alertDismissible(String message) { 64 | Alert alert = new Alert(message); 65 | alert.setDismissible(true); 66 | return alert; 67 | } 68 | 69 | public static Badge badge(String text) { 70 | return new Badge(text); 71 | } 72 | 73 | public static Badge badge(String href, String text) { 74 | Badge badge = new Badge(text); 75 | badge.setHref(href); 76 | return badge; 77 | } 78 | 79 | public static Breadcrumb breadcrumb() { 80 | return new Breadcrumb(); 81 | } 82 | 83 | public static Breadcrumb breadcrumb(Location... locations) { 84 | Breadcrumb breadcrumb = new Breadcrumb(); 85 | breadcrumb.add(locations); 86 | return breadcrumb; 87 | } 88 | 89 | public static Location location(String text) { 90 | return new Location(text); 91 | } 92 | 93 | public static Location location(String href, String text) { 94 | return new Location(href, text); 95 | } 96 | 97 | public static Button button(String text) { 98 | return new Button(text); 99 | } 100 | 101 | public static Button button(String text, String type) { 102 | Button button = new Button(text); 103 | button.setType(type); 104 | return button; 105 | } 106 | 107 | public static Button buttonToggle(String text) { 108 | Button button = new Button(text); 109 | button.setToggle(true); 110 | return button; 111 | } 112 | 113 | public static Button buttonLink(String href, String text) { 114 | Button button = new Button(text); 115 | button.setHref(href); 116 | return button; 117 | } 118 | 119 | public static ButtonGroup buttonGroup() { 120 | return new ButtonGroup(); 121 | } 122 | 123 | public static ButtonGroup buttonGroup(String label) { 124 | ButtonGroup buttonGroup = new ButtonGroup(); 125 | buttonGroup.setLabel(label); 126 | return buttonGroup; 127 | } 128 | 129 | public static ButtonGroup buttonGroup(Button ... buttons) { 130 | return buttonGroup(Strings.EMPTY, buttons); 131 | } 132 | 133 | public static ButtonGroup buttonGroup(String label, Button ... buttons) { 134 | ButtonGroup buttonGroup = new ButtonGroup(); 135 | buttonGroup.setLabel(label); 136 | buttonGroup.add(buttons); 137 | return buttonGroup; 138 | } 139 | 140 | public static Card card() { 141 | return new Card(); 142 | } 143 | 144 | public static Card card(String src) { 145 | return card(src, null); 146 | } 147 | 148 | public static Card card(String src, String alt) { 149 | return new Card(image(src, alt)); 150 | } 151 | 152 | public static Carousel carousel() { 153 | return new Carousel(); 154 | } 155 | 156 | public static Carousel carousel(String id) { 157 | Carousel carousel = new Carousel(); 158 | carousel.setId(id); 159 | return carousel; 160 | } 161 | 162 | public static Carousel carousel(Slide ... slides) { 163 | return carousel(null, slides); 164 | } 165 | 166 | public static Carousel carousel(String id, Slide ... slides) { 167 | Carousel carousel = new Carousel(); 168 | carousel.setId(id); 169 | for (Slide slide : slides) { 170 | carousel.add(slide); 171 | } 172 | 173 | return carousel; 174 | } 175 | 176 | public static Slide slide(String src) { 177 | return new Slide(new Image(src)); 178 | } 179 | 180 | public static Slide slide(String src, String caption) { 181 | Slide slide = new Slide(new Image(src)); 182 | slide.setCaption(caption); 183 | return slide; 184 | } 185 | 186 | public static Dropdown dropdown(String text) { 187 | return dropdown(text, null); 188 | } 189 | 190 | public static Dropdown dropdown(String text, String toggleId) { 191 | Toggle toggle = new Toggle(text); 192 | toggle.setId(toggleId); 193 | return new Dropdown(toggle); 194 | } 195 | 196 | public static Figure figure(Image image) { 197 | return new Figure(image); 198 | } 199 | 200 | public static Figure figure(String src) { 201 | return new Figure(image(src)); 202 | } 203 | 204 | public static Figure figure(String src, String alt) { 205 | return new Figure(image(src, alt)); 206 | } 207 | 208 | public static Figure figure(String src, String alt, String title) { 209 | return new Figure(image(src, alt, title)); 210 | } 211 | 212 | public static Navigation navigation() { 213 | return new Navigation(); 214 | } 215 | 216 | public static Navigation navigation(Link...links) { 217 | Navigation navigation = new Navigation(); 218 | navigation.add(links); 219 | return navigation; 220 | } 221 | 222 | public static NavigationHeader navigationHeader() { 223 | return new NavigationHeader(); 224 | } 225 | 226 | public static NavigationHeader navigationHeader(String href, String text) { 227 | return navigationHeader(href, text, new Link[0]); 228 | } 229 | 230 | public static NavigationHeader navigationHeader(Link... links) { 231 | NavigationHeader header = new NavigationHeader(); 232 | header.add(links); 233 | return header; 234 | } 235 | 236 | public static NavigationHeader navigationHeader(String href, String text, Link...links) { 237 | NavigationHeader navigationHeader = new NavigationHeader(); 238 | navigationHeader.setBrand(link(href, text)); 239 | if( links!=null ) { 240 | navigationHeader.add(links); 241 | } 242 | 243 | return navigationHeader; 244 | } 245 | 246 | public static Sidebar sidebar() { 247 | return new Sidebar(); 248 | } 249 | 250 | public static Sidebar sidebar(String header) { 251 | return sidebar(header, new Link[0]); 252 | } 253 | 254 | public static Sidebar sidebar(Link... links) { 255 | return sidebar(null, links); 256 | } 257 | 258 | public static Sidebar sidebar(String header, Link... links) { 259 | Sidebar sidebar = sidebar(); 260 | sidebar.setHeader(header); 261 | if(links!=null) { 262 | sidebar.add(links); 263 | } 264 | 265 | return sidebar; 266 | } 267 | 268 | public static Submenu submenu(String text, Link... links) { 269 | return submenu(text, "menu_"+System.currentTimeMillis(), null, links); 270 | } 271 | 272 | public static Submenu submenu(String text, String id, Link... links) { 273 | return submenu(text, id, null, links); 274 | } 275 | 276 | public static Submenu submenu(String text, String id, String className, Link... links) { 277 | Submenu submenu = new Submenu(text, id, links); 278 | submenu.setClassName(className); 279 | return submenu; 280 | } 281 | 282 | public static Link link(String href, String text) { 283 | return new Link(href, text); 284 | } 285 | 286 | public static Link link(String href, String text, String title) { 287 | Link link = new Link(href, text); 288 | link.setTitle(title); 289 | return link; 290 | } 291 | 292 | public static Link link(String href, String text, String title, String target) { 293 | return link(href, text, title, target, null); 294 | } 295 | 296 | public static Link link(String href, String text, String title, String target, String rel) { 297 | Link link = new Link(href, text); 298 | link.setTitle(title); 299 | link.setTarget(target); 300 | link.setRel(rel); 301 | return link; 302 | } 303 | 304 | public static Image image(String src) { 305 | return new Image(src); 306 | } 307 | 308 | public static Image image(String src, String alt) { 309 | return new Image(src, alt, null); 310 | } 311 | 312 | public static Image image(String src, String alt, String title) { 313 | return new Image(src, alt, title); 314 | } 315 | 316 | } 317 | -------------------------------------------------------------------------------- /src/main/java/io/github/thymeleaf/ui/Element.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.github.thymeleaf.ui; 18 | 19 | import javax.servlet.http.HttpServletRequest; 20 | 21 | import io.github.thymeleaf.ui.internal.Strings; 22 | import lombok.Getter; 23 | import lombok.Setter; 24 | 25 | /** 26 | * Base HTML element 27 | */ 28 | @Setter 29 | public abstract class Element implements HasHtmlAttributes, HasStatus { 30 | private @Getter String id; 31 | private @Getter String className; // html class attribute 32 | private boolean active; 33 | private boolean disabled; 34 | private boolean visible = true; 35 | 36 | public String getName() { 37 | final String simpleName = getClass().getSimpleName(); 38 | return Strings.isNotEmpty(simpleName) ? simpleName : getClass().getSuperclass().getSimpleName(); 39 | } 40 | 41 | @Override 42 | public boolean isActive(HttpServletRequest request) { 43 | return active; 44 | } 45 | 46 | @Override 47 | public boolean isDisabled(HttpServletRequest request) { 48 | return disabled; 49 | } 50 | 51 | @Override 52 | public boolean isVisible(HttpServletRequest request) { 53 | return visible; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/io/github/thymeleaf/ui/HasHtmlAttributes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.github.thymeleaf.ui; 18 | 19 | /** 20 | * Elements that can handle id attribute 21 | */ 22 | public interface HasHtmlAttributes { 23 | 24 | String getId(); 25 | 26 | void setId(String id); 27 | 28 | String getClassName(); 29 | 30 | void setClassName(String className); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/io/github/thymeleaf/ui/HasStatus.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.github.thymeleaf.ui; 18 | 19 | import javax.servlet.http.HttpServletRequest; 20 | 21 | public interface HasStatus { 22 | 23 | boolean isActive(HttpServletRequest request); 24 | 25 | boolean isDisabled(HttpServletRequest request); 26 | 27 | boolean isVisible(HttpServletRequest request); 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/io/github/thymeleaf/ui/Renderable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.github.thymeleaf.ui; 18 | 19 | public interface Renderable { 20 | 21 | String getTemplate(); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/io/github/thymeleaf/ui/components/Alert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.github.thymeleaf.ui.components; 18 | 19 | import io.github.thymeleaf.ui.Component; 20 | import lombok.Getter; 21 | import lombok.NoArgsConstructor; 22 | import lombok.Setter; 23 | 24 | @Getter 25 | @Setter 26 | @NoArgsConstructor 27 | public class Alert extends Component { 28 | private String message; 29 | private boolean dismissible; 30 | 31 | public Alert(String message) { 32 | this.message = message; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/io/github/thymeleaf/ui/components/Badge.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.github.thymeleaf.ui.components; 18 | 19 | import javax.servlet.http.HttpServletRequest; 20 | 21 | import io.github.thymeleaf.ui.Component; 22 | import io.github.thymeleaf.ui.internal.Strings; 23 | import io.github.thymeleaf.ui.internal.Urls; 24 | import lombok.Getter; 25 | import lombok.NoArgsConstructor; 26 | import lombok.Setter; 27 | 28 | @Setter 29 | @NoArgsConstructor 30 | public class Badge extends Component { 31 | private @Getter String text; 32 | private String href; 33 | 34 | public Badge(String text) { 35 | this.text = text; 36 | } 37 | 38 | public String getHref(HttpServletRequest request) { 39 | return Urls.resolve(href, request); 40 | } 41 | 42 | public boolean hasLink() { 43 | return Strings.isNotEmpty(href); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/io/github/thymeleaf/ui/components/Breadcrumb.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.github.thymeleaf.ui.components; 18 | 19 | import java.util.ArrayList; 20 | import java.util.Collections; 21 | import java.util.List; 22 | 23 | import javax.servlet.http.HttpServletRequest; 24 | 25 | import io.github.thymeleaf.ui.Component; 26 | import io.github.thymeleaf.ui.Element; 27 | import io.github.thymeleaf.ui.internal.Checks; 28 | import io.github.thymeleaf.ui.internal.Strings; 29 | import io.github.thymeleaf.ui.internal.Urls; 30 | import lombok.Getter; 31 | import lombok.RequiredArgsConstructor; 32 | 33 | public class Breadcrumb extends Component { 34 | private final List locations = new ArrayList<>(); 35 | 36 | public void add(Location... locations) { 37 | Checks.checkNotNullArgument(locations); 38 | for (Location location : locations) { 39 | this.locations.add(location); 40 | } 41 | } 42 | 43 | public void setLocations(List locations) { 44 | this.locations.addAll(locations); 45 | } 46 | 47 | public List getLocations() { 48 | return Collections.unmodifiableList(locations); 49 | } 50 | 51 | @RequiredArgsConstructor 52 | public static class Location extends Element { 53 | private final String href; 54 | private final @Getter String text; 55 | 56 | public Location(String text) { 57 | this.href = Strings.EMPTY; 58 | this.text = text; 59 | } 60 | 61 | public boolean hasLink() { 62 | return Strings.isNotEmpty(href); 63 | } 64 | 65 | public String getHref(HttpServletRequest request) { 66 | return Urls.resolve(href, request); 67 | } 68 | 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/io/github/thymeleaf/ui/components/Button.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.github.thymeleaf.ui.components; 18 | 19 | import javax.servlet.http.HttpServletRequest; 20 | 21 | import io.github.thymeleaf.ui.Component; 22 | import io.github.thymeleaf.ui.internal.Strings; 23 | import io.github.thymeleaf.ui.internal.Urls; 24 | import lombok.Getter; 25 | import lombok.NoArgsConstructor; 26 | import lombok.Setter; 27 | 28 | @Setter 29 | @NoArgsConstructor 30 | public class Button extends Component { 31 | public static final String DEFAULT_TYPE = "button"; 32 | private @Getter String text; 33 | private @Getter String type = DEFAULT_TYPE; // button, input, reset 34 | private @Getter boolean toggle; 35 | private String href; 36 | 37 | public Button(String text) { 38 | this.text = text; 39 | } 40 | 41 | public String getHref(HttpServletRequest request) { 42 | return Urls.resolve(href, request); 43 | } 44 | 45 | public boolean hasLink() { 46 | return Strings.isNotEmpty(href); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/io/github/thymeleaf/ui/components/ButtonGroup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.github.thymeleaf.ui.components; 18 | 19 | import java.util.ArrayList; 20 | import java.util.Collections; 21 | import java.util.List; 22 | 23 | import io.github.thymeleaf.ui.Component; 24 | import io.github.thymeleaf.ui.internal.Checks; 25 | import lombok.Getter; 26 | import lombok.Setter; 27 | 28 | @Getter 29 | @Setter 30 | public class ButtonGroup extends Component { 31 | private final List 6 | -------------------------------------------------------------------------------- /src/main/resources/templates/ui/themes/default/badge-component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/main/resources/templates/ui/themes/default/breadcrumb-component.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/templates/ui/themes/default/button-component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/main/resources/templates/ui/themes/default/button-group-component.html: -------------------------------------------------------------------------------- 1 |
2 | 3 |
-------------------------------------------------------------------------------- /src/main/resources/templates/ui/themes/default/card-component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | 4 |
5 |
[[*{title}]]
6 |
[[*{subtitle}]]
7 |

[[*{text}]]

8 | [[${link.text}]] 9 |
10 | 11 |
-------------------------------------------------------------------------------- /src/main/resources/templates/ui/themes/default/carousel-component.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/templates/ui/themes/default/dropdown-component.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/templates/ui/themes/default/figure-component.html: -------------------------------------------------------------------------------- 1 |
2 | 3 |
[[*{caption}]]
4 |
-------------------------------------------------------------------------------- /src/main/resources/templates/ui/themes/default/navigation-component.html: -------------------------------------------------------------------------------- 1 | 18 | -------------------------------------------------------------------------------- /src/main/resources/templates/ui/themes/default/navigation-header-component.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/templates/ui/themes/default/sidebar-component.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/test/java/io/github/thymeleaf/ui/ComponentsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.github.thymeleaf.ui; 18 | 19 | import static io.github.thymeleaf.ui.Components.alert; 20 | import static io.github.thymeleaf.ui.Components.alertDismissible; 21 | import static io.github.thymeleaf.ui.Components.badge; 22 | import static io.github.thymeleaf.ui.Components.breadcrumb; 23 | import static io.github.thymeleaf.ui.Components.button; 24 | import static io.github.thymeleaf.ui.Components.buttonGroup; 25 | import static io.github.thymeleaf.ui.Components.buttonToggle; 26 | import static io.github.thymeleaf.ui.Components.card; 27 | import static io.github.thymeleaf.ui.Components.carousel; 28 | import static io.github.thymeleaf.ui.Components.dropdown; 29 | import static io.github.thymeleaf.ui.Components.figure; 30 | import static io.github.thymeleaf.ui.Components.image; 31 | import static io.github.thymeleaf.ui.Components.link; 32 | import static io.github.thymeleaf.ui.Components.location; 33 | import static io.github.thymeleaf.ui.Components.navigation; 34 | import static io.github.thymeleaf.ui.Components.navigationHeader; 35 | import static io.github.thymeleaf.ui.Components.sidebar; 36 | import static io.github.thymeleaf.ui.Components.slide; 37 | 38 | import javax.servlet.http.HttpServletRequest; 39 | 40 | import org.junit.Test; 41 | 42 | import io.github.thymeleaf.ui.components.Alert; 43 | import io.github.thymeleaf.ui.components.Badge; 44 | import io.github.thymeleaf.ui.components.Breadcrumb; 45 | import io.github.thymeleaf.ui.components.Breadcrumb.Location; 46 | import io.github.thymeleaf.ui.components.Button; 47 | import io.github.thymeleaf.ui.components.ButtonGroup; 48 | import io.github.thymeleaf.ui.components.Card; 49 | import io.github.thymeleaf.ui.components.Carousel; 50 | import io.github.thymeleaf.ui.components.Dropdown; 51 | import io.github.thymeleaf.ui.components.Dropdown.Toggle; 52 | import io.github.thymeleaf.ui.components.Figure; 53 | import io.github.thymeleaf.ui.components.Navigation; 54 | import io.github.thymeleaf.ui.components.NavigationHeader; 55 | import io.github.thymeleaf.ui.components.Sidebar; 56 | import io.github.thymeleaf.ui.elements.Image; 57 | import io.github.thymeleaf.ui.elements.Link; 58 | 59 | public class ComponentsTest { 60 | 61 | @Test 62 | public void componentsApiTest() throws Exception { 63 | new Alert("text"); 64 | new Alert("Alert text").setDismissible(true); 65 | 66 | alert(""); 67 | alertDismissible(""); 68 | 69 | new Badge("3"); 70 | badge("3"); 71 | badge("#", "text"); 72 | 73 | Breadcrumb breadcrumb = new Breadcrumb(); 74 | breadcrumb.add(new Location("#", "text")); 75 | breadcrumb(location("text")); 76 | breadcrumb().add(location("#","text")); 77 | 78 | Button button = new Button("text"); 79 | button.setHref("#"); 80 | 81 | button("text"); 82 | button("text", "type"); 83 | buttonToggle("text"); 84 | 85 | new ButtonGroup(); 86 | new ButtonGroup().add(button("text")); 87 | new ButtonGroup().add(button("text"), button("text")); 88 | buttonGroup(); //.empty(); 89 | buttonGroup().add(button("text")); 90 | buttonGroup().add(button("text"), button("text")); 91 | buttonGroup(button("text")); 92 | buttonGroup(button("text"), button("text")); 93 | 94 | new Card(new Image("src")); 95 | card("src"); 96 | card("src", "alt"); 97 | Card card = card("src"); 98 | card.setHeader("h"); 99 | card.setTitle("t"); 100 | card.setSubtitle("s"); 101 | card.setText("t"); 102 | card.setFooter("f"); 103 | card.addLink("#", "text"); 104 | 105 | new Carousel(); 106 | carousel("id"); 107 | carousel(slide("src")); 108 | carousel(slide("src"), slide("src")); 109 | carousel("id", slide("src")); 110 | carousel("id").setShowControls(true); 111 | carousel("id").setShowIndicators(true); 112 | 113 | new Dropdown(new Toggle("")); 114 | dropdown("toggle"); 115 | dropdown("text"); 116 | dropdown("text", "id"); 117 | dropdown("text", "id").add(link("#", "text"), link("#", "text")); 118 | 119 | new Dropdown.Toggle("text"); 120 | Dropdown.Toggle.toggle("text"); 121 | Dropdown.Toggle.toggle("id", "text"); 122 | Dropdown.Toggle.toggle("id", "text", "className"); 123 | 124 | 125 | new Figure(new Image("src")); 126 | figure("src"); 127 | figure("src", "alt"); 128 | figure("src", "alt", "title"); 129 | 130 | new Navigation(); 131 | navigation(); 132 | navigation(link("#", "text")); 133 | 134 | new NavigationHeader(); 135 | new NavigationHeader().add(link("#", "text")); 136 | navigationHeader(); 137 | navigationHeader(link("#", "text")); 138 | navigationHeader("#", "text"); 139 | navigationHeader("#", "text", link("#", "text")); 140 | 141 | new Sidebar(); 142 | sidebar(); 143 | sidebar("header"); 144 | sidebar("header", link("#", "text")); 145 | sidebar(link("#", "text")); 146 | } 147 | 148 | @Test 149 | public void elementsApiTest() throws Exception { 150 | new Link("#", "Link"); 151 | link("#", "text", "title"); 152 | Link link = new Link("#", "Link"); 153 | link.setRel("rel"); 154 | link.setTarget("target"); 155 | new Link("#","Link") { 156 | @Override 157 | public boolean isActive(HttpServletRequest request) { 158 | return false; 159 | } 160 | @Override 161 | public boolean isDisabled(HttpServletRequest request) { 162 | return false; 163 | } 164 | @Override 165 | public boolean isVisible(HttpServletRequest request) { 166 | return true; 167 | } 168 | }; 169 | 170 | link("#", "Link"); 171 | link("#", "link", "title"); 172 | link("#", "Link", "Title", "target"); 173 | link("#", "Link", "Title", "target", "rel"); 174 | 175 | new Image("src"); 176 | image("src"); 177 | image("src", "alt"); 178 | image("src", "alt", "title"); 179 | } 180 | 181 | } 182 | -------------------------------------------------------------------------------- /src/test/java/io/github/thymeleaf/ui/dialect/DialectBenchmarkTest.java: -------------------------------------------------------------------------------- 1 | package io.github.thymeleaf.ui.dialect; 2 | 3 | import static io.github.thymeleaf.ui.Components.carousel; 4 | import static io.github.thymeleaf.ui.Components.dropdown; 5 | import static io.github.thymeleaf.ui.Components.link; 6 | import static io.github.thymeleaf.ui.Components.navigationHeader; 7 | import static io.github.thymeleaf.ui.Components.sidebar; 8 | import static io.github.thymeleaf.ui.Components.slide; 9 | import static io.github.thymeleaf.ui.Components.submenu; 10 | 11 | import org.junit.Test; 12 | import org.slf4j.Logger; 13 | import org.slf4j.LoggerFactory; 14 | import org.thymeleaf.context.Context; 15 | import org.thymeleaf.spring4.SpringTemplateEngine; 16 | import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver; 17 | 18 | import io.github.thymeleaf.ui.components.Alert; 19 | import io.github.thymeleaf.ui.components.Breadcrumb; 20 | import io.github.thymeleaf.ui.components.Card; 21 | import io.github.thymeleaf.ui.components.Dropdown; 22 | import io.github.thymeleaf.ui.components.Navigation; 23 | import io.github.thymeleaf.ui.components.NavigationHeader; 24 | import io.github.thymeleaf.ui.components.Sidebar; 25 | import io.github.thymeleaf.ui.elements.Link; 26 | import io.github.thymeleaf.ui.components.Breadcrumb.Location; 27 | 28 | public class DialectBenchmarkTest { 29 | 30 | private static final Logger LOGGER = LoggerFactory.getLogger(DialectBenchmarkTest.class); 31 | 32 | @Test 33 | // @Ignore 34 | public void benchmark() throws Exception { 35 | ClassLoaderTemplateResolver res = new ClassLoaderTemplateResolver(); 36 | res.setCacheable(false); 37 | SpringTemplateEngine engine = new SpringTemplateEngine(); 38 | engine.addTemplateResolver(res); 39 | 40 | UiDialect uiDialect = new UiDialect(); 41 | engine.addDialect(uiDialect); 42 | ComponentTemplateResolver uiTemplateResolver = new ComponentTemplateResolver("default"); 43 | uiTemplateResolver.setOrder(1); 44 | uiTemplateResolver.setCacheable(false); 45 | engine.addTemplateResolver(uiTemplateResolver); 46 | 47 | long startup = System.currentTimeMillis(); 48 | 49 | String html = null; 50 | for (int i = 0; i < 1; i++) { 51 | Context context = new Context(); 52 | 53 | Alert alert = new Alert("From java"); 54 | alert.setId("theid"); 55 | alert.setDismissible(true); 56 | context.setVariable("theAlert", alert); 57 | 58 | Card card = new Card(); 59 | card.setId("cardId"); 60 | card.setHeader("my header"); 61 | context.setVariable("theCard", card); 62 | 63 | Breadcrumb breadcrumb = new Breadcrumb(); 64 | breadcrumb.add(new Location("href","text")); 65 | context.setVariable("breadcrumb", breadcrumb); 66 | 67 | Navigation nav = new Navigation(); 68 | nav.add(new Link("href","alt")); 69 | nav.add(new Link("href","alt")); 70 | context.setVariable("nav", nav); 71 | 72 | NavigationHeader header = navigationHeader("#", "navheader", link("#", "link")); 73 | Dropdown dropdown = dropdown("tog", "t1"); 74 | dropdown.add(link("#", "Link")); 75 | dropdown.add(link("#", "Link2")); 76 | dropdown.divider(); 77 | dropdown.add(link("#", "Link")); 78 | header.add(dropdown); 79 | context.setVariable("navigationHeader", header); 80 | 81 | Sidebar sidebar = sidebar("Header", link("#", "link"), link("#", "link")); 82 | sidebar.add(submenu("Menu", link("#", "link"), link("#", "Link"))); 83 | context.setVariable("sidebar", sidebar); 84 | 85 | context.setVariable("msg", "Mensaje molón"); 86 | context.setVariable("carousel", carousel(slide("src", "caption text"), slide("src", "caption text"))); 87 | html = engine.process("/test.html", context); 88 | } 89 | 90 | LOGGER.info(html); 91 | 92 | LOGGER.info("time: " + (System.currentTimeMillis() - startup) + "ms"); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/test/resources/test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
7 | 8 |
9 | 10 |
11 | 12 | 13 | 14 |
15 | 16 |
17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 |
33 | 34 | 35 | 36 |
37 | 38 |
39 | 40 | 41 | 42 |
43 | 44 |
45 | 46 | 47 | 48 |
49 | 50 |
51 | 52 | 53 | 54 |
55 | 56 |
57 | 58 | 59 | 60 |
61 | 62 |
63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | --------------------------------------------------------------------------------