Skip to content

Commit

Permalink
Basic load .md files into viewer component.
Browse files Browse the repository at this point in the history
  • Loading branch information
Templarian committed Dec 30, 2016
1 parent 322e9b9 commit 9b20dbd
Show file tree
Hide file tree
Showing 92 changed files with 6,265 additions and 22 deletions.
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@ The [Material Design Icons](https://materialdesignicons.com) project has been gr

## Tech Stack

Pretty much starting this with the latest of everything. Angular2, ngAngular, Bootstrap4, TypeScript2.
Pretty much starting this with the latest of everything. Angular, ngAngular (Bootstrap 4), TypeScript2.

## Running Locally

Clone the project and install `angular-cli` globally. This will handle running the Angular project.

```
npm install angular-cli --global
npm install
ng serve
```

## Goals

Expand All @@ -26,8 +36,4 @@ Pretty much starting this with the latest of everything. Angular2, ngAngular, Bo

## API Endpoints

Below will document each public facing endpoint the system has and all the various query parameters each allows.

```text
api/
```
To view all the documented endpoints please open `src/content/api.md`.
5 changes: 4 additions & 1 deletion angular-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
"styles": [
"styles.scss"
],
"scripts": [],
"scripts": [
"assets/third-party/highlight/highlight.pack.js",
"../node_modules/remarkable/dist/remarkable.js"
],
"environments": {
"source": "environments/environment.ts",
"dev": "environments/environment.ts",
Expand Down
37 changes: 34 additions & 3 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ import { HttpModule } from '@angular/http';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { RouterModule, Routes } from '@angular/router';

// Statics
import 'rxjs/add/observable/throw';

// Operators
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/debounceTime';
import 'rxjs/add/operator/distinctUntilChanged';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/switchMap';
import 'rxjs/add/operator/toPromise';

import { AppComponent } from './app.component';
import { IconComponent } from './shared/icon/icon.component';
import { HeaderComponent } from './shared/header/header.component';
Expand All @@ -18,12 +29,28 @@ import { PageNotFoundComponent } from './pageNotFound/pageNotFound.component';
const appRoutes: Routes = [
//{ path: 'crisis-center', component: CrisisListComponent },
//{ path: 'hero/:id', component: HeroDetailComponent },
{
path: 'getting-started/angular',
component: ViewerComponent,
data: {
title: 'Getting Started - Angular',
file: 'content/getting-started-angular.md'
}
},
{
path: 'getting-started/angularjs',
component: ViewerComponent,
data: {
title: 'Getting Started - AngularJS',
file: 'content/getting-started-angularjs.md'
}
},
{
path: 'getting-started/web',
component: ViewerComponent,
data: {
title: 'Getting Started - Web',
file: 'content/getting-started-web'
file: 'content/getting-started-web.md'
}
},
{ path: '',
Expand All @@ -50,8 +77,12 @@ const appRoutes: Routes = [
NgbModule.forRoot(),
RouterModule.forRoot(appRoutes)
],
providers: [],
bootstrap: [AppComponent]
providers: [
// None
],
bootstrap: [
AppComponent
]
})
export class AppModule {

Expand Down
16 changes: 8 additions & 8 deletions src/app/shared/header/header.component.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<nav class="navbar navbar-light">
<div class="row">
<div class="col-md-4">
<a class="navbar-brand" href="#">
<a class="navbar-brand" routerLink="/" routerLinkActive="active">
<svg viewBox="0 0 24 24">
<path d="M2,2H8V4H16V2H22V8H20V16H22V22H16V20H8V22H2V16H4V8H2V2M16,8V6H8V8H6V16H8V18H16V16H18V8H16M4,4V6H6V4H4M18,4V6H20V4H18M4,18V20H6V18H4M18,18V20H20V18H18Z" />
</svg>
Expand All @@ -16,36 +16,36 @@
<li ngbDropdown class="nav-item dropdown">
<a ngbDropdownToggle class="nav-link dropdown-toggle" href="#" id="gettingStartedDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Getting Started</a>
<div class="dropdown-menu" aria-labelledby="gettingStartedDropdown">
<a class="dropdown-item" href="#">
<a class="dropdown-item" routerLink="/getting-started/android" routerLinkActive="active">
<mdi-icon [name]="'android'"></mdi-icon>
Android
<small>Vector Drawables</small>
</a>
<a class="dropdown-item" href="#">
<a class="dropdown-item" routerLink="/getting-started/angular" routerLinkActive="active">
<mdi-icon [name]="'angular'"></mdi-icon>
Angular
<small>Webfont / Component</small>
</a>
<a class="dropdown-item" href="#">
<a class="dropdown-item" routerLink="/getting-started/angularjs" routerLinkActive="active">
<mdi-icon [name]="'angularjs'"></mdi-icon>
AngularJS
<small>1.x Support</small>
</a>
<a class="dropdown-item" href="#">
<a class="dropdown-item" routerLink="/getting-started/bootstrap" routerLinkActive="active">
<mdi-icon [name]="'bootstrap'"></mdi-icon>
Bootstrap
<small>Webfont / Shim</small>
</a>
<a class="dropdown-item" href="#">
<a class="dropdown-item" routerLink="/getting-started/polymer" routerLinkActive="active">
<mdi-icon [name]="'polymer'"></mdi-icon>
Polymer
<small>v0.5 / v1.0 Supported</small>
</a>
<a class="dropdown-item" href="#">
<a class="dropdown-item" routerLink="/getting-started/webpack" routerLinkActive="active">
<mdi-icon [name]="'webpack'"></mdi-icon>
Webpack
</a>
<a class="dropdown-item" href="#">
<a class="dropdown-item" routerLink="/getting-started/web" routerLinkActive="active">
<mdi-icon [name]="'html'"></mdi-icon>
Web
<small>Helper Classes</small>
Expand Down
2 changes: 1 addition & 1 deletion src/app/viewer/viewer.component.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<div class="content"></div>
<div class="content" [innerHtml]="pageData">Loading...</div>
33 changes: 31 additions & 2 deletions src/app/viewer/viewer.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,39 @@
import { Component } from '@angular/core';
import { ActivatedRoute, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { ViewerService } from './viewer.service';

@Component({
selector: 'mdi-viewer',
templateUrl: './viewer.component.html',
styleUrls: ['./viewer.component.scss']
styleUrls: ['./viewer.component.scss'],
providers: [
ViewerService
]
})
export class ViewerComponent {


errorMessage: string;

constructor (public route: ActivatedRoute,
private viewerService: ViewerService) {

}

pageData: string = 'Loading...';

loadContent (data) {
this.viewerService.getMarkdownFileHtml(data.file)
.subscribe(v => this.pageData = v,
e => this.errorMessage = e);
}

ngOnInit() {
this.route
.data
.subscribe(x => this.loadContent(x))
}

ngOnDestroy() {
//this.sub.unsubscribe();
}
}
38 changes: 38 additions & 0 deletions src/app/viewer/viewer.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';

declare var Remarkable: any;

@Injectable()
export class ViewerService {

remarkable = new Remarkable();

constructor (private http: Http) {}

getMarkdownFileHtml (markdownFile: string): Observable<string> {
return this.http.get(markdownFile)
.map(res => this.extractData(res))
.catch(this.handleError);
}

private extractData(res: Response) {
return this.remarkable.render(res.text());
}

private handleError (error: Response | any) {
// In a real world app, we might use a remote logging infrastructure
let errMsg: string;
if (error instanceof Response) {
const body = error.json() || '';
const err = body.error || JSON.stringify(body);
errMsg = `${error.status} - ${error.statusText || ''} ${err}`;
} else {
errMsg = error.message ? error.message : error.toString();
}
console.error(errMsg);
return Observable.throw(errMsg);
}

}
24 changes: 24 additions & 0 deletions src/assets/third-party/highlight/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Copyright (c) 2006, Ivan Sagalaev
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of highlight.js nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2 changes: 2 additions & 0 deletions src/assets/third-party/highlight/highlight.pack.js

Large diffs are not rendered by default.

108 changes: 108 additions & 0 deletions src/assets/third-party/highlight/styles/agate.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*!
* Agate by Taufik Nurrohman <https://github.com/tovic>
* ----------------------------------------------------
*
* #ade5fc
* #a2fca2
* #c6b4f0
* #d36363
* #fcc28c
* #fc9b9b
* #ffa
* #fff
* #333
* #62c8f3
* #888
*
*/

.hljs {
display: block;
overflow-x: auto;
padding: 0.5em;
background: #333;
color: white;
}

.hljs-name,
.hljs-strong {
font-weight: bold;
}

.hljs-code,
.hljs-emphasis {
font-style: italic;
}

.hljs-tag {
color: #62c8f3;
}

.hljs-variable,
.hljs-template-variable,
.hljs-selector-id,
.hljs-selector-class {
color: #ade5fc;
}

.hljs-string,
.hljs-bullet {
color: #a2fca2;
}

.hljs-type,
.hljs-title,
.hljs-section,
.hljs-attribute,
.hljs-quote,
.hljs-built_in,
.hljs-builtin-name {
color: #ffa;
}

.hljs-number,
.hljs-symbol,
.hljs-bullet {
color: #d36363;
}

.hljs-keyword,
.hljs-selector-tag,
.hljs-literal {
color: #fcc28c;
}

.hljs-comment,
.hljs-deletion,
.hljs-code {
color: #888;
}

.hljs-regexp,
.hljs-link {
color: #c6b4f0;
}

.hljs-meta {
color: #fc9b9b;
}

.hljs-deletion {
background-color: #fc9b9b;
color: #333;
}

.hljs-addition {
background-color: #a2fca2;
color: #333;
}

.hljs a {
color: inherit;
}

.hljs a:focus,
.hljs a:hover {
color: inherit;
text-decoration: underline;
}
Loading

0 comments on commit 9b20dbd

Please sign in to comment.