OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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:convert'; | 5 import 'dart:convert'; |
6 import 'dart:io'; | 6 import 'dart:io'; |
7 | 7 |
| 8 import 'package:intl/intl.dart'; |
| 9 |
8 /// Contains a collection of Pages. | 10 /// Contains a collection of Pages. |
9 abstract class Site { | 11 abstract class Site { |
10 final String title; | 12 final String title; |
11 List<Page> pages = []; | 13 List<Page> pages = []; |
12 | 14 |
13 Site(this.title); | 15 Site(this.title); |
14 | 16 |
15 String get customCss => ''; | 17 String get customCss => ''; |
16 | 18 |
17 void handleGetRequest(HttpRequest request) { | 19 void handleGetRequest(HttpRequest request) { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 } | 102 } |
101 | 103 |
102 void h3(String text, {bool raw: false}) { | 104 void h3(String text, {bool raw: false}) { |
103 buf.writeln('<h3>${raw ? text : escape(text)}</h3>'); | 105 buf.writeln('<h3>${raw ? text : escape(text)}</h3>'); |
104 } | 106 } |
105 | 107 |
106 void h4(String text, {bool raw: false}) { | 108 void h4(String text, {bool raw: false}) { |
107 buf.writeln('<h4>${raw ? text : escape(text)}</h4>'); | 109 buf.writeln('<h4>${raw ? text : escape(text)}</h4>'); |
108 } | 110 } |
109 | 111 |
110 void ul<T>(Iterable<T> items, void gen(T item)) { | 112 void ul<T>(Iterable<T> items, void gen(T item), {String classes}) { |
111 buf.writeln('<ul>'); | 113 buf.writeln('<ul${classes == null ? '' : ' class=$classes'}>'); |
112 for (T item in items) { | 114 for (T item in items) { |
113 buf.write('<li>'); | 115 buf.write('<li>'); |
114 gen(item); | 116 gen(item); |
115 buf.write('</li>'); | 117 buf.write('</li>'); |
116 } | 118 } |
117 buf.writeln('</ul>'); | 119 buf.writeln('</ul>'); |
118 } | 120 } |
119 | 121 |
120 void inputList<T>(Iterable<T> items, void gen(T item)) { | 122 void inputList<T>(Iterable<T> items, void gen(T item)) { |
121 buf.writeln('<select size="8" style="width: 100%">'); | 123 buf.writeln('<select size="8" style="width: 100%">'); |
(...skipping 27 matching lines...) Expand all Loading... |
149 | 151 |
150 void blankslate(String str) { | 152 void blankslate(String str) { |
151 div(() => buf.writeln(str), classes: 'blankslate'); | 153 div(() => buf.writeln(str), classes: 'blankslate'); |
152 } | 154 } |
153 | 155 |
154 bool isCurrentPage(String pathToTest) => path == pathToTest; | 156 bool isCurrentPage(String pathToTest) => path == pathToTest; |
155 } | 157 } |
156 | 158 |
157 String escape(String text) => text == null ? '' : HTML_ESCAPE.convert(text); | 159 String escape(String text) => text == null ? '' : HTML_ESCAPE.convert(text); |
158 | 160 |
159 String printInteger(int value) { | 161 final NumberFormat numberFormat = new NumberFormat.decimalPattern(); |
160 return value.toString(); | |
161 } | |
162 | 162 |
163 String printMilliseconds(num value) { | 163 String printInteger(int value) => numberFormat.format(value); |
164 return '${value.toStringAsFixed(1)} ms'; | |
165 } | |
166 | 164 |
167 String printPercentage(num value) { | 165 String printMilliseconds(num value) => '${numberFormat.format(value)} ms'; |
168 return '${(value * 100).toStringAsFixed(1)}%'; | 166 |
169 } | 167 String printPercentage(num value) => '${(value * 100).toStringAsFixed(1)}%'; |
OLD | NEW |