From 67ee007fb0d5234ed35eb4042d3b94632cc819ee Mon Sep 17 00:00:00 2001 From: Patrice Chalin Date: Mon, 4 Jul 2016 08:56:14 -0700 Subject: [PATCH 01/13] chore(docs build): add flag to control log output level closes #1823 Gulp targets like `check-deploy` and `serve-and-sync-devguide` are quite verbose. This PR allows the `dgeni` logging level to be controlled using the `--dgeni-log` flag. E.g., use `--dgen-log="error"` to see only errors. Also sets log level to "error" when gulp is silent and log level for createShredMapPackage --- gulpfile.js | 23 +++++++++----- tools/api-builder/angular.io-package/index.js | 3 +- tools/api-builder/docs-package/index.js | 5 --- tools/doc-shredder/doc-shredder.js | 31 ++++++++++--------- 4 files changed, 32 insertions(+), 30 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index f5085f6dd5..44e0787e9b 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -46,22 +46,27 @@ var exampleZipper = require(path.resolve(TOOLS_PATH, '_example-zipper/exampleZip var plunkerBuilder = require(path.resolve(TOOLS_PATH, 'plunker-builder/plunkerBuilder')); var fsUtils = require(path.resolve(TOOLS_PATH, 'fs-utils/fsUtils')); +const isSilent = !!argv.silent; +if (isSilent) gutil.log = gutil.noop; +const _dgeniLogLevel = argv.dgeniLog || (isSilent ? 'error' : 'info'); var _devguideShredOptions = { examplesDir: path.join(DOCS_PATH, '_examples'), fragmentsDir: path.join(DOCS_PATH, '_fragments'), - zipDir: path.join(RESOURCES_PATH, 'zips') + zipDir: path.join(RESOURCES_PATH, 'zips'), + logLevel: _dgeniLogLevel }; var _devguideShredJadeOptions = { - jadeDir: DOCS_PATH - + jadeDir: DOCS_PATH, + logLevel: _dgeniLogLevel }; var _apiShredOptions = { examplesDir: path.join(ANGULAR_PROJECT_PATH, 'modules/@angular/examples'), fragmentsDir: path.join(DOCS_PATH, '_fragments/_api'), - zipDir: path.join(RESOURCES_PATH, 'zips/api') + zipDir: path.join(RESOURCES_PATH, 'zips/api'), + logLevel: _dgeniLogLevel }; var _excludePatterns = ['**/node_modules/**', '**/typings/**', '**/packages/**']; @@ -625,7 +630,7 @@ gulp.task('_shred-devguide-examples', ['_shred-clean-devguide', '_copy-example-b }); gulp.task('_shred-devguide-shared-jade', ['_shred-clean-devguide-shared-jade', '_copy-example-boilerplate'], function() { - return docShredder.shred( _devguideShredJadeOptions); + return docShredder.shred(_devguideShredJadeOptions); }); gulp.task('_shred-clean-devguide-shared-jade', function(cb) { @@ -646,7 +651,7 @@ gulp.task('_shred-clean-devguide', function(cb) { gulp.task('_shred-api-examples', ['_shred-clean-api'], function() { checkAngularProjectPath(); - return docShredder.shred( _apiShredOptions); + return docShredder.shred(_apiShredOptions); }); gulp.task('_shred-clean-api', function(cb) { @@ -1023,7 +1028,8 @@ function buildApiDocs(targetLanguage) { try { // Build a specialized package to generate different versions of the API docs var package = new Package('apiDocs', [require(path.resolve(TOOLS_PATH, 'api-builder/angular.io-package'))]); - package.config(function(targetEnvironments, writeFilesProcessor, readTypeScriptModules) { + package.config(function(log, targetEnvironments, writeFilesProcessor, readTypeScriptModules) { + log.level = _dgeniLogLevel; ALLOWED_LANGUAGES.forEach(function(target) { targetEnvironments.addAllowed(target); }); if (targetLanguage) { targetEnvironments.activate(targetLanguage); @@ -1058,7 +1064,8 @@ function buildShredMaps(shouldWrite) { fragmentsDir: _devguideShredOptions.fragmentsDir, jadeDir: './public/docs', outputDir: './public/docs', - writeFilesEnabled: shouldWrite + writeFilesEnabled: shouldWrite, + logLevel: _dgeniLogLevel }; return docShredder.buildShredMap(options).then(function(docs) { return docs; diff --git a/tools/api-builder/angular.io-package/index.js b/tools/api-builder/angular.io-package/index.js index 11ffe8cb17..faabf62a12 100644 --- a/tools/api-builder/angular.io-package/index.js +++ b/tools/api-builder/angular.io-package/index.js @@ -155,8 +155,7 @@ module.exports = new Package('angular.io', [basePackage, targetPackage, cheatshe ])); }) -.config(function(filterUnwantedDecorators, log) { - log.level = 'info'; +.config(function(filterUnwantedDecorators) { filterUnwantedDecorators.decoratorsToIgnore = [ 'CONST', 'IMPLEMENTS', diff --git a/tools/api-builder/docs-package/index.js b/tools/api-builder/docs-package/index.js index 5988639330..52ead1ba98 100644 --- a/tools/api-builder/docs-package/index.js +++ b/tools/api-builder/docs-package/index.js @@ -20,11 +20,6 @@ module.exports = new Package('angular-v2-docs', [jsdocPackage, nunjucksPackage, .processor(require('./processors/addNotYetDocumentedProperty')) .processor(require('./processors/createDecoratorDocs')) -// Configure the log service -.config(function(log) { - log.level = 'info'; -}) - .config(function(parseTagsProcessor) { parseTagsProcessor.tagDefinitions.push({ name: 'internal', transforms: function() { return true; } }); parseTagsProcessor.tagDefinitions.push({ name: 'syntax' }); diff --git a/tools/doc-shredder/doc-shredder.js b/tools/doc-shredder/doc-shredder.js index 434113026a..b65f8da2ce 100644 --- a/tools/doc-shredder/doc-shredder.js +++ b/tools/doc-shredder/doc-shredder.js @@ -6,6 +6,8 @@ var _ = require('lodash'); var globby = require('globby'); var ignoreDirs = ['**/node_modules/**', '**/dist/**', '**/typings/**']; +var _getLogLevel = function (options) { return options.logLevel || 'info'; } + var shred = function(shredOptions) { try { var pkg; @@ -14,7 +16,7 @@ var shred = function(shredOptions) { } else { pkg = createShredExamplePackage(shredOptions); } - var dgeni = new Dgeni([ pkg]); + var dgeni = new Dgeni([pkg]); return dgeni.generate(); } catch(err) { console.log(err); @@ -31,7 +33,8 @@ var shredSingleExampleDir = function(shredOptions, fileDir) { var options = { includeSubdirs: true, examplesDir: examplesDir, - fragmentsDir: fragmentsDir + fragmentsDir: fragmentsDir, + logLevel: _getLogLevel(shredOptions) } var cleanPath = path.join(fragmentsDir, '*.*') return del([ cleanPath, '!**/*.ovr.*']).then(function(paths) { @@ -49,7 +52,8 @@ var shredSingleDir = function(shredOptions, filePath) { var options = { includeSubdirs: false, examplesDir: examplesDir, - fragmentsDir: fragmentsDir + fragmentsDir: fragmentsDir, + logLevel: _getLogLevel(shredOptions) } var cleanPath = path.join(fragmentsDir, '*.*') return del([ cleanPath, '!**/*.ovr.*']).then(function(paths) { @@ -66,7 +70,8 @@ var shredSingleJadeDir = function(shredOptions, filePath) { var options = { includeSubdirs: false, - jadeDir: jadeDir + jadeDir: jadeDir, + logLevel: _getLogLevel(shredOptions) } // var cleanPath = path.join(jadeDir, '_.*.jade') //return delPromise([ cleanPath]).then(function(paths) { @@ -105,12 +110,12 @@ function createShredExamplePackage(shredOptions) { initializePackage(pkg) .factory(require('./fileReaders/regionFileReader')) .processor(require('./processors/renderAsMarkdownProcessor')) - .config(function(readFilesProcessor, regionFileReader) { readFilesProcessor.fileReaders = [regionFileReader]; }) // default configs - may be overridden - .config(function(readFilesProcessor) { + .config(function(log, readFilesProcessor) { + log.level = _getLogLevel(shredOptions); // Specify the base path used when resolving relative paths to source and output files readFilesProcessor.basePath = "/"; @@ -128,7 +133,7 @@ function createShredExamplePackage(shredOptions) { // this just uses globby to 'preglob' the include files ( and exclude the node_modules). var includeFiles = globby.sync( includeFiles, { ignore: ignoreDirs } ); - console.log(`Shredding ${includeFiles.length} files inside ${shredOptions.examplesDir}`); + log.info(`Shredding ${includeFiles.length} files inside ${shredOptions.examplesDir}`); readFilesProcessor.sourceFiles = [ { // Process all candidate files in `src` and its subfolders ... @@ -159,7 +164,8 @@ function createShredJadePackage(shredOptions) { .factory(require('./fileReaders/regionFileReader')) .processor(require('./processors/renderAsJadeProcessor')) - .config(function(readFilesProcessor, regionFileReader) { + .config(function(log, readFilesProcessor, regionFileReader) { + log.level = _getLogLevel(shredOptions); readFilesProcessor.fileReaders = [regionFileReader]; }) // default configs - may be overridden @@ -211,7 +217,8 @@ var createShredMapPackage = function(mapOptions) { .config(function(shredMapProcessor) { shredMapProcessor.options = options; }) - .config(function(readFilesProcessor, extractPathsReader ) { + .config(function(log, readFilesProcessor, extractPathsReader ) { + log.level = _getLogLevel(mapOptions); readFilesProcessor.fileReaders = [ extractPathsReader]; }) // default configs - may be overridden @@ -281,8 +288,6 @@ var createShredMapPackage = function(mapOptions) { //}); }); - - return pkg; } @@ -334,8 +339,4 @@ function initializePackage(pkg) { .processor({ name: 'docs-rendered', $runAfter: ['rendering-docs'] }) .processor({ name: 'writing-files', $runAfter: ['docs-rendered'] }) .processor({ name: 'files-written', $runAfter: ['writing-files'] }) - .config(function(log) { - // Set logging level - log.level = 'info'; - }) } From 341f32d7f636ef9d4ce6f16d5eaccad8b427e14e Mon Sep 17 00:00:00 2001 From: Foxandxss Date: Tue, 5 Jul 2016 00:46:57 +0200 Subject: [PATCH 02/13] docs(webpack): add angular2-template-loader closes #1825 --- public/docs/_examples/package.json | 1 + .../_examples/webpack/ts/config/webpack.common.js | 2 +- .../_examples/webpack/ts/config/webpack.test.js | 2 +- .../_examples/webpack/ts/src/app/app.component.ts | 4 ++-- public/docs/ts/latest/guide/webpack.jade | 14 ++++++++++---- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/public/docs/_examples/package.json b/public/docs/_examples/package.json index 9e085a4714..552731818b 100644 --- a/public/docs/_examples/package.json +++ b/public/docs/_examples/package.json @@ -45,6 +45,7 @@ }, "devDependencies": { "angular-cli": "^1.0.0-beta.5", + "angular2-template-loader": "^0.4.0", "canonical-path": "0.0.2", "concurrently": "^2.1.0", "css-loader": "^0.23.1", diff --git a/public/docs/_examples/webpack/ts/config/webpack.common.js b/public/docs/_examples/webpack/ts/config/webpack.common.js index 07e74adc65..5de5af96d2 100644 --- a/public/docs/_examples/webpack/ts/config/webpack.common.js +++ b/public/docs/_examples/webpack/ts/config/webpack.common.js @@ -24,7 +24,7 @@ module.exports = { loaders: [ { test: /\.ts$/, - loader: 'ts' + loaders: ['ts', 'angular2-template-loader'] }, { test: /\.html$/, diff --git a/public/docs/_examples/webpack/ts/config/webpack.test.js b/public/docs/_examples/webpack/ts/config/webpack.test.js index 5c24d4e81e..352e4f6126 100644 --- a/public/docs/_examples/webpack/ts/config/webpack.test.js +++ b/public/docs/_examples/webpack/ts/config/webpack.test.js @@ -10,7 +10,7 @@ module.exports = { loaders: [ { test: /\.ts$/, - loader: 'ts' + loaders: ['ts', 'angular2-template-loader'] }, { test: /\.html$/, diff --git a/public/docs/_examples/webpack/ts/src/app/app.component.ts b/public/docs/_examples/webpack/ts/src/app/app.component.ts index 590e5008ec..2b79d055b2 100644 --- a/public/docs/_examples/webpack/ts/src/app/app.component.ts +++ b/public/docs/_examples/webpack/ts/src/app/app.component.ts @@ -5,8 +5,8 @@ import '../../public/css/styles.css'; @Component({ selector: 'my-app', - template: require('./app.component.html'), - styles: [require('./app.component.css')] + templateUrl: './app.component.html', + styleUrls: ['./app.component.css'] }) export class AppComponent { } // #enddocregion diff --git a/public/docs/ts/latest/guide/webpack.jade b/public/docs/ts/latest/guide/webpack.jade index 4a717c93d5..83404e4295 100644 --- a/public/docs/ts/latest/guide/webpack.jade +++ b/public/docs/ts/latest/guide/webpack.jade @@ -233,9 +233,10 @@ a(id="common-configuration") :marked * ts - a loader to transpile our Typescript code to ES5, guided by the `tsconfig.json` file + * angular2-template-loader - loads angular components' template and styles * html - for component templates * images/fonts - Images and fonts are bundled as well. - * css - The pattern matches application-wide styles; the second handles component-scoped styles (the ones specified in a component's `styleUrls` metadata property). + * css - The pattern matches application-wide styles; the second handles component-scoped styles (the ones specified in a component's `styleUrls` metadata property) .l-sub-section :marked The first pattern excludes `.css` files within the `/src/app` directories where our component-scoped styles sit. @@ -245,6 +246,10 @@ a(id="common-configuration") The second pattern filters for component-scoped styles and loads them as strings via the `raw` loader — which is what Angular expects to do with styles specified in a `styleUrls` metadata property. +.l-sub-section + :marked + Multiple loaders can be also chained using the array notation. + :marked Finally we add two plugins: @@ -441,9 +446,10 @@ p. The `HtmlWebpackPlugin` inserts them dynamically at runtime. * The `AppComponent` in `app.component.ts` imports the application-wide css with a simple `import` statement. - - * The `AppComponent` itself has its own html template and css files which we load with the `require()` method - supplied by Webpack. Webpack stashes those component-scoped files in the `app.js` bundle too. + + * The `AppComponent` itself has its own html template and css file. WebPack loads them with calls to `require()`. + Webpack stashes those component-scoped files in the `app.js` bundle too. + We don't see those calls in our source code; they're added behind the scenes by the `angular2-template-loader` plug-in. * The `vendor.ts` consists of vendor dependency `import` statements that drive the `vendor.js` bundle. The application imports these modules too; they'd be duplicated in the `app.js` bundle From da58ff45c7896d2f883c751bbd1d520009c6a3c5 Mon Sep 17 00:00:00 2001 From: Foxandxss Date: Tue, 5 Jul 2016 15:06:13 +0200 Subject: [PATCH 03/13] docs(style-guide): update style-guide samples to use v3 router closes #1828 --- .../style-guide/ts/app/app.component.ts | 58 +----------------- .../style-guide/ts/app/app.routes.ts | 61 +++++++++++++++++++ .../docs/_examples/style-guide/ts/app/main.ts | 4 +- 3 files changed, 64 insertions(+), 59 deletions(-) create mode 100644 public/docs/_examples/style-guide/ts/app/app.routes.ts diff --git a/public/docs/_examples/style-guide/ts/app/app.component.ts b/public/docs/_examples/style-guide/ts/app/app.component.ts index 27287bfd7c..d90494c212 100644 --- a/public/docs/_examples/style-guide/ts/app/app.component.ts +++ b/public/docs/_examples/style-guide/ts/app/app.component.ts @@ -1,65 +1,9 @@ import { Component } from '@angular/core'; -import { RouteConfig, ROUTER_DIRECTIVES } from '@angular/router-deprecated'; - -import { AppComponent as S0101 } from '../01-01/app'; -import { AppComponent as S0207 } from '../02-07/app'; -import { AppComponent as S0208 } from '../02-08/app'; -import { AppComponent as S0301 } from '../03-01/app'; -import { AppComponent as S0302 } from '../03-02/app'; -import { AppComponent as S0303 } from '../03-03/app'; -import { AppComponent as S0304 } from '../03-04/app'; -import { AppComponent as S0305 } from '../03-05/app'; -import { AppComponent as S0306 } from '../03-06/app'; -import { AppComponent as S0410 } from '../04-10/app'; -import { AppComponent as S0414 } from '../04-14/app'; -import { AppComponent as S0502 } from '../05-02/app'; -import { AppComponent as S0503 } from '../05-03/app'; -import { AppComponent as S0504 } from '../05-04/app'; -import { AppComponent as S0512 } from '../05-12/app'; -import { AppComponent as S0513 } from '../05-13/app'; -import { AppComponent as S0514 } from '../05-14/app'; -import { AppComponent as S0515 } from '../05-15/app'; -import { AppComponent as S0516 } from '../05-16/app'; -import { AppComponent as S0517 } from '../05-17/app'; -import { AppComponent as S0601 } from '../06-01/app'; -import { AppComponent as S0603 } from '../06-03/app'; -import { AppComponent as S0701 } from '../07-01/app'; -import { AppComponent as S0703 } from '../07-03/app'; -import { AppComponent as S0704 } from '../07-04/app'; -import { AppComponent as S0901 } from '../09-01/app'; +import { ROUTER_DIRECTIVES } from '@angular/router'; @Component({ selector: 'my-app', templateUrl: 'app/app.component.html', directives: [ROUTER_DIRECTIVES] }) -@RouteConfig([ - { path: '/01-01', name: '01-01', component: S0101 }, - { path: '/02-07', name: '02-07', component: S0207 }, - { path: '/02-08', name: '02-08', component: S0208 }, - { path: '/03-01', name: '03-01', component: S0301 }, - { path: '/03-02', name: '03-02', component: S0302 }, - { path: '/03-03', name: '03-03', component: S0303 }, - { path: '/03-04', name: '03-04', component: S0304 }, - { path: '/03-05', name: '03-05', component: S0305 }, - { path: '/03-06', name: '03-06', component: S0306 }, - { path: '/04-10', name: '04-10', component: S0410 }, - { path: '/04-14', name: '04-14', component: S0414 }, - { path: '/05-02', name: '05-02', component: S0502 }, - { path: '/05-03', name: '05-03', component: S0503 }, - { path: '/05-04', name: '05-04', component: S0504 }, - { path: '/05-12', name: '05-12', component: S0512 }, - { path: '/05-13', name: '05-13', component: S0513 }, - { path: '/05-14', name: '05-14', component: S0514 }, - { path: '/05-15', name: '05-15', component: S0515 }, - { path: '/05-16', name: '05-16', component: S0516 }, - { path: '/05-17', name: '05-17', component: S0517 }, - { path: '/06-01', name: '06-01', component: S0601 }, - { path: '/06-03', name: '06-03', component: S0603 }, - { path: '/07-01', name: '07-01', component: S0701 }, - { path: '/07-03', name: '07-03', component: S0703 }, - { path: '/07-04', name: '07-04', component: S0704 }, - { path: '/09-01', name: '09-01', component: S0901 }, - -]) export class AppComponent { } diff --git a/public/docs/_examples/style-guide/ts/app/app.routes.ts b/public/docs/_examples/style-guide/ts/app/app.routes.ts new file mode 100644 index 0000000000..9254169331 --- /dev/null +++ b/public/docs/_examples/style-guide/ts/app/app.routes.ts @@ -0,0 +1,61 @@ +import { provideRouter, RouterConfig } from '@angular/router'; + +import { AppComponent as S0101 } from '../01-01/app'; +import { AppComponent as S0207 } from '../02-07/app'; +import { AppComponent as S0208 } from '../02-08/app'; +import { AppComponent as S0301 } from '../03-01/app'; +import { AppComponent as S0302 } from '../03-02/app'; +import { AppComponent as S0303 } from '../03-03/app'; +import { AppComponent as S0304 } from '../03-04/app'; +import { AppComponent as S0305 } from '../03-05/app'; +import { AppComponent as S0306 } from '../03-06/app'; +import { AppComponent as S0410 } from '../04-10/app'; +import { AppComponent as S0414 } from '../04-14/app'; +import { AppComponent as S0502 } from '../05-02/app'; +import { AppComponent as S0503 } from '../05-03/app'; +import { AppComponent as S0504 } from '../05-04/app'; +import { AppComponent as S0512 } from '../05-12/app'; +import { AppComponent as S0513 } from '../05-13/app'; +import { AppComponent as S0514 } from '../05-14/app'; +import { AppComponent as S0515 } from '../05-15/app'; +import { AppComponent as S0516 } from '../05-16/app'; +import { AppComponent as S0517 } from '../05-17/app'; +import { AppComponent as S0601 } from '../06-01/app'; +import { AppComponent as S0603 } from '../06-03/app'; +import { AppComponent as S0701 } from '../07-01/app'; +import { AppComponent as S0703 } from '../07-03/app'; +import { AppComponent as S0704 } from '../07-04/app'; +import { AppComponent as S0901 } from '../09-01/app'; + +const routes: RouterConfig = [ + { path: '01-01', component: S0101 }, + { path: '02-07', component: S0207 }, + { path: '02-08', component: S0208 }, + { path: '03-01', component: S0301 }, + { path: '03-02', component: S0302 }, + { path: '03-03', component: S0303 }, + { path: '03-04', component: S0304 }, + { path: '03-05', component: S0305 }, + { path: '03-06', component: S0306 }, + { path: '04-10', component: S0410 }, + { path: '04-14', component: S0414 }, + { path: '05-02', component: S0502 }, + { path: '05-03', component: S0503 }, + { path: '05-04', component: S0504 }, + { path: '05-12', component: S0512 }, + { path: '05-13', component: S0513 }, + { path: '05-14', component: S0514 }, + { path: '05-15', component: S0515 }, + { path: '05-16', component: S0516 }, + { path: '05-17', component: S0517 }, + { path: '06-01', component: S0601 }, + { path: '06-03', component: S0603 }, + { path: '07-01', component: S0701 }, + { path: '07-03', component: S0703 }, + { path: '07-04', component: S0704 }, + { path: '09-01', component: S0901 }, +]; + +export const APP_ROUTER_PROVIDERS = [ + provideRouter(routes) +]; diff --git a/public/docs/_examples/style-guide/ts/app/main.ts b/public/docs/_examples/style-guide/ts/app/main.ts index 5eec1d8f88..b58fbb68dd 100644 --- a/public/docs/_examples/style-guide/ts/app/main.ts +++ b/public/docs/_examples/style-guide/ts/app/main.ts @@ -1,15 +1,15 @@ import { bootstrap } from '@angular/platform-browser-dynamic'; -import { ROUTER_PROVIDERS } from '@angular/router-deprecated'; import { XHRBackend, HTTP_PROVIDERS } from '@angular/http'; import { HashLocationStrategy, LocationStrategy } from '@angular/common'; import { InMemoryBackendService, SEED_DATA } from 'angular2-in-memory-web-api'; import 'rxjs/add/operator/map'; +import { APP_ROUTER_PROVIDERS } from './app.routes'; import { HeroData } from './hero-data'; import { AppComponent } from './app.component'; bootstrap(AppComponent, [ - ROUTER_PROVIDERS, + APP_ROUTER_PROVIDERS, HTTP_PROVIDERS, { provide: LocationStrategy, useClass: HashLocationStrategy }, { provide: XHRBackend, useClass: InMemoryBackendService }, From 8b05dd272650736c6318b5da67587d54ae7b0f1c Mon Sep 17 00:00:00 2001 From: Foxandxss Date: Tue, 5 Jul 2016 15:48:43 +0200 Subject: [PATCH 04/13] chore: show new forms library via the api-builder closes #1829 --- tools/api-builder/angular.io-package/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/api-builder/angular.io-package/index.js b/tools/api-builder/angular.io-package/index.js index faabf62a12..9f59e99221 100644 --- a/tools/api-builder/angular.io-package/index.js +++ b/tools/api-builder/angular.io-package/index.js @@ -64,6 +64,7 @@ module.exports = new Package('angular.io', [basePackage, targetPackage, cheatshe '@angular/common/testing.ts', '@angular/core/index.ts', '@angular/core/testing.ts', + '@angular/forms/index.ts', '@angular/http/index.ts', '@angular/http/testing.ts', '@angular/platform-browser/index.ts', From 7f991dc4f12d6256db4f5f4ff237f04e152d1ec4 Mon Sep 17 00:00:00 2001 From: Christos Koutsiaris Date: Tue, 5 Jul 2016 15:02:47 +0100 Subject: [PATCH 05/13] docs(typescript-configuration): TypeScript handbook documentation link change closes #1830 Page has moved to http://www.typescriptlang.org/docs/handbook/tsconfig-json.html --- public/docs/ts/latest/guide/typescript-configuration.jade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/docs/ts/latest/guide/typescript-configuration.jade b/public/docs/ts/latest/guide/typescript-configuration.jade index ac4705a272..b60b926b93 100644 --- a/public/docs/ts/latest/guide/typescript-configuration.jade +++ b/public/docs/ts/latest/guide/typescript-configuration.jade @@ -23,7 +23,7 @@ a(id="tsconfig") .l-sub-section :marked Get details about `tsconfig.json` from the official - [TypeScript wiki](https://github.com/Microsoft/TypeScript/wiki/tsconfig.json). + [TypeScript wiki](http://www.typescriptlang.org/docs/handbook/tsconfig-json.html). :marked We created the following `tsconfig.json` for the [QuickStart](../quickstart.html): +makeJson('quickstart/ts/tsconfig.1.json', null, 'tsconfig.json')(format=".") From 962b215048fb8a0d4d948ece56856e11b929b57d Mon Sep 17 00:00:00 2001 From: Ward Bell Date: Wed, 6 Jul 2016 00:07:18 -0700 Subject: [PATCH 06/13] chore(glossary/ts): redirect old glossary to correct location within the guide folder --- firebase.json | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/firebase.json b/firebase.json index 069b61f208..80ebf15663 100644 --- a/firebase.json +++ b/firebase.json @@ -20,7 +20,13 @@ }, { "source": "/docs/ts/latest/guide/setup.html", - "destination": "/docs/ts/latest/index.html" + "destination": "/docs/ts/latest/index.html", + "type": 301 + }, + { + "source": "/docs/ts/latest/glossary.html", + "destination": "/docs/ts/latest/guide/glossary.html", + "type": 301 }, { "source": "/docs/ts/latest/testing", From d1dd2b82f4c0e572b3d4b9c95eeeb5ef51078f2b Mon Sep 17 00:00:00 2001 From: Ward Bell Date: Wed, 6 Jul 2016 01:11:00 -0700 Subject: [PATCH 07/13] docs(router): changes suggested by Deb Kurata in #1808 --- public/docs/_examples/router/ts/app/auth.guard.ts | 15 ++++----------- public/docs/ts/latest/guide/router.jade | 2 +- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/public/docs/_examples/router/ts/app/auth.guard.ts b/public/docs/_examples/router/ts/app/auth.guard.ts index 68feb96883..52317985c1 100755 --- a/public/docs/_examples/router/ts/app/auth.guard.ts +++ b/public/docs/_examples/router/ts/app/auth.guard.ts @@ -1,20 +1,13 @@ // #docregion -import { Injectable } from '@angular/core'; -import { CanActivate, - Router, - ActivatedRouteSnapshot, - RouterStateSnapshot } from '@angular/router'; -import { AuthService } from './auth.service'; +import { Injectable } from '@angular/core'; +import { CanActivate, Router } from '@angular/router'; +import { AuthService } from './auth.service'; @Injectable() export class AuthGuard implements CanActivate { constructor(private authService: AuthService, private router: Router) {} - canActivate( - // Not using but worth knowing about - next: ActivatedRouteSnapshot, - state: RouterStateSnapshot - ) { + canActivate() { if (this.authService.isLoggedIn) { return true; } this.router.navigate(['/login']); return false; diff --git a/public/docs/ts/latest/guide/router.jade b/public/docs/ts/latest/guide/router.jade index c3d6d3a7ec..0f4ed85a2a 100644 --- a/public/docs/ts/latest/guide/router.jade +++ b/public/docs/ts/latest/guide/router.jade @@ -1052,7 +1052,7 @@ h2#guards Route Guards We'll examine other router guards in a future update to this chapter. :marked We can have multiple guards at every level of a routing hierarchy. - The router checks the `CanDeactive` guards first, from deepest child route to the top. + The router checks the `CanDeactivate` guards first, from deepest child route to the top. Then it checks the `CanActivate` guards from the top down to the deepest child route. If _any_ guard returns false, pending guards that have not completed will be canceled, and the entire navigation is canceled. From 791b364f6ad9a906d093939f0bf30a3c30ba7d6b Mon Sep 17 00:00:00 2001 From: Brandon Roberts Date: Tue, 5 Jul 2016 15:12:32 -0500 Subject: [PATCH 08/13] chore(bios): Added bio for Brandon Roberts --- harp.json | 8 ++++++++ public/resources/images/bios/brandonroberts.jpg | Bin 0 -> 8771 bytes 2 files changed, 8 insertions(+) create mode 100644 public/resources/images/bios/brandonroberts.jpg diff --git a/harp.json b/harp.json index 5811da34b1..8af12262c8 100644 --- a/harp.json +++ b/harp.json @@ -484,6 +484,14 @@ "twitter": "ralph_wang_gde", "bio": "Ralph(Zhicheng Wang) is a senior consultant at ThoughWorks and also a GDE. He is a technology enthusiast and he is a passionate advocate of “Simplicity, Professionalism and Sharing”. In his eighteen years of R&D career, he worked as tester, R&D engineer, project manager, product manager and CTO. He is looking forward to the birth of his baby.", "type": "Community" + }, + "brandonroberts": { + "name": "Brandon Roberts", + "picture": "/resources/images/bios/brandonroberts.jpg", + "twitter": "brandontroberts", + "website": "https://github.com/brandonroberts", + "bio": "Brandon is a front-end developer for a game studio developing web applications for STEM-based learning games. He is also a natural born troubleshooter who helps solve Angular issues on Github and Gitter support channels, particularly dealing with routing. He is also a member of the Angular docs team.", + "type": "Community" } } } diff --git a/public/resources/images/bios/brandonroberts.jpg b/public/resources/images/bios/brandonroberts.jpg new file mode 100644 index 0000000000000000000000000000000000000000..df3b82e93848702203f15adea22dc6fb0c3e647d GIT binary patch literal 8771 zcmbt(bx<5z^Y$zYEWw=x76~qa;9;>K!F_QJu(-owK@ub(fxzOvxVr?6LT~~E+29a@ z22BVSi16Fo`_{cxU%g+|Cw*#8Kh@LS(@&ps=8u`HxvN!xQcF!!4FG{afCg>=SD%1L z)etvl0MOM11ONaa0ti6V02qfrxB-Be0D`|T0BC`j|G@|l-+z4Y0N}A3fd3yKOPu~A zxXgc||D*AW@c!}mS_J+FPyBJcIsl{%Tzvw3P_90{?Bc>AfV8rvF8-g4IQa{6{{<Czu3}z*+#ZSYRWdNp`77stoz7mPu_ia4wn9N_y0C*v?J($(G(hs$vIhCi-A9RAY_T8F>!#vknRH~#(y`x_%vaNJ07 znBC=XeB%#x_#6M>!j5$H_rm#j;xLz&XCSVIzvRyVj88xaA-YCPf^%r21n@v$FdjabfZ)$T07c;L1Nc+~)YnCo z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VNky$;xf#>j0riF6f(?uk1^e3tF0`%cCV>&8cMg3u z_63t@MtVo()}Gs^D|ye4$t^r^V$PCz4tksUGt^8b;hWSJ9J=-#nK_v>-}UgADK#vs z;bsH3gUTw+Vw;)yH`Es!s<+ctoVn&X?}C&999=Eq3#|v) z7nekfd?Wo(NM*&m%oLJx%{BH^A-hpfyl7dHk8|SP-j4&FRi%Y8u;KG&wlKP5gy$u< zcT5!7pgg?dPMsKuqeF{l@ek1f8ElHiHTG?ZkvoXR@Rz9g)|v>EqN`Ijmi+O@_{mgB z`_z{|jOgOeCI&X_QpHV+9@g3gyqB=PVf`$TNTT<-Os>V4 zgl~L0w1L9iPx_GTN$$^J?lp{%nfwt$SWVvsl7&nkk71Quq19T~f+AKlVV%pQ>@mwA zuf!=C;Xs*!FY0H_RG%57>UV(k4fT$#B^utDI{fXZg*2u+hSjA0;$wP4BQgk$vZo7H zl=7nE?yV^3`boXL?lZXYL({qmY&jvlHH9@cS2#neoImxGg;&q|?fxrZrcs+B%cS~w zi(H+pms<4Ua5$)JC@|>52BD;WrdY`Gu4)ibvl7!FQD}f~jZo_672t~{p1S+(pNlpwK}qv#aeGS7NcOG+)HV96k)T+-KXoFepHN>;#wtNH%{jk+th literal 0 HcmV?d00001 From 3a45a7a070af81f90800bb75503866e977dc47ba Mon Sep 17 00:00:00 2001 From: Naomi Black Date: Wed, 6 Jul 2016 14:56:08 -0700 Subject: [PATCH 09/13] Revert "chore(glossary/ts): redirect old glossary to correct location within the guide folder" This reverts commit 962b215048fb8a0d4d948ece56856e11b929b57d. --- firebase.json | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/firebase.json b/firebase.json index 80ebf15663..069b61f208 100644 --- a/firebase.json +++ b/firebase.json @@ -20,13 +20,7 @@ }, { "source": "/docs/ts/latest/guide/setup.html", - "destination": "/docs/ts/latest/index.html", - "type": 301 - }, - { - "source": "/docs/ts/latest/glossary.html", - "destination": "/docs/ts/latest/guide/glossary.html", - "type": 301 + "destination": "/docs/ts/latest/index.html" }, { "source": "/docs/ts/latest/testing", From ff718f4211aa6326a8756aecfe96148ce49815f7 Mon Sep 17 00:00:00 2001 From: Patrice Chalin Date: Thu, 7 Jul 2016 11:42:04 -0700 Subject: [PATCH 10/13] docs(cheatsheet/dart): alert reader of possible inaccuracies (#1814) Until we can generate the cheat sheet properly, at least alert reader of possible inaccuracies. --- public/docs/dart/latest/cheatsheet.jade | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/public/docs/dart/latest/cheatsheet.jade b/public/docs/dart/latest/cheatsheet.jade index 8d260e148e..739ad031ab 100644 --- a/public/docs/dart/latest/cheatsheet.jade +++ b/public/docs/dart/latest/cheatsheet.jade @@ -1,6 +1,8 @@ - var base = current.path[4] ? '.' : './guide'; .banner.grid-fluid - p.text-body.c10 This cheat sheet is provisional and may change. Angular 2 is currently in Release Candidate. + .alert.is-important + :marked + **Known issue:** Some cheat sheet entries are currently inaccurate, reflecting TypeScript instead of Dart. article(class="l-content-small grid-fluid docs-content") .cheatsheet From 801ac76da0ea49b6485e0a66d60620556a577696 Mon Sep 17 00:00:00 2001 From: Patrice Chalin Date: Thu, 7 Jul 2016 14:00:19 -0700 Subject: [PATCH 11/13] docs(guide/displaying-data): proofread (#1819) * docs(displaying-data/dart): proofread - Dart prose simplified by removing discussion of "additions to pubspec.yaml" which are no longer necessary given the current state of QuickStart. - E2e suites passed: public/docs/_examples/displaying-data/dart public/docs/_examples/displaying-data/ts Contributes to #1598 and #1508. * docs(displaying-data/ts): proofread - TS prose updated to include @kwalrath's revisions from a while ago, with some of my edits as well. - E2e suites passed: public/docs/_examples/displaying-data/dart public/docs/_examples/displaying-data/ts * docs(displaying-data/ts): post-review edits --- .../dart/lib/app_component.dart | 40 ++- .../dart/lib/app_component_1.dart | 9 +- .../dart/lib/app_component_2.dart | 42 ++- .../dart/lib/app_component_3.dart | 47 ++- .../displaying-data/dart/lib/hero.dart | 4 +- .../displaying-data/dart/pubspec.yaml | 2 +- .../displaying-data/dart/web/index.html | 7 +- .../displaying-data/dart/web/main.dart | 2 +- .../ts/app/app-ctor.component.ts | 3 +- .../displaying-data/ts/app/app.component.2.ts | 8 +- .../displaying-data/ts/app/app.component.3.ts | 6 +- .../displaying-data/ts/app/app.component.ts | 6 +- .../_examples/displaying-data/ts/app/hero.ts | 4 +- .../_examples/displaying-data/ts/index.html | 4 +- public/docs/dart/latest/_quickstart_repo.jade | 4 + .../dart/latest/guide/displaying-data.jade | 271 ++---------------- .../docs/ts/latest/guide/displaying-data.jade | 225 ++++++++------- 17 files changed, 224 insertions(+), 460 deletions(-) create mode 100644 public/docs/dart/latest/_quickstart_repo.jade diff --git a/public/docs/_examples/displaying-data/dart/lib/app_component.dart b/public/docs/_examples/displaying-data/dart/lib/app_component.dart index 25402e3e3b..5f64cef0d2 100644 --- a/public/docs/_examples/displaying-data/dart/lib/app_component.dart +++ b/public/docs/_examples/displaying-data/dart/lib/app_component.dart @@ -3,30 +3,28 @@ import 'package:angular2/core.dart'; import 'hero.dart'; -final List _heroes = [ - new Hero(1, 'Windstorm'), - new Hero(13, 'Bombasto'), - new Hero(15, 'Magneta'), - new Hero(20, 'Tornado') -]; - @Component( selector: 'my-app', template: ''' -

{{title}}

-

My favorite hero is: {{myHero.name}}

-

Heroes:

-
    -
  • - {{ hero.name }} -
  • -
-// #docregion message -

There are many heroes!

-// #enddocregion message -''') +

{{title}}

+

My favorite hero is: {{myHero.name}}

+

Heroes:

+
    +
  • + {{ hero.name }} +
  • +
+ // #docregion message +

There are many heroes!

+ // #enddocregion message + ''') class AppComponent { String title = 'Tour of Heroes'; - List heroes = _heroes; - Hero myHero = _heroes[0]; + List heroes = [ + new Hero(1, 'Windstorm'), + new Hero(13, 'Bombasto'), + new Hero(15, 'Magneta'), + new Hero(20, 'Tornado') + ]; + Hero get myHero => heroes.first; } diff --git a/public/docs/_examples/displaying-data/dart/lib/app_component_1.dart b/public/docs/_examples/displaying-data/dart/lib/app_component_1.dart index 20f946fcc5..93a4e5a5a9 100644 --- a/public/docs/_examples/displaying-data/dart/lib/app_component_1.dart +++ b/public/docs/_examples/displaying-data/dart/lib/app_component_1.dart @@ -3,11 +3,12 @@ import 'package:angular2/core.dart'; @Component( selector: 'my-app', -// #docregion template + // #docregion template template: ''' -

{{title}}

-

My favorite hero is: {{myHero}}

''' -// #enddocregion template +

{{title}}

+

My favorite hero is: {{myHero}}

+ ''' + // #enddocregion template ) class AppComponent { String title = 'Tour of Heroes'; diff --git a/public/docs/_examples/displaying-data/dart/lib/app_component_2.dart b/public/docs/_examples/displaying-data/dart/lib/app_component_2.dart index 3d64fd0c02..b28e013dec 100644 --- a/public/docs/_examples/displaying-data/dart/lib/app_component_2.dart +++ b/public/docs/_examples/displaying-data/dart/lib/app_component_2.dart @@ -1,36 +1,26 @@ // #docregion import 'package:angular2/core.dart'; -// #docregion mock-heroes -const List _heroes = const [ - 'Windstorm', - 'Bombasto', - 'Magneta', - 'Tornado' -]; -// #enddocregion mock-heroes - @Component( selector: 'my-app', -// #docregion template + // #docregion template template: ''' -

{{title}}

-

My favorite hero is: {{myHero}}

-

Heroes:

-
    -// #docregion li-repeater -
  • - {{ hero }} -
  • -// #enddocregion li-repeater -
''' -// #enddocregion template +

{{title}}

+

My favorite hero is: {{myHero}}

+

Heroes:

+
    + // #docregion li +
  • + {{ hero }} +
  • + // #enddocregion li +
+ ''' + // #enddocregion template ) -// #docregion mock-heroes +// #docregion class class AppComponent { String title = 'Tour of Heroes'; - List heroes = _heroes; - String myHero = _heroes[0]; + List heroes = ['Windstorm', 'Bombasto', 'Magneta', 'Tornado']; + String get myHero => heroes.first; } -// #enddocregion mock-heroes -// #enddocregion diff --git a/public/docs/_examples/displaying-data/dart/lib/app_component_3.dart b/public/docs/_examples/displaying-data/dart/lib/app_component_3.dart index 51d2827a2a..35e3e94f77 100644 --- a/public/docs/_examples/displaying-data/dart/lib/app_component_3.dart +++ b/public/docs/_examples/displaying-data/dart/lib/app_component_3.dart @@ -1,35 +1,34 @@ // #docregion import 'package:angular2/core.dart'; -// #docregion heroes +// #docregion import import 'hero.dart'; - -final List _heroes = [ - new Hero(1, 'Windstorm'), - new Hero(13, 'Bombasto'), - new Hero(15, 'Magneta'), - new Hero(20, 'Tornado') -]; -// #enddocregion heroes +// #enddocregion import @Component( selector: 'my-app', -// #docregion template + // #docregion template template: ''' -

{{title}}

-

My favorite hero is: {{myHero.name}}

-

Heroes:

-
    -
  • - {{ hero.name }} -
  • -
''' -// #enddocregion template +

{{title}}

+

My favorite hero is: {{myHero.name}}

+

Heroes:

+
    +
  • + {{ hero.name }} +
  • +
+ ''' + // #enddocregion template ) -// #docregion heroes +// #docregion class class AppComponent { String title = 'Tour of Heroes'; - List heroes = _heroes; - Hero myHero = _heroes[0]; + // #docregion heroes + List heroes = [ + new Hero(1, 'Windstorm'), + new Hero(13, 'Bombasto'), + new Hero(15, 'Magneta'), + new Hero(20, 'Tornado') + ]; + Hero get myHero => heroes.first; + // #enddocregion heroes } -// #enddocregion heroes -// #enddocregion diff --git a/public/docs/_examples/displaying-data/dart/lib/hero.dart b/public/docs/_examples/displaying-data/dart/lib/hero.dart index 6542e4f4ca..65d712ee93 100644 --- a/public/docs/_examples/displaying-data/dart/lib/hero.dart +++ b/public/docs/_examples/displaying-data/dart/lib/hero.dart @@ -1,9 +1,9 @@ // #docregion class Hero { - int id; + final int id; String name; Hero(this.id, this.name); + String toString() => '$id: $name'; } -// #enddocregion diff --git a/public/docs/_examples/displaying-data/dart/pubspec.yaml b/public/docs/_examples/displaying-data/dart/pubspec.yaml index eb112ebb45..2ca27306c6 100644 --- a/public/docs/_examples/displaying-data/dart/pubspec.yaml +++ b/public/docs/_examples/displaying-data/dart/pubspec.yaml @@ -1,6 +1,6 @@ # #docregion name: displaying_data -description: Displaying Data Example +description: Displaying Data version: 0.0.1 environment: sdk: '>=1.13.0 <2.0.0' diff --git a/public/docs/_examples/displaying-data/dart/web/index.html b/public/docs/_examples/displaying-data/dart/web/index.html index 6585d21511..e9b9c097a1 100644 --- a/public/docs/_examples/displaying-data/dart/web/index.html +++ b/public/docs/_examples/displaying-data/dart/web/index.html @@ -3,13 +3,14 @@ Displaying Data - + + + - Loading... - + diff --git a/public/docs/_examples/displaying-data/dart/web/main.dart b/public/docs/_examples/displaying-data/dart/web/main.dart index 6a3620979c..f640544559 100644 --- a/public/docs/_examples/displaying-data/dart/web/main.dart +++ b/public/docs/_examples/displaying-data/dart/web/main.dart @@ -9,7 +9,7 @@ import 'package:angular2/platform/browser.dart'; // #docregion final import 'package:displaying_data/app_component.dart'; -main() { +void main() { // #enddocregion final // pick one // bootstrap(v1.AppComponent); diff --git a/public/docs/_examples/displaying-data/ts/app/app-ctor.component.ts b/public/docs/_examples/displaying-data/ts/app/app-ctor.component.ts index d9b816e558..b275baa8e6 100644 --- a/public/docs/_examples/displaying-data/ts/app/app-ctor.component.ts +++ b/public/docs/_examples/displaying-data/ts/app/app-ctor.component.ts @@ -7,7 +7,7 @@ import { Component } from '@angular/core';

My favorite hero is: {{myHero}}

` }) -// #docregion app-ctor +// #docregion class export class AppCtorComponent { title: string; myHero: string; @@ -17,4 +17,3 @@ export class AppCtorComponent { this.myHero = 'Windstorm'; } } -// #enddocregion app-ctor diff --git a/public/docs/_examples/displaying-data/ts/app/app.component.2.ts b/public/docs/_examples/displaying-data/ts/app/app.component.2.ts index 506215b36e..da7a653973 100644 --- a/public/docs/_examples/displaying-data/ts/app/app.component.2.ts +++ b/public/docs/_examples/displaying-data/ts/app/app.component.2.ts @@ -9,20 +9,18 @@ import { Component } from '@angular/core';

My favorite hero is: {{myHero}}

Heroes:

    - // #docregion li-repeater + // #docregion li
  • {{ hero }}
  • - // #enddocregion li-repeater + // #enddocregion li
` // #enddocregion template }) -// #docregion mock-heroes +// #docregion class export class AppComponent { title = 'Tour of Heroes'; heroes = ['Windstorm', 'Bombasto', 'Magneta', 'Tornado']; myHero = this.heroes[0]; } -// #enddocregion mock-heroes -// #enddocregion diff --git a/public/docs/_examples/displaying-data/ts/app/app.component.3.ts b/public/docs/_examples/displaying-data/ts/app/app.component.3.ts index 8ea79cce53..0705176292 100644 --- a/public/docs/_examples/displaying-data/ts/app/app.component.3.ts +++ b/public/docs/_examples/displaying-data/ts/app/app.component.3.ts @@ -1,8 +1,8 @@ // #docregion import { Component } from '@angular/core'; -// #docregion import-hero +// #docregion import import { Hero } from './hero'; -// #enddocregion import-hero +// #enddocregion import @Component({ selector: 'my-app', @@ -32,5 +32,3 @@ export class AppComponent { myHero = this.heroes[0]; // #enddocregion heroes } -// #enddocregion class -// #enddocregion diff --git a/public/docs/_examples/displaying-data/ts/app/app.component.ts b/public/docs/_examples/displaying-data/ts/app/app.component.ts index 1ba40c62c9..40c90e2d62 100644 --- a/public/docs/_examples/displaying-data/ts/app/app.component.ts +++ b/public/docs/_examples/displaying-data/ts/app/app.component.ts @@ -1,8 +1,6 @@ // #docplaster // #docregion final -// #docregion imports import { Component } from '@angular/core'; -// #enddocregion imports import { Hero } from './hero'; @Component({ @@ -17,12 +15,10 @@ import { Hero } from './hero'; // #docregion message -

There are many heroes!

+

There are many heroes!

// #enddocregion message ` }) - export class AppComponent { title = 'Tour of Heroes'; heroes = [ diff --git a/public/docs/_examples/displaying-data/ts/app/hero.ts b/public/docs/_examples/displaying-data/ts/app/hero.ts index e6b3745186..f89d26ad63 100644 --- a/public/docs/_examples/displaying-data/ts/app/hero.ts +++ b/public/docs/_examples/displaying-data/ts/app/hero.ts @@ -1,9 +1,9 @@ // #docregion export class Hero { constructor( - // #docregion id-parameter + // #docregion id public id: number, - // #enddocregion id-parameter + // #enddocregion id public name: string) { } } // #enddocregion diff --git a/public/docs/_examples/displaying-data/ts/index.html b/public/docs/_examples/displaying-data/ts/index.html index e74be1c5de..d9e9291661 100644 --- a/public/docs/_examples/displaying-data/ts/index.html +++ b/public/docs/_examples/displaying-data/ts/index.html @@ -19,10 +19,10 @@ - + loading... - + diff --git a/public/docs/dart/latest/_quickstart_repo.jade b/public/docs/dart/latest/_quickstart_repo.jade new file mode 100644 index 0000000000..e72fbfacf2 --- /dev/null +++ b/public/docs/dart/latest/_quickstart_repo.jade @@ -0,0 +1,4 @@ +.l-sub-section + :marked + Alternatively, begin with a + [download of the QuickStart source](https://github.com/angular-examples/quickstart/archive/master.zip). diff --git a/public/docs/dart/latest/guide/displaying-data.jade b/public/docs/dart/latest/guide/displaying-data.jade index 6e8b96f3c3..9207073069 100644 --- a/public/docs/dart/latest/guide/displaying-data.jade +++ b/public/docs/dart/latest/guide/displaying-data.jade @@ -1,257 +1,24 @@ -include ../_util-fns +extends ../../../ts/latest/guide/displaying-data.jade -:marked - We typically display data in Angular by binding controls in an HTML template - to properties of an Angular component. +block includes + include ../_util-fns + - var _iterableUrl = 'https://api.dartlang.org/stable/dart-core/Iterable-class.html'; + - var _boolean = 'boolean'; - In this chapter, we'll create a component with a list of heroes. Each hero has a name. - We'll display the list of hero names and - conditionally show a selected hero in a detail area below the list. +block quickstart-repo + //- Must have this block so that Jade picks up the Dart include. + include ../_quickstart_repo - The final UI looks like this: - -figure.image-display - img(src="/resources/images/devguide/displaying-data/final.png" alt="Final UI") - - - -.l-main-section -:marked - ## Showing component properties with interpolation - The easiest way to display a component property - is to bind the property name through interpolation. - With interpolation, we put the property name in the view template, enclosed in double curly braces: `{{myHero}}`. - - Let's build a small illustrative example together. - - - Create a new project folder (`displaying`) and create 3 files: - `pubspec.yaml`, `web/index.html`, and `web/main.dart`. - Put these contents in the files: - -- var stylePattern = [{ otl: /(platform_directives.*$)/gm }, null, null]; -+makeTabs('displaying-data/dart/pubspec.yaml, displaying-data/dart/web/index.html, displaying-data/dart/web/main.dart', ',,final', 'pubspec.yaml, web/index.html, web/main.dart', stylePattern) - -:marked - All of this code should look familiar from the - [QuickStart](../quickstart.html), - except for the `platform_directives` entry in `pubspec.yaml` - and the imports in `main.dart`. - - In `pubspec.yaml`, the `platform_directives` entry lets us use - core directives, such as the `ngFor` directive that we'll soon add to our app. - - In `main.dart`, importing `app_component.dart` lets us implement part - of the app in a different Dart file. The QuickStart version of `main.dart` - imported `core.dart`, but we don't need that import here because - this version of `main.dart` is so basic: it only bootstraps the app, - and doesn't implement any components or other injectable types. - - So that the code can run, - let's create a stub for the `` component. - - Create a new directory called `lib`. - In it, put a file called `app_component.dart` - with the following code: - -+makeExample('displaying-data/dart/lib/app_component_1.dart', null, 'lib/app_component.dart') - -:marked - We defined a component with two properties: `title` and `myHero`. - The template displays the two component properties using double curly brace - interpolation: - -+makeExample('displaying-data/dart/lib/app_component_1.dart', 'template')(format=".") - -:marked - Angular automatically pulls the value of the `title` and `myHero` properties from the component and - inserts those values into the browser. Angular updates the display - when these properties change. - - -.l-sub-section +block hero-class :marked - More precisely, the redisplay occurs after some kind of asynchronous event related to - the view such as a keystroke, a timer completion, or an async `XHR` response. - We don't have those in this sample. - But then the properties aren't changing on their own either. For the moment we must operate on faith. -:marked - Notice that we haven't called **new** to create an instance of the `AppComponent` class. - Angular is creating an instance for us. How? + We've defined a class with a constructor, two properties (`id` and `name`), + and a `toString()` method. - Notice the CSS `selector` in the `@Component` decorator that specifies an element named "my-app". - Remember back in QuickStart that we added the `` element to the body of our `index.html` file: -+makeExample('displaying-data/dart/web/index.html', 'my-app')(format=".") - - -:marked - When we bootstrap with the `AppComponent` class (in `main.dart`), Angular looks for a `` - in the `index.html`, finds it, instantiates an instance of `AppComponent`, and renders it - inside the `` tag. - - Try running the app. It should display the title and hero name: -figure.image-display - img(src="/resources/images/devguide/displaying-data/title-and-hero.png" alt="Title and Hero") -// TODO: Here the TS version says "Let's review some of the choices we made and consider alternatives." However, it's unclear where this review ends. Clarify the structure in the TS, and make sure this is the best place for the Dart version of this section. - -#performance.l-sub-section - :marked - ### Template inline or template file? - - We can store our component's template in one of two places. - We can define it *inline* using the `template` property, as we do here. - Or we can define the template in a separate HTML file and link to it in - the component metadata using the `@Component` decorator's `templateUrl` property. - - The choice between inline and separate HTML is a matter of taste, - circumstances, and organization policy. - Here we're using inline HTML because the template is small, and the demo - is simpler without the additional HTML file. - - In either style, the template data bindings have the same access to the component's properties. - - - -.l-main-section -:marked - ## Showing a list property with ***ngFor** - - We want to display a list of heroes. We begin by adding a list of hero names to the component and redefine `myHero` to be the first name in the list. -+makeExample('displaying-data/dart/lib/app_component_2.dart', 'mock-heroes', 'lib/app_component.dart (excerpt)')(format=".") - -:marked - Now we use the Angular `ngFor` "repeater" directive in the template to display - each item in the `heroes` list. - -+makeExample('displaying-data/dart/lib/app_component_2.dart', 'template','lib/app_component.dart (excerpt)')(format=".") - - -:marked - Our presentation is the familiar HTML unordered list with `
    ` and `
  • ` tags. Let's focus on the `
  • ` tag. -+makeExample('displaying-data/dart/lib/app_component_2.dart', 'li-repeater')(format=".") - -:marked - We added a somewhat mysterious `*ngFor` to the `
  • ` element. - That's the Angular "repeater" directive. - Its presence on the `
  • ` tag marks that `
  • ` element (and its children) as the "repeater template". - -.alert.is-important - :marked - Don't forget the leading asterisk (\*) in `*ngFor`. It is an essential part of the syntax. - Learn more about this and `ngFor` in the [Template Syntax](./template-syntax.html#ngFor) chapter. - -:marked - Notice the `hero` in the `ngFor` double-quoted instruction; - it is an example of a [template input variable](./template-syntax.html#ngForMicrosyntax). - - Angular duplicates the `
  • ` for each item in the list, setting the `hero` variable - to the item (the hero) in the current iteration. Angular uses that variable as the - context for the interpolation in the double curly braces. - -.l-sub-section - :marked - We happened to give `ngFor` a list to display. - In fact, `ngFor` can repeat items for any [Iterable](https://api.dartlang.org/stable/dart-core/Iterable-class.html) object. - -:marked - Now the heroes appear in an unordered list. - -figure.image-display - img(src="/resources/images/devguide/displaying-data/hero-names-list.png" alt="After ngfor") - -.callout.is-important - header Did the app break? - :marked - If the app stops working after adding `*ngFor`, - make sure `pubspec.yaml` has the [correct **platform_directives** entry](#platform_directives). - A missing or incorrect `platform_directives` entry results in template parse errors. - -.l-main-section -:marked - ## Creating a class for the data - - We are defining our data directly inside our component. - That's fine for a demo but certainly isn't a best practice. It's not even a good practice. - Although we won't do anything about that in this chapter, we'll make a mental note to fix this down the road. - - At the moment, we're binding to a list of strings. We do that occasionally in real applications, but - most of the time we're binding to more specialized objects. - - Let's turn our list of hero names into a list of `Hero` objects. For that we'll need a `Hero` class. - - Create a new file in the `lib/` folder called `hero.dart` with the following code. -+makeExample('displaying-data/dart/lib/hero.dart',null,'lib/hero.dart') - -:marked - We've defined a class with a constructor, a string description, and two properties: `id` and `name`. - -.l-main-section -:marked - ## Using the Hero class - Let's make the `heroes` property in our component return a list of these Hero objects. -- var stylePattern = { otl: /(import.*$)|(final)|(new Hero.*$)/gm }; -+makeExample('displaying-data/dart/lib/app_component_3.dart', 'heroes', 'app_component.dart (excerpt)', stylePattern)(format=".") - -:marked - We'll have to update the template. - At the moment it displays the string value of the `Hero` object. - Let's fix that so we display only the hero's `name` property. -- var stylePattern = { otl: /(myHero\.name)|(hero\.name)/gm }; -+makeExample('displaying-data/dart/lib/app_component_3.dart', 'template','app_component.dart (template)', stylePattern)(format=".") - - -:marked - Our display looks the same, but now we know much better what a hero really is. - - -.l-main-section -:marked - ## Conditional display with NgIf - - Sometimes the app should display a view or a portion of a view only under specific circumstances. - - In our example, we'd like to display a message if we have a large number of heroes — say, more than 3. - - The Angular `ngIf` directive inserts or removes an element based on a boolean condition. - We can see it in action by adding the following paragraph at the bottom of the template: -+makeExample('displaying-data/dart/lib/app_component.dart', 'message') -.alert.is-important - :marked - Don't forget the leading asterisk (\*) in `*ngIf`. It is an essential part of the syntax. - Learn more about this and `ngIf` in the [Template Syntax](./template-syntax.html#ngIf) chapter. - -:marked - The [template expression](./template-syntax.html#template-expressions) inside the double quotes - looks much like Dart, and it _is_ much like Dart. - When the component's list of heroes has more than 3 items, Angular adds the paragraph to the DOM and the message appears. - If there are 3 or fewer items, Angular omits the paragraph, so no message appears. - -.alert.is-helpful - :marked - Angular isn't showing and hiding the message. It is adding and removing the paragraph element from the DOM. - That hardly matters here. But it would matter a great deal, from a performance perspective, if - we were conditionally including or excluding a big chunk of HTML with many data bindings. - -:marked - Try it out. Because the list has four items, the message should appear. - Go back into `app_component.dart` and delete or comment out one of the elements from the hero list. - The browser should refresh automatically and the message should disappear. - -.l-main-section -:marked - ## Summary - Now we know how to use: - - **interpolation** with double curly braces to display a component property - - **`ngFor`** to display a list of items - - a Dart class to shape the **model data** for our component and display properties of that model - - **`ngIf`** to conditionally display a chunk of HTML based on a boolean expression - - Here's our final code: - -+makeTabs(`displaying-data/dart/lib/app_component.dart, - displaying-data/dart/lib/hero.dart, - displaying-data/dart/pubspec.yaml, - displaying-data/dart/web/index.html, - displaying-data/dart/web/main.dart`, - ',,,,final', - 'lib/app_component.dart, lib/hero.dart, pubspec.yaml, web/index.html, web/main.dart') +block final-code + +makeTabs(`displaying-data/dart/lib/app_component.dart, + displaying-data/dart/lib/hero.dart, + displaying-data/dart/pubspec.yaml, + displaying-data/dart/web/index.html, + displaying-data/dart/web/main.dart`, + ',,,,final', + 'lib/app_component.dart, lib/hero.dart, pubspec.yaml, web/index.html, web/main.dart') diff --git a/public/docs/ts/latest/guide/displaying-data.jade b/public/docs/ts/latest/guide/displaying-data.jade index dd46ce09a3..5fbf0e7ff7 100644 --- a/public/docs/ts/latest/guide/displaying-data.jade +++ b/public/docs/ts/latest/guide/displaying-data.jade @@ -1,34 +1,34 @@ -include ../_util-fns - - - +block includes + include ../_util-fns + - var _iterableUrl = 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols'; + - var _boolean = 'truthy/falsey'; + :marked We typically display data in Angular by binding controls in an HTML template to properties of an Angular component. In this chapter, we'll create a component with a list of heroes. Each hero has a name. We'll display the list of hero names and - conditionally show a selected hero in a detail area below the list. + conditionally show a message below the list. The final UI looks like this: figure.image-display img(src="/resources/images/devguide/displaying-data/final.png" alt="Final UI") - + :marked # Table Of Contents - + * [Showing component properties with interpolation](#interpolation) - * [Showing an array property with NgFor](#ngFor) + * [Showing !{_an} !{_array} property with NgFor](#ngFor) * [Conditional display with NgIf](#ngIf) - + .l-sub-section :marked - The [live example](/resources/live-examples/displaying-data/ts/plnkr.html) - demonstrates all of the syntax and code snippets described in this chapter. + The demonstrates all of the syntax and code + snippets described in this chapter. - -.l-main-section +.l-main-section#interpolation :marked ## Showing component properties with interpolation The easiest way to display a component property @@ -37,14 +37,17 @@ figure.image-display Let's build a small illustrative example together. - Create a new project folder (`displaying-data`) and follow the steps in the [QuickStart](../quickstart.html). + Create a new project folder () and follow the steps in the [QuickStart](../quickstart.html). + +block quickstart-repo + include ../_quickstart_repo -include ../_quickstart_repo :marked - Then modify the `app.component.ts` file by changing the template and the body of the component. + Then modify the file by + changing the template and the body of the component. When we're done, it should look like this: -+makeExample('displaying-data/ts/app/app.component.1.ts', null, 'app/app.component.ts') ++makeExample('app/app.component.1.ts') :marked We added two properties to the formerly empty component: `title` and `myHero`. @@ -52,94 +55,99 @@ include ../_quickstart_repo Our revised template displays the two component properties using double curly brace interpolation: -+makeExample('displaying-data/ts/app/app.component.1.ts', 'template')(format=".") -.l-sub-section - :marked - The template is a multi-line string within ECMAScript 2015 backticks (\`). - The backtick (\`) — which is *not* the same character as a single - quote (') — has many nice features. The feature we're exploiting here - is the ability to compose the string over several lines, which makes for - much more readable HTML. ++makeExcerpt('app/app.component.1.ts', 'template', '') + ++ifDocsFor('ts') + .l-sub-section + :marked + The template is a multi-line string within ECMAScript 2015 backticks (\`). + The backtick (\`) — which is *not* the same character as a single + quote (`'`) — has many nice features. The feature we're exploiting here + is the ability to compose the string over several lines, which makes for + much more readable HTML. :marked Angular automatically pulls the value of the `title` and `myHero` properties from the component and inserts those values into the browser. Angular updates the display when these properties change. + .l-sub-section :marked More precisely, the redisplay occurs after some kind of asynchronous event related to the view such as a keystroke, a timer completion, or an async `XHR` response. We don't have those in this sample. But then the properties aren't changing on their own either. For the moment we must operate on faith. + :marked Notice that we haven't called **new** to create an instance of the `AppComponent` class. Angular is creating an instance for us. How? - Notice the CSS `selector` in the `@Component` decorator that specifies an element named "my-app". - Remember back in QuickStart that we added the `` element to the body of our `index.html` -+makeExample('displaying-data/ts/index.html', 'my-app')(format=".") + Notice the CSS `selector` in the `@Component` !{_decorator} that specifies an element named `my-app`. + Remember back in [QuickStart](../quickstart.html) that we added the `` element to the body of our `index.html` file: + ++makeExcerpt('index.html', 'body') :marked - When we bootstrap with the `AppComponent` class (see `main.ts`), Angular looks for a `` + When we bootstrap with the `AppComponent` class (in ), Angular looks for a `` in the `index.html`, finds it, instantiates an instance of `AppComponent`, and renders it inside the `` tag. - We're ready to see changes in a running app by firing up the npm script that both compiles and serves our applications - while watching for changes. -code-example(format=""). - npm start -:marked - We should see the title and hero name: + Try running the app. It should display the title and hero name: figure.image-display img(src="/resources/images/devguide/displaying-data/title-and-hero.png" alt="Title and Hero") -:marked - Let's review some of the choices we made and consider alternatives. ++ifDocsFor('ts') + :marked + Let's review some of the choices we made and consider alternatives. + +:marked ## Template inline or template file? We can store our component's template in one of two places. We can define it *inline* using the `template` property, as we do here. Or we can define the template in a separate HTML file and link to it in - the component metadata using the `@Component` decorator's `templateUrl` property. + the component metadata using the `@Component` !{_decorator}'s `templateUrl` property. The choice between inline and separate HTML is a matter of taste, circumstances, and organization policy. Here we're using inline HTML because the template is small, and the demo - is simpler without the HTML file. + is simpler without the additional HTML file. In either style, the template data bindings have the same access to the component's properties. - ## Constructor or variable initialization? ++ifDocsFor('ts') + :marked + ## Constructor or variable initialization? - We initialized our component properties using variable assignment. - This is a wonderfully concise and compact technique. + We initialized our component properties using variable assignment. + This is a wonderfully concise and compact technique. - Some folks prefer to declare the properties and initialize them within a constructor like this: -+makeExample('displaying-data/ts/app/app-ctor.component.ts', 'app-ctor')(format=".") + Some folks prefer to declare the properties and initialize them within a constructor like this: + +makeExcerpt('app/app-ctor.component.ts', 'class') + + :marked + That's fine too. The choice is a matter of taste and organization policy. + We'll adopt the more terse "variable assignment" style in this chapter simply because + there will be less code to read. + +.l-main-section#ngFor +:marked + ## Showing !{_an} !{_array} property with ***ngFor** + + We want to display a list of heroes. We begin by adding !{_an} !{_array} of hero names to the component and redefine `myHero` to be the first name in the !{_array}. + ++makeExcerpt('app/app.component.2.ts', 'class') :marked - That's fine too. The choice is a matter of taste and organization policy. - We'll adopt the more terse "variable assignment" style in this chapter simply because - there will be less code to read. - - -.l-main-section -:marked - ## Showing an array property with ***ngFor** - - We want to display a list of heroes. We begin by adding a mock heroes name array to the component, - just above `myHero`, and redefine `myHero` to be the first name in the array. -+makeExample('displaying-data/ts/app/app.component.2.ts', 'mock-heroes', 'app/app.component.ts (class)')(format=".") - -:marked - Now we use the Angular `ngFor` "repeater" directive in the template to display + Now we use the Angular `ngFor` directive in the template to display each item in the `heroes` list. -+makeExample('displaying-data/ts/app/app.component.2.ts', 'template','app/app.component.ts (template)')(format=".") ++makeExcerpt('app/app.component.2.ts', 'template') :marked Our presentation is the familiar HTML unordered list with `
      ` and `
    • ` tags. Let's focus on the `
    • ` tag. -+makeExample('displaying-data/ts/app/app.component.2.ts', 'li-repeater')(format=".") + ++makeExcerpt('app/app.component.2.ts ()', 'li', '') :marked We added a somewhat mysterious `*ngFor` to the `
    • ` element. @@ -152,7 +160,7 @@ figure.image-display Learn more about this and `ngFor` in the [Template Syntax](./template-syntax.html#ngFor) chapter. :marked - Notice the `hero` in the `ngFor` double-quoted instruction; + Notice the `hero` in the `ngFor` double-quoted instruction; it is an example of a [template input variable](./template-syntax.html#ngForMicrosyntax). Angular duplicates the `
    • ` for each item in the list, setting the `hero` variable @@ -161,12 +169,11 @@ figure.image-display .l-sub-section :marked - We happened to give `ngFor` an array to display. - In fact, `ngFor` can repeat items for any [iterable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols) + We happened to give `ngFor` !{_an} !{_array} to display. + In fact, `ngFor` can repeat items for any [iterable](!{_iterableUrl}) object. :marked - Assuming we're still running under the `npm start` command, - we should see heroes appearing in an unordered list. + Now the heroes appear in an unordered list. figure.image-display img(src="/resources/images/devguide/displaying-data/hero-names-list.png" alt="After ngfor") @@ -179,57 +186,62 @@ figure.image-display That's fine for a demo but certainly isn't a best practice. It's not even a good practice. Although we won't do anything about that in this chapter, we'll make a mental note to fix this down the road. - At the moment, we're binding to an array of strings. We do that occasionally in real applications, but - most of the time we're displaying objects — potentially instances of classes. + At the moment, we're binding to !{_an} !{_array} of strings. We do that occasionally in real applications, but + most of the time we're binding to more specialized objects. - Let's turn our array of hero names into an array of `Hero` objects. For that we'll need a `Hero` class. + Let's turn our !{_array} of hero names into !{_an} !{_array} of `Hero` objects. For that we'll need a `Hero` class. - Create a new file in the `app/` folder called `hero.ts` with the following short bit of code. -+makeExample('displaying-data/ts/app/hero.ts', null, 'app/hero.ts')(format = ".") + Create a new file in the `!{_appDir}` folder called with the following code: + ++makeExcerpt('app/hero.ts') -:marked - We've defined a class with a constructor and two properties: `id` and `name`. +block hero-class + :marked + We've defined a class with a constructor and two properties: `id` and `name`. - It might not look like we have properties, but we do. We're taking - advantage of a TypeScript shortcut in our declaration of the constructor parameters. + It might not look like we have properties, but we do. We're taking + advantage of a TypeScript shortcut in our declaration of the constructor parameters. - Consider the first parameter: -+makeExample('displaying-data/ts/app/hero.ts', 'id-parameter') + Consider the first parameter: -:marked - That brief syntax does a lot: - * declares a constructor parameter and its type - * declares a public property of the same name - * initializes that property with the corresponding argument when we "new" an instance of the class + +makeExcerpt('app/hero.ts ()', 'id') + + :marked + That brief syntax does a lot: + * Declares a constructor parameter and its type + * Declares a public property of the same name + * Initializes that property with the corresponding argument when we "new" an instance of the class .l-main-section :marked ## Using the Hero class - Let's redefine the `heroes` property in our component to return an array of these Hero objects - and also set the `myHero` property with the first of these mock heroes. -+makeExample('displaying-data/ts/app/app.component.3.ts', 'heroes', 'app.component.ts (excerpt)')(format=".") + Let's make the `heroes` property in our component return !{_an} !{_array} of these `Hero` objects. + ++makeExcerpt('app/app.component.3.ts', 'heroes') :marked We'll have to update the template. - At the moment it displays the entire `hero` object, which used to be a string value. - Let's fix that so we interpolate the `hero.name` property. -+makeExample('displaying-data/ts/app/app.component.3.ts', 'template','app.component.ts (template)')(format=".") + At the moment it displays the hero's `id` and `name`. + Let's fix that so we display only the hero's `name` property. + ++makeExcerpt('app/app.component.3.ts', 'template') :marked Our display looks the same, but now we know much better what a hero really is. - -.l-main-section +.l-main-section#ngIf :marked ## Conditional display with NgIf - Sometimes the app should display a view or a portion of a view only under specific circumstances. + Sometimes an app needs to display a view or a portion of a view only under specific circumstances. - In our example, we'd like to display a message if we have a large number of heroes — say, more than 3. + In our example, we'd like to display a message if we have a large number of heroes, say, more than 3. - The Angular `ngIf` directive inserts or removes an element based on a truthy/falsey condition. + The Angular `ngIf` directive inserts or removes an element based on a !{_boolean} condition. We can see it in action by adding the following paragraph at the bottom of the template: -+makeExample('displaying-data/ts/app/app.component.ts', 'message') + ++makeExcerpt('app/app.component.ts', 'message') + .alert.is-important :marked Don't forget the leading asterisk (\*) in `*ngIf`. It is an essential part of the syntax. @@ -237,7 +249,7 @@ figure.image-display :marked The [template expression](./template-syntax.html#template-expressions) inside the double quotes - looks much like JavaScript and it _is_ much like JavaScript. + looks much like !{_Lang}, and it _is_ much like !{_Lang}. When the component's list of heroes has more than 3 items, Angular adds the paragraph to the DOM and the message appears. If there are 3 or fewer items, Angular omits the paragraph, so no message appears. @@ -248,23 +260,24 @@ figure.image-display we were conditionally including or excluding a big chunk of HTML with many data bindings. :marked - Try it out. Because the array has four items, the message should appear. - Go back into `app.component.ts` and delete or comment out one of the elements from the hero array. + Try it out. Because the !{_array} has four items, the message should appear. + Go back into and delete or comment out one of the elements from the hero !{_array}. The browser should refresh automatically and the message should disappear. .l-main-section :marked ## Summary Now we know how to use: - - **interpolation** with double curly braces to display a component property - - **`ngFor`** to display a list of items - - a TypeScript class to shape the **model data** for our component and display properties of that model - - **`ngIf`** to conditionally display a chunk of HTML based on a boolean expression + - **Interpolation** with double curly braces to display a component property + - **ngFor** to display !{_an} !{_array} of items + - A !{_Lang} class to shape the **model data** for our component and display properties of that model + - **ngIf** to conditionally display a chunk of HTML based on a boolean expression Here's our final code: -+makeTabs(`displaying-data/ts/app/app.component.ts, - displaying-data/ts/app/hero.ts, - displaying-data/ts/app/main.ts`, - 'final,,', - 'app/app.component.ts, app/hero.ts, main.ts') +block final-code + +makeTabs(`displaying-data/ts/app/app.component.ts, + displaying-data/ts/app/hero.ts, + displaying-data/ts/app/main.ts`, + 'final,,', + 'app/app.component.ts, app/hero.ts, main.ts') From 2c5f0dbd9ae470bc0399ce7846bcc8063101db3d Mon Sep 17 00:00:00 2001 From: Ward Bell Date: Thu, 7 Jul 2016 18:46:35 -0700 Subject: [PATCH 12/13] docs(router): more little fixes from #1808 --- .../_examples/router/ts/app/app.routes.1.ts | 6 +++--- .../_examples/router/ts/app/app.routes.2.ts | 2 +- .../_examples/router/ts/app/app.routes.3.ts | 10 +++++----- .../_examples/router/ts/app/app.routes.4.ts | 10 +++++----- .../_examples/router/ts/app/app.routes.5.ts | 18 +++++++++--------- .../docs/_examples/router/ts/app/app.routes.ts | 18 +++++++++--------- .../crisis-center/crisis-center.routes.1.ts | 2 +- .../crisis-center/crisis-center.routes.2.ts | 2 +- .../crisis-center/crisis-center.routes.3.ts | 2 +- .../crisis-center/crisis-center.routes.4.ts | 2 +- .../app/crisis-center/crisis-center.routes.ts | 2 +- .../router/ts/app/heroes/heroes.routes.ts | 2 +- .../_examples/router/ts/app/login.routes.ts | 5 +++-- public/docs/_examples/router/ts/app/main.1.ts | 8 ++++---- public/docs/_examples/router/ts/app/main.2.ts | 4 ++-- public/docs/_examples/router/ts/app/main.3.ts | 8 ++++---- public/docs/_examples/router/ts/app/main.ts | 8 ++++---- 17 files changed, 55 insertions(+), 54 deletions(-) diff --git a/public/docs/_examples/router/ts/app/app.routes.1.ts b/public/docs/_examples/router/ts/app/app.routes.1.ts index 8c4caeda55..f22d480744 100644 --- a/public/docs/_examples/router/ts/app/app.routes.1.ts +++ b/public/docs/_examples/router/ts/app/app.routes.1.ts @@ -7,9 +7,9 @@ import { provideRouter, RouterConfig } from '@angular/router'; // #enddocregion // #docregion base-routes -import { HeroListComponent } from './hero-list.component'; +import { HeroListComponent } from './hero-list.component'; import { CrisisCenterComponent } from './crisis-center/crisis-center.component'; -import { HeroDetailComponent } from './heroes/hero-detail.component'; +import { HeroDetailComponent } from './heroes/hero-detail.component'; // #enddocregion base-routes // #docregion @@ -24,7 +24,7 @@ export const routes: RouterConfig = [ // #enddocregion hero-detail-route ]; -export const APP_ROUTER_PROVIDERS = [ +export const appRouterProviders = [ provideRouter(routes) ]; // #enddocregion route-config diff --git a/public/docs/_examples/router/ts/app/app.routes.2.ts b/public/docs/_examples/router/ts/app/app.routes.2.ts index d0d64e2ea0..c79e8ad17c 100644 --- a/public/docs/_examples/router/ts/app/app.routes.2.ts +++ b/public/docs/_examples/router/ts/app/app.routes.2.ts @@ -13,7 +13,7 @@ export const routes: RouterConfig = [ { path: 'heroes', component: HeroListComponent } ]; -export const APP_ROUTER_PROVIDERS = [ +export const appRouterProviders = [ provideRouter(routes) ]; // #enddocregion route-config diff --git a/public/docs/_examples/router/ts/app/app.routes.3.ts b/public/docs/_examples/router/ts/app/app.routes.3.ts index c6e9cffc72..e49d055672 100644 --- a/public/docs/_examples/router/ts/app/app.routes.3.ts +++ b/public/docs/_examples/router/ts/app/app.routes.3.ts @@ -1,15 +1,15 @@ // #docplaster // #docregion -import { provideRouter } from '@angular/router'; +import { provideRouter, RouterConfig } from '@angular/router'; import { CrisisListComponent } from './crisis-center/crisis-list.component'; -import { HeroesRoutes } from './heroes/heroes.routes'; +import { heroesRoutes } from './heroes/heroes.routes'; -export const routes = [ - ...HeroesRoutes, +export const routes: RouterConfig = [ + ...heroesRoutes, { path: 'crisis-center', component: CrisisListComponent } ]; -export const APP_ROUTER_PROVIDERS = [ +export const appRouterProviders = [ provideRouter(routes) ]; diff --git a/public/docs/_examples/router/ts/app/app.routes.4.ts b/public/docs/_examples/router/ts/app/app.routes.4.ts index c6ab75c5be..d51635a676 100644 --- a/public/docs/_examples/router/ts/app/app.routes.4.ts +++ b/public/docs/_examples/router/ts/app/app.routes.4.ts @@ -1,14 +1,14 @@ // #docregion import { provideRouter, RouterConfig } from '@angular/router'; -import { CrisisCenterRoutes } from './crisis-center/crisis-center.routes'; -import { HeroesRoutes } from './heroes/heroes.routes'; +import { crisisCenterRoutes } from './crisis-center/crisis-center.routes'; +import { heroesRoutes } from './heroes/heroes.routes'; export const routes: RouterConfig = [ - ...HeroesRoutes, - ...CrisisCenterRoutes + ...heroesRoutes, + ...crisisCenterRoutes ]; -export const APP_ROUTER_PROVIDERS = [ +export const appRouterProviders = [ provideRouter(routes) ]; diff --git a/public/docs/_examples/router/ts/app/app.routes.5.ts b/public/docs/_examples/router/ts/app/app.routes.5.ts index cb8a39c0a6..87e64af66e 100644 --- a/public/docs/_examples/router/ts/app/app.routes.5.ts +++ b/public/docs/_examples/router/ts/app/app.routes.5.ts @@ -1,19 +1,19 @@ // #docregion import { provideRouter, RouterConfig } from '@angular/router'; -import { CrisisCenterRoutes } from './crisis-center/crisis-center.routes'; -import { HeroesRoutes } from './heroes/heroes.routes'; +import { crisisCenterRoutes } from './crisis-center/crisis-center.routes'; +import { heroesRoutes } from './heroes/heroes.routes'; -import { LoginRoutes, - AUTH_PROVIDERS } from './login.routes'; +import { loginRoutes, + authProviders } from './login.routes'; export const routes: RouterConfig = [ - ...HeroesRoutes, - ...LoginRoutes, - ...CrisisCenterRoutes + ...heroesRoutes, + ...loginRoutes, + ...crisisCenterRoutes ]; -export const APP_ROUTER_PROVIDERS = [ +export const appRouterProviders = [ provideRouter(routes), - AUTH_PROVIDERS + authProviders ]; diff --git a/public/docs/_examples/router/ts/app/app.routes.ts b/public/docs/_examples/router/ts/app/app.routes.ts index 45a7f49577..2f003bab55 100644 --- a/public/docs/_examples/router/ts/app/app.routes.ts +++ b/public/docs/_examples/router/ts/app/app.routes.ts @@ -1,22 +1,22 @@ // #docregion import { provideRouter, RouterConfig } from '@angular/router'; -import { CrisisCenterRoutes } from './crisis-center/crisis-center.routes'; -import { HeroesRoutes } from './heroes/heroes.routes'; +import { crisisCenterRoutes } from './crisis-center/crisis-center.routes'; +import { heroesRoutes } from './heroes/heroes.routes'; -import { LoginRoutes, - AUTH_PROVIDERS } from './login.routes'; +import { loginRoutes, + authProviders } from './login.routes'; import { CanDeactivateGuard } from './interfaces'; export const routes: RouterConfig = [ - ...HeroesRoutes, - ...LoginRoutes, - ...CrisisCenterRoutes + ...heroesRoutes, + ...loginRoutes, + ...crisisCenterRoutes ]; -export const APP_ROUTER_PROVIDERS = [ +export const appRouterProviders = [ provideRouter(routes), - AUTH_PROVIDERS, + authProviders, CanDeactivateGuard ]; diff --git a/public/docs/_examples/router/ts/app/crisis-center/crisis-center.routes.1.ts b/public/docs/_examples/router/ts/app/crisis-center/crisis-center.routes.1.ts index 0c50d6b7df..7f28dabdcf 100644 --- a/public/docs/_examples/router/ts/app/crisis-center/crisis-center.routes.1.ts +++ b/public/docs/_examples/router/ts/app/crisis-center/crisis-center.routes.1.ts @@ -5,7 +5,7 @@ import { CrisisListComponent } from './crisis-list.component'; import { CrisisCenterComponent } from './crisis-center.component'; // #docregion routes -export const CrisisCenterRoutes: RouterConfig = [ +export const crisisCenterRoutes: RouterConfig = [ { path: 'crisis-center', component: CrisisCenterComponent, diff --git a/public/docs/_examples/router/ts/app/crisis-center/crisis-center.routes.2.ts b/public/docs/_examples/router/ts/app/crisis-center/crisis-center.routes.2.ts index 5f44ba160a..3e8d2f391e 100644 --- a/public/docs/_examples/router/ts/app/crisis-center/crisis-center.routes.2.ts +++ b/public/docs/_examples/router/ts/app/crisis-center/crisis-center.routes.2.ts @@ -5,7 +5,7 @@ import { CrisisListComponent } from './crisis-list.component'; import { CrisisCenterComponent } from './crisis-center.component'; // #docregion routes -export const CrisisCenterRoutes: RouterConfig = [ +export const crisisCenterRoutes: RouterConfig = [ // #docregion redirect { path: '', diff --git a/public/docs/_examples/router/ts/app/crisis-center/crisis-center.routes.3.ts b/public/docs/_examples/router/ts/app/crisis-center/crisis-center.routes.3.ts index 75af21c534..9a307f6541 100644 --- a/public/docs/_examples/router/ts/app/crisis-center/crisis-center.routes.3.ts +++ b/public/docs/_examples/router/ts/app/crisis-center/crisis-center.routes.3.ts @@ -8,7 +8,7 @@ import { CrisisAdminComponent } from './crisis-admin.component'; import { CanDeactivateGuard } from '../interfaces'; -export const CrisisCenterRoutes: RouterConfig = [ +export const crisisCenterRoutes: RouterConfig = [ { path: '', redirectTo: '/crisis-center', diff --git a/public/docs/_examples/router/ts/app/crisis-center/crisis-center.routes.4.ts b/public/docs/_examples/router/ts/app/crisis-center/crisis-center.routes.4.ts index b49bf6dfda..538044ebba 100644 --- a/public/docs/_examples/router/ts/app/crisis-center/crisis-center.routes.4.ts +++ b/public/docs/_examples/router/ts/app/crisis-center/crisis-center.routes.4.ts @@ -9,7 +9,7 @@ import { CrisisAdminComponent } from './crisis-admin.component'; import { CanDeactivateGuard } from '../interfaces'; import { AuthGuard } from '../auth.guard'; -export const CrisisCenterRoutes: RouterConfig = [ +export const crisisCenterRoutes: RouterConfig = [ { path: '', redirectTo: '/crisis-center', diff --git a/public/docs/_examples/router/ts/app/crisis-center/crisis-center.routes.ts b/public/docs/_examples/router/ts/app/crisis-center/crisis-center.routes.ts index 6f40ce64b3..f8b87190f8 100644 --- a/public/docs/_examples/router/ts/app/crisis-center/crisis-center.routes.ts +++ b/public/docs/_examples/router/ts/app/crisis-center/crisis-center.routes.ts @@ -8,7 +8,7 @@ import { CrisisAdminComponent } from './crisis-admin.component'; import { CanDeactivateGuard } from '../interfaces'; import { AuthGuard } from '../auth.guard'; -export const CrisisCenterRoutes: RouterConfig = [ +export const crisisCenterRoutes: RouterConfig = [ { path: '', redirectTo: '/crisis-center', diff --git a/public/docs/_examples/router/ts/app/heroes/heroes.routes.ts b/public/docs/_examples/router/ts/app/heroes/heroes.routes.ts index 80018d1f26..d5d092c016 100644 --- a/public/docs/_examples/router/ts/app/heroes/heroes.routes.ts +++ b/public/docs/_examples/router/ts/app/heroes/heroes.routes.ts @@ -3,7 +3,7 @@ import { RouterConfig } from '@angular/router'; import { HeroListComponent } from './hero-list.component'; import { HeroDetailComponent } from './hero-detail.component'; -export const HeroesRoutes: RouterConfig = [ +export const heroesRoutes: RouterConfig = [ { path: 'heroes', component: HeroListComponent }, // #docregion hero-detail-route { path: 'hero/:id', component: HeroDetailComponent } diff --git a/public/docs/_examples/router/ts/app/login.routes.ts b/public/docs/_examples/router/ts/app/login.routes.ts index 6dabba376f..f50d2d7264 100644 --- a/public/docs/_examples/router/ts/app/login.routes.ts +++ b/public/docs/_examples/router/ts/app/login.routes.ts @@ -1,10 +1,11 @@ // #docregion +import { RouterConfig } from '@angular/router'; import { AuthGuard } from './auth.guard'; import { AuthService } from './auth.service'; import { LoginComponent } from './login.component'; -export const LoginRoutes = [ +export const loginRoutes: RouterConfig = [ { path: 'login', component: LoginComponent } ]; -export const AUTH_PROVIDERS = [AuthGuard, AuthService]; +export const authProviders = [AuthGuard, AuthService]; diff --git a/public/docs/_examples/router/ts/app/main.1.ts b/public/docs/_examples/router/ts/app/main.1.ts index 08e6ff4b45..deff5b9ac5 100644 --- a/public/docs/_examples/router/ts/app/main.1.ts +++ b/public/docs/_examples/router/ts/app/main.1.ts @@ -2,9 +2,9 @@ // #docplaster // #docregion all // main entry point -import { bootstrap } from '@angular/platform-browser-dynamic'; -import { AppComponent } from './app.component'; -import { APP_ROUTER_PROVIDERS } from './app.routes'; +import { bootstrap } from '@angular/platform-browser-dynamic'; +import { AppComponent } from './app.component'; +import { appRouterProviders } from './app.routes'; // #enddocregion @@ -19,7 +19,7 @@ import { AppComponent as ac } from './app.component.ts'; // './app.component.1'; bootstrap(ac, [ // #docregion all - APP_ROUTER_PROVIDERS + appRouterProviders ]) .catch(err => console.error(err)); // #enddocregion all diff --git a/public/docs/_examples/router/ts/app/main.2.ts b/public/docs/_examples/router/ts/app/main.2.ts index 7bd785b232..10e4e4b18a 100644 --- a/public/docs/_examples/router/ts/app/main.2.ts +++ b/public/docs/_examples/router/ts/app/main.2.ts @@ -11,7 +11,7 @@ import { LocationStrategy, HashLocationStrategy } from '@angular/common'; import { AppComponent } from './app.component'; -import { APP_ROUTER_PROVIDERS } from './app.routes'; +import { appRouterProviders } from './app.routes'; // #enddocregion @@ -25,7 +25,7 @@ import { AppComponent as ac } from './app.component.ts'; // './app.component.2'; bootstrap(ac, [ // #docregion - APP_ROUTER_PROVIDERS, + appRouterProviders, { provide: LocationStrategy, useClass: HashLocationStrategy } // .../#/crisis-center/ ]) diff --git a/public/docs/_examples/router/ts/app/main.3.ts b/public/docs/_examples/router/ts/app/main.3.ts index 5d08ced304..e1be742421 100644 --- a/public/docs/_examples/router/ts/app/main.3.ts +++ b/public/docs/_examples/router/ts/app/main.3.ts @@ -1,11 +1,11 @@ /* third version */ // #docregion // main entry point -import { bootstrap } from '@angular/platform-browser-dynamic'; -import { AppComponent } from './app.component.3'; -import { APP_ROUTER_PROVIDERS } from './app.routes'; +import { bootstrap } from '@angular/platform-browser-dynamic'; +import { AppComponent } from './app.component.3'; +import { appRouterProviders } from './app.routes'; bootstrap(AppComponent, [ - APP_ROUTER_PROVIDERS + appRouterProviders ]) .catch(err => console.error(err)); diff --git a/public/docs/_examples/router/ts/app/main.ts b/public/docs/_examples/router/ts/app/main.ts index 7bc0ed4622..6142cad5ee 100644 --- a/public/docs/_examples/router/ts/app/main.ts +++ b/public/docs/_examples/router/ts/app/main.ts @@ -1,10 +1,10 @@ // #docregion // main entry point -import { bootstrap } from '@angular/platform-browser-dynamic'; -import { AppComponent } from './app.component'; -import { APP_ROUTER_PROVIDERS } from './app.routes'; +import { bootstrap } from '@angular/platform-browser-dynamic'; +import { AppComponent } from './app.component'; +import { appRouterProviders } from './app.routes'; bootstrap(AppComponent, [ - APP_ROUTER_PROVIDERS + appRouterProviders ]) .catch(err => console.error(err)); From 0664a271baaaa115bec0a8525eccaad5baf133d3 Mon Sep 17 00:00:00 2001 From: Ward Bell Date: Thu, 7 Jul 2016 15:27:15 -0700 Subject: [PATCH 13/13] docs(style-guide): spell const variables in lower camel case Changes previous guidance on const which insisted on UPPER_SNAKE_CASE --- .../style-guide/ts/03-02/app/app.component.ts | 12 ++++--- .../ts/03-02/app/shared/data.service.avoid.ts | 7 ---- .../ts/03-02/app/shared/data.service.ts | 7 ++-- public/docs/ts/latest/guide/style-guide.jade | 35 +++++++++++++++---- 4 files changed, 40 insertions(+), 21 deletions(-) delete mode 100644 public/docs/_examples/style-guide/ts/03-02/app/shared/data.service.avoid.ts diff --git a/public/docs/_examples/style-guide/ts/03-02/app/app.component.ts b/public/docs/_examples/style-guide/ts/03-02/app/app.component.ts index 15ccb3c351..cb62984849 100644 --- a/public/docs/_examples/style-guide/ts/03-02/app/app.component.ts +++ b/public/docs/_examples/style-guide/ts/03-02/app/app.component.ts @@ -1,15 +1,19 @@ import { Component } from '@angular/core'; -import { HEROES_URL, VILLAINS_URL } from './shared'; +import { heroesUrl, mockHeroes, VILLAINS_URL } from './shared'; @Component({ selector: 'sg-app', template: `
      Heroes url: {{heroesUrl}}
      Villains url: {{villainsUrl}}
      - `, + +

      Mock Heroes

      +
      {{hero}}
      + ` }) export class AppComponent { - heroesUrl = HEROES_URL; - villainsUrl = VILLAINS_URL; + heroes = mockHeroes; // prefer + heroesUrl = heroesUrl; // prefer + villainsUrl = VILLAINS_URL; // tolerate } diff --git a/public/docs/_examples/style-guide/ts/03-02/app/shared/data.service.avoid.ts b/public/docs/_examples/style-guide/ts/03-02/app/shared/data.service.avoid.ts deleted file mode 100644 index 49d5cb0d35..0000000000 --- a/public/docs/_examples/style-guide/ts/03-02/app/shared/data.service.avoid.ts +++ /dev/null @@ -1,7 +0,0 @@ -// #docregion -// #docregion example -/* avoid */ - -export const heroesUrl = 'api/heroes'; -export const villainsUrl = 'api/villains'; -// #enddocregion example diff --git a/public/docs/_examples/style-guide/ts/03-02/app/shared/data.service.ts b/public/docs/_examples/style-guide/ts/03-02/app/shared/data.service.ts index ad665a99c2..5c26478c7b 100644 --- a/public/docs/_examples/style-guide/ts/03-02/app/shared/data.service.ts +++ b/public/docs/_examples/style-guide/ts/03-02/app/shared/data.service.ts @@ -1,5 +1,4 @@ // #docregion -// #docregion example -export const HEROES_URL = 'api/heroes'; -export const VILLAINS_URL = 'api/villains'; -// #enddocregion example +export const mockHeroes = ['Sam', 'Jill']; // prefer +export const heroesUrl = 'api/heroes'; // prefer +export const VILLAINS_URL = 'api/villains'; // tolerate diff --git a/public/docs/ts/latest/guide/style-guide.jade b/public/docs/ts/latest/guide/style-guide.jade index 753c8d9b6d..e24feff721 100644 --- a/public/docs/ts/latest/guide/style-guide.jade +++ b/public/docs/ts/latest/guide/style-guide.jade @@ -651,20 +651,43 @@ a(href="#toc") Back to top .s-rule.do :marked - **Do** use uppercase with underscores when naming constants. + **Do** declare variables with `const` if their values should not change during the application lifetime. .s-why :marked - **Why?** Follows conventional thinking for constants. + **Why?** Conveys to readers that the value is invariant. .s-why.s-why-last :marked - **Why?** Constants can easily be identified. + TypeScript helps enforce that intent by requiring immediate initialization and by + preventing subsequent re-assignment. + +.s-rule.consider + :marked + **Consider** spelling `const` variables in lower camel case. -+makeExample('style-guide/ts/03-02/app/shared/data.service.avoid.ts', 'example', 'app/shared/data.service.ts')(avoid=1) -:marked +.s-why + :marked + **Why?** lower camel case variable names (`heroRoutes`) are easier to read and understand + than the traditional UPPER_SNAKE_CASE names (`HERO_ROUTES`). -+makeExample('style-guide/ts/03-02/app/shared/data.service.ts', 'example', 'app/shared/data.service.ts') +.s-why.s-why-last + :marked + **Why?** The tradition of naming constants in UPPER_SNAKE_CASE reflects + an era before the modern IDEs that quickly reveal the `const` declaration. + TypeScript itself prevents accidental reassignment. + +.s-rule.do + :marked + **Do** tolerate _existing_ `const` variables that are spelled in UPPER_SNAKE_CASE. + +.s-why.s-why-last + :marked + **Why?** Although we recommend creating _new_ constants in lower camel case, + the tradition of UPPER_SNAKE_CASE remains popular and pervasive, + especially in third party modules. + ++makeExample('style-guide/ts/03-02/app/shared/data.service.ts', '', 'app/shared/data.service.ts') :marked a(href="#toc") Back to top