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

Side by Side Diff: lib/src/codegen.dart

Issue 12225039: Support for observable models, fixes #259 (Closed) Base URL: https://github.com/dart-lang/web-ui.git@master
Patch Set: Created 7 years, 10 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
« no previous file with comments | « lib/src/analyzer.dart ('k') | lib/src/compiler.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /** Collects common snippets of generated code. */ 5 /** Collects common snippets of generated code. */
6 library codegen; 6 library codegen;
7 7
8 import 'file_system/path.dart'; 8 import 'file_system/path.dart';
9 import 'info.dart'; 9 import 'info.dart';
10 import 'utils.dart'; 10 import 'utils.dart';
11 11
12 /** 12 /**
13 * Header with common imports, used in every generated .dart file. If path is 13 * Header with common imports, used in every generated .dart file. If path is
14 * null then there is no file associated with the template (used by testing 14 * null then there is no file associated with the template (used by testing
15 * so we'll display <MEMORY> for file name. 15 * so we'll display <MEMORY> for file name.
16 */ 16 */
17 String header(Path path, String libraryName) => """ 17 String header(Path path, String libraryName) {
18 var library = libraryName != null ? '\nlibrary $libraryName;\n' : '';
19 return """
18 // Auto-generated from ${path != null ? path.filename : "<MEMORY>"}. 20 // Auto-generated from ${path != null ? path.filename : "<MEMORY>"}.
19 // DO NOT EDIT. 21 // DO NOT EDIT.
20 22 $library
21 library $libraryName;
22
23 $imports 23 $imports
24 """; 24 """;
25 }
25 26
26 // TODO(sigmund): include only those imports that are used by the code. 27 // TODO(sigmund): include only those imports that are used by the code.
27 String get imports => """ 28 String get imports => """
28 import 'dart:html' as autogenerated; 29 import 'dart:html' as autogenerated;
29 import 'dart:svg' as autogenerated_svg; 30 import 'dart:svg' as autogenerated_svg;
30 import 'package:web_ui/web_ui.dart' as autogenerated; 31 import 'package:web_ui/web_ui.dart' as autogenerated;
31 """; 32 """;
32 33
33 /** 34 /**
34 * The code that will be used to bootstrap the application, this is inlined in 35 * The code that will be used to bootstrap the application, this is inlined in
35 * the main.html.html output file. 36 * the main.html.html output file.
36 */ 37 */
37 String bootstrapCode(Path userMainImport) => """ 38 String bootstrapCode(Path userMainImport, bool useObservers) => """
38 library bootstrap; 39 library bootstrap;
39 40
41 import 'package:web_ui/watcher.dart' as watcher;
40 import '$userMainImport' as userMain; 42 import '$userMainImport' as userMain;
41 43
42 main() { 44 main() {
45 watcher.useObservers = $useObservers;
43 userMain.main(); 46 userMain.main();
44 userMain.init_autogenerated(); 47 userMain.init_autogenerated();
45 } 48 }
46 """; 49 """;
47 50
48 /** Generate text for a list of imports. */ 51 /** Generate text for a list of imports. */
49 String importList(Iterable<Path> imports) => 52 String importList(Iterable<Path> imports) =>
50 imports.map((url) => "import '$url';").join('\n'); 53 imports.map((url) => "import '$url';").join('\n');
51
52 /**
53 * Text corresponding to a directive, fixed in case the code is in a different
54 * output location.
55 */
56 String directiveText(
57 DartDirectiveInfo directive, LibraryInfo src, PathInfo pathInfo) {
58 var buff = new StringBuffer();
59 var uri = pathInfo.transformUrl(src.inputPath, directive.uri);
60 buff..add(directive.label)
61 ..add(" '")
62 ..add(uri.replaceAll("'", "\\'"))
63 ..add("'");
64 if (directive.prefix != null) {
65 buff..add(' as ')
66 ..add(directive.prefix);
67 }
68 if (directive.show != null) {
69 buff..add(' show ')
70 ..add(directive.show.join(','));
71 }
72 if (directive.hide != null) {
73 buff..add(' hide ')
74 ..add(directive.hide.join(','));
75 }
76 buff.add(';');
77 return buff.toString();
78 }
OLDNEW
« no previous file with comments | « lib/src/analyzer.dart ('k') | lib/src/compiler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698