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

Side by Side Diff: site/try/src/extract_theme.dart

Issue 2232273004: Delete site/try (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 4 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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 import 'dart:io';
6
7 StringBuffer themes = new StringBuffer();
8
9 void main(List<String> arguments) {
10 print('part of trydart.themes;\n');
11 arguments.forEach(extractTheme);
12 print('''
13 /// List of known themes. The default is the first theme.
14 const List<Theme> THEMES = const <Theme> [
15 const Theme(),
16 $themes];''');
17 }
18
19 final DECORATION_PATTERN = new RegExp(r'^ *<([a-z][^ ]+)[ ]');
20
21 String attr(String name, String line) {
22 var match = new RegExp('$name'r'="([^"]*)"').firstMatch(line);
23 if (match == null) return null;
24 return match[1];
25 }
26
27 void extractTheme(String filename) {
28 bool openedTheme = false;
29 for (String line in new File(filename).readAsLinesSync()) {
30 if (line.startsWith('<colorTheme')) {
31 openTheme(line, filename);
32 openedTheme = true;
33 } else if (line.startsWith('</colorTheme>')) {
34 if (!openedTheme) throw 'Theme not found in $filename';
35 closeTheme();
36 openedTheme = false;
37 } else if (DECORATION_PATTERN.hasMatch(line)) {
38 if (!openedTheme) throw 'Theme not found in $filename';
39 printDecoration(line);
40 }
41 }
42 }
43
44 openTheme(String line, String filename) {
45 var name = attr('name', line);
46 var author = attr('author', line);
47 if (name == null) name = 'Untitled';
48 if (name == 'Default') name = 'Dart Editor';
49 var declaration = name.replaceAll(new RegExp('[^a-zA-Z0-9_]'), '_');
50 themes.write(' const ${declaration}Theme(),\n');
51 print('/// $name theme extracted from');
52 print('/// $filename.');
53 if (author != null) {
54 print('/// Author: $author.');
55 }
56 print("""
57 class ${declaration}Theme extends Theme {
58 const ${declaration}Theme();
59
60 String get name => '$name';
61 """);
62 }
63
64 closeTheme() {
65 print('}\n');
66 }
67
68 printDecoration(String line) {
69 String name = DECORATION_PATTERN.firstMatch(line)[1];
70 if (name == 'class') name = 'className';
71 if (name == 'enum') name = 'enumName';
72 StringBuffer properties = new StringBuffer();
73 var color = attr('color', line);
74 if (color != null) {
75 properties.write("color: '$color'");
76 }
77 var bold = attr('bold', line) == 'true';
78 if (bold) {
79 if (!properties.isEmpty) properties.write(', ');
80 properties.write('bold: true');
81 }
82 print(' Decoration get $name => const Decoration($properties);');
83 }
OLDNEW
« dart.gyp ('K') | « site/try/src/editor.dart ('k') | site/try/src/extracted_themes.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698