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

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
« no previous file with comments | « pkg/polymer/test/build/unique_message_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 hashTag = 'msg_${id.package}_${id.id}';
76 var markdown =
77 '## ${template.description} [#${id.id}](#$hashTag)\n\n$details\n\n----\n';
78 var html = markdownToHtml(markdown);
79 // We add the anchor inside the <h2> title, otherwise the link doesn't work.
80 return '\n\n${html.replaceFirst("<h2>", "<h2 id=\"$hashTag\">")}';
81 }
82
83 const _HEADER = '''
84 <!doctype html>
85 <!--
86 This file is autogenerated with polymer/tool/create_message_details_page.dart
87 -->
88 <html>
89 <style>
90 @font-face {
91 font-family: 'Montserrat';
92 font-style: normal;
93 font-weight: 400;
94 src: url(https://themes.googleusercontent.com/static/fonts/montserrat/v4/zhcz- _WihjSQC0oHJ9TCYL3hpw3pgy2gAi-Ip7WPMi0.woff) format('woff');
95 }
96 @font-face {
97 font-family: 'Montserrat';
98 font-style: normal;
99 font-weight: 700;
100 src: url(https://themes.googleusercontent.com/static/fonts/montserrat/v4/IQHow _FEYlDC4Gzy_m8fcnbFhgvWbfSbdVg11QabG8w.woff) format('woff');
101 }
102 @font-face {
103 font-family: 'Roboto';
104 font-style: normal;
105 font-weight: 300;
106 src: url(https://themes.googleusercontent.com/static/fonts/roboto/v10/Hgo13k-t fSpn0qi1SFdUfbO3LdcAZYWl9Si6vvxL-qU.woff) format('woff');
107 }
108 @font-face {
109 font-family: 'Roboto';
110 font-style: normal;
111 font-weight: 400;
112 src: url(https://themes.googleusercontent.com/static/fonts/roboto/v10/CrYjSnGj rRCn0pd9VQsnFOvvDin1pK8aKteLpeZ5c0A.woff) format('woff');
113 }
114
115 body {
116 width: 80vw;
117 margin: 20px;
118 font-family: Roboto, sans-serif;
119 }
120
121 h1 {
122 font-family: Montserrat, sans-serif;
123 box-sizing: border-box;
124 color: rgb(72, 72, 72);
125 display: block;
126 font-style: normal;
127 font-variant: normal;
128 font-weight: normal;
129 }
130
131 h2 {
132 font-family: Montserrat, sans-serif;
133 box-sizing: border-box;
134 color: rgb(72, 72, 72);
135 display: block;
136 font-style: normal;
137 font-variant: normal;
138 font-weight: normal;
139 }
140
141 pre {
142 display: block;
143 padding: 9.5px;
144 margin: 0 0 10px;
145 line-height: 1.42857143;
146 color: #333;
147 word-break: break-all;
148 word-wrap: break-word;
149 background-color: #f5f5f5;
150 border: 1px solid #ccc;
151 border-radius: 4px;
152 }
153
154 code {
155 font-family: Menlo,Monaco,Consolas,"Courier New",monospace;
156 box-sizing: border-box;
157 padding: 0;
158 font-size: 90%;
159 color: #0084c5;
160 white-space: nowrap;
161 border-radius: 4px;
162 background-color: #f9f2f4;
163 }
164
165 pre > code {
166 white-space: inherit;
167 }
168
169 a {
170 color: rgb(42, 100, 150);
171 }
172
173 h2 > a {
174 display: none;
175 font-size: 0.8em;
176 }
177
178 h2:hover > a {
179 display: inline;
180 }
181 </style>
182 <body>
183 ''';
184
185 const _FOOTER = '''
186 </body>
187 </html>
188 ''';
OLDNEW
« no previous file with comments | « 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