-
Notifications
You must be signed in to change notification settings - Fork 0
/
Style.scala
133 lines (100 loc) · 2.65 KB
/
Style.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package swebdsl.ui
class Style {
import scala.collection.mutable.Stack
val styles = new StringBuffer
var styleStack = new Stack[String]
var typeOfStyle = 'body
//var parent : Style = null
var css = new StringBuffer
private var codeStyle: Symbol = 'body
def >>(s: Style) = s
def header: Style = {
styleStack.push(".header")
this
}
def header(c: => Unit): Style = {
setSelector(".header", c)
this
}
def section() = {
styleStack.push(".section")
this
}
def section(c: => Unit): Style = {
setSelector(".header", c)
this
}
def navigate() = {
styleStack.push(".navigate")
this
}
def navigate(c: => Unit): Style = {
setSelector(".navigate", c)
this
}
def block(s: String) = {
styleStack.push("." + s)
this
}
def body() = {
styleStack.push("body")
this
}
def native(s: String)(c: => Unit) = {
setSelector(s, c)
this
}
def body(c: => Unit): Style = {
setSelector("body", c)
this
}
implicit def int2UnitInt(i: Int) = new UnitIntWrapper(i)
//
def setSelector(s: String, c: => Unit) = {
styleStack.push(s)
c
styles.append(styleStack.mkString(" ") + " { " + css + " } \n")
styleStack = new Stack[String]()
css = new StringBuffer
}
def fontsize: UnitInt = throw new IllegalAccessError("Cannot read property, only set")
def fontsize_=(i: UnitInt) {
setSpecificStyle("font-size: " + i + "; ")
}
def color: String = throw new IllegalAccessError("Cannot read property, only set")
def color_=(c: String) {
setSpecificStyle("color: " + c + "; ")
}
def bgcolor: String = throw new IllegalAccessError("Cannot read property, only set")
def bgcolor_=(c: String) {
setSpecificStyle("background-color: " + c + "; ")
}
def fontfamily: String = throw new IllegalAccessError("Cannot read property, only set")
def fontfamily_=(ff: String) {
setSpecificStyle("font-family: " + ff + "; ")
}
def width: UnitInt = throw new IllegalAccessError("Cannot read property, only set")
def width_=(w: UnitInt) {
setSpecificStyle("width: " + w + "; ")
}
def setSpecificStyle(css: String) {
this.css.append(css)
}
override def toString: String =
"<style>" + styles.toString + "</style>"
}
abstract class UnitInt
class UnitIntWrapper(i: Int) {
class PtUnitInt(i: Int) extends UnitInt {
override def toString = i + "pt"
}
class EmUnitInt(i: Int) extends UnitInt {
override def toString = i + "em"
}
class PercentUnitInt(i: Int) extends UnitInt {
override def toString = i + "%"
}
def pt = new PtUnitInt(i)
def em = new EmUnitInt(i)
def percent = new PercentUnitInt(i)
}