package nl.astraeus.tag import org.junit.Test /** * Created by rnentjes on 20-10-15. */ fun form(id: String, inline: Boolean = false): ContainerTag { val result = form().withId(id) if (inline) { result.withClass("form-online") } result.withMethod("post") return result } fun textInput(id: String, label: String = "", ph: String = "", value: String = ""): ContainerTag { val result = div().withClass("form-group") result.with(label(label).attr("for", id)) result.with(input() .withClass("form-control") .withType("text") .withId(id) .withName(id) .withValue(escape(value)) .withPlaceholder(ph) ) return result } class BasicTest { @Test fun basicTest() { val html = div().with( h1("Hello world!") ).with(hr()) assert(html.render() == "<div><h1>Hello world!</h1><hr/></div>") assert (html.render(pretty = true) == "<div>\n <h1>\n Hello world!\n </h1>\n <hr/>\n</div>") } @Test fun bsTest() { val form = form("form", inline = true) form.with(textInput("name", "Name", "Type your name here")) form.with(textInput("email", "Email", "Type your email here", "<test>")) println(form.render(pretty=true)) assert ( form.render(pretty = true) == """<form id="form" class="form-online" method="post"> <div class="form-group"> <label for="name"> Name </label> <input class="form-control" type="text" id="name" name="name" value="" placeholder="Type your name here"/> </div> <div class="form-group"> <label for="email"> Email </label> <input class="form-control" type="text" id="email" name="email" value="&#60;test&#62;" placeholder="Type your email here"/> </div> </form>""") val head = head() head.with(style().withType("text/css").withSrc("/res/css/bs.css")) val html = html().with(head).with(body().with(form)) println(html.render(pretty = true)) } }