| 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('../file_system.dart'); | 5 #import('dart:dom'); |
| 6 | |
| 7 #import("dart:dom"); | |
| 8 #import('css.dart'); | 6 #import('css.dart'); |
| 9 #import('../../frog/lang.dart', prefix:'lang'); | 7 #import('../../frog/lang.dart', prefix:'lang'); |
| 10 #import('../../frog/file_system_memory.dart'); | 8 #import('../../frog/file_system_memory.dart'); |
| 11 | 9 |
| 12 void runCss([bool debug = false, bool parseOnly = false]) { | 10 void runCss([bool debug = false, bool parseOnly = false]) { |
| 13 final HTMLTextAreaElement classes = document.getElementById('classes'); | 11 final HTMLTextAreaElement classes = document.getElementById('classes'); |
| 14 final HTMLTextAreaElement expression = document.getElementById('expression'); | 12 final HTMLTextAreaElement expression = document.getElementById('expression'); |
| 15 final HTMLDivElement result = document.getElementById('result'); | 13 final HTMLDivElement result = document.getElementById('result'); |
| 16 | 14 |
| 17 List<String> knownWorld = classes.value.split("\n"); | 15 List<String> knownWorld = classes.value.split("\n"); |
| 18 List<String> knownClasses = []; | 16 List<String> knownClasses = []; |
| 19 List<String> knownIds = []; | 17 List<String> knownIds = []; |
| 20 for (var name in knownWorld) { | 18 for (final name in knownWorld) { |
| 21 if (name.startsWith('.')) { | 19 if (name.startsWith('.')) { |
| 22 knownClasses.add(name.substring(1)); | 20 knownClasses.add(name.substring(1)); |
| 23 } else if (name.startsWith('#')) { | 21 } else if (name.startsWith('#')) { |
| 24 knownIds.add(name.substring(1)); | 22 knownIds.add(name.substring(1)); |
| 25 } | 23 } |
| 26 } | 24 } |
| 27 | 25 |
| 28 CssWorld cssWorld = new CssWorld(knownClasses, knownIds); | 26 CssWorld cssWorld = new CssWorld(knownClasses, knownIds); |
| 29 bool templateValid = true; | 27 bool templateValid = true; |
| 30 String dumpTree = ""; | 28 String dumpTree = ""; |
| 31 | 29 |
| 32 String cssExpr = expression.value; | 30 String cssExpr = expression.value; |
| 33 if (!debug) { | 31 if (!debug) { |
| 34 try { | 32 try { |
| 35 cssParseAndValidate(cssExpr, cssWorld); | 33 cssParseAndValidate(cssExpr, cssWorld); |
| 36 } catch (var cssException) { | 34 } catch (final cssException) { |
| 37 templateValid = false; | 35 templateValid = false; |
| 38 dumpTree = cssException.toString(); | 36 dumpTree = cssException.toString(); |
| 39 } | 37 } |
| 40 } else if (parseOnly) { | 38 } else if (parseOnly) { |
| 41 try { | 39 try { |
| 42 Parser parser = new Parser(new lang.SourceFile( | 40 Parser parser = new Parser(new lang.SourceFile( |
| 43 lang.SourceFile.IN_MEMORY_FILE, cssExpr)); | 41 lang.SourceFile.IN_MEMORY_FILE, cssExpr)); |
| 44 Stylesheet stylesheet = parser.parse(); | 42 Stylesheet stylesheet = parser.parse(); |
| 45 StringBuffer stylesheetTree = new StringBuffer(); | 43 StringBuffer stylesheetTree = new StringBuffer(); |
| 46 String prettyStylesheet = stylesheet.toString(); | 44 String prettyStylesheet = stylesheet.toString(); |
| 47 stylesheetTree.add("${prettyStylesheet}\n"); | 45 stylesheetTree.add("${prettyStylesheet}\n"); |
| 48 stylesheetTree.add("\n============>Tree Dump<============\n"); | 46 stylesheetTree.add("\n============>Tree Dump<============\n"); |
| 49 stylesheetTree.add(stylesheet.toDebugString()); | 47 stylesheetTree.add(stylesheet.toDebugString()); |
| 50 dumpTree = stylesheetTree.toString(); | 48 dumpTree = stylesheetTree.toString(); |
| 51 } catch (var cssParseException) { | 49 } catch (final cssParseException) { |
| 52 templateValid = false; | 50 templateValid = false; |
| 53 dumpTree = cssParseException.toString(); | 51 dumpTree = cssParseException.toString(); |
| 54 } | 52 } |
| 55 } else { | 53 } else { |
| 56 try { | 54 try { |
| 57 dumpTree = cssParseAndValidateDebug(cssExpr, cssWorld); | 55 dumpTree = cssParseAndValidateDebug(cssExpr, cssWorld); |
| 58 } catch (var cssException) { | 56 } catch (final cssException) { |
| 59 templateValid = false; | 57 templateValid = false; |
| 60 dumpTree = cssException.toString(); | 58 dumpTree = cssException.toString(); |
| 61 } | 59 } |
| 62 } | 60 } |
| 63 | 61 |
| 64 var bgcolor = templateValid ? "white" : "red"; | 62 var bgcolor = templateValid ? "white" : "red"; |
| 65 var color = templateValid ? "black" : "white"; | 63 var color = templateValid ? "black" : "white"; |
| 66 var valid = templateValid ? "VALID" : "NOT VALID"; | 64 var valid = templateValid ? "VALID" : "NOT VALID"; |
| 67 String resultStyle = 'margin: 0; height: 138px; width: 100%; border: 0; border
-top: 1px solid black;'; | 65 String resultStyle = 'margin: 0; height: 138px; width: 100%; border: 0; border
-top: 1px solid black;'; |
| 68 result.innerHTML = ''' | 66 result.innerHTML = ''' |
| (...skipping 19 matching lines...) Expand all Loading... |
| 88 <button onclick="runCss(true, true)" style="position: absolute; left: 430px;
top: 135px;">Parse</button> | 86 <button onclick="runCss(true, true)" style="position: absolute; left: 430px;
top: 135px;">Parse</button> |
| 89 <button onclick="runCss()" style="position: absolute; left: 500px; top: 135p
x;">Check</button> | 87 <button onclick="runCss()" style="position: absolute; left: 500px; top: 135p
x;">Check</button> |
| 90 <button onclick="runCss(true)" style="position: absolute; left: 570px; top:
135px;">Debug</button> | 88 <button onclick="runCss(true)" style="position: absolute; left: 570px; top:
135px;">Debug</button> |
| 91 <div style="top: 160px; left: 225px; position: absolute;"> | 89 <div style="top: 160px; left: 225px; position: absolute;"> |
| 92 <span style="font-weight:bold;">Result</span><br/> | 90 <span style="font-weight:bold;">Result</span><br/> |
| 93 <div id="result" style="width: 400px; height: 158px; border: black solid 1
px;"></textarea> | 91 <div id="result" style="width: 400px; height: 158px; border: black solid 1
px;"></textarea> |
| 94 </div> | 92 </div> |
| 95 '''; | 93 '''; |
| 96 | 94 |
| 97 document.body.appendChild(element); | 95 document.body.appendChild(element); |
| 98 // document.body.elements.add(element); | |
| 99 | 96 |
| 100 // TODO(terry): Needed so runCss isn't shakened out. | 97 // TODO(terry): Needed so runCss isn't shakened out. |
| 101 if (false) { | 98 if (false) { |
| 102 runCss(); | 99 runCss(); |
| 103 } | 100 } |
| 104 | 101 |
| 105 initCssWorld(false); | 102 initCssWorld(false); |
| 106 } | 103 } |
| OLD | NEW |