├── .circleci └── config.yml ├── .gitignore ├── LICENSE ├── README.md ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src ├── main └── kotlin │ └── org │ └── celtric │ └── kotlin │ └── html │ ├── _building_blocks.kt │ ├── a.kt │ ├── abbr.kt │ ├── address.kt │ ├── area.kt │ ├── article.kt │ ├── aside.kt │ ├── audio.kt │ ├── b.kt │ ├── bdi.kt │ ├── bdo.kt │ ├── blockquote.kt │ ├── body.kt │ ├── br.kt │ ├── button.kt │ ├── canvas.kt │ ├── caption.kt │ ├── cite.kt │ ├── code.kt │ ├── col.kt │ ├── colgroup.kt │ ├── data.kt │ ├── datalist.kt │ ├── dd.kt │ ├── del.kt │ ├── details.kt │ ├── dfn.kt │ ├── dialog.kt │ ├── div.kt │ ├── dl.kt │ ├── dt.kt │ ├── em.kt │ ├── embed.kt │ ├── fieldset.kt │ ├── figcaption.kt │ ├── figure.kt │ ├── footer.kt │ ├── form.kt │ ├── h1.kt │ ├── h2.kt │ ├── h3.kt │ ├── h4.kt │ ├── h5.kt │ ├── h6.kt │ ├── head.kt │ ├── header.kt │ ├── hr.kt │ ├── html.kt │ ├── i.kt │ ├── img.kt │ ├── input.kt │ ├── ins.kt │ ├── kbd.kt │ ├── label.kt │ ├── legend.kt │ ├── li.kt │ ├── link.kt │ ├── main.kt │ ├── map.kt │ ├── mark.kt │ ├── meta.kt │ ├── meter.kt │ ├── nav.kt │ ├── non_element_nodes.kt │ ├── noscript.kt │ ├── object.kt │ ├── ol.kt │ ├── optgroup.kt │ ├── option.kt │ ├── output.kt │ ├── p.kt │ ├── param.kt │ ├── picture.kt │ ├── pre.kt │ ├── progress.kt │ ├── q.kt │ ├── s.kt │ ├── samp.kt │ ├── script.kt │ ├── section.kt │ ├── select.kt │ ├── small.kt │ ├── source.kt │ ├── span.kt │ ├── strong.kt │ ├── style.kt │ ├── sub.kt │ ├── summary.kt │ ├── sup.kt │ ├── table.kt │ ├── tbody.kt │ ├── td.kt │ ├── template.kt │ ├── textarea.kt │ ├── tfoot.kt │ ├── th.kt │ ├── thead.kt │ ├── time.kt │ ├── title.kt │ ├── tr.kt │ ├── track.kt │ ├── u.kt │ ├── ul.kt │ ├── video.kt │ └── wbr.kt └── test └── kotlin └── org └── celtric └── kotlin └── html ├── AttributesTest.kt ├── DoctypeTest.kt ├── ElementContentTest.kt ├── ErrorsTest.kt ├── FullDocumentTest.kt ├── ListsTest.kt ├── RenderingOptionsTest.kt ├── TextTest.kt └── utils.kt /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | jobs: 3 | build: 4 | docker: 5 | - image: circleci/openjdk:8-jdk 6 | 7 | working_directory: ~/kotlin-html 8 | 9 | environment: 10 | JVM_OPTS: -Xmx3200m 11 | TERM: dumb 12 | 13 | steps: 14 | - checkout 15 | 16 | # Download and cache dependencies 17 | - restore_cache: 18 | keys: 19 | - v1-dependencies-{{ checksum "build.gradle" }} 20 | # fallback to using the latest cache if no exact match is found 21 | - v1-dependencies- 22 | 23 | - run: gradle dependencies 24 | 25 | - save_cache: 26 | paths: 27 | - ~/.gradle 28 | key: v1-dependencies-{{ checksum "build.gradle" }} 29 | 30 | # run tests 31 | - run: gradle test 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.gradle/ 2 | /.idea/ 3 | /build/ 4 | /out/ 5 | *.properties 6 | -------------------------------------------------------------------------------- /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 2015 David Åse 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 | [![CircleCI](https://img.shields.io/circleci/project/github/celtric/kotlin-html.svg)](https://circleci.com/gh/celtric/kotlin-html) 2 | [![License](https://img.shields.io/github/license/celtric/kotlin-html.svg)](https://github.com/celtric/kotlin-html/blob/master/LICENSE) 3 | [![Download](https://api.bintray.com/packages/celtric/maven/kotlin-html/images/download.svg)](https://bintray.com/celtric/maven/kotlin-html/_latestVersion) 4 | 5 | # kotlin-html 6 | 7 | _kotlin-html_ is a library to generate HTML in Kotlin. 8 | 9 | This library is heavily inspired by [kotlinx.html](https://github.com/Kotlin/kotlinx.html), but with a strong emphasis on context-independent composability. 10 | 11 | ## Getting started 12 | 13 | You can define HTML elements independently from an HTML document. The following code: 14 | 15 | ```kotlin 16 | p("A paragraph") 17 | ``` 18 | 19 | will render the following HTML when `.render()` is called: 20 | 21 | ```html 22 |

A paragraph

23 | ``` 24 | _Note: all HTML examples in this README are generated after calling `.render()` on the expression presented in Kotlin. It's encouraged that you keep the number `.render()` calls to the minimum and instead combine elements to increase your code's expressiveness._ 25 | 26 | ### Composability 27 | 28 | You can join any number of elements: 29 | 30 | ```kotlin 31 | p("First paragraph") + p("Second paragraph") 32 | ``` 33 | 34 | HTML: 35 | 36 | ```html 37 |

First paragraph

38 |

Second paragraph

39 | ``` 40 | 41 | You can also easily interact with list transformations: 42 | 43 | ```kotlin 44 | val people = listOf("Gael", "Laura", "Ricard") 45 | 46 | ul { people.map { li(it) } } 47 | ``` 48 | 49 | HTML: 50 | 51 | ```html 52 | 57 | ``` 58 | 59 | Working with functions is also straightforward: 60 | 61 | ```kotlin 62 | ul { numbers() } 63 | 64 | fun numbers() = li("One") + li("Two") + li("Three") 65 | ``` 66 | 67 | HTML: 68 | 69 | ```html 70 | 75 | ``` 76 | 77 | ### Attributes 78 | 79 | Attributes are optional. If you wish to define them, you must use a block for the content: 80 | 81 | ```kotlin 82 | p("A paragraph") // Text-only element, cannot contain attributes 83 | p { "A paragraph" } // Equivalent to previous line 84 | p(classes = "a-class") { "A paragraph" } // Same paragraph with "a-class" class 85 | ``` 86 | 87 | HTML 88 | 89 | ```html 90 |

A paragraph

91 |

A paragraph

92 |

A paragraph

93 | ``` 94 | 95 | Each element offers some relevant attributes depending on its tag: 96 | 97 | ```kotlin 98 | a(href = "http://www.example.com/", target = "_blank") { "A link" } 99 | img(src = "/img/logo.png", alt = "Our site") 100 | ``` 101 | 102 | HTML 103 | 104 | ```html 105 | A link 106 | Our site 107 | ``` 108 | 109 | In case you wish to define other attributes you can do so using `other`: 110 | 111 | ```kotlin 112 | div(other = mapOf("key" to "value")) { "Content" } 113 | ``` 114 | 115 | HTML 116 | 117 | ```html 118 |
Content
119 | ``` 120 | 121 | Custom data attributes are also supported: 122 | 123 | ```kotlin 124 | div(data = mapOf("user" to "celtric")) { "Content" } 125 | ``` 126 | 127 | HTML 128 | 129 | ```html 130 |
Content
131 | ``` 132 | 133 | ### Text 134 | 135 | You can join elements and text: 136 | 137 | ```kotlin 138 | strong("Strongly") + " disagree" 139 | p(strong("Strongly") + " disagree") 140 | ``` 141 | 142 | HTML: 143 | 144 | ```html 145 | Strongly disagree 146 |

Strongly disagree

147 | ``` 148 | 149 | Due to a limitation in Kotlin's overloading capabilities, a native string cannot be the first element in a list: 150 | 151 | ```kotlin 152 | "foo" + strong("bar") // NOT allowed by Kotlin operator overloading 153 | text("foo") + strong("bar") // Valid Kotlin 154 | strong("foo") + "bar" // Valid Kotlin, as the native string is not the first element 155 | ``` 156 | 157 | ## Full example 158 | 159 | ```kotlin 160 | import org.celtric.kotlin.html.* 161 | 162 | fun main(args : Array) { 163 | val document = doctype("html") + html { 164 | head { 165 | title("Document title") + 166 | meta(charset = "utf-8") + 167 | link(href = "css/style.css", rel = "stylesheet") + 168 | script(type = "text/javascript", src = "js/script.js") 169 | } + 170 | body { 171 | div(classes = "container") { 172 | h1("A title") + 173 | p(classes = "introduction") { 174 | "A paragraph" 175 | } + 176 | ul { 177 | li(a("http://www.example.com/", "A link")) + 178 | li(a("http://www.example.com/", "A second link")) 179 | } 180 | } 181 | } 182 | } 183 | 184 | print(document.render()) 185 | } 186 | ``` 187 | 188 | HTML: 189 | 190 | ```html 191 | 192 | 193 | 194 | Document title 195 | 196 | 197 | 198 | 199 | 200 |
201 |

A title

202 |

A paragraph

203 | 207 |
208 | 209 | 210 | ``` 211 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext.kotlin_version = "1.2.21" 3 | ext.junit_version = "5.0.3" 4 | 5 | repositories { 6 | jcenter() 7 | } 8 | 9 | dependencies { 10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 11 | classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7" 12 | } 13 | } 14 | 15 | group "org.celtric.kotlin" 16 | version "0.1.4" 17 | 18 | apply plugin: "kotlin" 19 | apply plugin: "maven-publish" 20 | apply plugin: "com.jfrog.bintray" 21 | 22 | repositories { 23 | jcenter() 24 | } 25 | 26 | dependencies { 27 | compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" 28 | 29 | testCompile "org.junit.jupiter:junit-jupiter-api:$junit_version" 30 | testRuntime "org.junit.jupiter:junit-jupiter-engine:$junit_version" 31 | } 32 | 33 | compileKotlin { kotlinOptions.jvmTarget = "1.8" } 34 | compileTestKotlin { kotlinOptions.jvmTarget = "1.8" } 35 | 36 | task sourcesJar(type: Jar, dependsOn: classes) { 37 | classifier = "sources" 38 | from sourceSets.main.allSource 39 | } 40 | 41 | artifacts { 42 | archives sourcesJar 43 | } 44 | 45 | publishing { 46 | publications { 47 | mavenPublication(MavenPublication) { 48 | from components.java 49 | artifact sourcesJar 50 | } 51 | } 52 | } 53 | 54 | bintray { 55 | user = project.hasProperty("bintray.user") ? project.property("bintray.user") : null 56 | key = project.hasProperty("bintray.apikey") ? project.property("bintray.apikey") : null 57 | publications = ["mavenPublication"] 58 | 59 | pkg { 60 | repo = "maven" 61 | name = "kotlin-html" 62 | 63 | version { 64 | attributes = ["gradle-plugin": "com.use.less:com.use.less.gradle:gradle-useless-plugin"] 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/celtric/kotlin-html/70cd501bb534ad84f8c8c3a8f8fb18dddd7054e4/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Feb 13 19:36:36 CET 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-bin.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'kotlin-html' 2 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/_building_blocks.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | class HTMLException(message: String) : RuntimeException(message) 4 | 5 | data class RenderingOptions( 6 | val indentWith: String = " ", 7 | val indentLevel: Int = 0, 8 | val lineSeparator: String = System.lineSeparator()) { 9 | fun indent() = indentWith.repeat(indentLevel) 10 | fun nextLevel() = copy(indentLevel = indentLevel + 1) 11 | } 12 | 13 | private typealias Options = RenderingOptions 14 | 15 | //---[ Nodes ]--------------------------------------------------------------------------// 16 | 17 | sealed class Node { 18 | abstract fun render(opt: Options = Options()): String 19 | abstract fun isBlock(): Boolean 20 | operator fun plus(text: String): List = plus(Text(text)) 21 | operator fun plus(node: Node): List = listOf(this, node) 22 | operator fun plus(nodes: List): List = listOf(this) + nodes 23 | fun toList(): List = listOf(this) 24 | } 25 | 26 | class DocumentType(val type: String) : Node() { 27 | override fun render(opt: Options) = "${opt.indent()}${opt.lineSeparator}" 28 | override fun isBlock() = true 29 | } 30 | 31 | class Text(val content: String) : Node() { 32 | override fun render(opt: Options) = opt.indent() + content 33 | override fun isBlock() = false 34 | } 35 | 36 | // Due to Kotlin's function overloading limitations, we are forced to use Any for content and check for valid types at 37 | // runtime. 38 | // @see https://discuss.kotlinlang.org/t/overloaded-function-with-lambda-parameter-of-different-return-types/6053 39 | sealed class Element(val name: String, val _isBlock: Boolean, unvalidatedContent: Any, val attributes: AllAttributes) : Node() { 40 | 41 | val content = when { 42 | unvalidatedContent == Unit -> Text("") 43 | unvalidatedContent is String -> Text(unvalidatedContent) 44 | unvalidatedContent is Number -> Text(unvalidatedContent.toString()) 45 | unvalidatedContent is Node -> unvalidatedContent 46 | (unvalidatedContent is List<*> && (unvalidatedContent.isEmpty() || unvalidatedContent.first() is Node)) -> @Suppress("UNCHECKED_CAST") NodeList(unvalidatedContent as List) 47 | else -> throw HTMLException("Content must be String, Number, Node or List, ${contentType(unvalidatedContent)} given.") 48 | } 49 | 50 | override fun render(opt: Options): String { 51 | val renderedContent = 52 | if (content.isBlock()) "${opt.lineSeparator}${content.render(opt.nextLevel())}${opt.indent()}" 53 | else content.render() 54 | 55 | return "${opt.indent()}<$name${attributes.render()}>$renderedContent" + if (isBlock()) opt.lineSeparator else "" 56 | } 57 | 58 | override fun isBlock() = _isBlock 59 | 60 | private fun contentType(content: Any): String = when { 61 | content !is Collection<*> -> content.javaClass.simpleName 62 | content.isEmpty() -> "${content.javaClass.simpleName}" 63 | content.first() is Collection<*> -> "${content.javaClass.simpleName}<${contentType(content.first()!!)}>" 64 | else -> "${content.javaClass.simpleName}<${content.first()!!.javaClass.simpleName}>" 65 | } 66 | } 67 | 68 | class BlockElement(name: String, content: Any, attributes: AllAttributes) : Element(name, true, content, attributes) 69 | class InlineElement(name: String, content: Any, attributes: AllAttributes) : Element(name, false, content, attributes) 70 | 71 | sealed class EmptyElement(val name: String, val _isBlock: Boolean, val attributes: AllAttributes? = null) : Node() { 72 | override fun render(opt: Options) = 73 | "${opt.indent()}<$name${attributes?.render()?:""}>" + if (isBlock()) opt.lineSeparator else "" 74 | override fun isBlock() = _isBlock 75 | } 76 | 77 | class EmptyBlockElement(name: String, attributes: AllAttributes? = null) : EmptyElement(name, true, attributes) 78 | class EmptyInlineElement(name: String, attributes: AllAttributes? = null) : EmptyElement(name, false, attributes) 79 | 80 | //---[ Lists of nodes ]-----------------------------------------------------------------// 81 | 82 | private class NodeList(val nodes: List) : Node() { 83 | override fun render(opt: Options) = nodes.render(opt) 84 | override fun isBlock() = nodes.any { it.isBlock() } 85 | } 86 | 87 | fun List.render(opt: Options = Options()) = joinToString("") { 88 | it.render(opt) + if (!it.isBlock() && any { it.isBlock() }) "\n" else "" 89 | } 90 | 91 | operator fun List.plus(text: String): List = plus(Text(text)) 92 | 93 | //---[ Attributes ]---------------------------------------------------------------------// 94 | 95 | typealias Attributes = Map 96 | 97 | private fun Attributes.renderAttributes(prefix: String = "") = 98 | filter { it.value != null && it.value != false && it.value != "" } 99 | .map { Pair(it.key, if (it.value is Boolean) "" else "=\"${it.value}\"") } 100 | .joinToString("") { " " + prefix + it.first + it.second } 101 | 102 | class AllAttributes(val common: Attributes, val other: Attributes, val data: Attributes) { 103 | fun render() = common.renderAttributes() + other.renderAttributes() + data.renderAttributes("data-") 104 | } 105 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/a.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun a( 4 | // Mandatory 5 | href: String, 6 | 7 | // Optional 8 | rel: String? = null, 9 | target: String? = null, 10 | 11 | // Global 12 | classes: String? = null, 13 | id: String? = null, 14 | title: String? = null, 15 | 16 | // Custom 17 | other: Attributes = emptyMap(), 18 | data: Attributes = emptyMap(), 19 | 20 | // Content 21 | content: () -> Any 22 | ) = InlineElement("a", content(), AllAttributes(mapOf( 23 | "href" to href, 24 | "rel" to rel, 25 | "target" to target, 26 | "class" to classes, 27 | "id" to id, 28 | "title" to title 29 | ), other, data)) 30 | 31 | fun a(href: String, content: String) = a(href) { content } 32 | fun a(href: String, content: Node) = a(href) { content } 33 | fun a(href: String, content: List) = a(href) { content } 34 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/abbr.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun abbr( 4 | // Mandatory 5 | title: String, 6 | 7 | // Global 8 | classes: String? = null, 9 | id: String? = null, 10 | 11 | // Custom 12 | other: Attributes = emptyMap(), 13 | data: Attributes = emptyMap(), 14 | 15 | // Content 16 | content: () -> Any 17 | ) = InlineElement("abbr", content(), AllAttributes(mapOf( 18 | "title" to title, 19 | "class" to classes, 20 | "id" to id 21 | ), other, data)) 22 | 23 | fun abbr(title: String, content: String) = abbr(title) { content } 24 | fun abbr(title: String, content: Node) = abbr(title) { content } 25 | fun abbr(title: String, content: List) = abbr(title) { content } 26 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/address.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun address( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | 8 | // Custom 9 | other: Attributes = emptyMap(), 10 | data: Attributes = emptyMap(), 11 | 12 | // Content 13 | content: () -> Any 14 | ) = BlockElement("address", content(), AllAttributes(mapOf( 15 | "class" to classes, 16 | "id" to id 17 | ), other, data)) 18 | 19 | fun address(content: String) = address { content } 20 | fun address(content: Node) = address { content } 21 | fun address(content: List) = address { content } 22 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/area.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | // TODO 4 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/article.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun article( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | 8 | // Custom 9 | other: Attributes = emptyMap(), 10 | data: Attributes = emptyMap(), 11 | 12 | // Content 13 | content: () -> Any 14 | ) = BlockElement("article", content(), AllAttributes(mapOf( 15 | "class" to classes, 16 | "id" to id 17 | ), other, data)) 18 | 19 | fun article(content: String) = article { content } 20 | fun article(content: Node) = article { content } 21 | fun article(content: List) = article { content } 22 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/aside.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun aside( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | 8 | // Custom 9 | other: Attributes = emptyMap(), 10 | data: Attributes = emptyMap(), 11 | 12 | // Content 13 | content: () -> Any 14 | ) = BlockElement("aside", content(), AllAttributes(mapOf( 15 | "class" to classes, 16 | "id" to id 17 | ), other, data)) 18 | 19 | fun aside(content: String) = aside { content } 20 | fun aside(content: Node) = aside { content } 21 | fun aside(content: List) = aside { content } 22 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/audio.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | // TODO 4 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/b.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun b( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | title: String? = null, 8 | 9 | // Custom 10 | other: Attributes = emptyMap(), 11 | data: Attributes = emptyMap(), 12 | 13 | // Content 14 | content: () -> Any 15 | ) = InlineElement("b", content(), AllAttributes(mapOf( 16 | "class" to classes, 17 | "id" to id, 18 | "title" to title 19 | ), other, data)) 20 | 21 | fun b(content: String) = b { content } 22 | fun b(content: Node) = b { content } 23 | fun b(content: List) = b { content } 24 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/bdi.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun bdi( 4 | // Optional 5 | dir: String? = null, 6 | 7 | // Global 8 | classes: String? = null, 9 | id: String? = null, 10 | title: String? = null, 11 | 12 | // Custom 13 | other: Attributes = emptyMap(), 14 | data: Attributes = emptyMap(), 15 | 16 | // Content 17 | content: () -> Any 18 | ) = InlineElement("bdi", content(), AllAttributes(mapOf( 19 | "dir" to dir, 20 | "class" to classes, 21 | "id" to id, 22 | "title" to title 23 | ), other, data)) 24 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/bdo.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun bdo( 4 | // Mandatory 5 | dir: String, 6 | 7 | // Global 8 | classes: String? = null, 9 | id: String? = null, 10 | title: String? = null, 11 | 12 | // Custom 13 | other: Attributes = emptyMap(), 14 | data: Attributes = emptyMap(), 15 | 16 | // Content 17 | content: () -> Any 18 | ) = InlineElement("bdo", content(), AllAttributes(mapOf( 19 | "dir" to dir, 20 | "class" to classes, 21 | "id" to id, 22 | "title" to title 23 | ), other, data)) 24 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/blockquote.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun blockquote( 4 | // Optional 5 | cite: String? = null, 6 | 7 | // Global 8 | classes: String? = null, 9 | id: String? = null, 10 | 11 | // Custom 12 | other: Attributes = emptyMap(), 13 | data: Attributes = emptyMap(), 14 | 15 | // Content 16 | content: () -> Any 17 | ) = BlockElement("blockquote", content(), AllAttributes(mapOf( 18 | "cite" to cite, 19 | "class" to classes, 20 | "id" to id 21 | ), other, data)) 22 | 23 | fun blockquote(content: String) = blockquote { content } 24 | fun blockquote(content: Node) = blockquote { content } 25 | fun blockquote(content: List) = blockquote { content } 26 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/body.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun body( 4 | // Optional 5 | lang: String? = null, 6 | 7 | // Global 8 | classes: String? = null, 9 | 10 | // Custom 11 | other: Attributes = emptyMap(), 12 | data: Attributes = emptyMap(), 13 | 14 | // Content 15 | content: () -> Any 16 | ) = BlockElement("body", content(), AllAttributes(mapOf( 17 | "class" to classes, 18 | "lang" to lang 19 | ), other, data)) 20 | 21 | fun body(content: String) = body { content } 22 | fun body(content: Node) = body { content } 23 | fun body(content: List) = body { content } 24 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/br.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun br() = EmptyBlockElement("br") 4 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/button.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun button( 4 | // Optional 5 | type: String? = null, 6 | name: String? = null, 7 | value: String? = null, 8 | disabled: Boolean = false, 9 | autofocus: Boolean = false, 10 | 11 | // Global 12 | classes: String? = null, 13 | id: String? = null, 14 | title: String? = null, 15 | 16 | // Custom 17 | other: Attributes = emptyMap(), 18 | data: Attributes = emptyMap(), 19 | 20 | // Content 21 | content: () -> Any 22 | ) = InlineElement("button", content(), AllAttributes(mapOf( 23 | "type" to type, 24 | "name" to name, 25 | "value" to value, 26 | "disabled" to disabled, 27 | "autofocus" to autofocus, 28 | "class" to classes, 29 | "id" to id, 30 | "title" to title 31 | ), other, data)) 32 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/canvas.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun canvas( 4 | // Mandatory 5 | width: Int, 6 | height: Int, 7 | 8 | // Global 9 | classes: String? = null, 10 | id: String? = null, 11 | 12 | // Custom 13 | other: Attributes = emptyMap(), 14 | data: Attributes = emptyMap(), 15 | 16 | // Content 17 | content: () -> Any 18 | ) = BlockElement("canvas", content(), AllAttributes(mapOf( 19 | "width" to width, 20 | "height" to height, 21 | "class" to classes, 22 | "id" to id 23 | ), other, data)) 24 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/caption.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun caption( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | 8 | // Custom 9 | other: Attributes = emptyMap(), 10 | data: Attributes = emptyMap(), 11 | 12 | // Content 13 | content: () -> Any 14 | ) = BlockElement("caption", content(), AllAttributes(mapOf( 15 | "class" to classes, 16 | "id" to id 17 | ), other, data)) 18 | 19 | fun caption(content: String) = caption { content } 20 | fun caption(content: Node) = caption { content } 21 | fun caption(content: List) = caption { content } 22 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/cite.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun cite( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | title: String? = null, 8 | 9 | // Custom 10 | other: Attributes = emptyMap(), 11 | data: Attributes = emptyMap(), 12 | 13 | // Content 14 | content: () -> Any 15 | ) = InlineElement("cite", content(), AllAttributes(mapOf( 16 | "class" to classes, 17 | "id" to id, 18 | "title" to title 19 | ), other, data)) 20 | 21 | fun cite(content: String) = cite { content } 22 | fun cite(content: Node) = cite { content } 23 | fun cite(content: List) = cite { content } 24 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/code.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun code( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | title: String? = null, 8 | 9 | // Custom 10 | other: Attributes = emptyMap(), 11 | data: Attributes = emptyMap(), 12 | 13 | // Content 14 | content: () -> Any 15 | ) = InlineElement("code", content(), AllAttributes(mapOf( 16 | "class" to classes, 17 | "id" to id, 18 | "title" to title 19 | ), other, data)) 20 | 21 | fun code(content: String) = code { content } 22 | fun code(content: Node) = code { content } 23 | fun code(content: List) = code { content } 24 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/col.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | // TODO 4 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/colgroup.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | // TODO 4 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/data.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun data( 4 | // Mandatory, 5 | value: String, 6 | 7 | // Global 8 | classes: String? = null, 9 | id: String? = null, 10 | title: String? = null, 11 | 12 | // Custom 13 | other: Attributes = emptyMap(), 14 | data: Attributes = emptyMap(), 15 | 16 | // Content 17 | content: () -> Any 18 | ) = InlineElement("data", content(), AllAttributes(mapOf( 19 | "value" to value, 20 | "class" to classes, 21 | "id" to id, 22 | "title" to title 23 | ), other, data)) 24 | 25 | fun data(value: String, content: String) = data(value) { content } 26 | fun data(value: String, content: Node) = data(value) { content } 27 | fun data(value: String, content: List) = data(value) { content } 28 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/datalist.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun datalist( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | 8 | // Custom 9 | other: Attributes = emptyMap(), 10 | data: Attributes = emptyMap(), 11 | 12 | // Content 13 | content: () -> Any 14 | ) = BlockElement("datalist", content(), AllAttributes(mapOf( 15 | "class" to classes, 16 | "id" to id 17 | ), other, data)) 18 | 19 | fun datalist(content: String) = datalist { content } 20 | fun datalist(content: Node) = datalist { content } 21 | fun datalist(content: List) = datalist { content } 22 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/dd.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun dd( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | 8 | // Custom 9 | other: Attributes = emptyMap(), 10 | data: Attributes = emptyMap(), 11 | 12 | // Content 13 | content: () -> Any 14 | ) = BlockElement("dd", content(), AllAttributes(mapOf( 15 | "class" to classes, 16 | "id" to id 17 | ), other, data)) 18 | 19 | fun dd(content: String) = dd { content } 20 | fun dd(content: Node) = dd { content } 21 | fun dd(content: List) = dd { content } 22 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/del.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun del( 4 | // Optional 5 | cite: String? = null, 6 | datetime: String? = null, 7 | 8 | // Global 9 | classes: String? = null, 10 | id: String? = null, 11 | title: String? = null, 12 | 13 | // Custom 14 | other: Attributes = emptyMap(), 15 | data: Attributes = emptyMap(), 16 | 17 | // Content 18 | content: () -> Any 19 | ) = InlineElement("del", content(), AllAttributes(mapOf( 20 | "cite" to cite, 21 | "datetime" to datetime, 22 | "class" to classes, 23 | "id" to id, 24 | "title" to title 25 | ), other, data)) 26 | 27 | fun del(content: String) = del { content } 28 | fun del(content: Node) = del { content } 29 | fun del(content: List) = del { content } 30 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/details.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun details( 4 | // Optional 5 | open: Boolean = false, 6 | 7 | // Global 8 | classes: String? = null, 9 | id: String? = null, 10 | 11 | // Custom 12 | other: Attributes = emptyMap(), 13 | data: Attributes = emptyMap(), 14 | 15 | // Content 16 | content: () -> Any 17 | ) = BlockElement("details", content(), AllAttributes(mapOf( 18 | "open" to open, 19 | "class" to classes, 20 | "id" to id 21 | ), other, data)) 22 | 23 | fun details(content: String) = details { content } 24 | fun details(content: Node) = details { content } 25 | fun details(content: List) = details { content } 26 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/dfn.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun dfn( 4 | // Optional 5 | title: String? = null, 6 | 7 | // Global 8 | classes: String? = null, 9 | id: String? = null, 10 | 11 | // Custom 12 | other: Attributes = emptyMap(), 13 | data: Attributes = emptyMap(), 14 | 15 | // Content 16 | content: () -> Any 17 | ) = InlineElement("dfn", content(), AllAttributes(mapOf( 18 | "title" to title, 19 | "class" to classes, 20 | "id" to id 21 | ), other, data)) 22 | 23 | fun dfn(content: String) = dfn { content } 24 | fun dfn(content: Node) = dfn { content } 25 | fun dfn(content: List) = dfn { content } 26 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/dialog.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun dialog( 4 | // Optional 5 | open: Boolean = false, 6 | 7 | // Global 8 | classes: String? = null, 9 | id: String? = null, 10 | 11 | // Custom 12 | other: Attributes = emptyMap(), 13 | data: Attributes = emptyMap(), 14 | 15 | // Content 16 | content: () -> Any 17 | ) = BlockElement("dialog", content(), AllAttributes(mapOf( 18 | "open" to open, 19 | "class" to classes, 20 | "id" to id 21 | ), other, data)) 22 | 23 | fun dialog(content: String) = dialog { content } 24 | fun dialog(content: Node) = dialog { content } 25 | fun dialog(content: List) = dialog { content } 26 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/div.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun div( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | 8 | // Custom 9 | other: Attributes = emptyMap(), 10 | data: Attributes = emptyMap(), 11 | 12 | // Content 13 | content: () -> Any 14 | ) = BlockElement("div", content(), AllAttributes(mapOf( 15 | "class" to classes, 16 | "id" to id 17 | ), other, data)) 18 | 19 | fun div(content: String) = div { content } 20 | fun div(content: Node) = div { content } 21 | fun div(content: List) = div { content } 22 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/dl.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun dl( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | 8 | // Custom 9 | other: Attributes = emptyMap(), 10 | data: Attributes = emptyMap(), 11 | 12 | // Content 13 | content: () -> Any 14 | ) = BlockElement("dl", content(), AllAttributes(mapOf( 15 | "class" to classes, 16 | "id" to id 17 | ), other, data)) 18 | 19 | fun dl(content: String) = dl { content } 20 | fun dl(content: Node) = dl { content } 21 | fun dl(content: List) = dl { content } 22 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/dt.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun dt( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | 8 | // Custom 9 | other: Attributes = emptyMap(), 10 | data: Attributes = emptyMap(), 11 | 12 | // Content 13 | content: () -> Any 14 | ) = BlockElement("dt", content(), AllAttributes(mapOf( 15 | "class" to classes, 16 | "id" to id 17 | ), other, data)) 18 | 19 | fun dt(content: String) = dt { content } 20 | fun dt(content: Node) = dt { content } 21 | fun dt(content: List) = dt { content } 22 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/em.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun em( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | title: String? = null, 8 | 9 | // Custom 10 | other: Attributes = emptyMap(), 11 | data: Attributes = emptyMap(), 12 | 13 | // Content 14 | content: () -> Any 15 | ) = InlineElement("em", content(), AllAttributes(mapOf( 16 | "class" to classes, 17 | "id" to id, 18 | "title" to title 19 | ), other, data)) 20 | 21 | fun em(content: String) = em { content } 22 | fun em(content: Node) = em { content } 23 | fun em(content: List) = em { content } 24 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/embed.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun embed( 4 | // Mandatory 5 | type: String, 6 | src: String, 7 | width: Int, 8 | height: Int, 9 | 10 | // Global 11 | classes: String? = null, 12 | id: String? = null, 13 | 14 | // Custom 15 | other: Attributes = emptyMap(), 16 | data: Attributes = emptyMap() 17 | ) = EmptyBlockElement("embed", AllAttributes(mapOf( 18 | "type" to type, 19 | "src" to src, 20 | "width" to width, 21 | "height" to height, 22 | "class" to classes, 23 | "id" to id 24 | ), other, data)) 25 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/fieldset.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun fieldset( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | 8 | // Custom 9 | other: Attributes = emptyMap(), 10 | data: Attributes = emptyMap(), 11 | 12 | // Content 13 | content: () -> Any 14 | ) = BlockElement("fieldset", content(), AllAttributes(mapOf( 15 | "class" to classes, 16 | "id" to id 17 | ), other, data)) 18 | 19 | fun fieldset(content: String) = fieldset { content } 20 | fun fieldset(content: Node) = fieldset { content } 21 | fun fieldset(content: List) = fieldset { content } 22 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/figcaption.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun figcaption( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | 8 | // Custom 9 | other: Attributes = emptyMap(), 10 | data: Attributes = emptyMap(), 11 | 12 | // Content 13 | content: () -> Any 14 | ) = BlockElement("figcaption", content(), AllAttributes(mapOf( 15 | "class" to classes, 16 | "id" to id 17 | ), other, data)) 18 | 19 | fun figcaption(content: String) = figcaption { content } 20 | fun figcaption(content: Node) = figcaption { content } 21 | fun figcaption(content: List) = figcaption { content } 22 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/figure.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun figure( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | 8 | // Custom 9 | other: Attributes = emptyMap(), 10 | data: Attributes = emptyMap(), 11 | 12 | // Content 13 | content: () -> Any 14 | ) = BlockElement("figure", content(), AllAttributes(mapOf( 15 | "class" to classes, 16 | "id" to id 17 | ), other, data)) 18 | 19 | fun figure(content: String) = figure { content } 20 | fun figure(content: Node) = figure { content } 21 | fun figure(content: List) = figure { content } 22 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/footer.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun footer( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | 8 | // Custom 9 | other: Attributes = emptyMap(), 10 | data: Attributes = emptyMap(), 11 | 12 | // Content 13 | content: () -> Any 14 | ) = BlockElement("footer", content(), AllAttributes(mapOf( 15 | "class" to classes, 16 | "id" to id 17 | ), other, data)) 18 | 19 | fun footer(content: String) = footer { content } 20 | fun footer(content: Node) = footer { content } 21 | fun footer(content: List) = footer { content } 22 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/form.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun form( 4 | // Optional 5 | action: String? = null, 6 | method: String? = null, 7 | acceptCharset: String? = null, 8 | autocomplete: String? = null, 9 | enctype: String? = null, 10 | name: String? = null, 11 | novalidate : Boolean = false, 12 | target: String? = null, 13 | 14 | // Global 15 | classes: String? = null, 16 | id: String? = null, 17 | 18 | // Custom 19 | other: Attributes = emptyMap(), 20 | data: Attributes = emptyMap(), 21 | 22 | // Content 23 | content: () -> Any 24 | ) = BlockElement("form", content(), AllAttributes(mapOf( 25 | "action" to action, 26 | "method" to method, 27 | "accept-charset" to acceptCharset, 28 | "autocomplete" to autocomplete, 29 | "enctype" to enctype, 30 | "name" to name, 31 | "novalidate " to novalidate , 32 | "target" to target, 33 | "class" to classes, 34 | "id" to id 35 | ), other, data)) 36 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/h1.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun h1( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | 8 | // Custom 9 | other: Attributes = emptyMap(), 10 | data: Attributes = emptyMap(), 11 | 12 | // Content 13 | content: () -> Any 14 | ) = BlockElement("h1", content(), AllAttributes(mapOf( 15 | "class" to classes, 16 | "id" to id 17 | ), other, data)) 18 | 19 | fun h1(content: String) = h1 { content } 20 | fun h1(content: Node) = h1 { content } 21 | fun h1(content: List) = h1 { content } 22 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/h2.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun h2( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | 8 | // Custom 9 | other: Attributes = emptyMap(), 10 | data: Attributes = emptyMap(), 11 | 12 | // Content 13 | content: () -> Any 14 | ) = BlockElement("h2", content(), AllAttributes(mapOf( 15 | "class" to classes, 16 | "id" to id 17 | ), other, data)) 18 | 19 | fun h2(content: String) = h2 { content } 20 | fun h2(content: Node) = h2 { content } 21 | fun h2(content: List) = h2 { content } 22 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/h3.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun h3( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | 8 | // Custom 9 | other: Attributes = emptyMap(), 10 | data: Attributes = emptyMap(), 11 | 12 | // Content 13 | content: () -> Any 14 | ) = BlockElement("h3", content(), AllAttributes(mapOf( 15 | "class" to classes, 16 | "id" to id 17 | ), other, data)) 18 | 19 | fun h3(content: String) = h3 { content } 20 | fun h3(content: Node) = h3 { content } 21 | fun h3(content: List) = h3 { content } 22 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/h4.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun h4( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | 8 | // Custom 9 | other: Attributes = emptyMap(), 10 | data: Attributes = emptyMap(), 11 | 12 | // Content 13 | content: () -> Any 14 | ) = BlockElement("h4", content(), AllAttributes(mapOf( 15 | "class" to classes, 16 | "id" to id 17 | ), other, data)) 18 | 19 | fun h4(content: String) = h4 { content } 20 | fun h4(content: Node) = h4 { content } 21 | fun h4(content: List) = h4 { content } 22 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/h5.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun h5( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | 8 | // Custom 9 | other: Attributes = emptyMap(), 10 | data: Attributes = emptyMap(), 11 | 12 | // Content 13 | content: () -> Any 14 | ) = BlockElement("h5", content(), AllAttributes(mapOf( 15 | "class" to classes, 16 | "id" to id 17 | ), other, data)) 18 | 19 | fun h5(content: String) = h5 { content } 20 | fun h5(content: Node) = h5 { content } 21 | fun h5(content: List) = h5 { content } 22 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/h6.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun h6( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | 8 | // Custom 9 | other: Attributes = emptyMap(), 10 | data: Attributes = emptyMap(), 11 | 12 | // Content 13 | content: () -> Any 14 | ) = BlockElement("h6", content(), AllAttributes(mapOf( 15 | "class" to classes, 16 | "id" to id 17 | ), other, data)) 18 | 19 | fun h6(content: String) = h6 { content } 20 | fun h6(content: Node) = h6 { content } 21 | fun h6(content: List) = h6 { content } 22 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/head.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun head( 4 | // Custom 5 | other: Attributes = emptyMap(), 6 | data: Attributes = emptyMap(), 7 | 8 | // Content 9 | content: () -> Any 10 | ) = BlockElement("head", content(), AllAttributes(emptyMap(), other, data)) 11 | 12 | fun head(content: String) = head { content } 13 | fun head(content: Node) = head { content } 14 | fun head(content: List) = head { content } 15 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/header.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun header( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | 8 | // Custom 9 | other: Attributes = emptyMap(), 10 | data: Attributes = emptyMap(), 11 | 12 | // Content 13 | content: () -> Any 14 | ) = BlockElement("header", content(), AllAttributes(mapOf( 15 | "class" to classes, 16 | "id" to id 17 | ), other, data)) 18 | 19 | fun header(content: String) = header { content } 20 | fun header(content: Node) = header { content } 21 | fun header(content: List) = header { content } 22 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/hr.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun hr( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | 8 | // Custom 9 | other: Attributes = emptyMap(), 10 | data: Attributes = emptyMap() 11 | ) = EmptyBlockElement("hr", AllAttributes(mapOf( 12 | "class" to classes, 13 | "id" to id 14 | ), other, data)) 15 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/html.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun html( 4 | // Optional 5 | xmlns: String? = null, 6 | 7 | // Global 8 | classes: String? = null, 9 | dir: String? = null, 10 | lang: String? = null, 11 | 12 | // Custom 13 | other: Attributes = emptyMap(), 14 | data: Attributes = emptyMap(), 15 | 16 | // Content 17 | content: () -> Any 18 | ) = BlockElement("html", content(), AllAttributes(mapOf( 19 | "xmlns" to xmlns, 20 | "class" to classes, 21 | "dir" to dir, 22 | "lang" to lang 23 | ), other, data)) 24 | 25 | fun html(content: String) = html { content } 26 | fun html(content: Node) = html { content } 27 | fun html(content: List) = html { content } 28 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/i.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun i( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | title: String? = null, 8 | 9 | // Custom 10 | other: Attributes = emptyMap(), 11 | data: Attributes = emptyMap(), 12 | 13 | // Content 14 | content: () -> Any 15 | ) = InlineElement("i", content(), AllAttributes(mapOf( 16 | "class" to classes, 17 | "id" to id, 18 | "title" to title 19 | ), other, data)) 20 | 21 | fun i(content: String) = i { content } 22 | fun i(content: Node) = i { content } 23 | fun i(content: List) = i { content } 24 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/img.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun img( 4 | // Mandatory 5 | src: String, 6 | alt: String, 7 | 8 | // Global 9 | classes: String? = null, 10 | id: String? = null, 11 | title: String? = null, 12 | 13 | // Custom 14 | other: Attributes = emptyMap(), 15 | data: Attributes = emptyMap() 16 | ) = EmptyInlineElement("img", AllAttributes(mapOf( 17 | "src" to src, 18 | "alt" to alt, 19 | "class" to classes, 20 | "id" to id, 21 | "title" to title 22 | ), other, data)) 23 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/input.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun input( 4 | // Mandatory 5 | type: String, 6 | 7 | // Optional 8 | accept: String? = null, 9 | autocomplete: String? = null, 10 | autofocus: Boolean = false, 11 | capture: Boolean = false, 12 | checked: Boolean = false, 13 | disabled: Boolean = false, 14 | list: String? = null, 15 | max: String? = null, 16 | maxlength: Int? = null, 17 | min: String? = null, 18 | minlength: Int? = null, 19 | multiple: Boolean = false, 20 | name: String? = null, 21 | pattern: String? = null, 22 | placeholder: String? = null, 23 | readonly: Boolean = false, 24 | required: Boolean = false, 25 | size: Int? = null, 26 | step: String? = null, 27 | value: String? = null, 28 | 29 | // Global 30 | classes: String? = null, 31 | id: String? = null, 32 | title: String? = null, 33 | 34 | // Custom 35 | other: Attributes = emptyMap(), 36 | data: Attributes = emptyMap() 37 | ) = EmptyBlockElement("input", AllAttributes(mapOf( 38 | "type" to type, 39 | "accept" to accept, 40 | "autocomplete" to autocomplete, 41 | "autofocus" to autofocus, 42 | "capture" to capture, 43 | "checked" to checked, 44 | "disabled" to disabled, 45 | "list" to list, 46 | "max" to max, 47 | "maxlength" to maxlength, 48 | "min" to min, 49 | "minlength" to minlength, 50 | "multiple" to multiple, 51 | "name" to name, 52 | "pattern" to pattern, 53 | "placeholder" to placeholder, 54 | "readonly" to readonly, 55 | "required" to required, 56 | "size" to size, 57 | "step" to step, 58 | "value" to value, 59 | "class" to classes, 60 | "id" to id, 61 | "title" to title 62 | ), other, data)) 63 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/ins.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun ins( 4 | // Optional 5 | cite: String? = null, 6 | datetime: String? = null, 7 | 8 | // Global 9 | classes: String? = null, 10 | id: String? = null, 11 | title: String? = null, 12 | 13 | // Custom 14 | other: Attributes = emptyMap(), 15 | data: Attributes = emptyMap(), 16 | 17 | // Content 18 | content: () -> Any 19 | ) = InlineElement("ins", content(), AllAttributes(mapOf( 20 | "cite" to cite, 21 | "datetime" to datetime, 22 | "class" to classes, 23 | "id" to id, 24 | "title" to title 25 | ), other, data)) 26 | 27 | fun ins(content: String) = ins { content } 28 | fun ins(content: Node) = ins { content } 29 | fun ins(content: List) = ins { content } 30 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/kbd.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun kbd( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | title: String? = null, 8 | 9 | // Custom 10 | other: Attributes = emptyMap(), 11 | data: Attributes = emptyMap(), 12 | 13 | // Content 14 | content: () -> Any 15 | ) = InlineElement("kbd", content(), AllAttributes(mapOf( 16 | "class" to classes, 17 | "id" to id, 18 | "title" to title 19 | ), other, data)) 20 | 21 | fun kbd(content: String) = kbd { content } 22 | fun kbd(content: Node) = kbd { content } 23 | fun kbd(content: List) = kbd { content } 24 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/label.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun label( 4 | // Optional 5 | `for`: String? = null, 6 | 7 | // Global 8 | classes: String? = null, 9 | id: String? = null, 10 | 11 | // Custom 12 | other: Attributes = emptyMap(), 13 | data: Attributes = emptyMap(), 14 | 15 | // Content 16 | content: () -> Any 17 | ) = BlockElement("label", content(), AllAttributes(mapOf( 18 | "for" to `for`, 19 | "class" to classes, 20 | "id" to id 21 | ), other, data)) 22 | 23 | fun label(content: String) = label { content } 24 | fun label(content: Node) = label { content } 25 | fun label(content: List) = label { content } 26 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/legend.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun legend( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | 8 | // Custom 9 | other: Attributes = emptyMap(), 10 | data: Attributes = emptyMap(), 11 | 12 | // Content 13 | content: () -> Any 14 | ) = BlockElement("legend", content(), AllAttributes(mapOf( 15 | "class" to classes, 16 | "id" to id 17 | ), other, data)) 18 | 19 | fun legend(content: String) = legend { content } 20 | fun legend(content: Node) = legend { content } 21 | fun legend(content: List) = legend { content } 22 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/li.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun li( 4 | // Optional 5 | value: String? = null, 6 | 7 | // Global 8 | classes: String? = null, 9 | id: String? = null, 10 | 11 | // Custom 12 | other: Attributes = emptyMap(), 13 | data: Attributes = emptyMap(), 14 | 15 | // Content 16 | content: () -> Any 17 | ) = BlockElement("li", content(), AllAttributes(mapOf( 18 | "value" to value, 19 | "class" to classes, 20 | "id" to id 21 | ), other, data)) 22 | 23 | fun li(content: String) = li { content } 24 | fun li(content: Node) = li { content } 25 | fun li(content: List) = li { content } 26 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/link.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun link( 4 | // Optional 5 | crossorigin: String? = null, 6 | href: String? = null, 7 | media: String? = null, 8 | rel: String? = null, 9 | sizes: String? = null, 10 | title: String? = null, 11 | type: String? = null, 12 | 13 | // Custom 14 | other: Attributes = emptyMap(), 15 | data: Attributes = emptyMap() 16 | ) = EmptyBlockElement("link", AllAttributes(mapOf( 17 | "crossorigin" to crossorigin, 18 | "href" to href, 19 | "media" to media, 20 | "rel" to rel, 21 | "sizes" to sizes, 22 | "title" to title, 23 | "type" to type 24 | ), other, data)) 25 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/main.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun main( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | 8 | // Custom 9 | other: Attributes = emptyMap(), 10 | data: Attributes = emptyMap(), 11 | 12 | // Content 13 | content: () -> Any 14 | ) = BlockElement("main", content(), AllAttributes(mapOf( 15 | "class" to classes, 16 | "id" to id 17 | ), other, data)) 18 | 19 | fun main(content: String) = main { content } 20 | fun main(content: Node) = main { content } 21 | fun main(content: List) = main { content } 22 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/map.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun map( 4 | // Optional 5 | name: String? = null, 6 | 7 | // Global 8 | classes: String? = null, 9 | id: String? = null, 10 | 11 | // Custom 12 | other: Attributes = emptyMap(), 13 | data: Attributes = emptyMap(), 14 | 15 | // Content 16 | content: () -> Any 17 | ) = BlockElement("map", content(), AllAttributes(mapOf( 18 | "name" to name, 19 | "class" to classes, 20 | "id" to id 21 | ), other, data)) 22 | 23 | fun map(content: String) = map { content } 24 | fun map(content: Node) = map { content } 25 | fun map(content: List) = map { content } 26 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/mark.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun mark( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | title: String? = null, 8 | 9 | // Custom 10 | other: Attributes = emptyMap(), 11 | data: Attributes = emptyMap(), 12 | 13 | // Content 14 | content: () -> Any 15 | ) = InlineElement("mark", content(), AllAttributes(mapOf( 16 | "class" to classes, 17 | "id" to id, 18 | "title" to title 19 | ), other, data)) 20 | 21 | fun mark(content: String) = mark { content } 22 | fun mark(content: Node) = mark { content } 23 | fun mark(content: List) = mark { content } 24 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/meta.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun meta( 4 | // Optional 5 | charset: String? = null, 6 | content: String? = null, 7 | httpEquiv: String? = null, 8 | name: String? = null, 9 | 10 | // Custom 11 | other: Attributes = emptyMap(), 12 | data: Attributes = emptyMap() 13 | ) = EmptyBlockElement("meta", AllAttributes(mapOf( 14 | "charset" to charset, 15 | "content" to content, 16 | "http-equiv" to httpEquiv, 17 | "name" to name 18 | ), other, data)) 19 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/meter.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | // TODO 4 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/nav.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun nav( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | 8 | // Custom 9 | other: Attributes = emptyMap(), 10 | data: Attributes = emptyMap(), 11 | 12 | // Content 13 | content: () -> Any 14 | ) = BlockElement("nav", content(), AllAttributes(mapOf( 15 | "class" to classes, 16 | "id" to id 17 | ), other, data)) 18 | 19 | fun nav(content: String) = nav { content } 20 | fun nav(content: Node) = nav { content } 21 | fun nav(content: List) = nav { content } 22 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/non_element_nodes.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun doctype(type: String) = DocumentType(type) 4 | fun text(content: String) = Text(content) 5 | fun text(content: () -> String) = Text(content()) 6 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/noscript.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun noscript( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | 8 | // Custom 9 | other: Attributes = emptyMap(), 10 | data: Attributes = emptyMap(), 11 | 12 | // Content 13 | content: () -> Any 14 | ) = BlockElement("noscript", content(), AllAttributes(mapOf( 15 | "class" to classes, 16 | "id" to id 17 | ), other, data)) 18 | 19 | fun noscript(content: String) = noscript { content } 20 | fun noscript(content: Node) = noscript { content } 21 | fun noscript(content: List) = noscript { content } 22 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/object.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | // TODO 4 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/ol.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun ol( 4 | // Optional 5 | type: String? = null, 6 | start: Int? = null, 7 | reversed: Boolean = false, 8 | 9 | // Global 10 | classes: String? = null, 11 | id: String? = null, 12 | 13 | // Custom 14 | other: Attributes = emptyMap(), 15 | data: Attributes = emptyMap(), 16 | 17 | // Mandatory 18 | content: () -> Any 19 | ) = BlockElement("ol", content(), AllAttributes(mapOf( 20 | "type" to type, 21 | "start" to start, 22 | "reversed" to reversed, 23 | "class" to classes, 24 | "id" to id 25 | ), other, data)) 26 | 27 | fun ol(content: String) = ol { content } 28 | fun ol(content: Node) = ol { content } 29 | fun ol(content: List) = ol { content } 30 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/optgroup.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun optgroup( 4 | // Mandatory 5 | label: String, 6 | 7 | // Optional 8 | disabled: Boolean = false, 9 | 10 | // Global 11 | classes: String? = null, 12 | id: String? = null, 13 | 14 | // Custom 15 | other: Attributes = emptyMap(), 16 | data: Attributes = emptyMap(), 17 | 18 | // Content 19 | content: () -> Any 20 | ) = BlockElement("optgroup", content(), AllAttributes(mapOf( 21 | "label" to label, 22 | "disabled" to disabled, 23 | "class" to classes, 24 | "id" to id 25 | ), other, data)) 26 | 27 | fun optgroup(label: String, content: String) = optgroup(label) { content } 28 | fun optgroup(label: String, content: Node) = optgroup(label) { content } 29 | fun optgroup(label: String, content: List) = optgroup(label) { content } 30 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/option.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun option( 4 | // Optional 5 | value: String? = null, 6 | label: String? = null, 7 | selected: Boolean = false, 8 | disabled: Boolean = false, 9 | 10 | // Global 11 | classes: String? = null, 12 | id: String? = null, 13 | 14 | // Custom 15 | other: Attributes = emptyMap(), 16 | data: Attributes = emptyMap(), 17 | 18 | // Content 19 | content: () -> Any 20 | ) = BlockElement("option", content(), AllAttributes(mapOf( 21 | "value" to value, 22 | "label" to label, 23 | "selected" to selected, 24 | "disabled" to disabled, 25 | "class" to classes, 26 | "id" to id 27 | ), other, data)) 28 | 29 | fun option(content: String) = option { content } 30 | fun option(content: Node) = option { content } 31 | fun option(content: List) = option { content } 32 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/output.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun output( 4 | // Optional 5 | name: String? = null, 6 | `for`: String? = null, 7 | 8 | // Global 9 | classes: String? = null, 10 | id: String? = null, 11 | title: String? = null, 12 | 13 | // Custom 14 | other: Attributes = emptyMap(), 15 | data: Attributes = emptyMap(), 16 | 17 | // Content 18 | content: () -> Any 19 | ) = InlineElement("output", content(), AllAttributes(mapOf( 20 | "name" to name, 21 | "for" to `for`, 22 | "class" to classes, 23 | "id" to id, 24 | "title" to title 25 | ), other, data)) 26 | 27 | fun output(content: String) = output { content } 28 | fun output(content: Node) = output { content } 29 | fun output(content: List) = output { content } 30 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/p.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun p( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | 8 | // Custom 9 | other: Attributes = emptyMap(), 10 | data: Attributes = emptyMap(), 11 | 12 | // Content 13 | content: () -> Any 14 | ) = BlockElement("p", content(), AllAttributes(mapOf( 15 | "class" to classes, 16 | "id" to id 17 | ), other, data)) 18 | 19 | fun p(content: String) = p { content } 20 | fun p(content: Node) = p { content } 21 | fun p(content: List) = p { content } 22 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/param.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun param( 4 | // Mandatory 5 | name: String, 6 | value: String, 7 | 8 | // Custom 9 | other: Attributes = emptyMap() 10 | ) = EmptyBlockElement("param", AllAttributes(mapOf( 11 | "name" to name, 12 | "value" to value 13 | ), other, emptyMap())) 14 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/picture.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun picture( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | 8 | // Custom 9 | other: Attributes = emptyMap(), 10 | data: Attributes = emptyMap(), 11 | 12 | // Content 13 | content: () -> Any 14 | ) = BlockElement("picture", content(), AllAttributes(mapOf( 15 | "class" to classes, 16 | "id" to id 17 | ), other, data)) 18 | 19 | fun picture(content: String) = picture { content } 20 | fun picture(content: Node) = picture { content } 21 | fun picture(content: List) = picture { content } 22 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/pre.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun pre( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | 8 | // Custom 9 | other: Attributes = emptyMap(), 10 | data: Attributes = emptyMap(), 11 | 12 | // Content 13 | content: () -> Any 14 | ) = BlockElement("pre", content(), AllAttributes(mapOf( 15 | "class" to classes, 16 | "id" to id 17 | ), other, data)) 18 | 19 | fun pre(content: String) = pre { content } 20 | fun pre(content: Node) = pre { content } 21 | fun pre(content: List) = pre { content } 22 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/progress.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun progress( 4 | // Mandatory 5 | value: String, 6 | max: String, 7 | 8 | // Custom 9 | other: Attributes = emptyMap() 10 | ) = EmptyBlockElement("progress", AllAttributes(mapOf( 11 | "value" to value, 12 | "max" to max 13 | ), other, emptyMap())) 14 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/q.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun q( 4 | // Optional 5 | cite: String? = null, 6 | 7 | // Global 8 | classes: String? = null, 9 | id: String? = null, 10 | 11 | // Custom 12 | other: Attributes = emptyMap(), 13 | data: Attributes = emptyMap(), 14 | 15 | // Content 16 | content: () -> Any 17 | ) = InlineElement("q", content(), AllAttributes(mapOf( 18 | "cite" to cite, 19 | "class" to classes, 20 | "id" to id 21 | ), other, data)) 22 | 23 | fun q(content: String) = q { content } 24 | fun q(content: Node) = q { content } 25 | fun q(content: List) = q { content } 26 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/s.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun s( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | title: String? = null, 8 | 9 | // Custom 10 | other: Attributes = emptyMap(), 11 | data: Attributes = emptyMap(), 12 | 13 | // Content 14 | content: () -> Any 15 | ) = InlineElement("s", content(), AllAttributes(mapOf( 16 | "class" to classes, 17 | "id" to id, 18 | "title" to title 19 | ), other, data)) 20 | 21 | fun s(content: String) = s { content } 22 | fun s(content: Node) = s { content } 23 | fun s(content: List) = s { content } 24 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/samp.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun samp( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | title: String? = null, 8 | 9 | // Custom 10 | other: Attributes = emptyMap(), 11 | data: Attributes = emptyMap(), 12 | 13 | // Content 14 | content: () -> Any 15 | ) = InlineElement("samp", content(), AllAttributes(mapOf( 16 | "class" to classes, 17 | "id" to id, 18 | "title" to title 19 | ), other, data)) 20 | 21 | fun samp(content: String) = samp { content } 22 | fun samp(content: Node) = samp { content } 23 | fun samp(content: List) = samp { content } 24 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/script.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun script( 4 | // Optional 5 | type: String? = null, 6 | src: String? = null, 7 | async: Boolean = false, 8 | crossorigin: String? = null, 9 | defer: Boolean = false, 10 | 11 | // Global 12 | classes: String? = null, 13 | id: String? = null, 14 | 15 | // Custom 16 | other: Attributes = emptyMap(), 17 | data: Attributes = emptyMap(), 18 | 19 | // Content 20 | content: () -> Any = {} 21 | ) = BlockElement("script", content(), AllAttributes(mapOf( 22 | "type" to type, 23 | "src" to src, 24 | "async" to async, 25 | "crossorigin" to crossorigin, 26 | "defer" to defer, 27 | "class" to classes, 28 | "id" to id 29 | ), other, data)) 30 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/section.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun section( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | 8 | // Custom 9 | other: Attributes = emptyMap(), 10 | data: Attributes = emptyMap(), 11 | 12 | // Content 13 | content: () -> Any 14 | ) = BlockElement("section", content(), AllAttributes(mapOf( 15 | "class" to classes, 16 | "id" to id 17 | ), other, data)) 18 | 19 | fun section(content: String) = section { content } 20 | fun section(content: Node) = section { content } 21 | fun section(content: List) = section { content } 22 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/select.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun select( 4 | // Optional 5 | autofocus: Boolean = false, 6 | disabled: Boolean = false, 7 | multiple: Boolean = false, 8 | name: String? = null, 9 | required: Boolean = false, 10 | size: Int? = null, 11 | 12 | // Global 13 | classes: String? = null, 14 | id: String? = null, 15 | 16 | // Custom 17 | other: Attributes = emptyMap(), 18 | data: Attributes = emptyMap(), 19 | 20 | // Content 21 | content: () -> Any 22 | ) = BlockElement("select", content(), AllAttributes(mapOf( 23 | "autofocus" to autofocus, 24 | "disabled" to disabled, 25 | "multiple" to multiple, 26 | "name" to name, 27 | "required" to required, 28 | "size" to size, 29 | "class" to classes, 30 | "id" to id 31 | ), other, data)) 32 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/small.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun small( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | title: String? = null, 8 | 9 | // Custom 10 | other: Attributes = emptyMap(), 11 | data: Attributes = emptyMap(), 12 | 13 | // Content 14 | content: () -> Any 15 | ) = InlineElement("small", content(), AllAttributes(mapOf( 16 | "class" to classes, 17 | "id" to id, 18 | "title" to title 19 | ), other, data)) 20 | 21 | fun small(content: String) = small { content } 22 | fun small(content: Node) = small { content } 23 | fun small(content: List) = small { content } 24 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/source.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | // TODO 4 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/span.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun span( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | title: String? = null, 8 | 9 | // Custom 10 | other: Attributes = emptyMap(), 11 | data: Attributes = emptyMap(), 12 | 13 | // Content 14 | content: () -> Any 15 | ) = InlineElement("span", content(), AllAttributes(mapOf( 16 | "class" to classes, 17 | "id" to id, 18 | "title" to title 19 | ), other, data)) 20 | 21 | fun span(content: String) = span { content } 22 | fun span(content: Node) = span { content } 23 | fun span(content: List) = span { content } 24 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/strong.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun strong( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | title: String? = null, 8 | 9 | // Custom 10 | other: Attributes = emptyMap(), 11 | data: Attributes = emptyMap(), 12 | 13 | // Content 14 | content: () -> Any 15 | ) = InlineElement("strong", content(), AllAttributes(mapOf( 16 | "class" to classes, 17 | "id" to id, 18 | "title" to title 19 | ), other, data)) 20 | 21 | fun strong(content: String) = strong { content } 22 | fun strong(content: Node) = strong { content } 23 | fun strong(content: List) = strong { content } 24 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/style.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun style( 4 | // Optional 5 | type: String? = null, 6 | media: String? = null, 7 | nonce: String? = null, 8 | title: String? = null, 9 | 10 | // Custom 11 | other: Attributes = emptyMap(), 12 | data: Attributes = emptyMap(), 13 | 14 | // Content 15 | content: () -> Any 16 | ) = BlockElement("style", content(), AllAttributes(mapOf( 17 | "type" to type, 18 | "media" to media, 19 | "nonce" to nonce, 20 | "title" to title 21 | ), other, data)) 22 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/sub.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun sub( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | title: String? = null, 8 | 9 | // Custom 10 | other: Attributes = emptyMap(), 11 | data: Attributes = emptyMap(), 12 | 13 | // Content 14 | content: () -> Any 15 | ) = InlineElement("sub", content(), AllAttributes(mapOf( 16 | "class" to classes, 17 | "id" to id, 18 | "title" to title 19 | ), other, data)) 20 | 21 | fun sub(content: String) = sub { content } 22 | fun sub(content: Node) = sub { content } 23 | fun sub(content: List) = sub { content } 24 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/summary.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun summary( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | 8 | // Custom 9 | other: Attributes = emptyMap(), 10 | data: Attributes = emptyMap(), 11 | 12 | // Content 13 | content: () -> Any 14 | ) = BlockElement("summary", content(), AllAttributes(mapOf( 15 | "class" to classes, 16 | "id" to id 17 | ), other, data)) 18 | 19 | fun summary(content: String) = summary { content } 20 | fun summary(content: Node) = summary { content } 21 | fun summary(content: List) = summary { content } 22 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/sup.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun sup( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | title: String? = null, 8 | 9 | // Custom 10 | other: Attributes = emptyMap(), 11 | data: Attributes = emptyMap(), 12 | 13 | // Content 14 | content: () -> Any 15 | ) = InlineElement("sup", content(), AllAttributes(mapOf( 16 | "class" to classes, 17 | "id" to id, 18 | "title" to title 19 | ), other, data)) 20 | 21 | fun sup(content: String) = sup { content } 22 | fun sup(content: Node) = sup { content } 23 | fun sup(content: List) = sup { content } 24 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/table.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun table( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | 8 | // Custom 9 | other: Attributes = emptyMap(), 10 | data: Attributes = emptyMap(), 11 | 12 | // Content 13 | content: () -> Any 14 | ) = BlockElement("table", content(), AllAttributes(mapOf( 15 | "class" to classes, 16 | "id" to id 17 | ), other, data)) 18 | 19 | fun table(content: String) = table { content } 20 | fun table(content: Node) = table { content } 21 | fun table(content: List) = table { content } 22 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/tbody.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun tbody( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | 8 | // Custom 9 | other: Attributes = emptyMap(), 10 | data: Attributes = emptyMap(), 11 | 12 | // Content 13 | content: () -> Any 14 | ) = BlockElement("tbody", content(), AllAttributes(mapOf( 15 | "class" to classes, 16 | "id" to id 17 | ), other, data)) 18 | 19 | fun tbody(content: String) = tbody { content } 20 | fun tbody(content: Node) = tbody { content } 21 | fun tbody(content: List) = tbody { content } 22 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/td.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun td( 4 | // Optional 5 | colspan: Int? = null, 6 | rowspan: Int? = null, 7 | 8 | // Global 9 | classes: String? = null, 10 | id: String? = null, 11 | title: String? = null, 12 | 13 | // Custom 14 | other: Attributes = emptyMap(), 15 | data: Attributes = emptyMap(), 16 | 17 | // Content 18 | content: () -> Any 19 | ) = BlockElement("td", content(), AllAttributes(mapOf( 20 | "colspan" to colspan, 21 | "rowspan" to rowspan, 22 | "class" to classes, 23 | "id" to id, 24 | "title" to title 25 | ), other, data)) 26 | 27 | fun td(content: String) = td { content } 28 | fun td(content: Node) = td { content } 29 | fun td(content: List) = td { content } 30 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/template.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun template( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | 8 | // Custom 9 | other: Attributes = emptyMap(), 10 | data: Attributes = emptyMap(), 11 | 12 | // Content 13 | content: () -> Any 14 | ) = BlockElement("template", content(), AllAttributes(mapOf( 15 | "class" to classes, 16 | "id" to id 17 | ), other, data)) 18 | 19 | fun template(content: String) = template { content } 20 | fun template(content: Node) = template { content } 21 | fun template(content: List) = template { content } 22 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/textarea.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun textarea( 4 | // Optional 5 | autofocus: Boolean = false, 6 | cols: Int? = null, 7 | disabled: Boolean = false, 8 | maxlength: Int? = null, 9 | minlength: Int? = null, 10 | name: String? = null, 11 | placeholder: String? = null, 12 | readonly: Boolean = false, 13 | required: Boolean = false, 14 | rows: Int? = null, 15 | spellcheck: Boolean = false, 16 | wrap: String? = null, 17 | 18 | // Global 19 | classes: String? = null, 20 | id: String? = null, 21 | 22 | // Custom 23 | other: Attributes = emptyMap(), 24 | data: Attributes = emptyMap(), 25 | 26 | // Content 27 | content: () -> Any 28 | ) = BlockElement("textarea", content(), AllAttributes(mapOf( 29 | "autofocus" to autofocus, 30 | "cols" to cols, 31 | "disabled" to disabled, 32 | "maxlength" to maxlength, 33 | "minlength" to minlength, 34 | "name" to name, 35 | "placeholder" to placeholder, 36 | "readonly" to readonly, 37 | "required" to required, 38 | "rows" to rows, 39 | "spellcheck" to spellcheck, 40 | "wrap" to wrap, 41 | "class" to classes, 42 | "id" to id 43 | ), other, data)) 44 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/tfoot.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun tfoot( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | 8 | // Custom 9 | other: Attributes = emptyMap(), 10 | data: Attributes = emptyMap(), 11 | 12 | // Content 13 | content: () -> Any 14 | ) = BlockElement("tfoot", content(), AllAttributes(mapOf( 15 | "class" to classes, 16 | "id" to id 17 | ), other, data)) 18 | 19 | fun tfoot(content: String) = tfoot { content } 20 | fun tfoot(content: Node) = tfoot { content } 21 | fun tfoot(content: List) = tfoot { content } 22 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/th.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun th( 4 | // Optional 5 | colspan: Int? = null, 6 | rowspan: Int? = null, 7 | 8 | // Global 9 | classes: String? = null, 10 | id: String? = null, 11 | title: String? = null, 12 | 13 | // Custom 14 | other: Attributes = emptyMap(), 15 | data: Attributes = emptyMap(), 16 | 17 | // Content 18 | content: () -> Any 19 | ) = BlockElement("th", content(), AllAttributes(mapOf( 20 | "colspan" to colspan, 21 | "rowspan" to rowspan, 22 | "class" to classes, 23 | "id" to id, 24 | "title" to title 25 | ), other, data)) 26 | 27 | fun th(content: String) = th { content } 28 | fun th(content: Node) = th { content } 29 | fun th(content: List) = th { content } 30 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/thead.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun thead( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | 8 | // Custom 9 | other: Attributes = emptyMap(), 10 | data: Attributes = emptyMap(), 11 | 12 | // Content 13 | content: () -> Any 14 | ) = BlockElement("thead", content(), AllAttributes(mapOf( 15 | "class" to classes, 16 | "id" to id 17 | ), other, data)) 18 | 19 | fun thead(content: String) = thead { content } 20 | fun thead(content: Node) = thead { content } 21 | fun thead(content: List) = thead { content } 22 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/time.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun time( 4 | // Optional 5 | datetime: String? = null, 6 | 7 | // Global 8 | classes: String? = null, 9 | id: String? = null, 10 | title: String? = null, 11 | 12 | // Custom 13 | other: Attributes = emptyMap(), 14 | data: Attributes = emptyMap(), 15 | 16 | // Content 17 | content: () -> Any 18 | ) = InlineElement("time", content(), AllAttributes(mapOf( 19 | "datetime" to datetime, 20 | "class" to classes, 21 | "id" to id, 22 | "title" to title 23 | ), other, data)) 24 | 25 | fun time(content: String) = time { content } 26 | fun time(content: Node) = time { content } 27 | fun time(content: List) = time { content } 28 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/title.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun title( 4 | // Custom 5 | other: Attributes = emptyMap(), 6 | data: Attributes = emptyMap(), 7 | 8 | // Content 9 | content: () -> String 10 | ) = BlockElement("title", Text(content()), AllAttributes(emptyMap(), other, data)) 11 | 12 | fun title(content: String) = title { content } 13 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/tr.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun tr( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | title: String? = null, 8 | 9 | // Custom 10 | other: Attributes = emptyMap(), 11 | data: Attributes = emptyMap(), 12 | 13 | // Content 14 | content: () -> Any 15 | ) = BlockElement("tr", content(), AllAttributes(mapOf( 16 | "class" to classes, 17 | "id" to id, 18 | "title" to title 19 | ), other, data)) 20 | 21 | fun tr(content: String) = tr { content } 22 | fun tr(content: Node) = tr { content } 23 | fun tr(content: List) = tr { content } 24 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/track.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | // TODO 4 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/u.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun u( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | title: String? = null, 8 | 9 | // Custom 10 | other: Attributes = emptyMap(), 11 | data: Attributes = emptyMap(), 12 | 13 | // Content 14 | content: () -> Any 15 | ) = InlineElement("u", content(), AllAttributes(mapOf( 16 | "class" to classes, 17 | "id" to id, 18 | "title" to title 19 | ), other, data)) 20 | 21 | fun u(content: String) = u { content } 22 | fun u(content: Node) = u { content } 23 | fun u(content: List) = u { content } 24 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/ul.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun ul( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | 8 | // Custom 9 | other: Attributes = emptyMap(), 10 | data: Attributes = emptyMap(), 11 | 12 | // Mandatory 13 | content: () -> Any 14 | ) = BlockElement("ul", content(), AllAttributes(mapOf( 15 | "class" to classes, 16 | "id" to id 17 | ), other, data)) 18 | 19 | fun ul(content: String) = ul { content } 20 | fun ul(content: Node) = ul { content } 21 | fun ul(content: List) = ul { content } 22 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/video.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | // TODO 4 | -------------------------------------------------------------------------------- /src/main/kotlin/org/celtric/kotlin/html/wbr.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | fun wbr( 4 | // Global 5 | classes: String? = null, 6 | id: String? = null, 7 | title: String? = null, 8 | 9 | // Custom 10 | other: Attributes = emptyMap(), 11 | data: Attributes = emptyMap(), 12 | 13 | // Content 14 | content: () -> Any 15 | ) = InlineElement("wbr", content(), AllAttributes(mapOf( 16 | "class" to classes, 17 | "id" to id, 18 | "title" to title 19 | ), other, data)) 20 | 21 | fun wbr(content: String) = wbr { content } 22 | fun wbr(content: Node) = wbr { content } 23 | fun wbr(content: List) = wbr { content } 24 | -------------------------------------------------------------------------------- /src/test/kotlin/org/celtric/kotlin/html/AttributesTest.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | import org.junit.jupiter.api.Test 4 | 5 | internal class AttributesTest { 6 | 7 | @Test fun global_attributes() { 8 | span(classes = "class1 class2", id = "unique-id", title = "A title") { "Content" } 9 | .assertRenders("""Content""") 10 | } 11 | 12 | @Test fun other_attributes() { 13 | span(other = mapOf("a" to "b", "c" to "d")) { "Content" } 14 | .assertRenders("""Content""") 15 | } 16 | 17 | @Test fun data_attributes() { 18 | span(data = mapOf("a" to "b", "c" to "d")) { "Content" } 19 | .assertRenders("""Content""") 20 | } 21 | 22 | @Test fun boolean_attributes() { 23 | span { "Content" } 24 | .assertRenders("Content") 25 | 26 | span(other = mapOf("foo" to false)) { "Content" } 27 | .assertRenders("Content") 28 | 29 | span(other = mapOf("foo" to true)) { "Content" } 30 | .assertRenders("Content") 31 | } 32 | 33 | @Test fun empty_attributes() { 34 | span(classes = "", other = mapOf(), data = mapOf()) {} 35 | .assertRenders("") 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/kotlin/org/celtric/kotlin/html/DoctypeTest.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | import org.junit.jupiter.api.Test 4 | 5 | internal class DoctypeTest { 6 | 7 | @Test fun doctype() { 8 | doctype("html").assertRenders("\n") 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/test/kotlin/org/celtric/kotlin/html/ElementContentTest.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | import org.junit.jupiter.api.Test 4 | 5 | internal class ElementContentTest { 6 | 7 | @Test fun `numbers are automatically cast to text`() { 8 | span { 1 }.assertRenders("1") 9 | span { 1L }.assertRenders("1") 10 | span { 1.0 }.assertRenders("1.0") 11 | span { 1.0f }.assertRenders("1.0") 12 | } 13 | 14 | @Test fun `content can be an empty list`() { 15 | span(emptyList()).assertRenders("") 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/test/kotlin/org/celtric/kotlin/html/ErrorsTest.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | import org.junit.jupiter.api.Assertions.* 4 | import org.junit.jupiter.api.Test 5 | 6 | internal class ErrorsTest { 7 | 8 | @Test fun `offers useful message when invalid content is passed`() { 9 | assertThrows(HTMLException::class.java, { span { listOf(listOf("Foo")) } }) 10 | .let { assertEquals("Content must be String, Number, Node or List, SingletonList> given.", it.message) } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/test/kotlin/org/celtric/kotlin/html/FullDocumentTest.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | import org.junit.jupiter.api.Test 4 | 5 | internal class FullDocumentTest { 6 | 7 | @Test fun full_document() { 8 | (doctype("html") + html { 9 | head { 10 | title("Document title") + 11 | meta(charset = "utf-8") + 12 | link(href = "css/style.css", rel = "stylesheet") + 13 | script(type = "text/javascript", src = "js/script.js") 14 | } + 15 | body { 16 | div(classes = "container") { 17 | h1("A title") + 18 | p(classes = "introduction") { 19 | "A paragraph" 20 | } + 21 | ul { 22 | li(a("http://www.example.com/", "A link")) + 23 | li(a("http://www.example.com/", "A second link")) 24 | } + 25 | span { "Inline element"} + 26 | div { "Block element"} 27 | } 28 | } 29 | }).assertRendersMultiline(""" 30 | 31 | 32 | 33 | Document title 34 | 35 | 36 | 37 | 38 | 39 |
40 |

A title

41 |

A paragraph

42 | 46 | Inline element 47 |
Block element
48 |
49 | 50 | 51 | """) 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/test/kotlin/org/celtric/kotlin/html/ListsTest.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | import org.junit.jupiter.api.Test 4 | 5 | internal class ListsTest { 6 | 7 | @Test fun list_of_nodes() { 8 | (p("foo") + p("bar")).assertRendersMultiline(""" 9 |

foo

10 |

bar

11 | """) 12 | } 13 | 14 | @Test fun from_list_transformation() { 15 | val people = listOf("Gael", "Laura", "Ricard") 16 | 17 | ul { 18 | people.map { li { it } } 19 | }.assertRendersMultiline(""" 20 |
    21 |
  • Gael
  • 22 |
  • Laura
  • 23 |
  • Ricard
  • 24 |
25 | """) 26 | } 27 | 28 | @Test fun from_list_transformations() { 29 | val people = listOf("Gael", "Laura", "Ricard") 30 | 31 | ul { 32 | people.map { li { people.map { em { it } } } } 33 | }.assertRendersMultiline(""" 34 |
    35 |
  • GaelLauraRicard
  • 36 |
  • GaelLauraRicard
  • 37 |
  • GaelLauraRicard
  • 38 |
39 | """) 40 | } 41 | 42 | @Test fun `the way lists are grouped when combined is irrelevant`() { 43 | val elem = li("Element") 44 | val reference = elem + elem + elem + elem 45 | 46 | ((elem) + (elem + elem + elem)).assertRendersSameAs(reference) 47 | ((elem + elem) + (elem + elem)).assertRendersSameAs(reference) 48 | ((elem + elem + elem) + (elem)).assertRendersSameAs(reference) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/test/kotlin/org/celtric/kotlin/html/RenderingOptionsTest.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | import org.junit.jupiter.api.Assertions.assertEquals 4 | import org.junit.jupiter.api.Test 5 | 6 | internal class RenderingOptionsTest { 7 | 8 | private val html = div(div(div("foo"))) 9 | 10 | @Test fun default_options() { 11 | val eol = System.lineSeparator() 12 | assertEquals("
$eol
$eol
foo
$eol
$eol
$eol", 13 | html.render()) 14 | } 15 | 16 | @Test fun custom_options() { 17 | assertEquals("..
#...
#....
foo
#...
#..
#", 18 | html.render(RenderingOptions(".", 2, "#"))) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/test/kotlin/org/celtric/kotlin/html/TextTest.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | import org.junit.jupiter.api.Test 4 | 5 | internal class TextTest { 6 | 7 | @Test fun single_text() { 8 | text("A text").assertRenders("A text") 9 | text { "A text" }.assertRenders("A text") 10 | } 11 | 12 | @Test fun composed_text() { 13 | (text("A") + " " + "text").assertRenders("A text") 14 | (text("A") + " " + text("text")).assertRenders("A text") 15 | (text("A") + text(" ") + "text").assertRenders("A text") 16 | (text("A") + text(" ") + text("text")).assertRenders("A text") 17 | } 18 | 19 | @Test fun text_inside_other_elements() { 20 | p("A text").assertRenders("

A text

\n") 21 | p(text("A text")).assertRenders("

A text

\n") 22 | p(text("A") + " " + "text").assertRenders("

A text

\n") 23 | } 24 | 25 | @Test fun indented_text_with_inline_elements() { 26 | p(text("First") + text("Second")).assertRenders("

FirstSecond

\n") 27 | } 28 | 29 | @Test fun indented_text_with_block_elements() { 30 | p(text("First") + br() + text("Second")).assertRendersMultiline(""" 31 |

32 | First 33 |
34 | Second 35 |

36 | """) 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/kotlin/org/celtric/kotlin/html/utils.kt: -------------------------------------------------------------------------------- 1 | package org.celtric.kotlin.html 2 | 3 | import org.junit.jupiter.api.Assertions 4 | 5 | val testRenderingOptions = RenderingOptions(lineSeparator = "\n") 6 | 7 | fun Node.assertRenders(expected: String) { 8 | toList().assertRenders(expected) 9 | } 10 | 11 | fun List.assertRenders(expected: String) { 12 | Assertions.assertEquals(expected, render(testRenderingOptions)) 13 | } 14 | 15 | fun Node.assertRendersMultiline(expected: String) { 16 | toList().assertRendersMultiline(expected) 17 | } 18 | 19 | fun List.assertRendersMultiline(expected: String) { 20 | Assertions.assertEquals(expected.trimIndent() + "\n", render(testRenderingOptions)) 21 | } 22 | 23 | fun List.assertRendersSameAs(other: List) { 24 | Assertions.assertEquals(other.render(testRenderingOptions), render(testRenderingOptions)) 25 | } 26 | --------------------------------------------------------------------------------