Skip to content

Commit

Permalink
Add config option 'excludeProtectionLevels'
Browse files Browse the repository at this point in the history
  • Loading branch information
fredericbonnet committed Nov 21, 2020
1 parent fe987ed commit 172ce94
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 10 deletions.
9 changes: 8 additions & 1 deletion packages/core/src/services/configuration.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export type ConfigurationOptions = {

/** Prefix string/regexp to ignore in index pages */
ignorePrefix: string;

/** Protection levels to exclude from output (e.g. "private") */
excludeProtectionLevels: string[];
};

/**
Expand Down Expand Up @@ -50,7 +53,11 @@ import defaultOptions from './default-options.json';
class ConfigurationServiceAdapter implements ConfigurationService {
constructor() {}

options: ConfigurationOptions = defaultOptions as ConfigurationOptions;
options: ConfigurationOptions = {
...defaultOptions,
// Fix strange issue with empty arrays being coalesced to never[]
excludeProtectionLevels: defaultOptions.excludeProtectionLevels as string[],
} as ConfigurationOptions;

getIgnoredPrefixRE() {
return new RegExp(`^(${this.options.ignorePrefix})`);
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/services/default-options.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"mdExtension": ".md",
"contentsSuffix": "_contents",
"indexSuffix": "_index",
"ignorePrefix": ""
"ignorePrefix": "",
"excludeProtectionLevels": []
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from '@seaborg/core';
import { CompoundKind, CompoundType } from '@seaborg/core/lib/models';
import { isString, isUndefined } from 'util';
import { visibleProtectionLevels } from '../../../helpers';
import { IndentedItem } from '..';

export const buildTree = (
Expand Down Expand Up @@ -41,7 +42,8 @@ export const buildTree = (
const children = pipe(
innerCompound,
map((refid: string) => doxygenIndex.compounds.find(withRefId(refid))),
filter(negate(isUndefined))
filter(negate(isUndefined)),
filter(visibleProtectionLevels)
)(compound) as CompoundType[];
return [self, ...children.flatMap(flatten(level + 1))];
};
Expand All @@ -55,7 +57,7 @@ export default (kind: CompoundKind, compounds: CompoundType[]) => {
} catch {
template = require('./default').default;
}
const result = template(kind, compounds);
const result = template(kind, compounds.filter(visibleProtectionLevels));

return result;
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CompoundKind, CompoundType } from '@seaborg/core/lib/models';
import { joinParagraphs } from '../../../helpers';
import { joinParagraphs, visibleProtectionLevels } from '../../../helpers';
import { compoundList } from '..';

/** Index entry template */
Expand All @@ -24,7 +24,7 @@ export default (kind: CompoundKind, compounds: CompoundType[]) => {
} catch {
template = require('./default').default;
}
const result = template(kind, compounds);
const result = template(kind, compounds.filter(visibleProtectionLevels));

return result;
};
8 changes: 6 additions & 2 deletions packages/markdown/src/doxygen-index/global/contents-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
joinParagraphs,
joinLines,
bulletItem,
visibleProtectionLevels,
} from '../../helpers';

/** Template for member title */
Expand All @@ -29,12 +30,15 @@ const compoundTitle = ({ name, refid, kind, title }: CompoundType) =>
const compoundItem = (compound: CompoundType) =>
joinLines([
bulletItem(compoundTitle(compound)),
...compound.members.map(memberItem),
...compound.members.filter(visibleProtectionLevels).map(memberItem),
]);

/** Main template */
const template = (compounds: CompoundType[]) =>
joinParagraphs(['# Contents', joinLines(compounds.map(compoundItem))]);
joinParagraphs([
'# Contents',
joinLines(compounds.filter(visibleProtectionLevels).map(compoundItem)),
]);

export default (index: DoxygenType) => {
const { compounds } = index;
Expand Down
15 changes: 13 additions & 2 deletions packages/markdown/src/doxygen-index/global/index-page.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { pipe, reduce, configuration } from '@seaborg/core';
import { pipe, reduce, configuration, filter } from '@seaborg/core';
import {
DoxygenType,
CompoundType,
Expand All @@ -9,7 +9,14 @@ import { DoxRefKind } from '../../doxygen';
import { labels as compoundLabels } from '../../doxygen/DoxCompoundKind';
import { labels as memberLabels } from '../../doxygen/DoxMemberKind';
import { uniqueBy, sortBy, groupBy, initial } from '../../operators';
import { bulletItem, joinLines, joinParagraphs, md, ref } from '../../helpers';
import {
bulletItem,
joinLines,
joinParagraphs,
md,
ref,
visibleProtectionLevels,
} from '../../helpers';

/** Template for reference item */
const referenceItem = ({ kind, refid, name, label }: Reference) =>
Expand All @@ -29,6 +36,7 @@ type Reference = {
refid: string;
name: string;
label: string;
prot?: string;
};

/** Get reference from compound */
Expand All @@ -37,6 +45,7 @@ const compoundReference = (compound: CompoundType): Reference => ({
refid: compound.refid,
name: compoundName(compound),
label: compoundLabels[compound.kind],
prot: compound.prot,
});

/** Get reference from member */
Expand All @@ -45,6 +54,7 @@ const memberReference = (member: MemberType): Reference => ({
refid: member.refid,
name: member.name as string,
label: memberLabels[member.kind],
prot: member.prot,
});

/** Get compound name */
Expand All @@ -66,6 +76,7 @@ const referenceKey = pipe(referenceName, stripPrefix, initial);

/** Build index from references */
const buildIndex = pipe(
filter(visibleProtectionLevels),
reduce(uniqueBy(referenceId), []),
sortBy(referenceName),
groupBy(referenceKey)
Expand Down
4 changes: 4 additions & 0 deletions packages/markdown/src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,7 @@ export const joinParagraphs = (paragraphs: any[]) =>

/** Pad single paragraph */
export const padParagraph = (s: string) => '\n' + s.trim() + '\n';

/** Filter out elements with excluded protection level */
export const visibleProtectionLevels = ({ prot }: any) =>
!prot || !configuration.options.excludeProtectionLevels.includes(prot);

0 comments on commit 172ce94

Please sign in to comment.