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

Side by Side Diff: dart/site/try/decoration.dart

Issue 125123002: try.dartlang.org version 5. (Closed) Base URL: /Users/ahe/Dart/all@master
Patch Set: Created 6 years, 11 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 library trydart.decoration;
6
7 import 'dart:html';
8
9 class Decoration {
10 final String color;
11 final bool bold;
12 final bool italic;
13 final bool stress;
14 final bool important;
15
16 const Decoration({this.color: '#000000',
17 this.bold: false,
18 this.italic: false,
19 this.stress: false,
20 this.important: false});
21
22 Element applyTo(text) {
23 if (text is String) {
24 text = new Text(text);
25 }
26 if (bold) {
27 text = new Element.tag('b')..append(text);
28 }
29 if (italic) {
30 text = new Element.tag('i')..append(text);
31 }
32 if (stress) {
33 text = new Element.tag('em')..append(text);
34 }
35 if (important) {
36 text = new Element.tag('strong')..append(text);
37 }
38 return new SpanElement()..append(text)..style.color = color;
39 }
40 }
41
42 class DiagnosticDecoration extends Decoration {
43 final String kind;
44 final String message;
45
46 const DiagnosticDecoration(
47 this.kind,
48 this.message,
49 {String color: '#000000',
50 bool bold: false,
51 bool italic: false,
52 bool stress: false,
53 bool important: false})
54 : super(color: color, bold: bold, italic: italic, stress: stress,
55 important: important);
56
57 Element applyTo(text) {
58 var element = super.applyTo(text);
59 var nodes = new List.from(element.nodes);
60 element.nodes.clear();
61 var tip = new Text('');
62 if (kind == 'error') {
63 tip = error(message);
64 }
65 return element..append(
66 new AnchorElement()
67 ..classes.add('diagnostic')
68 ..nodes.addAll(nodes)
69 ..append(tip));
70 }
71 }
72
73 info(text) {
74 if (text is String) {
75 text = new Text(text);
76 }
77 return new SpanElement()
78 ..classes.addAll(['alert', 'alert-info'])
79 ..style.opacity = '0.75'
80 ..append(text);
81 }
82
83 error(text) {
84 if (text is String) {
85 text = new Text(text);
86 }
87 return new SpanElement()
88 ..classes.addAll(['alert', 'alert-error'])
89 ..style.opacity = '0.75'
90 ..append(text);
91 }
92
93 warning(text) {
94 if (text is String) {
95 text = new Text(text);
96 }
97 return new SpanElement()
98 ..classes.add('alert')
99 ..style.opacity = '0.75'
100 ..append(text);
101 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698