1 | "use strict";
|
2 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
3 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
4 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
5 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
6 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
7 | };
|
8 | var __metadata = (this && this.__metadata) || function (k, v) {
|
9 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
10 | };
|
11 | var core_1 = require('@angular/core');
|
12 | var http_1 = require('@angular/http');
|
13 | var _ = require('lodash');
|
14 | var jsdoc2md = require('jsdoc-to-markdown');
|
15 | var marked = require('marked');
|
16 | var ApiLoadResolve = (function () {
|
17 | function ApiLoadResolve(http) {
|
18 | this.http = http;
|
19 | }
|
20 | ApiLoadResolve.prototype.escapeAngularBindings = function (html) {
|
21 | return html.replace(/[{}]/g, function (match) {
|
22 | return '<span>{{ \'' + match + '\' }}</span>';
|
23 | });
|
24 | };
|
25 | ApiLoadResolve.prototype.resolve = function (route) {
|
26 | var routeData = route.data;
|
27 | if (routeData.isStaticApi) {
|
28 | var apiFile_1 = routeData.apiFile;
|
29 | console.log('Loading URL: ', apiFile_1.markdownFilePath);
|
30 | return this.http
|
31 | .get(apiFile_1.markdownFilePath)
|
32 | .map(function (res) { return res.text(); })
|
33 | .map(function (text) { return marked(text); })
|
34 | .map(this.escapeAngularBindings)
|
35 | .map(function (parsedDocs) {
|
36 | return {
|
37 | jsDoc: parsedDocs,
|
38 | apiName: apiFile_1.name
|
39 | };
|
40 | });
|
41 | }
|
42 | else {
|
43 | var apiFile_2 = routeData.apiFile;
|
44 | var apiDefinition = routeData.apiDefinition;
|
45 | var apiVersion = routeData.apiVersion;
|
46 | var repo_1 = apiFile_2.apiRepository || apiDefinition.apiRepository;
|
47 | var revision_1 = apiFile_2.revision || apiVersion.revision;
|
48 | var filePath_1 = apiFile_2.filePath || apiFile_2.mdFile;
|
49 | var url = 'https://raw.githubusercontent.com/' + repo_1 + '/' + revision_1 + '/' + filePath_1;
|
50 | if (filePath_1.charAt(0) === '/' && filePath_1.toLowerCase().indexOf('.md') > -1) {
|
51 | url = filePath_1;
|
52 | }
|
53 | return this.http
|
54 | .get(url)
|
55 | .map(function (res) { return res.text(); })
|
56 | .map(function (sourceCode) {
|
57 | var fileExt = _.last(filePath_1.split('.')).toLowerCase();
|
58 | if (fileExt === 'md') {
|
59 | return sourceCode;
|
60 | }
|
61 | return jsdoc2md.renderSync({ source: sourceCode, 'no-cache': true });
|
62 | })
|
63 | .map(function (text) { return marked(text); })
|
64 | .map(this.escapeAngularBindings)
|
65 | .map(function (parsedDocs) {
|
66 | return {
|
67 | jsDoc: parsedDocs,
|
68 | revision: revision_1,
|
69 | repo: repo_1,
|
70 | filePath: filePath_1,
|
71 | apiName: apiFile_2.apiTitle
|
72 | };
|
73 | });
|
74 | }
|
75 | };
|
76 | ApiLoadResolve = __decorate([
|
77 | core_1.Injectable(),
|
78 | __metadata('design:paramtypes', [http_1.Http])
|
79 | ], ApiLoadResolve);
|
80 | return ApiLoadResolve;
|
81 | }());
|
82 | exports.ApiLoadResolve = ApiLoadResolve;
|
83 |
|
\ | No newline at end of file |