Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Update CSS DSL to fixed kotlin varargs. Make sure Kotlin is at least …

…0.4.491
  • Loading branch information...
commit e01458cdcf9b718bca71825bcd33f28ca8e1402c 1 parent dcf37be
Maxim Shafirov authored February 01, 2013
2  .idea/libraries/KotlinRuntime.xml
@@ -8,4 +8,4 @@
8 8
       <root url="jar://$PROJECT_DIR$/lib/kotlin-runtime.jar!/src" />
9 9
     </SOURCES>
10 10
   </library>
11  
-</component>
  11
+</component>
4  samples/KaraDemo/src/karademo/styles/DefaultStyles.kt
@@ -21,7 +21,7 @@ class DefaultStyles() : Stylesheet() {
21 21
             borderRadius = 5.px
22 22
         }
23 23
 
24  
-        forAny(array(input(att("type") equalTo "text"), textarea)) {
  24
+        forAny(input(att("type") equalTo "text"), textarea) {
25 25
             padding = box(4.px)
26 26
             width = 300.px
27 27
         }
@@ -37,7 +37,7 @@ class DefaultStyles() : Stylesheet() {
37 37
             td.c(cLabel) {
38 38
                 textAlign = TextAlign.right
39 39
             }
40  
-            td(array(cLabel, top)) {
  40
+            td(cLabel, top) {
41 41
                 verticalAlign = VerticalAlign.top
42 42
             }
43 43
         }
39  src/KaraLib/src/kara/styles/Element.kt
@@ -44,7 +44,7 @@ open class Element() {
44 44
 
45 45
     public inner class IdSelector(val name : String) : SelectorTrait, Selector {
46 46
         fun invoke(body : StyledElement.() -> Unit) {
47  
-            any.invoke(this, body)
  47
+            any.invoke(this, body = body)
48 48
         }
49 49
 
50 50
         override fun toExternalForm(): String {
@@ -54,33 +54,19 @@ open class Element() {
54 54
 
55 55
     public inner open class TagSelector(val name : String) : Selector {
56 56
         fun id(name: String) : Selector = invoke(IdSelector(name))
57  
-        fun id(name : String, body : StyledElement.() -> Unit) = invoke(IdSelector(name), body)
58  
-        fun id(id : IdSelector, body : StyledElement.() -> Unit) = invoke(id, body)
  57
+        fun id(name : String, body : StyledElement.() -> Unit) = id(IdSelector(name), body)
  58
+        fun id(id : IdSelector, body : StyledElement.() -> Unit) = invoke(id, body = body)
59 59
 
60  
-        // TODO: When KT-3300 is fixed, make klass a vararg to allow multiple clases
61  
-        fun c(klass : StyleClass, body : StyledElement.() -> Unit) {
62  
-            invoke(klass, body)
  60
+        fun c(vararg klass : StyleClass, body : StyledElement.() -> Unit) {
  61
+            invoke(*(klass as Array<SelectorTrait>), body = body)
63 62
         }
64  
-        fun c(klass : StyleClass) : Selector = invoke(klass)
  63
+        fun c(vararg klass : StyleClass) : Selector = invoke(*(klass as Array<SelectorTrait>))
65 64
 
66  
-        fun invoke(body : StyledElement.() -> Unit) {
67  
-            invoke(EmptyTrait, body)
68  
-        }
69  
-
70  
-        // TODO: varargs fail due to http://youtrack.jetbrains.com/issue/KT-3300
71  
-        fun invoke(traits : Array<SelectorTrait>, body : StyledElement.() -> Unit) {
  65
+        fun invoke(vararg traits : SelectorTrait, body : StyledElement.() -> Unit) {
72 66
             s(SimpleSelector(this, traits).toExternalForm(), body)
73 67
         }
74 68
 
75  
-        fun invoke(t: SelectorTrait, body : StyledElement.() -> Unit) {
76  
-            invoke(array(t), body)
77  
-        }
78  
-
79  
-        fun invoke(t: SelectorTrait) : Selector {
80  
-            return invoke(array(t))
81  
-        }
82  
-
83  
-        fun invoke(t: Array<SelectorTrait>) : Selector {
  69
+        fun invoke(vararg t: SelectorTrait) : Selector {
84 70
             return SimpleSelector(this, t)
85 71
         }
86 72
 
@@ -133,7 +119,7 @@ open class Element() {
133 119
     public fun id(name: String) : SelectorTrait = IdSelector(name)
134 120
 
135 121
     fun c(klass : StyleClass, body : StyledElement.() -> Unit) {
136  
-        any.invoke(klass, body)
  122
+        any.invoke(klass, body = body)
137 123
     }
138 124
 
139 125
     public fun att(name : String) : Attribute = Attribute(name, HasAttribute(name))
@@ -168,7 +154,7 @@ open class Element() {
168 154
         }
169 155
     }
170 156
 
171  
-    class SimpleSelector(val tag : TagSelector, val traits : Array<SelectorTrait>) : Selector {
  157
+    class SimpleSelector(val tag : TagSelector, val traits : Array<out SelectorTrait>) : Selector {
172 158
         override fun toExternalForm() : String {
173 159
             val answer = StringBuilder()
174 160
 
@@ -189,12 +175,11 @@ open class Element() {
189 175
         }
190 176
     }
191 177
 
192  
-    //TODO: vararg
193  
-    public fun forAny(selectors : Array<Selector>, body : StyledElement.() -> Unit) {
  178
+    public fun forAny(vararg selectors : Selector, body : StyledElement.() -> Unit) {
194 179
         s(UnionSelector(selectors).toExternalForm(), body)
195 180
     }
196 181
 
197  
-    public fun forAny(selectors : Array<Selector>) : UnionSelector {
  182
+    public fun forAny(vararg selectors : Selector) : UnionSelector {
198 183
         return UnionSelector(selectors)
199 184
     }
200 185
 
2  src/KaraLib/src/kara/views/ErrorView.kt
@@ -36,7 +36,7 @@ class ErrorLayout() : HtmlLayout() {
36 36
                         marginTop = 0.px
37 37
                     }
38 38
                 }
39  
-                any(array(id("actioninfo"), id("stacktrace"))) {
  39
+                any(id("actioninfo"), id("stacktrace")) {
40 40
                     padding = box(8.px, 12.px)
41 41
                     backgroundColor = c("#f0f0f0")
42 42
                     border = "1px solid #ccc"
8  src/KaraTests/src/karatests/styles/CSSSelectorsTest.kt
@@ -51,12 +51,12 @@ class SelectorsTest {
51 51
 
52 52
     Test fun tagWithClasses() {
53 53
         test("div.c1", {div.c(c1) })
54  
-        test("div.c1.c2", {div(array(c1, c2)) })
  54
+        test("div.c1.c2", {div(c1, c2) })
55 55
     }
56 56
 
57 57
     Test fun idWithClasses() {
58  
-        test("#id.c1", {any (array(id("id"), c1))})
59  
-        test("#id.c1.c2", {any(array(id("id"), c1, c2))})
  58
+        test("#id.c1", {any (id("id"), c1)})
  59
+        test("#id.c1.c2", {any(id("id"), c1, c2)})
60 60
     }
61 61
 
62 62
     Test fun attributeFilters() {
@@ -70,6 +70,6 @@ class SelectorsTest {
70 70
     }
71 71
 
72 72
     Test fun compositeSelector() {
73  
-        test("div#id,.c1", { forAny(array(div.id("id"), c1)) })
  73
+        test("div#id,.c1", { forAny(div.id("id"), c1) })
74 74
     }
75 75
 }

0 notes on commit e01458c

Please sign in to comment.
Something went wrong with that request. Please try again.