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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: dart/site/try/decoration.dart
diff --git a/dart/site/try/decoration.dart b/dart/site/try/decoration.dart
new file mode 100644
index 0000000000000000000000000000000000000000..87e62b879fa7a1e51a8bfcc964884b7de420c46a
--- /dev/null
+++ b/dart/site/try/decoration.dart
@@ -0,0 +1,101 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library trydart.decoration;
+
+import 'dart:html';
+
+class Decoration {
+ final String color;
+ final bool bold;
+ final bool italic;
+ final bool stress;
+ final bool important;
+
+ const Decoration({this.color: '#000000',
+ this.bold: false,
+ this.italic: false,
+ this.stress: false,
+ this.important: false});
+
+ Element applyTo(text) {
+ if (text is String) {
+ text = new Text(text);
+ }
+ if (bold) {
+ text = new Element.tag('b')..append(text);
+ }
+ if (italic) {
+ text = new Element.tag('i')..append(text);
+ }
+ if (stress) {
+ text = new Element.tag('em')..append(text);
+ }
+ if (important) {
+ text = new Element.tag('strong')..append(text);
+ }
+ return new SpanElement()..append(text)..style.color = color;
+ }
+}
+
+class DiagnosticDecoration extends Decoration {
+ final String kind;
+ final String message;
+
+ const DiagnosticDecoration(
+ this.kind,
+ this.message,
+ {String color: '#000000',
+ bool bold: false,
+ bool italic: false,
+ bool stress: false,
+ bool important: false})
+ : super(color: color, bold: bold, italic: italic, stress: stress,
+ important: important);
+
+ Element applyTo(text) {
+ var element = super.applyTo(text);
+ var nodes = new List.from(element.nodes);
+ element.nodes.clear();
+ var tip = new Text('');
+ if (kind == 'error') {
+ tip = error(message);
+ }
+ return element..append(
+ new AnchorElement()
+ ..classes.add('diagnostic')
+ ..nodes.addAll(nodes)
+ ..append(tip));
+ }
+}
+
+info(text) {
+ if (text is String) {
+ text = new Text(text);
+ }
+ return new SpanElement()
+ ..classes.addAll(['alert', 'alert-info'])
+ ..style.opacity = '0.75'
+ ..append(text);
+}
+
+error(text) {
+ if (text is String) {
+ text = new Text(text);
+ }
+ return new SpanElement()
+ ..classes.addAll(['alert', 'alert-error'])
+ ..style.opacity = '0.75'
+ ..append(text);
+}
+
+warning(text) {
+ if (text is String) {
+ text = new Text(text);
+ }
+ return new SpanElement()
+ ..classes.add('alert')
+ ..style.opacity = '0.75'
+ ..append(text);
+}

Powered by Google App Engine
This is Rietveld 408576698