Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

[WIP] docs(style-guide): add style-guide - v.4 #1180

Merged
merged 1 commit into from
Apr 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ var globby = require("globby");
var treeKill = require("tree-kill");
var blc = require("broken-link-checker");

var tslint = require('gulp-tslint');

// TODO:
// 1. Think about using runSequence
// 2. Think about using spawn instead of exec in case of long error messages.
Expand All @@ -45,6 +47,7 @@ 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'));


var _devguideShredOptions = {
examplesDir: path.join(DOCS_PATH, '_examples'),
fragmentsDir: path.join(DOCS_PATH, '_fragments'),
Expand Down Expand Up @@ -498,6 +501,20 @@ gulp.task('_zip-examples', function() {
});


// Linting

gulp.task('lint', function() {
return gulp.src(['./public/docs/_examples/style-guide/ts/**/*.ts', '!./public/docs/_examples/style-guide/ts/**/*.avoid.ts'])
.pipe(tslint({
rulesDirectory: ['node_modules/codelyzer'],
configuration: require('./tslint.json')
}))
.pipe(tslint.report('prose', {
summarizeFailureOutput: true
}));
});


// Helper functions

function harpCompile() {
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"harp": "harp",
"live-server": "live-server",
"test-api-builder": "jasmine-node tools/api-builder",

"protractor": "protractor"
},
"repository": {
Expand All @@ -28,10 +27,11 @@
"devDependencies": {
"archiver": "^0.16.0",
"assert-plus": "^0.1.5",
"broken-link-checker":"0.7.0",
"broken-link-checker": "0.7.0",
"browser-sync": "^2.9.3",
"canonical-path": "0.0.2",
"cross-spawn": "^2.1.0",
"codelyzer": "0.0.18",
"del": "^1.2.0",
"dgeni": "^0.4.0",
"dgeni-packages": "^0.11.1",
Expand All @@ -42,6 +42,7 @@
"gulp": "^3.5.6",
"gulp-env": "0.4.0",
"gulp-task-listing": "^1.0.1",
"gulp-tslint": "^4.3.5",
"gulp-util": "^3.0.6",
"gulp-watch": "^4.3.4",
"harp": "^0.20.3",
Expand All @@ -66,6 +67,7 @@
"protractor": "^3.0.0",
"q": "^1.4.1",
"tree-kill": "^1.0.0",
"tslint": "^3.2.2",
"typescript": "1.7.3",
"yargs": "^3.23.0"
},
Expand Down
25 changes: 6 additions & 19 deletions public/docs/_examples/style-guide/ts/01-01/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,16 @@
// #docplaster

// #docregion
/* recommended */

// app.component.ts
import { Component, OnInit } from 'angular2/core';
import { Component } from 'angular2/core';

import { Hero } from './hero';
import { HeroService } from './hero.service';
import { HeroesComponent } from './heroes/heroes.component';
import { HeroService } from './heroes/hero.service';

@Component({
selector: 'toh-app',
template: `
<pre>{{heroes | json}}</pre>
<toh-heroes></toh-heroes>
`,
styleUrls: ['app/app.component.css'],
directives: [HeroesComponent],
providers: [HeroService]
})
export class AppComponent implements OnInit{
heroes: Hero[] = [];

constructor(private heroService: HeroService) {}

ngOnInit() {
this.heroService.getHeroes()
.then(heroes => this.heroes = heroes);
}
}
export class AppComponent { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// #docregion
/* avoid */

import { bootstrap } from 'angular2/platform/browser';
import { Component, OnInit } from 'angular2/core';

class Hero {
id: number;
name: string;
}

@Component({
selector: 'my-app',
template: `
<h1>{{title}}</h1>
<pre>{{heroes | json}}</pre>
`,
styleUrls: ['app/app.component.css']
})
class AppComponent implements OnInit {
title = 'Tour of Heroes';

heroes: Hero[] = [];

ngOnInit() {
getHeroes().then(heroes => this.heroes = heroes);
}
}

bootstrap(AppComponent, []);

const HEROES: Hero[] = [
{id: 1, name: 'Bombasto'},
{id: 2, name: 'Tornado'},
{id: 3, name: 'Magneta'},
];

function getHeroes(): Promise<Hero[]> {
return Promise.resolve(HEROES); // TODO: get hero data from the server;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
// #docplaster

// #docregion
/* recommended */

export class Hero {
id: number;
name: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
// #docplaster

// #docregion
/* recommended */

import { Injectable } from 'angular2/core';
import { HEROES } from './mock-heroes';

import { HEROES } from './mock-heroes';

@Injectable()
export class HeroService {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// #docregion
import { Component, OnInit } from 'angular2/core';

import { Hero } from './hero.model';
import { HeroService } from './hero.service';

@Component({
selector: 'toh-heroes',
template: `
<pre>{{heroes | json}}</pre>
`
})
export class HeroesComponent implements OnInit {
heroes: Hero[] = [];

constructor(private heroService: HeroService) {}

ngOnInit() {
this.heroService.getHeroes()
.then(heroes => this.heroes = heroes);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// #docregion
import { Hero } from './hero.model';

export const HEROES: Hero[] = [
{id: 1, name: 'Bombasto'},
{id: 2, name: 'Tornado'},
{id: 3, name: 'Magneta'},
];
5 changes: 1 addition & 4 deletions public/docs/_examples/style-guide/ts/01-01/app/main.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// #docplaster

// #docregion
/* recommended */
import { bootstrap } from 'angular2/platform/browser';

import { bootstrap } from 'angular2/platform/browser';
import { AppComponent } from './app.component';

bootstrap(AppComponent, []);
93 changes: 0 additions & 93 deletions public/docs/_examples/style-guide/ts/01-01/app/placeholder.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// #docregion
/* avoid */

// HeroComponent is in the Tour of Heroes feature
@Component({
selector: 'hero'
})
export class HeroComponent {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// #docregion
import { Component } from 'angular2/core';

// #docregion example
@Component({
selector: 'toh-hero'
})
export class HeroComponent {}
// #enddocregion example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// #docregion
/* avoid */

// UsersComponent is in an Admin feature
@Component({
selector: 'users'
})
export class UsersComponent {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// #docregion
import { Component } from 'angular2/core';

// #docregion example
@Component({
selector: 'admin-users'
})
export class UsersComponent {}
// #enddocregion example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// #docregion
/* avoid */

@Directive({
selector: '[validate]'
})
export class ValidateDirective {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// #docregion
import { Directive } from 'angular2/core';

// #docregion example
@Directive({
selector: '[tohValidate]'
})
export class ValidateDirective {}
// #enddocregion example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!-- #docregion -->
<toh-hero-button></toh-hero-button>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// #docregion
/* avoid */

@Component({
selector: 'tohHeroButton'
})
export class HeroButtonComponent {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// #docregion
import { Component } from 'angular2/core';

// #docregion example
@Component({
selector: 'toh-hero-button'
})
export class HeroButtonComponent {}
// #enddocregion example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!-- #docregion -->
<toh-hero-button></toh-hero-button>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- #docregion -->
<!-- avoid -->
<div tohHeroButton></div>
Loading