Skip to content

Commit

Permalink
feat(app): remove base html tag, file:// support
Browse files Browse the repository at this point in the history
fix #47, #35
[skip ci]
  • Loading branch information
vogloblinsky committed Feb 6, 2017
1 parent cceb933 commit 0e5227d
Show file tree
Hide file tree
Showing 12 changed files with 143 additions and 93 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ Options:
-V, --version output the version number
-p, --tsconfig [config] A tsconfig.json file
-d, --output [folder] Where to store the generated documentation
-b, --base [base] Base reference of html tag <base>
-y, --extTheme [file] External styling theme
-n, --name [name] Title documentation
-a, --assetsFolder [folder] External assets folder to copy in generated documentation folder
Expand Down
64 changes: 46 additions & 18 deletions src/app/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,14 @@ export class Application {
$markdownengine.getReadmeFile().then((readmeData: string) => {
this.configuration.addPage({
name: 'index',
context: 'readme'
context: 'readme',
depth: 1,
pageType: COMPODOC_DEFAULTS.PAGE_TYPES.ROOT
});
this.configuration.addPage({
name: 'overview',
context: 'overview'
context: 'overview',
pageType: COMPODOC_DEFAULTS.PAGE_TYPES.ROOT
});
this.configuration.mainData.readme = readmeData;
logger.info('README.md file found');
Expand Down Expand Up @@ -195,7 +198,9 @@ export class Application {
});
this.configuration.addPage({
name: 'modules',
context: 'modules'
context: 'modules',
depth: 1,
pageType: COMPODOC_DEFAULTS.PAGE_TYPES.ROOT
});
let i = 0,
len = this.configuration.mainData.modules.length;
Expand All @@ -205,7 +210,9 @@ export class Application {
path: 'modules',
name: this.configuration.mainData.modules[i].name,
context: 'module',
module: this.configuration.mainData.modules[i]
module: this.configuration.mainData.modules[i],
depth: 2,
pageType: COMPODOC_DEFAULTS.PAGE_TYPES.INTERNAL
});
}
}
Expand All @@ -221,7 +228,9 @@ export class Application {
path: 'pipes',
name: this.configuration.mainData.pipes[i].name,
context: 'pipe',
pipe: this.configuration.mainData.pipes[i]
pipe: this.configuration.mainData.pipes[i],
depth: 2,
pageType: COMPODOC_DEFAULTS.PAGE_TYPES.INTERNAL
});
}
}
Expand All @@ -237,7 +246,9 @@ export class Application {
path: 'classes',
name: this.configuration.mainData.classes[i].name,
context: 'class',
class: this.configuration.mainData.classes[i]
class: this.configuration.mainData.classes[i],
depth: 2,
pageType: COMPODOC_DEFAULTS.PAGE_TYPES.INTERNAL
});
}
}
Expand All @@ -252,7 +263,9 @@ export class Application {
path: 'interfaces',
name: this.configuration.mainData.interfaces[i].name,
context: 'interface',
interface: this.configuration.mainData.interfaces[i]
interface: this.configuration.mainData.interfaces[i],
depth: 2,
pageType: COMPODOC_DEFAULTS.PAGE_TYPES.INTERNAL
});
}
}
Expand All @@ -263,7 +276,9 @@ export class Application {

this.configuration.addPage({
name: 'miscellaneous',
context: 'miscellaneous'
context: 'miscellaneous',
depth: 1,
pageType: COMPODOC_DEFAULTS.PAGE_TYPES.ROOT
});
}

Expand All @@ -288,7 +303,9 @@ export class Application {
path: 'components',
name: that.configuration.mainData.components[i].name,
context: 'component',
component: that.configuration.mainData.components[i]
component: that.configuration.mainData.components[i],
depth: 2,
pageType: COMPODOC_DEFAULTS.PAGE_TYPES.INTERNAL
});
i++;
loop();
Expand Down Expand Up @@ -323,7 +340,9 @@ export class Application {
path: 'directives',
name: this.configuration.mainData.directives[i].name,
context: 'directive',
directive: this.configuration.mainData.directives[i]
directive: this.configuration.mainData.directives[i],
depth: 2,
pageType: COMPODOC_DEFAULTS.PAGE_TYPES.INTERNAL
});
}
}
Expand All @@ -340,7 +359,9 @@ export class Application {
path: 'injectables',
name: this.configuration.mainData.injectables[i].name,
context: 'injectable',
injectable: this.configuration.mainData.injectables[i]
injectable: this.configuration.mainData.injectables[i],
depth: 2,
pageType: COMPODOC_DEFAULTS.PAGE_TYPES.INTERNAL
});
}
}
Expand All @@ -351,7 +372,9 @@ export class Application {

this.configuration.addPage({
name: 'routes',
context: 'routes'
context: 'routes',
depth: 1,
pageType: COMPODOC_DEFAULTS.PAGE_TYPES.ROOT
});
}

Expand Down Expand Up @@ -543,7 +566,9 @@ export class Application {
name: 'coverage',
context: 'coverage',
files: files,
data: coverageData
data: coverageData,
depth: 1,
pageType: COMPODOC_DEFAULTS.PAGE_TYPES.ROOT
});
}

Expand Down Expand Up @@ -581,11 +606,14 @@ export class Application {
logger.error(errorMessage);
});
} else {
$searchEngine.generateSearchIndexJson(this.configuration.mainData.output);
if (this.configuration.mainData.assetsFolder !== '') {
this.processAssetsFolder();
}
this.processResources();
$searchEngine.generateSearchIndexJson(this.configuration.mainData.output).then(() => {
if (this.configuration.mainData.assetsFolder !== '') {
this.processAssetsFolder();
}
this.processResources();
}, (e) => {
logger.error(e);
});
}
};
loop();
Expand Down
2 changes: 2 additions & 0 deletions src/app/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ interface Page {
injectable?: any;
files?: any;
data?: any;
depth?: number;
pageType?: string;
}

interface IMainData {
Expand Down
15 changes: 15 additions & 0 deletions src/app/engines/html.engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as Handlebars from 'handlebars';
//import * as helpers from 'handlebars-helpers';
import { $dependenciesEngine } from './dependencies.engine';
import { extractLeadingText, splitLinkText } from '../../utils/link-parser';
import { COMPODOC_DEFAULTS } from '../../utils/defaults';

export class HtmlEngine {
cache: Object = {};
Expand Down Expand Up @@ -196,6 +197,20 @@ export class HtmlEngine {
return description;
});

Handlebars.registerHelper('relativeURL', function(depth, currentPageType, targetPageType) {
//console.log('relativeURL: ', depth, currentPageType, targetPageType);
// if depth 2 & type == internal, set on same level, otherwise go up
let result = '';
if (currentPageType === COMPODOC_DEFAULTS.PAGE_TYPES.INTERNAL && targetPageType === COMPODOC_DEFAULTS.PAGE_TYPES.ROOT) {
result = '../';
} else if (currentPageType === COMPODOC_DEFAULTS.PAGE_TYPES.INTERNAL && targetPageType === COMPODOC_DEFAULTS.PAGE_TYPES.INTERNAL) {
result = '../';
} else if (currentPageType === COMPODOC_DEFAULTS.PAGE_TYPES.ROOT && targetPageType === COMPODOC_DEFAULTS.PAGE_TYPES.ROOT) {
result = './';
}
return result;
});

Handlebars.registerHelper('functionSignature', function(method) {
const args = method.args.map(function(arg) {
var _result = $dependenciesEngine.find(arg.type);
Expand Down
29 changes: 21 additions & 8 deletions src/app/engines/search.engine.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as path from 'path';
import * as fs from 'fs-extra';
import * as Handlebars from 'handlebars';
import { logger } from '../../logger';
import { Configuration } from '../configuration';

Expand Down Expand Up @@ -45,13 +46,25 @@ export class SearchEngine {
this.getSearchIndex().add(doc);
}
generateSearchIndexJson(outputFolder) {
fs.writeJson(path.resolve(process.cwd() + path.sep + outputFolder + path.sep + 'search_index.json'), {
index: this.getSearchIndex(),
store: this.documentsStore
}, function (err) {
if(err) {
logger.error('Error during search index file generation ', err);
}
});
return new Promise((resolve, reject) => {
fs.readFile(path.resolve(__dirname + '/../src/templates/partials/search-index.hbs'), 'utf8', (err, data) => {
if (err) {
reject('Error during search index generation');
} else {
let template:any = Handlebars.compile(data),
result = template({
index: JSON.stringify(this.getSearchIndex()),
store: JSON.stringify(this.documentsStore)
});
fs.writeFile(path.resolve(process.cwd() + path.sep + outputFolder + path.sep + '/js/search/search_index.js'), result, 'utf8', function (err) {
if(err) {
logger.error('Error during search index file generation ', err);
reject(err);
}
resolve();
});
}
});
});
}
};
5 changes: 0 additions & 5 deletions src/index-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export class CliApplication extends Application
.usage('<src> [options]')
.option('-p, --tsconfig [config]', 'A tsconfig.json file')
.option('-d, --output [folder]', 'Where to store the generated documentation (default: ./documentation)', COMPODOC_DEFAULTS.folder)
.option('-b, --base [base]', 'Base reference of html tag <base>', COMPODOC_DEFAULTS.base)
.option('-y, --extTheme [file]', 'External styling theme file')
.option('-n, --name [name]', 'Title documentation', COMPODOC_DEFAULTS.title)
.option('-a, --assetsFolder [folder]', 'External assets folder to copy in generated documentation folder')
Expand All @@ -52,10 +51,6 @@ export class CliApplication extends Application
this.configuration.mainData.output = program.output;
}

if (program.base) {
this.configuration.mainData.base = program.base;
}

if (program.extTheme) {
this.configuration.mainData.extTheme = program.extTheme;
}
Expand Down
16 changes: 3 additions & 13 deletions src/resources/js/search/search-lunr.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,9 @@
var that = this,
d = new promise.Promise();

$.ajax({
type: 'GET',
url: './search_index.json',
dataType: 'json',
success: function(data){
that.index = lunr.Index.load(data.index);
that.store = data.store;
d.done();
},
error: function(xhr, type){
console.error('Error loading search index json');
}
});
that.index = lunr.Index.load(COMPODOC_SEARCH_INDEX.index);
that.store = COMPODOC_SEARCH_INDEX.store;
d.done();

return d;
};
Expand Down
34 changes: 17 additions & 17 deletions src/templates/page.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>{{data.documentationMainName}}</title>
<meta name="description" content="">
<base href="{{data.base}}">
<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="icon" type="image/x-icon" href="./images/favicon.ico">
<link rel="stylesheet" href="./styles/style.css">
<link rel="icon" type="image/x-icon" href="{{relativeURL data.depth data.pageType 'root'}}/images/favicon.ico">
<link rel="stylesheet" href="{{relativeURL data.depth data.pageType 'root'}}/styles/style.css">
{{#if data.theme}}
{{#compare data.theme "!==" 'gitbook'}}
<link rel="stylesheet" href="./styles/{{data.theme}}.css">
<link rel="stylesheet" href="{{relativeURL data.depth data.pageType 'root'}}/styles/{{data.theme}}.css">
{{/compare}}
{{/if}}
</head>
<body>

<div class="navbar navbar-default navbar-fixed-top visible-xs">
<a href="./" class="navbar-brand">{{data.documentationMainName}}</a>
<a href="{{relativeURL data.depth data.pageType 'root'}}" class="navbar-brand">{{data.documentationMainName}}</a>
<button type="button" class="btn btn-default btn-menu fa fa-bars" id="btn-menu"></button>
</div>

Expand Down Expand Up @@ -109,22 +108,23 @@
</div>
</div>

<script src="./js/libs/bootstrap-native.js"></script>
<script src="{{relativeURL data.depth data.pageType 'root'}}/js/libs/bootstrap-native.js"></script>

<script src="./js/libs/es6-shim.min.js"></script>
<script src="./js/libs/EventDispatcher.js"></script>
<script src="./js/libs/promise.min.js"></script>
<script src="./js/libs/zepto.min.js"></script>
<script src="{{relativeURL data.depth data.pageType 'root'}}/js/libs/es6-shim.min.js"></script>
<script src="{{relativeURL data.depth data.pageType 'root'}}/js/libs/EventDispatcher.js"></script>
<script src="{{relativeURL data.depth data.pageType 'root'}}/js/libs/promise.min.js"></script>
<script src="{{relativeURL data.depth data.pageType 'root'}}/js/libs/zepto.min.js"></script>

<script src="./js/compodoc.js"></script>
<script src="{{relativeURL data.depth data.pageType 'root'}}/js/compodoc.js"></script>

<script src="./js/search/search.js"></script>
<script src="./js/search/lunr.min.js"></script>
<script src="./js/search/search-lunr.js"></script>
<script src="{{relativeURL data.depth data.pageType 'root'}}/js/search/search.js"></script>
<script src="{{relativeURL data.depth data.pageType 'root'}}/js/search/lunr.min.js"></script>
<script src="{{relativeURL data.depth data.pageType 'root'}}/js/search/search-lunr.js"></script>

<script src="./js/menu.js"></script>
<script src="./js/libs/highlight.pack.js"></script>
<script src="./js/libs/highlightjs-line-numbers.min.js"></script>
<script src="{{relativeURL data.depth data.pageType 'root'}}/js/menu.js"></script>
<script src="{{relativeURL data.depth data.pageType 'root'}}/js/libs/highlight.pack.js"></script>
<script src="{{relativeURL data.depth data.pageType 'root'}}/js/libs/highlightjs-line-numbers.min.js"></script>
<script src="{{relativeURL data.depth data.pageType 'root'}}/js/search/search_index.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
hljs.initHighlightingOnLoad();
Expand Down
Loading

0 comments on commit 0e5227d

Please sign in to comment.