Skip to content

Commit b776355

Browse files
petebacondarwinIgorMinar
authored andcommitted
build(aio): move doc-gen stuff from angular.io (angular#14097)
1 parent d1d0ce7 commit b776355

File tree

135 files changed

+5031
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

135 files changed

+5031
-1
lines changed

docs/src/app/app.component.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
Copyright 2016 Google Inc. All Rights Reserved.
3+
Use of this source code is governed by an MIT-style license that
4+
can be found in the LICENSE file at http://angular.io/license
5+
*/
6+
7+
import {Component, OnInit, NgZone } from '@angular/core';
8+
import {FormControl, ReactiveFormsModule} from '@angular/forms';
9+
import {Observable} from 'rxjs/Observable';
10+
import 'rxjs/add/operator/do';
11+
import 'rxjs/add/operator/switchMap';
12+
import {QueryResults, SearchWorkerClient} from './search-worker-client';
13+
14+
15+
@Component({
16+
selector: 'my-app',
17+
template: `
18+
<h1>Angular Docs Search</h1>
19+
<div class="search-bar"><input [formControl]="searchInput"></div>
20+
<div class="search-results">
21+
<div *ngIf="!(indexReady | async)">Waiting...</div>
22+
<ul>
23+
<li *ngFor="let result of (searchResult$ | async)">
24+
<a href="{{result.path}}">{{ result.title }} ({{result.type}})</a>
25+
</li>
26+
</ul>
27+
</div>
28+
`
29+
})
30+
export class AppComponent implements OnInit {
31+
searchResult$: Observable<QueryResults>;
32+
indexReady: Promise<boolean>;
33+
searchInput: FormControl;
34+
35+
constructor(private zone: NgZone) {}
36+
37+
ngOnInit() {
38+
const searchWorker = new SearchWorkerClient('app/search-worker.js', this.zone);
39+
this.indexReady = searchWorker.ready;
40+
this.searchInput = new FormControl();
41+
this.searchResult$ = this.searchInput.valueChanges
42+
.switchMap((searchText: string) => searchWorker.search(searchText));
43+
}
44+
}

docs/src/app/main.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
Copyright 2016 Google Inc. All Rights Reserved.
3+
Use of this source code is governed by an MIT-style license that
4+
can be found in the LICENSE file at http://angular.io/license
5+
*/
6+
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
7+
import {NgModule} from '@angular/core';
8+
import {BrowserModule} from '@angular/platform-browser';
9+
import {ReactiveFormsModule} from '@angular/forms';
10+
import {AppComponent} from 'app/app.component';
11+
12+
@NgModule({
13+
imports: [ BrowserModule, ReactiveFormsModule ],
14+
declarations: [ AppComponent ],
15+
bootstrap: [ AppComponent ]
16+
})
17+
class AppModule {
18+
19+
}
20+
21+
platformBrowserDynamic().bootstrapModule(AppModule);

docs/src/app/search-worker-client.ts

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
Copyright 2016 Google Inc. All Rights Reserved.
3+
Use of this source code is governed by an MIT-style license that
4+
can be found in the LICENSE file at http://angular.io/license
5+
*/
6+
7+
import {NgZone} from '@angular/core';
8+
import {Observable} from 'rxjs/Observable';
9+
import {Subscriber} from 'rxjs/Subscriber';
10+
import 'rxjs/add/observable/fromPromise';
11+
import 'rxjs/add/observable/of';
12+
import 'rxjs/add/operator/switchMap';
13+
14+
15+
export interface QueryResults {}
16+
17+
export interface ResultsReadyMessage {
18+
type: 'query-results';
19+
id: number;
20+
query: string;
21+
results: QueryResults;
22+
}
23+
24+
export class SearchWorkerClient {
25+
ready: Promise<boolean>;
26+
worker: Worker;
27+
private _queryId = 0;
28+
29+
constructor(url: string, private zone: NgZone) {
30+
this.worker = new Worker(url);
31+
this.ready = this._waitForIndex(this.worker);
32+
}
33+
34+
search(query: string) {
35+
return Observable.fromPromise(this.ready)
36+
.switchMap(() => this._createQuery(query));
37+
}
38+
39+
private _waitForIndex(worker: Worker) {
40+
return new Promise((resolve, reject) => {
41+
42+
worker.onmessage = (e) => {
43+
if(e.data.type === 'index-ready') {
44+
resolve(true);
45+
cleanup();
46+
}
47+
};
48+
49+
worker.onerror = (e) => {
50+
reject(e);
51+
cleanup();
52+
};
53+
});
54+
55+
function cleanup() {
56+
worker.onmessage = null;
57+
worker.onerror = null;
58+
}
59+
}
60+
61+
private _createQuery(query: string) {
62+
return new Observable<QueryResults>((subscriber: Subscriber<QueryResults>) => {
63+
64+
// get a new identifier for this query that we can match to results
65+
const id = this._queryId++;
66+
67+
const handleMessage = (message: MessageEvent) => {
68+
const {type, id: queryId, results} = message.data as ResultsReadyMessage;
69+
if (type === 'query-results' && id === queryId) {
70+
this.zone.run(() => {
71+
subscriber.next(results);
72+
subscriber.complete();
73+
});
74+
}
75+
};
76+
77+
const handleError = (error: ErrorEvent) => {
78+
this.zone.run(() => {
79+
subscriber.error(error);
80+
});
81+
};
82+
83+
// Wire up the event listeners for this query
84+
this.worker.addEventListener('message', handleMessage);
85+
this.worker.addEventListener('error', handleError);
86+
87+
// Post the query to the web worker
88+
this.worker.postMessage({query, id});
89+
90+
// At completion/error unwire the event listeners
91+
return () => {
92+
this.worker.removeEventListener('message', handleMessage);
93+
this.worker.removeEventListener('error', handleError);
94+
};
95+
});
96+
}
97+
}

docs/src/app/search-worker.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
'use strict';
2+
3+
/* eslint-env worker */
4+
/* global importScripts, lunr */
5+
6+
importScripts('https://unpkg.com/lunr@0.7.2');
7+
8+
var index = createIndex();
9+
var pages = {};
10+
11+
makeRequest('search-data.json', loadIndex);
12+
13+
self.onmessage = handleMessage;
14+
15+
// Create the lunr index - the docs should be an array of objects, each object containing
16+
// the path and search terms for a page
17+
function createIndex() {
18+
return lunr(/** @this */function() {
19+
this.ref('path');
20+
this.field('titleWords', {boost: 50});
21+
this.field('members', {boost: 40});
22+
this.field('keywords', {boost: 20});
23+
});
24+
}
25+
26+
27+
// Use XHR to make a request to the server
28+
function makeRequest(url, callback) {
29+
var searchDataRequest = new XMLHttpRequest();
30+
searchDataRequest.onload = function() {
31+
callback(JSON.parse(this.responseText));
32+
};
33+
searchDataRequest.open('GET', url);
34+
searchDataRequest.send();
35+
}
36+
37+
38+
// Create the search index from the searchInfo which contains the information about each page to be indexed
39+
function loadIndex(searchInfo) {
40+
// Store the pages data to be used in mapping query results back to pages
41+
// Add search terms from each page to the search index
42+
searchInfo.forEach(function(page) {
43+
index.add(page);
44+
pages[page.path] = page;
45+
});
46+
self.postMessage({type: 'index-ready'});
47+
}
48+
49+
50+
// The worker receives a message everytime the web app wants to query the index
51+
function handleMessage(message) {
52+
var id = message.data.id;
53+
var query = message.data.query;
54+
var results = queryIndex(query);
55+
self.postMessage({type: 'query-results', id: id, query: query, results: results});
56+
}
57+
58+
59+
// Query the index and return the processed results
60+
function queryIndex(query) {
61+
// Only return the array of paths to pages
62+
return index.search(query).map(function(hit) { return pages[hit.ref]; });
63+
}

docs/src/app/tsconfig.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"compilerOptions": {
3+
"baseUrl": ".",
4+
"declaration": true,
5+
"emitDecoratorMetadata": true,
6+
"experimentalDecorators": true,
7+
"module": "commonjs",
8+
"moduleResolution": "node",
9+
"outDir": "../dist/tools/",
10+
"noImplicitAny": true,
11+
"noFallthroughCasesInSwitch": true,
12+
"paths": {
13+
},
14+
"rootDir": ".",
15+
"sourceMap": true,
16+
"inlineSources": true,
17+
"lib": ["es6", "dom"],
18+
"target": "es5",
19+
"skipLibCheck": true,
20+
"typeRoots": [
21+
"../../../node_modules"
22+
]
23+
},
24+
"exclude": [
25+
"node_modules",
26+
"typings-test",
27+
"public_api_guard",
28+
"docs"
29+
]
30+
}

docs/src/index.html

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Hello Angular</title>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
<style>
8+
body {color:#369;font-family: Arial,Helvetica,sans-serif;}
9+
</style>
10+
11+
<!-- Polyfills for older browsers -->
12+
<script src="https://unpkg.com/core-js/client/shim.min.js"></script>
13+
14+
<script src="https://unpkg.com/zone.js@0.7.2?main=browser"></script>
15+
<script src="https://unpkg.com/reflect-metadata@0.1.8"></script>
16+
<script src="https://unpkg.com/systemjs@0.19.39/dist/system.src.js"></script>
17+
18+
<script src="systemjs.config.web.js"></script>
19+
<script>
20+
System.import('app').catch(function(err){ console.error(err); });
21+
</script>
22+
</head>
23+
24+
<body>
25+
<my-app>Loading AppComponent content here ...</my-app>
26+
</body>
27+
28+
</html>

docs/src/systemjs.config.web.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
Copyright 2016 Google Inc. All Rights Reserved.
3+
Use of this source code is governed by an MIT-style license that
4+
can be found in the LICENSE file at http://angular.io/license
5+
*/
6+
7+
System.config({
8+
// DEMO ONLY! REAL CODE SHOULD NOT TRANSPILE IN THE BROWSER
9+
transpiler: 'ts',
10+
typescriptOptions: {
11+
// Copy of compiler options in standard tsconfig.json
12+
"target": "es5",
13+
"module": "commonjs",
14+
"moduleResolution": "node",
15+
"sourceMap": true,
16+
"emitDecoratorMetadata": true,
17+
"experimentalDecorators": true,
18+
"noImplicitAny": true,
19+
"suppressImplicitAnyIndexErrors": true
20+
},
21+
meta: {
22+
'typescript': {
23+
"exports": "ts"
24+
}
25+
},
26+
paths: {
27+
// paths serve as alias
28+
'npm:': 'https://unpkg.com/'
29+
},
30+
// map tells the System loader where to look for things
31+
map: {
32+
// our app is within the app folder
33+
app: 'app',
34+
35+
// angular bundles
36+
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
37+
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
38+
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
39+
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
40+
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
41+
'@angular/http': 'npm:@angular/http/bundles/http.umd.js',
42+
'@angular/router': 'npm:@angular/router/bundles/router.umd.js',
43+
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
44+
'@angular/upgrade': 'npm:@angular/upgrade/bundles/upgrade.umd.js',
45+
'@angular/upgrade/static': 'npm:@angular/upgrade/bundles/upgrade-static.umd.js',
46+
47+
// other libraries
48+
'rxjs': 'npm:rxjs',
49+
'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js',
50+
'ts': 'npm:plugin-typescript@4.0.10/lib/plugin.js',
51+
'typescript': 'npm:typescript@2.0.3/lib/typescript.js',
52+
53+
},
54+
// packages tells the System loader how to load when no filename and/or no extension
55+
packages: {
56+
app: {
57+
main: './main.ts',
58+
defaultExtension: 'ts'
59+
},
60+
rxjs: {
61+
defaultExtension: 'js'
62+
}
63+
}
64+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[{% for module, items in doc.data %}
2+
{% for item in items %}
3+
{
4+
"title": "{$ item.title $}",
5+
"path": "{$ item.exportDoc.path $}",
6+
"docType": "{$ item.docType $}",
7+
"stability": "{$ item.stability $}",
8+
"secure": "{$ item.security $}",
9+
"howToUse": "{$ item.howToUse | replace('"','\\"') $}",
10+
"whatItDoes": {% if item.whatItDoes %}"Exists"{% else %}"Not Done"{% endif %},
11+
"barrel" : "{$ module | replace("/index", "") $}"
12+
}{% if not loop.last %},{% endif %}
13+
{% endfor %}
14+
{% endfor %}
15+
]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
{%- for module, items in doc.data %}
3+
"{$ module | replace("/index", "") $}" : [{% for item in items %}
4+
{
5+
"title": "{$ item.title $}",
6+
"path": "{$ item.exportDoc.path $}",
7+
"docType": "{$ item.docType $}",
8+
"stability": "{$ item.stability $}",
9+
"secure": "{$ item.security $}",
10+
"barrel" : "{$ module | replace("/index", "") $}"
11+
}{% if not loop.last %},{% endif %}
12+
{% endfor %}]{% if not loop.last %},{% endif %}
13+
{% endfor -%}
14+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"currentEnvironment": {$ doc.currentEnvironment | json | trim $},
3+
"version": {$ doc.version.currentVersion | json | indent(2) | trim $},
4+
"sections": {$ doc.sections | json | indent(2) | trim $}
5+
}

0 commit comments

Comments
 (0)