Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Side by Side Diff: lib/css.dart

Issue 998843003: pkg/csslib: formatting (Closed) Base URL: https://github.com/dart-lang/csslib@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 library css; 5 library css;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 8
9 import 'package:path/path.dart' as path; 9 import 'package:path/path.dart' as path;
10 import 'package:source_span/source_span.dart'; 10 import 'package:source_span/source_span.dart';
(...skipping 21 matching lines...) Expand all
32 messages.error("Please provide a CSS/Sass file", null); 32 messages.error("Please provide a CSS/Sass file", null);
33 return; 33 return;
34 } 34 }
35 try { 35 try {
36 // Read the file. 36 // Read the file.
37 var filename = path.basename(inputPath); 37 var filename = path.basename(inputPath);
38 var contents = new File(inputPath).readAsStringSync(); 38 var contents = new File(inputPath).readAsStringSync();
39 var file = new SourceFile(contents, url: path.toUri(inputPath)); 39 var file = new SourceFile(contents, url: path.toUri(inputPath));
40 40
41 // Parse the CSS. 41 // Parse the CSS.
42 var tree = _time('Parse $filename', 42 var tree = _time(
43 () => new Parser(file, contents).parse(), verbose); 43 'Parse $filename', () => new Parser(file, contents).parse(), verbose);
44 44
45 _time('Analyzer $filename', 45 _time('Analyzer $filename', () => new Analyzer([tree], messages), verbose)
46 () => new Analyzer([tree], messages), verbose).run(); 46 .run();
47 47
48 // Emit the processed CSS. 48 // Emit the processed CSS.
49 var emitter = new CssPrinter(); 49 var emitter = new CssPrinter();
50 _time('Codegen $filename', 50 _time('Codegen $filename', () => emitter.visitTree(tree, pretty: true),
51 () => emitter.visitTree(tree, pretty: true), verbose); 51 verbose);
52 52
53 // Write the contents to a file. 53 // Write the contents to a file.
54 var outPath = path.join(path.dirname(inputPath), '_$filename'); 54 var outPath = path.join(path.dirname(inputPath), '_$filename');
55 new File(outPath).writeAsStringSync(emitter.toString()); 55 new File(outPath).writeAsStringSync(emitter.toString());
56 } catch (e) { 56 } catch (e) {
57 messages.error('error processing $inputPath. Original message:\n $e', null); 57 messages.error('error processing $inputPath. Original message:\n $e', null);
58 } 58 }
59 } 59 }
60 60
61 _time(String message, callback(), bool printTime) { 61 _time(String message, callback(), bool printTime) {
62 if (!printTime) return callback(); 62 if (!printTime) return callback();
63 final watch = new Stopwatch(); 63 final watch = new Stopwatch();
64 watch.start(); 64 watch.start();
65 var result = callback(); 65 var result = callback();
66 watch.stop(); 66 watch.stop();
67 final duration = watch.elapsedMilliseconds; 67 final duration = watch.elapsedMilliseconds;
68 _printMessage(message, duration); 68 _printMessage(message, duration);
69 return result; 69 return result;
70 } 70 }
71 71
72 void _printMessage(String message, int duration) { 72 void _printMessage(String message, int duration) {
73 var buf = new StringBuffer(); 73 var buf = new StringBuffer();
74 buf.write(message); 74 buf.write(message);
75 for (int i = message.length; i < 60; i++) buf.write(' '); 75 for (int i = message.length; i < 60; i++) buf.write(' ');
76 buf.write(' -- '); 76 buf.write(' -- ');
77 if (duration < 10) buf.write(' '); 77 if (duration < 10) buf.write(' ');
78 if (duration < 100) buf.write(' '); 78 if (duration < 100) buf.write(' ');
79 buf..write(duration)..write(' ms'); 79 buf
80 ..write(duration)
Jennifer Messerly 2015/03/19 20:25:30 i usually just get rid of cascades when this happe
81 ..write(' ms');
80 print(buf.toString()); 82 print(buf.toString());
81 } 83 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698