Skip to content

Commit

Permalink
feat(app): ##648 Add style url data to component documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
danielleroux committed Oct 14, 2018
1 parent a8881b4 commit bcc0dcf
Show file tree
Hide file tree
Showing 13 changed files with 126 additions and 3 deletions.
64 changes: 64 additions & 0 deletions src/app/application.ts
Expand Up @@ -1239,6 +1239,37 @@ export class Application {
);
}

private handleStyleurl(component): Promise<any> {
let dirname = path.dirname(component.file);

let styleDataPromise = component.styleUrls.map((styleUrl) => {
let stylePath = path.resolve(dirname + path.sep + styleUrl);

if (!this.fileEngine.existsSync(stylePath)) {
let err = `Cannot read style for ${component.name}`;
logger.error(err);
return new Promise((resolve, reject) => {});
}

return new Promise((resolve, reject) => {
this.fileEngine.get(stylePath).then(data => {
resolve({
data,
styleUrl
});
});
});
});

return Promise.all(styleDataPromise).then(
data => (component.styleData = data),
err => {
logger.error(err);
return Promise.reject('');
}
);
}

private getNavTabs(dependency): Array<any> {
let navTabConfig = this.configuration.mainData.navTabConfig;
navTabConfig = navTabConfig.length === 0 ? _.cloneDeep(COMPODOC_CONSTANTS.navTabDefinitions) : navTabConfig;
Expand Down Expand Up @@ -1267,6 +1298,7 @@ export class Application {
if (customTab.id === 'readme' && !dependency.readme) { return; }
if (customTab.id === 'example' && !dependency.exampleUrls) { return; }
if (customTab.id === 'templateData' && (!dependency.templateUrl || dependency.templateUrl.length === 0)) { return; }
if (customTab.id === 'styleData' && (!dependency.styleUrls || dependency.styleUrls.length === 0)) { return; }

navTabs.push(navTab);
});
Expand Down Expand Up @@ -1360,6 +1392,22 @@ at least one config for the 'info' or 'source' tab in --navTabConfig.`);
i++;
loop();
}

if (component.styleUrls.length > 0) {
logger.info(` ${component.name} has a styleUrl, include it`);
this.handleStyleurl(component).then(
() => {
i++;
loop();
},
e => {
logger.error(e);
}
);
} else {
i++;
loop();
}
} else {
let page = {
path: 'components',
Expand Down Expand Up @@ -1390,6 +1438,22 @@ at least one config for the 'info' or 'source' tab in --navTabConfig.`);
i++;
loop();
}

if (component.styleUrls.length > 0) {
logger.info(` ${component.name} has a styleUrl, include it`);
this.handleStyleurl(component).then(
() => {
i++;
loop();
},
e => {
logger.error(e);
}
);
} else {
i++;
loop();
}
}
} else {
mainResolve();
Expand Down
1 change: 1 addition & 0 deletions src/app/configuration.ts
Expand Up @@ -45,6 +45,7 @@ export class Configuration implements ConfigurationInterface {
disableSourceCode: COMPODOC_DEFAULTS.disableSourceCode,
disableDomTree: COMPODOC_DEFAULTS.disableDomTree,
disableTemplateTab: COMPODOC_DEFAULTS.disableTemplateTab,
disableStyleTab: COMPODOC_DEFAULTS.disableStyleTab,
disableGraph: COMPODOC_DEFAULTS.disableGraph,
disableMainGraph: COMPODOC_DEFAULTS.disableMainGraph,
disableCoverage: COMPODOC_DEFAULTS.disableCoverage,
Expand Down
1 change: 1 addition & 0 deletions src/app/interfaces/main-data.interface.ts
Expand Up @@ -39,6 +39,7 @@ export interface MainDataInterface {
disableSourceCode: boolean;
disableDomTree: boolean;
disableTemplateTab: boolean;
disableStyleTab: boolean;
disableGraph: boolean;
disableMainGraph: boolean;
disableCoverage: boolean;
Expand Down
3 changes: 2 additions & 1 deletion src/index-cli.ts
Expand Up @@ -97,7 +97,7 @@ export class CliApplication extends Application {
'--navTabConfig <tab configs>',
`List navigation tab objects in the desired order with two string properties ("id" and "label"). \
Double-quotes must be escaped with '\\'. \
Available tab IDs are "info", "readme", "source", "templateData", "tree", and "example". \
Available tab IDs are "info", "readme", "source", "templateData", "styleData", "tree", and "example". \
Note: Certain tabs will only be shown if applicable to a given dependency`,
list,
JSON.stringify(COMPODOC_DEFAULTS.navTabConfig)
Expand Down Expand Up @@ -137,6 +137,7 @@ Note: Certain tabs will only be shown if applicable to a given dependency`,
)
.option('--disableDomTree', 'Do not add dom tree tab', false)
.option('--disableTemplateTab', 'Do not add template tab', false)
.option('--disableStyleTab', 'Do not add style tab', false)
.option('--disableGraph', 'Do not add the dependency graph', false)
.option('--disableCoverage', 'Do not add the documentation coverage report', false)
.option('--disablePrivate', 'Do not show private in generated documentation', false)
Expand Down
9 changes: 9 additions & 0 deletions src/templates/partials/component.hbs
Expand Up @@ -36,6 +36,15 @@
</div>
{{/isTabEnabled}}

{{#isTabEnabled navTabs "styleData"}}
<div class="tab-pane fade {{#isInitialTab navTabs "styleData"}}active in{{/isInitialTab}}" id="c-styleData">
{{#each component.styleData}}
<p>{{ styleUrl }}</p>
<pre class="line-numbers"><code class="language-scss">{{ data }}</code></pre>
{{/each}}
</div>
{{/isTabEnabled}}

{{#isTabEnabled navTabs "tree"}}
<div class="tab-pane fade {{#isInitialTab navTabs "tree"}}active in{{/isInitialTab}}" id="c-tree">
<div id="tree-container"></div>
Expand Down
7 changes: 7 additions & 0 deletions src/utils/constants.ts
Expand Up @@ -28,6 +28,13 @@ export const COMPODOC_CONSTANTS = {
'label': 'Template',
'depTypes': ['component']
},
{
'id': 'styleData',
'href': '#styleData',
'data-link': 'style',
'label': 'Style',
'depTypes': ['component']
},
{
'id': 'tree',
'href': '#tree',
Expand Down
1 change: 1 addition & 0 deletions src/utils/defaults.ts
Expand Up @@ -16,6 +16,7 @@ export const COMPODOC_DEFAULTS = {
disableSourceCode: false,
disableDomTree: false,
disableTemplateTab: false,
disableStyleTab: false,
disableGraph: false,
disableMainGraph: false,
disableCoverage: false,
Expand Down
1 change: 1 addition & 0 deletions test/src/bar.component.ts
Expand Up @@ -4,6 +4,7 @@ import { BarService } from './bar.service';
@Component({
selector: 'app-bar',
templateUrl: `bar.template.html`,
styleUrl: ['bar.style.scss']
providers: [BarService]

})
Expand Down
29 changes: 28 additions & 1 deletion test/src/cli/cli-generation.spec.ts
Expand Up @@ -717,7 +717,34 @@ describe('CLI simple generation', () => {
expect(index).to.not.contain('id="templateData-tab"');
});
});


describe('when generation with --disableStyleTab flag', () => {

let stdoutString = undefined,
index = undefined;
before(function (done) {
tmp.create(distFolder);
let ls = shell('node', [
'./bin/index-cli.js',
'-p', './test/src/sample-files/tsconfig.simple.json',
'--disableStyleTab',
'-d', distFolder]);

if (ls.stderr.toString() !== '') {
console.error(`shell error: ${ls.stderr.toString()}`);
done('error');
}
stdoutString = ls.stdout.toString();
done();
});
after(() => tmp.clean(distFolder));

it('should not contain style tab', () => {
index = read(`${distFolder}/components/BarComponent.html`);
expect(index).to.not.contain('id="styleData-tab"');
});
});

describe('when generation with --disableGraph flag', () => {

let stdoutString = undefined,
Expand Down
2 changes: 1 addition & 1 deletion test/src/cli/cli-options.spec.ts
Expand Up @@ -92,7 +92,7 @@ describe('CLI Options', () => {
expect(runHelp.stdout.toString()).to.contain(
`List navigation tab objects in the desired order with two string properties ("id" and "label"). \
Double-quotes must be escaped with '\\'. \
Available tab IDs are "info", "readme", "source", "templateData", "tree", and "example". \
Available tab IDs are "info", "readme", "source", "templateData", "styleData", "tree", and "example". \
Note: Certain tabs will only be shown if applicable to a given dependency`);
});

Expand Down
1 change: 1 addition & 0 deletions test/src/sample-files/bar.component.ts
Expand Up @@ -4,6 +4,7 @@ import { BarService } from './bar.service';
@Component({
selector: 'app-bar',
templateUrl: `bar.template.html`,
styleUrls: ['bar.style.scss', 'bar2.style.scss'],
providers: [BarService]

})
Expand Down
5 changes: 5 additions & 0 deletions test/src/sample-files/bar.style.scss
@@ -0,0 +1,5 @@
:host {
h1 {
background: red;
}
}
5 changes: 5 additions & 0 deletions test/src/sample-files/bar2.style.scss
@@ -0,0 +1,5 @@
:host {
.some-class {
background: blue;
}
}

0 comments on commit bcc0dcf

Please sign in to comment.