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: update syntax.dart 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's welcome page,
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:math' as math; // Importing a library.
173
174 // Functions and variables can be inside or outside of classes.
175 var _shapes = new List(); // A global variable.
176 addShape(shape) [[highlight]]=>[[/highlight]] _shapes.add(shape); // Function sh orthand syntax: =>
177
178 [[highlight]]class[[/highlight]] Ellipse extends Shape { // Declaring a class.
179 num major = 0; // An instance variable (property).
180 num minor = 0;
181 static const _C = math.PI/4; // A constant.
182 num get area => _C*major*minor; // A property implemented with a getter.
183
184 Ellipse([[highlight]]this.major, this.minor[[/highlight]]); // Compact con structor syntax.
185 Ellipse.golden(this.major) { // A named constructor.
186 minor = major*(1 + math.sqrt(5))/2;
187 }
188 }
189
190 // Every app has a main() function, where execution starts.
191 [[highlight]]main()[[/highlight]] {
192 // The cascade operator (..) saves you from repetitive typing.
193 addShape(new Ellipse.golden(10)[[highlight]]..[[/highlight]]minor *= 2
194 [[highlight]]..[[/highlight]]rotation = 20
195 [[highlight]]..[[/highlight]]color = 'rgb(0,129 ,198)');
196 }
197 {% endprettify %}
198 </div>
199 </div>
200 </div>
201
202 <div class="tab-pane" id="types">
203 <p>
204 Declaring types is optional in Dart.
205 These types don't affect the runtime behavior,
206 but you can use them to clarify APIs
207 and get better help from tools—for example,
208 better code completion, easier navigation, and earlier error detection.
209 For details, see
210 <a href="/articles/optional-types/">Optional Types in Dart</a>.
211 </p>
212
213 <div class="row-fluid">
214 <div class="span6" id="without-types">
215 {% prettify dart %}
216 // Without types.
217 recalculate(origin, offset, estimate) {
218 // ...
219 }
220 {% endprettify %}
221 </div>
222 <div class="span6" id="with-types">
223 {% prettify dart %}
224 // With types (and an optional parameter).
225 [[highlight]]num[[/highlight]] recalculate([[highlight]]Point[[/highlight]] orig in,
226 [[highlight]]num[[/highlight]] offset,
227 {[[highlight]]bool[[/highlight]] estimate:false}) {
228 // ...
229 }
230 {% endprettify %}
231 </div>
232 </div>
233 </div>
234
235 <div class="tab-pane" id="futures">
236 <p>
237 Functions that do potentially expensive work return Futures.
238 To specify what happens when the function's work is done,
239 invoke <code>then()</code> on the Future.
240 To handle errors, invoke <code>catchError()</code>.
241 Learn more by reading
242 <a href="/articles/using-future-based-apis/">Using Future Based APIs</a> .
243 </p>
244
245 <div class="row-fluid">
246 <div class="span10 offset1">
247
248 {% prettify dart %}
249 import 'dart:io';
250 import 'dart:async';
251
252 void printDailyNewsDigest() {
253 File file = new File("dailyNewsDigest.txt");
254 [[highlight]]file.readAsString()[[/highlight]] // readAsStrin g() returns a Future.
255 [[highlight]].then[[/highlight]]((content) => print(content)) // Handle succ essful completion.
256 [[highlight]].catchError[[/highlight]]((error) => // Handle fail ure.
257 print("Sorry, no news today. Here's why:\n$error"));
258 }
259 {% endprettify %}
260 </div>
261 </div>
262 </div>
263 <div class="tab-pane" id="webui">
264 <p>
265 Here's an example of implementing a web app using the Web UI package.
266 To learn about web programming with Dart, try our
267 <a href="/docs/tutorials/">Dart tutorials</a>.
268 </p>
269
270 <div class="row-fluid">
271 <div class="span6" id="dart-code">
156 {% prettify dart %} 272 {% prettify dart %}
157 // Dart code: 273 // Dart code:
158 import 'package:web_ui/web_ui.dart'; 274 import 'package:web_ui/web_ui.dart';
159 275
160 @observable String myString = ''; 276 @observable
277 var [[highlight]]shout[[/highlight]] = new Shout();
161 278
162 String get shouted => myString.toUpperCase(); 279 @observable
163 280 class Shout {
164 String get palindrome => 281 String [[highlight]]myString[[/highlight]] = '';
165 myString + myString.split('').reversed.join(); 282 String get [[highlight]]shouted[[/highlight]] => myString.toUpperCase();
283 String get [[highlight]]palindrome[[/highlight]] =>
284 myString + myString.split('').reversed.join();
285 }
166 {% endprettify %} 286 {% endprettify %}
167 </div> 287 </div>
168 <div class="span6" id="html-code"> 288 <div class="span6" id="html-code">
169 {% prettify html %} 289 {% prettify html %}
170 <!-- HTML code: --> 290 <!-- HTML code: -->
171 <input type="text" bind-value="myString" 291 <template id="stringManipulation"
172 placeholder="Type here"> 292 instantiate="if [[highlight]]shout[[/highlight]] != null">
173 293 <input type="text"
174 <div> Shouted: {{'{{'}}shouted}} </div> 294 bind-value="shout.[[highlight]]myString[[/highlight]]"
175 <div> Palindromic: {{'{{'}}palindrome}} </div> 295 placeholder="Type here">
176 296
177 <script type="application/dart" src="little.dart"></script> 297 <div> Shouted: {{'{{'}}shout.[[highlight]]shouted[[/highlight]]}} </div>
178 <script src="packages/browser/dart.js"></script> 298 <div> Palindromic: {{'{{'}}shout.[[highlight]]palindrome[[/highlight]]}} </div >
299 </template>
179 {% endprettify %} 300 {% endprettify %}
180 {% comment %} 301 {% comment %}
181 Beginning double curlies are processed by liquid, 302 Beginning double curlies are processed by liquid,
182 so you have to surround them in single quotes, 303 so you have to surround them in single quotes,
183 surrounded by double curlies. Yup. 304 surrounded by double curlies. Yup.
184 {% endcomment %} 305 {% endcomment %}
185 </div> 306 </div>
186 </div> <!-- code --> 307 </div> <!-- code -->
187 308 </div>
309 </div>
310 </div>
188 </section> 311 </section>
189 312
190 313
191 <section id="get-started"> 314 <section id="get-started">
192 315
193 <h1> Get started </h1> 316 <h1> Get started </h1>
194 317
195 <p> 318 <p>
196 Getting started with Dart is easy. 319 Getting started with Dart is easy.
197 Just download Dart, 320 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 391 You can write Dart apps using any recent version of
269 {% include os-choices.html %} 392 {% include os-choices.html %}
270 The Dart development tools <b>do not&nbsp;support Windows XP</b>. 393 The Dart development tools <b>do not&nbsp;support Windows XP</b>.
271 Dart Editor requires Java version 6 or higher. 394 Dart Editor requires Java version 6 or higher.
272 </aside> 395 </aside>
273 396
274 </section> 397 </section>
275 398
276 </article> <!-- /.homepage --> 399 </article> <!-- /.homepage -->
277 400
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698