OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #import('dart:html'); | 5 #import('dart:html'); |
6 #import('css.dart'); | 6 #import('css.dart'); |
7 #import('../../frog/lang.dart', prefix:'lang'); | 7 #import('../lib/file_system_memory.dart'); |
8 #import('../../frog/file_system_memory.dart'); | |
9 | 8 |
10 void runCss([bool debug = false, bool parseOnly = false]) { | 9 void runCss([bool debug = false, bool parseOnly = false]) { |
11 final Document doc = window.document; | 10 final Document doc = window.document; |
12 final TextAreaElement classes = doc.query("#classes"); | 11 final TextAreaElement classes = doc.query("#classes"); |
13 final TextAreaElement expression = doc.query('#expression'); | 12 final TextAreaElement expression = doc.query('#expression'); |
14 final TableCellElement validity = doc.query('#validity'); | 13 final TableCellElement validity = doc.query('#validity'); |
15 final TableCellElement result = doc.query('#result'); | 14 final TableCellElement result = doc.query('#result'); |
16 | 15 |
17 List<String> knownWorld = classes.value.split("\n"); | 16 List<String> knownWorld = classes.value.split("\n"); |
18 List<String> knownClasses = []; | 17 List<String> knownClasses = []; |
(...skipping 13 matching lines...) Expand all Loading... |
32 String cssExpr = expression.value; | 31 String cssExpr = expression.value; |
33 if (!debug) { | 32 if (!debug) { |
34 try { | 33 try { |
35 cssParseAndValidate(cssExpr, cssWorld); | 34 cssParseAndValidate(cssExpr, cssWorld); |
36 } catch (final cssException) { | 35 } catch (final cssException) { |
37 templateValid = false; | 36 templateValid = false; |
38 dumpTree = cssException.toString(); | 37 dumpTree = cssException.toString(); |
39 } | 38 } |
40 } else if (parseOnly) { | 39 } else if (parseOnly) { |
41 try { | 40 try { |
42 Parser parser = new Parser(new lang.SourceFile( | 41 Parser parser = new Parser(new SourceFile( |
43 lang.SourceFile.IN_MEMORY_FILE, cssExpr)); | 42 SourceFile.IN_MEMORY_FILE, cssExpr)); |
44 Stylesheet stylesheet = parser.parse(); | 43 Stylesheet stylesheet = parser.parse(); |
45 StringBuffer stylesheetTree = new StringBuffer(); | 44 StringBuffer stylesheetTree = new StringBuffer(); |
46 String prettyStylesheet = stylesheet.toString(); | 45 String prettyStylesheet = stylesheet.toString(); |
47 stylesheetTree.add("${prettyStylesheet}\n"); | 46 stylesheetTree.add("${prettyStylesheet}\n"); |
48 stylesheetTree.add("\n============>Tree Dump<============\n"); | 47 stylesheetTree.add("\n============>Tree Dump<============\n"); |
49 stylesheetTree.add(stylesheet.toDebugString()); | 48 stylesheetTree.add(stylesheet.toDebugString()); |
50 dumpTree = stylesheetTree.toString(); | 49 dumpTree = stylesheetTree.toString(); |
51 } catch (final cssParseException) { | 50 } catch (final cssParseException) { |
52 templateValid = false; | 51 templateValid = false; |
53 dumpTree = cssParseException.toString(); | 52 dumpTree = cssParseException.toString(); |
54 } | 53 } |
55 } else { | 54 } else { |
56 try { | 55 try { |
57 dumpTree = cssParseAndValidateDebug(cssExpr, cssWorld); | 56 dumpTree = cssParseAndValidateDebug(cssExpr, cssWorld); |
58 } catch (final cssException) { | 57 } catch (final cssException) { |
59 templateValid = false; | 58 templateValid = false; |
60 dumpTree = cssException.toString(); | 59 dumpTree = cssException.toString(); |
61 } | 60 } |
62 } | 61 } |
63 | 62 |
64 final bgcolor = templateValid ? "white" : "red"; | 63 final bgcolor = templateValid ? "white" : "red"; |
65 final color = templateValid ? "black" : "white"; | 64 final color = templateValid ? "black" : "white"; |
66 final valid = templateValid ? "VALID" : "NOT VALID"; | 65 final valid = templateValid ? "VALID" : "NOT VALID"; |
67 String resultStyle = 'resize: none; margin: 0; height: 100%; width: 100%; padd
ing: 5px 7px;'; | 66 String resultStyle = "resize:none; margin:0; height:100%; width:100%;" |
68 String validityStyle = ''' | 67 "padding:5px 7px;"; |
69 font-weight: bold; background-color: $bgcolor; color: $color; border: 1px so
lid black; border-bottom: 0px solid white; | 68 String validityStyle = "font-weight:bold; background-color:$bgcolor;" |
70 '''; | 69 "color:$color; border:1px solid black; border-bottom:0px solid white;"; |
71 validity.innerHTML = ''' | 70 validity.innerHTML = ''' |
72 <div style="$validityStyle"> | 71 <div style="$validityStyle"> |
73 Expression: $cssExpr is $valid | 72 Expression: $cssExpr is $valid |
74 </div> | 73 </div> |
75 '''; | 74 '''; |
76 result.innerHTML = ''' | 75 result.innerHTML = "<textarea style=\"$resultStyle\">$dumpTree</textarea>"; |
77 <textarea style="$resultStyle">$dumpTree</textarea> | |
78 '''; | |
79 } | 76 } |
80 | 77 |
81 void main() { | 78 void main() { |
82 final element = new Element.tag('div'); | 79 final element = new Element.tag('div'); |
83 element.innerHTML = ''' | 80 element.innerHTML = ''' |
84 <table style="width: 100%; height: 100%;"> | 81 <table style="width: 100%; height: 100%;"> |
85 <tbody> | 82 <tbody> |
86 <tr> | 83 <tr> |
87 <td style="vertical-align: top; width: 200px;"> | 84 <td style="vertical-align: top; width: 200px;"> |
88 <table style="height: 100%;"> | 85 <table style="height: 100%;"> |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 </table> | 118 </table> |
122 </td> | 119 </td> |
123 </tr> | 120 </tr> |
124 | 121 |
125 <tr style="vertical-align: top; height: 50px;"> | 122 <tr style="vertical-align: top; height: 50px;"> |
126 <td> | 123 <td> |
127 <table> | 124 <table> |
128 <tbody> | 125 <tbody> |
129 <tr> | 126 <tr> |
130 <td> | 127 <td> |
131 <button onclick="runCss(true, true)">Parse</button> | 128 <button id=parse>Parse</button> |
132 </td> | 129 </td> |
133 <td> | 130 <td> |
134 <button onclick="runCss()">Check</button> | 131 <button id=check>Check</button> |
135 </td> | 132 </td> |
136 <td> | 133 <td> |
137 <button onclick="runCss(true)">Debug</button> | 134 <button id=debug>Debug</button> |
138 </td> | 135 </td> |
139 </tr> | 136 </tr> |
140 </tbody> | 137 </tbody> |
141 </table> | 138 </table> |
142 </td> | 139 </td> |
143 </tr> | 140 </tr> |
144 | 141 |
145 <tr style="vertical-align: top;"> | 142 <tr style="vertical-align: top;"> |
146 <td> | 143 <td> |
147 <table style="width: 100%; height: 100%;" border="0" cellpad
ding="0" cellspacing="0"> | 144 <table style="width: 100%; height: 100%;" border="0" cellpad
ding="0" cellspacing="0"> |
(...skipping 20 matching lines...) Expand all Loading... |
168 </table> | 165 </table> |
169 </td> | 166 </td> |
170 </tr> | 167 </tr> |
171 </tbody> | 168 </tbody> |
172 </table> | 169 </table> |
173 '''; | 170 '''; |
174 | 171 |
175 document.body.style.setProperty("background-color", "lightgray"); | 172 document.body.style.setProperty("background-color", "lightgray"); |
176 document.body.elements.add(element); | 173 document.body.elements.add(element); |
177 | 174 |
178 // TODO(terry): Needed so runCss isn't shakened out. | 175 ButtonElement parseButton = window.document.query('#parse'); |
179 if (false) { | 176 parseButton.on.click.add((MouseEvent e) { |
| 177 runCss(true, true); |
| 178 }); |
| 179 |
| 180 ButtonElement checkButton = window.document.query('#check'); |
| 181 checkButton.on.click.add((MouseEvent e) { |
180 runCss(); | 182 runCss(); |
181 } | 183 }); |
| 184 |
| 185 ButtonElement debugButton = window.document.query('#debug'); |
| 186 debugButton.on.click.add((MouseEvent e) { |
| 187 runCss(true); |
| 188 }); |
182 | 189 |
183 initCssWorld(false); | 190 initCssWorld(false); |
184 } | 191 } |
OLD | NEW |