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

Side by Side Diff: pkg/polymer/tool/create_message_details_page.dart

Issue 513023002: Step one towards stable error messages with details: (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2014, 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 /// Simple script to generate a page summarizing all error messages produces by
6 /// the polymer compiler code. The generated code will be placed directly under
7 /// the `polymer/lib/src/generated` folder. This script should be invoked from
8 /// the root of the polymer package either by doing:
9 ///
10 /// dart tool/create_message_details_page.dart
11 ///
12 /// or
13 ///
14 /// pub run tool/create_message_details_page
15 library polymer.tool.create_message_details_page;
16
17 import 'dart:io';
18 import 'dart:mirrors';
19
20 import 'package:code_transformers/messages/messages.dart';
21 import 'package:code_transformers/src/messages.dart' as m1; // used via mirrors
22 import 'package:observe/src/messages.dart' as m2; // used via mirrors
23 import 'package:polymer/src/build/messages.dart' as m3; // used via mirrors
24 import 'package:markdown/markdown.dart';
25 import 'package:path/path.dart' as path;
26
27 main() {
28 var seen = {};
29 var templates = [];
30 _getMessagesFrom(#polymer.src.build.messages, seen, templates);
31 _getMessagesFrom(#code_transformers.src.messages, seen, templates);
32 _getMessagesFrom(#observe.src.messages, seen, templates);
33
34 templates.sort((a, b) => a.id.compareTo(b.id));
35 var sb = new StringBuffer();
36 sb.write(_HEADER);
37
38 var lastPackage = '';
39 for (var t in templates) {
40 if (lastPackage != t.id.package) {
41 lastPackage = t.id.package;
42 sb.write(markdownToHtml(
43 '#Messages from package `$lastPackage`\n\n----\n'));
44 }
45 sb.write(_htmlFor(t));
46 }
47 sb.write(_FOOTER);
48 new File('lib/src/build/generated/messages.html')
49 .writeAsStringSync(sb.toString());
50 }
51
52 final _mirrors = currentMirrorSystem();
53
54 _getMessagesFrom(Symbol libName, Map seen, List templates) {
55 var lib = _mirrors.findLibrary(libName);
56 lib.declarations.forEach((symbol, decl) {
57 if (decl is! VariableMirror) return;
58 var template = lib.getField(symbol).reflectee;
59 var name = MirrorSystem.getName(symbol);
60 if (template is! MessageTemplate) return;
61 var id = template.id;
62 if (seen.containsKey(id)) {
63 print('error: duplicate id `$id`. '
64 'Currently set for both `$name` and `${seen[id]}`.');
65 }
66 seen[id] = name;
67 templates.add(template);
68 });
69 }
70
71 _htmlFor(MessageTemplate template) {
72 var details = template.details == null
73 ? 'No details available' : template.details;
74 var id = template.id;
75 var markdown =
76 '## ${template.description} [#${id.id}](#msg_$id)\n\n$details\n\n----\n';
77 var html = markdownToHtml(markdown);
78 // We add the anchor inside the <h2> title, otherwise the link doesn't work.
79 return '\n\n${html.replaceFirst("<h2>", "<h2 id=\"msg_$id\">")}';
80 }
81
82 const _HEADER = '''
83 <!doctype html>
84 <!--
85 This file is autogenerated with polymer/tool/create_message_details_page.dart
86 -->
87 <html>
88 <style>
89 @font-face {
90 font-family: 'Montserrat';
91 font-style: normal;
92 font-weight: 400;
93 src: url(https://themes.googleusercontent.com/static/fonts/montserrat/v4/zhcz- _WihjSQC0oHJ9TCYL3hpw3pgy2gAi-Ip7WPMi0.woff) format('woff');
94 }
95 @font-face {
96 font-family: 'Montserrat';
97 font-style: normal;
98 font-weight: 700;
jakemac 2014/09/03 17:20:41 it doesn't look like you are using both of these v
Siggi Cherem (dart-lang) 2014/09/04 02:32:18 good question - I copied these from the dartlang s
99 src: url(https://themes.googleusercontent.com/static/fonts/montserrat/v4/IQHow _FEYlDC4Gzy_m8fcnbFhgvWbfSbdVg11QabG8w.woff) format('woff');
100 }
101 @font-face {
102 font-family: 'Roboto';
103 font-style: normal;
104 font-weight: 300;
105 src: url(https://themes.googleusercontent.com/static/fonts/roboto/v10/Hgo13k-t fSpn0qi1SFdUfbO3LdcAZYWl9Si6vvxL-qU.woff) format('woff');
106 }
107 @font-face {
108 font-family: 'Roboto';
109 font-style: normal;
110 font-weight: 400;
111 src: url(https://themes.googleusercontent.com/static/fonts/roboto/v10/CrYjSnGj rRCn0pd9VQsnFOvvDin1pK8aKteLpeZ5c0A.woff) format('woff');
112 }
113
114 body {
115 width: 80vw;
jakemac 2014/09/03 17:20:41 indent
Siggi Cherem (dart-lang) 2014/09/04 02:32:18 Done.
116 margin: 20px;
117 font-family: Roboto, sans-serif;
118 }
119
120 h1 {
121 font-family: Montserrat, sans-serif;
122 box-sizing: border-box;
123 color: rgb(72, 72, 72);
124 display: block;
125 font-style: normal;
126 font-variant: normal;
127 font-weight: normal;
128 }
129
130 h2 {
131 font-family: Montserrat, sans-serif;
132 box-sizing: border-box;
133 color: rgb(72, 72, 72);
134 display: block;
135 font-style: normal;
136 font-variant: normal;
137 font-weight: normal;
138 }
139
140 pre {
141 display: block;
142 padding: 9.5px;
143 margin: 0 0 10px;
144 line-height: 1.42857143;
145 color: #333;
146 word-break: break-all;
147 word-wrap: break-word;
148 background-color: #f5f5f5;
149 border: 1px solid #ccc;
150 border-radius: 4px;
151 }
152
153 code {
154 font-family: Menlo,Monaco,Consolas,"Courier New",monospace;
155 box-sizing: border-box;
156 padding: 0;
157 font-size: 90%;
158 color: #0084c5;
159 white-space: nowrap;
160 border-radius: 4px;
161 background-color: #f9f2f4;
162 }
163
164 pre > code {
165 white-space: inherit;
166 }
167
168 a {
169 color: rgb(42, 100, 150);
170 }
171
172 h2 > a {
173 display: none;
174 font-size: 0.8em;
175 }
176
177 h2:hover > a {
178 display: inline;
jakemac 2014/09/03 17:20:41 indent
Siggi Cherem (dart-lang) 2014/09/04 02:32:18 Done.
179 }
180 </style>
181 <body>
182 ''';
183
184 const _FOOTER = '''
185 </body>
186 </html>
187 ''';
OLDNEW
« pkg/polymer/lib/src/build/messages.dart ('K') | « pkg/polymer/test/build/unique_message_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698