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: src/site/index.html

Issue 22528003: update examples on homepage (Closed) Base URL: https://github.com/dart-lang/dartlang.org.git@master
Patch Set: Created 7 years, 4 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
1 --- 1 ---
2 layout: homepage 2 layout: homepage
3 googleapi: true 3 googleapi: true
4 js: 4 js:
5 - url: /js/display-news.js 5 - url: /js/display-news.js
6 - url: /js/os-switcher.js 6 - url: /js/os-switcher.js
7 defer: true 7 defer: true
8 - url: /js/editor-downloads-analytics.js 8 - url: /js/editor-downloads-analytics.js
9 defer: true 9 defer: true
10 - url: /js/editor-version.js 10 - url: /js/editor-version.js
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 <div id="feed-posts"> 133 <div id="feed-posts">
134 </div> 134 </div>
135 </div> 135 </div>
136 </div> 136 </div>
137 </div> 137 </div>
138 </section> 138 </section>
139 139
140 <section id="code"> 140 <section id="code">
141 <h1> Code </h1> 141 <h1> Code </h1>
142 142
143 <p> 143 <p>
144 Experiment with Dart right in your browser: 144 You can find code examples in Dart Editor,
145 <a href="http://try.dartlang.org">try.dartlang.org</a> 145 in the <a href="/samples/">Samples page</a>,
146 and below.
147 You can also experiment with Dart right in your browser:
148 <a href="http://try.dartlang.org" target="_blank">try.dartlang.org</a>
146 </p> 149 </p>
147 150
148 <p> 151 <div class="tabbable">
149 Here's some code from a Dart web app that uses Web UI. 152 <ul class="nav nav-tabs">
150 To learn about web programming with Dart, try our 153 <li class="active"><a href="#language" data-toggle="tab">Syntax</a></li>
151 <a href="/docs/tutorials/">Dart tutorials</a>. 154 <li><a href="#types" data-toggle="tab">Optional types</a>< /li>
152 </p> 155 <li><a href="#futures" data-toggle="tab">Futures</a></li>
156 <li><a href="#webui" data-toggle="tab">Web UI</a></li>
157 </ul>
153 158
154 <div class="row-fluid"> 159 <div class="tab-content">
155 <div class="span6" id="dart-code"> 160 <div class="tab-pane active" id="language">
161 <p>
162 Dart aims to be unsurprising,
163 but it does add a few language features
164 to keep your code succinct yet understandable.
165 Read all about Dart syntax in the
166 <a href="/docs/dart-up-and-running/contents/ch02.html">Dart language tou r</a>.
167 </p>
168
169 <div class="row-fluid">
170 <div class="span10 offset1">
171 {% prettify dart %}
172 [[highlight]]import[[/highlight]] 'dart:html'; // Dart supp orts libraries...
173
174 [[highlight]]class[[/highlight]] Rectangle implements Shape { // ...and cla sses.
175 final num height, width;
176 Rectangle([[highlight]]this.height[[/highlight]], [[highlight]]this.width[[/hi ghlight]]); // Compact constructor syntax.
177 num perimeter() [[highlight]]=>[[/highlight]] 2*height + 2*width; // Function shorthand syntax.
178 }
179
180 // You can define functions either inside or outside of classes.
181 startOrEndTest() {
182 // ...
183 }
184
185 // Every app has a main() function, where execution starts.
186 [[highlight]]main()[[/highlight]] {
187 // The cascade operator (..) saves you from repetitive typing.
188 query("#button")
189 [[highlight]]..[[/highlight]]text = "Run test"
190 [[highlight]]..[[/highlight]]onClick.listen(startOrEndTest);
191 }
192 {% endprettify %}
193 </div>
194 </div>
195 </div>
196
197 <div class="tab-pane" id="types">
198 <p>
199 Declaring types is optional in Dart.
200 These types don't affect the runtime behavior,
201 but you can use them to clarify APIs
202 and get better help from tools.
203 </p>
204
205 <div class="row-fluid">
206 <div class="span6" id="without-types">
207 {% prettify dart %}
208 // Without types.
209 recalculate(origin, offset, estimate) {
210 // ...
211 }
212 {% endprettify %}
213 </div>
214 <div class="span6" id="with-types">
215 {% prettify dart %}
216 // With types (and an optional parameter).
217 [[highlight]]num[[/highlight]] recalculate([[highlight]]Point[[/highlight]] orig in,
218 [[highlight]]num[[/highlight]] offset,
219 {[[highlight]]bool[[/highlight]] estimate:false}) {
220 // ...
221 }
222 {% endprettify %}
223 </div>
224 </div>
225 </div>
226
227 <div class="tab-pane" id="futures">
228 <p>
229 Functions that do potentially expensive work return Futures.
230 To specify what happens when the function's work is done,
231 you invoke <code>then()</code> on the Future.
232 </p>
233
234 <div class="row-fluid">
235 <div class="span10 offset1">
236
237 {% prettify dart %}
238 import 'dart:io';
239 import 'dart:async';
240
241 void printDailyNewsDigest() {
242 File file = new File("dailyNewsDigest.txt");
243 [[highlight]]Future future = file.readAsString();[[/highlight]] // readAsStrin g() returns a Future.
244 future.then((content) {
245 [[highlight]]print(content);[[/highlight]] // Executes when the f uture's work is done.
246 });
247 }
248 {% endprettify %}
249 </div>
250 </div>
251 </div>
252 <div class="tab-pane" id="webui">
253 <p>
254 Here's an example of implementing a web app using the Web UI package.
255 To learn about web programming with Dart, try our
256 <a href="/docs/tutorials/">Dart tutorials</a>.
257 </p>
258
259 <div class="row-fluid">
260 <div class="span6" id="dart-code">
156 {% prettify dart %} 261 {% prettify dart %}
157 // Dart code: 262 // Dart code:
158 import 'package:web_ui/web_ui.dart'; 263 import 'package:web_ui/web_ui.dart';
159 264
160 @observable String myString = ''; 265 @observable String myString = '';
161 266
162 String get shouted => myString.toUpperCase(); 267 String get [[highlight]]shouted[[/highlight]] => myString.toUpperCase();
163 268
164 String get palindrome => 269 String get [[highlight]]palindrome[[/highlight]] =>
165 myString + myString.split('').reversed.join(); 270 myString + myString.split('').reversed.join();
166 {% endprettify %} 271 {% endprettify %}
167 </div> 272 </div>
168 <div class="span6" id="html-code"> 273 <div class="span6" id="html-code">
169 {% prettify html %} 274 {% prettify html %}
170 <!-- HTML code: --> 275 <!-- HTML code: -->
171 <input type="text" bind-value="myString" 276 <input type="text" bind-value="myString"
172 placeholder="Type here"> 277 placeholder="Type here">
173 278
174 <div> Shouted: {{'{{'}}shouted}} </div> 279 <div> Shouted: {{'{{'}}[[highlight]]shouted[[/highlight]]}} </div>
175 <div> Palindromic: {{'{{'}}palindrome}} </div> 280 <div> Palindromic: {{'{{'}}[[highlight]]palindrome[[/highlight]]}} </div>
176 281
177 <script type="application/dart" src="little.dart"></script> 282 <script type="application/dart" src="webui.dart"></script>
178 <script src="packages/browser/dart.js"></script> 283 <script src="packages/browser/dart.js"></script>
179 {% endprettify %} 284 {% endprettify %}
180 {% comment %} 285 {% comment %}
181 Beginning double curlies are processed by liquid, 286 Beginning double curlies are processed by liquid,
182 so you have to surround them in single quotes, 287 so you have to surround them in single quotes,
183 surrounded by double curlies. Yup. 288 surrounded by double curlies. Yup.
184 {% endcomment %} 289 {% endcomment %}
185 </div> 290 </div>
186 </div> <!-- code --> 291 </div> <!-- code -->
187 292 </div>
293 </div>
294 </div>
188 </section> 295 </section>
189 296
190 297
191 <section id="get-started"> 298 <section id="get-started">
192 299
193 <h1> Get started </h1> 300 <h1> Get started </h1>
194 301
195 <p> 302 <p>
196 Getting started with Dart is easy. 303 Getting started with Dart is easy.
197 Just download Dart, 304 Just download Dart,
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 You can write Dart apps using any recent version of 375 You can write Dart apps using any recent version of
269 {% include os-choices.html %} 376 {% include os-choices.html %}
270 The Dart development tools <b>do not&nbsp;support Windows XP</b>. 377 The Dart development tools <b>do not&nbsp;support Windows XP</b>.
271 Dart Editor requires Java version 6 or higher. 378 Dart Editor requires Java version 6 or higher.
272 </aside> 379 </aside>
273 380
274 </section> 381 </section>
275 382
276 </article> <!-- /.homepage --> 383 </article> <!-- /.homepage -->
277 384
OLDNEW
« no previous file with comments | « runtests.sh ('k') | src/tests/site/code/futures.dart » ('j') | src/tests/site/code/futures.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698