Skip to content

Commit

Permalink
change linkable interface
Browse files Browse the repository at this point in the history
  • Loading branch information
frangio committed Jul 10, 2019
1 parent 27b45ed commit a4122ec
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 38 deletions.
10 changes: 5 additions & 5 deletions contract.hbs
@@ -1,23 +1,23 @@
## {{anchor}} `{{name}}`
## <span id="{{anchor}}"></span> `{{name}}`

{{{natspec.devdoc}}}

{{#functions}}
- [`{{name}}({{args}})`][{{slug}}]
- [`{{name}}({{args}})`][{{anchor}}]
{{/functions}}

{{#events}}
- [`{{name}}({{args}})`][{{slug}}]
- [`{{name}}({{args}})`][{{anchor}}]
{{/events}}
{{#ownFunctions}}

### {{anchor}} `{{name}}({{args}}){{#if outputs}}{{outputs}}{{/if}}` ({{visibility}})
### <span id="{{anchor}}"></span> `{{name}}({{args}}){{#if outputs}}{{outputs}}{{/if}}` ({{visibility}})

{{{natspec.devdoc}}}
{{/ownFunctions}}
{{#ownEvents}}

### {{anchor}} `{{name}}({{args}})`
### <span id="{{anchor}}"></span> `{{name}}({{args}})`

{{{natspec.devdoc}}}
{{/ownEvents}}
2 changes: 1 addition & 1 deletion prelude.hbs
@@ -1,3 +1,3 @@
{{#links}}
[{{target.slug}}]: {{relativePath}}#{{target.slug}}
[{{target.anchor}}]: {{relativePath}}#{{target.anchor}}
{{/links}}
4 changes: 2 additions & 2 deletions src/sitemap.test.ts
Expand Up @@ -88,12 +88,12 @@ test('links', t => {
t.is(links.length, 2);

const bar = links[0];
t.is(bar.target.label, 'Bar');
t.is(bar.target.name, 'Bar');
t.is(bar.path, 'sub1.md');
t.is(bar.relativePath, '');

const foo = links[1];
t.is(foo.target.label, 'Foo');
t.is(foo.target.name, 'Foo');
t.is(foo.path, 'sub2.md');
t.is(foo.relativePath, 'sub2.md');
});
Expand Down
50 changes: 20 additions & 30 deletions src/solidity.ts
@@ -1,7 +1,6 @@
import { flatten, uniqBy } from 'lodash';
import path from 'path';
import execall from 'execall';
import handlebars from 'handlebars';

type ContractTemplate = (contract: SolidityContract) => string;

Expand Down Expand Up @@ -60,23 +59,18 @@ class SolidityFile {
}
}

export abstract class Linkable {
abstract label: string;
abstract slug: string;

get anchor(): handlebars.SafeString {
return new handlebars.SafeString(`<span id="${this.slug}"></span>`);
}
export interface Linkable {
anchor: string;
name: string;
fullName: string;
}

export class SolidityContract extends Linkable {
export class SolidityContract implements Linkable {
constructor(
private readonly source: SoliditySource,
readonly file: SolidityFile,
private readonly astNode: solc.ast.ContractDefinition,
) {
super();
}
) { }

toHTML(): string {
return this.source.contractTemplate(this);
Expand All @@ -86,11 +80,11 @@ export class SolidityContract extends Linkable {
return this.astNode.name;
}

get slug(): string {
get fullName(): string {
return this.name;
}

get label(): string {
get anchor(): string {
return this.name;
}

Expand Down Expand Up @@ -145,26 +139,24 @@ export class SolidityContract extends Linkable {
}
}

class SolidityFunction extends Linkable {
class SolidityFunction implements Linkable {
constructor(
readonly contract: SolidityContract,
private readonly astNode: solc.ast.FunctionDefinition,
) {
super();
}
) { }

get name(): string {
const { name, kind } = this.astNode;
const isRegularFunction = kind === 'function';
return isRegularFunction ? name : kind;
}

get slug(): string {
return `${this.contract.name}-${slugSignature(this.signature)}`
get fullName(): string {
return `${this.contract.name}.${this.name}`
}

get label(): string {
return `${this.contract.name}.${this.name}`
get anchor(): string {
return `${this.contract.name}-${slugSignature(this.signature)}`
}

get args(): SolidityTypedVariable[] {
Expand Down Expand Up @@ -196,24 +188,22 @@ class SolidityFunction extends Linkable {
}
}

class SolidityEvent extends Linkable {
class SolidityEvent implements Linkable {
constructor(
readonly contract: SolidityContract,
private readonly astNode: solc.ast.FunctionDefinition,
) {
super();
}
) { }

get name(): string {
return this.astNode.name;
}

get slug(): string {
return `${this.contract.name}-${slugSignature(this.signature)}`
get fullName(): string {
return `${this.contract.name}.${this.name}`
}

get label(): string {
return `${this.contract.name}.${this.name}`
get anchor(): string {
return `${this.contract.name}-${slugSignature(this.signature)}`
}

get args(): SolidityTypedVariable[] {
Expand Down

0 comments on commit a4122ec

Please sign in to comment.