-
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gherkin): added possibility to register custom flavors
- Loading branch information
Showing
10 changed files
with
346 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import ITokenMatcher from "../ITokenMatcher"; | ||
import {TokenType} from "../Parser"; | ||
import GherkinFlavor from "./GherkinFlavor"; | ||
|
||
/** | ||
* This class provides a way to extend the gherkin language by adding flavor implementations such as | ||
* AsciiDoc flavor or Markdown flavor. | ||
* | ||
*/ | ||
export default class CustomFlavorRegistry { | ||
private flavors: Array<GherkinFlavor>; | ||
|
||
constructor() { | ||
this.flavors = new Array<GherkinFlavor>(); | ||
} | ||
|
||
public registerFlavor(name: string, fileExtension: string, tokenMatcher: ITokenMatcher<TokenType>) { | ||
this.flavors.push(new GherkinFlavor(name, fileExtension, tokenMatcher)); | ||
} | ||
|
||
mediaTypeFor(uri: string): string { | ||
const flavor = this.flavors.find(flavor => uri.endsWith(flavor.fileExtension)) | ||
return flavor.mediaType; | ||
} | ||
|
||
tokenMatcherFor(sourceMediaType: string): ITokenMatcher<TokenType> { | ||
const flavor = this.flavors.find(flavor => flavor.mediaType === sourceMediaType); | ||
return flavor.tokenMatcher; | ||
} | ||
|
||
private static instance: CustomFlavorRegistry; | ||
public static getInstance() { | ||
if(!this.instance) { | ||
this.instance = new CustomFlavorRegistry(); | ||
} | ||
|
||
return this.instance; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import ITokenMatcher from "../ITokenMatcher"; | ||
import {TokenType} from "../Parser"; | ||
|
||
export default class GherkinFlavor { | ||
|
||
constructor(public name: string, public fileExtension: string, public tokenMatcher: ITokenMatcher<TokenType>) { | ||
|
||
} | ||
|
||
get mediaType(): string { | ||
return `text/x.cucumber.gherkin+${this.name}`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export type KeywordPrefixes = { | ||
BULLET: string, | ||
HEADER: string, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.