Permalink
Browse files

Typesafe inline style for html tags

  • Loading branch information...
shafirov committed Mar 14, 2013
1 parent 49f09cf commit c17cec3d711a7362dc32f28c382b68d8844855a2
Showing with 18 additions and 1 deletion.
  1. +6 −1 samples/KaraDemo/src/karademo/views/home/Index.kt
  2. +12 −0 src/KaraLib/src/kara/views/BodyTags.kt
@@ -2,6 +2,7 @@ package karademo.views.home
import kara.views.*
import kara.views.InputType
+import kara.styles.Color
class Index() : HtmlView() {
@@ -17,7 +18,11 @@ class Index() : HtmlView() {
p("Unordered List")
ul {
for (i in 1..5) {
- li("List Item $i")
+ li("List Item $i") {
+ style {
+ backgroundColor = Color.fromRgb(200, 100, i * 50)
+ }
+ }
}
}
p("Ordered List")
@@ -9,6 +9,7 @@ import kara.views.FormMethod
import kara.views.InputType
import kara.views.Wrap
import kara.controllers.Link
+import kara.styles.StyledElement
val <T> empty_init : T.() -> Unit = {}
@@ -35,6 +36,17 @@ abstract class BodyTag(name : String, isEmpty : Boolean) : TagWithText(name, isE
this[Attributes.title] = value
}
+ fun style(init : StyledElement.()->Unit) {
+ val element = StyledElement("inline")
+ element.init()
+ val builder = StringBuilder()
+ for ((k, v) in element.attributes) {
+ builder.append("$k:$v;")
+ }
+
+ this["style"] = builder.toString()
+ }
+
// tags
fun a(c : StyleClass? = null, id : String? = null, text : String = "", href : Link? = null, target : String? = null, init : A.() -> Unit = empty_init) {
val tag = A()

0 comments on commit c17cec3

Please sign in to comment.