| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 library css; | |
| 6 | |
| 7 import 'dart:math' as Math; | |
| 8 import '../lib/file_system.dart'; | |
| 9 import '../lib/file_system_memory.dart'; | |
| 10 | |
| 11 part 'cssoptions.dart'; | |
| 12 part 'source.dart'; | |
| 13 part 'tokenkind.dart'; | |
| 14 part 'token.dart'; | |
| 15 part 'tokenizer_base.dart'; | |
| 16 part 'tokenizer.dart'; | |
| 17 part 'treebase.dart'; | |
| 18 part 'tree.dart'; | |
| 19 part 'cssselectorexception.dart'; | |
| 20 part 'cssworld.dart'; | |
| 21 part 'parser.dart'; | |
| 22 part 'validate.dart'; | |
| 23 part 'generate.dart'; | |
| 24 part 'world.dart'; | |
| 25 | |
| 26 | |
| 27 void initCssWorld([bool commandLine = true]) { | |
| 28 FileSystem fs = new MemoryFileSystem(); | |
| 29 parseOptions([], fs); | |
| 30 initializeWorld(fs); | |
| 31 | |
| 32 // TODO(terry): Should be set by arguments. When run as a tool these aren't | |
| 33 // set when run internaly set these so we can compile CSS and catch any | |
| 34 // problems programmatically. | |
| 35 options.throwOnErrors = true; | |
| 36 options.throwOnFatal = true; | |
| 37 options.useColors = commandLine ? true : false; | |
| 38 options.warningsAsErrors = false; | |
| 39 options.showWarnings = true; | |
| 40 } | |
| 41 | |
| 42 // TODO(terry): Add obfuscation mapping file. | |
| 43 void cssParseAndValidate(String cssExpression, CssWorld cssworld) { | |
| 44 Parser parser = new Parser(new SourceFile(SourceFile.IN_MEMORY_FILE, | |
| 45 cssExpression)); | |
| 46 var tree = parser.parseTemplate(); | |
| 47 if (tree != null) { | |
| 48 Validate.template(tree.selectors, cssworld); | |
| 49 } | |
| 50 } | |
| 51 | |
| 52 // Returns pretty printed tree of the expression. | |
| 53 String cssParseAndValidateDebug(String cssExpression, CssWorld cssworld) { | |
| 54 Parser parser = new Parser(new SourceFile(SourceFile.IN_MEMORY_FILE, | |
| 55 cssExpression)); | |
| 56 String output = ""; | |
| 57 String prettyTree = ""; | |
| 58 try { | |
| 59 var tree = parser.parseTemplate(); | |
| 60 if (tree != null) { | |
| 61 prettyTree = tree.toDebugString(); | |
| 62 Validate.template(tree.selectors, cssworld); | |
| 63 output = prettyTree; | |
| 64 } | |
| 65 } catch (e) { | |
| 66 String error = e.toString(); | |
| 67 output = "$error\n$prettyTree"; | |
| 68 throw e; | |
| 69 } | |
| 70 | |
| 71 return output; | |
| 72 } | |
| OLD | NEW |