Skip to content
This repository has been archived by the owner on Feb 2, 2019. It is now read-only.

Commit

Permalink
feat(examples): add version service for accessing version.json data
Browse files Browse the repository at this point in the history
  • Loading branch information
justindujardin committed Dec 28, 2015
1 parent 380625e commit b52c83d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
13 changes: 10 additions & 3 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,6 @@ module.exports = function (grunt) {
smartypants: false
});

writeJson('public/version.json', {version: require('./package.json').version});

tasks.push(function buildCoverage() {
// Parse Lcov report and generate `coverage.json` file for site.
var parse = require('lcov-parse');
Expand Down Expand Up @@ -377,7 +375,7 @@ module.exports = function (grunt) {
});
});

tasks.push(function buildReadme() {
tasks.push(function buildReadmeFiles() {
glob("examples/components/**/readme.md", function (err, files) {
files.forEach(function parseDemo(readmeFile) {
var component = readableString(path.basename(path.dirname(readmeFile)));
Expand All @@ -388,6 +386,15 @@ module.exports = function (grunt) {
});
});

tasks.push(function buildProjectReadme() {
var rendered = marked(fs.readFileSync(path.join(__dirname, 'README.md')).toString());
writeJson('public/version.json', {
version: require('./package.json').version,
readme: rendered
});
next();
});

tasks.push(function buildExamples() {
glob("examples/components/**/*.html", function (err, files) {
files.forEach(function parseDemo(templateFile) {
Expand Down
3 changes: 2 additions & 1 deletion examples/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {Query} from "angular2/core";
import {QueryList} from "angular2/core";
import {NavigationService} from "./services/navigation";
import {AfterViewInit} from "angular2/core";
import {VersionService} from "./services/version";

//
// PLUNKR for ng2: http://plnkr.co/edit/UPJESEgyKFsm4hyW4fWR
Expand Down Expand Up @@ -63,6 +64,6 @@ export class DemosApp {

bootstrap(DemosApp, [
HTTP_PROVIDERS, ROUTER_PROVIDERS, MATERIAL_PROVIDERS,
ComponentsService, NavigationService,
ComponentsService, NavigationService, VersionService,
bind(LocationStrategy).toClass(HashLocationStrategy)
]);
1 change: 0 additions & 1 deletion examples/services/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export class ComponentsService {
http.get('public/meta.json')
.subscribe((res: Response) => {
this.components = res.json();
console.log(this.components);
resolve();
});

Expand Down
30 changes: 30 additions & 0 deletions examples/services/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {Injectable} from "angular2/core";
import {Http} from "angular2/http";
import {Response} from "angular2/http";

export interface IVersionMeta {
version:string;
readme:string;
}

@Injectable()
export class VersionService {
public meta: IVersionMeta = null;

private _promise: Promise<void>;

constructor(http: Http) {
this._promise = new Promise<void>((resolve) => {
http.get('public/version.json').subscribe((res: Response) => {
this.meta = res.json();
resolve();
});
});
}

getMeta(): Promise<IVersionMeta> {
return this._promise.then(() => {
return this.meta;
});
}
}

0 comments on commit b52c83d

Please sign in to comment.