judomanager-affiliation-pattern-parser
v1.0.7
Published
Tool used for parsing and rendering judomanager affiliation patterns
Readme
Affiliation Pattern Parser
Tool used for parsing and rendering of affiliation patterns.
Installation
Add to project using npm :
npm install judomanager-affiliation-pattern-parserUsage
Simple example of using parser and renderer to render an instance of pattern:
// CONFIG - retreived using api/AffiliationPatternPlaceholderConfiguration endpoint
// ENVIRONMENT - either: graphics, portal or score_board
// IGNORE_UNSUPPORTED_PLACEHOLDERS - true or false
const parser = new AffiliationPatternParser(CONFIG, ENVIRONMENT, IGNORE_UNSUPPORTED_PLACEHOLDERS);
const renderer = new AffiliationPatternRenderer();
let smt;
try {
smt = parser.parse(pattern);
// model - represents object that holds all of the neccessary affiliation data. Structure dependes on configuration and environment
// USE_INTERNATIONAL_NAMES - true of false
let whiteJudokaHTML = renderer.renderAllInTwoLines(smt, model, "white", USE_INTERNATIONAL_NAMES);
let blueJudokaHTML = renderer.renderAllInTwoLines(smt, model, "blue", USE_INTERNATIONAL_NAMES);
} catch (err) {
// Use err to alert user what went wrong during parsing
}Renderer supports multiple functions to render affiliation pattern, that each handles how to render country a bit diffrently:
// Renders whole pattern in one line. Moves country entity to the beggining of the line
renderer.renderAllInLine(smt, model, judokaColor, USE_INTERNATIONAL_NAMES);
// Renders pattern in two line. First line is always for country entity, second line is the rest of the pattern
renderer.renderAllInTwoLines(smt, model, judokaColor, USE_INTERNATIONAL_NAMES);
// Renders whole pattern in one line, but ignores country entity
renderer.renderOnlyMain(smt, model, judokaColor, USE_INTERNATIONAL_NAMES);
// Renders only country entity and ignore the rest of the pattern
renderer.renderOnlyCountry(smt, model, judokaColor, USE_INTERNATIONAL_NAMES);
Custom Renderer
In case you want to create your own renderer use getRenderTree(smt, model, judoka_color) function of AffiliationPatternRenderer to obtain render tree, that you can than use as an input of your renderer.
Example:
const parser = new AffiliationPatternParser(CONFIG, ENVIRONMENT, IGNORE_UNSUPPORTED_PLACEHOLDERS);
const renderer = new AffiliationPatternRenderer();
const smt = parser.parse(pattern);
const judokaColor = "white";
const countryRenderMode = "seperate_line_first";
// Possible values for countryRenderMode are:
// ignore (Ignores country entity when rendering)
// same_line_normal (Renders pattern in one line, directly as it is written)
// same_line_first (Renders pattern in one line, but moves country entity at the beggining)
// seperate_line_first (Renders pattern in two lines. Country is always in the first line)
// only_country (Renders only country and ignores the rest of the pattern)
let renderTree = renderer.getRenderTree(smt, model, judokaColor, countryRenderMode);
// Example of render tree for '{country_image} {country_short} {club_image} - {club} ({region_short})'
// Use this render tree structure to easly implement your own renderer
// [
// {
// "type": "level",
// "children": [
// {
// "type": "image",
// "key": "country_image",
// "value": "https://cdn.judomanager.com/countries/flags/20x15/pol.png"
// },
// {
// "type": "space"
// },
// {
// "type": "string",
// "key": "country_short",
// "value": "POL"
// }
// ]
// },
// {
// "type": "level",
// "children": [
// {
// "type": "space"
// },
// {
// "type": "image",
// "key": "club_image",
// "value": "https://cdn.judomanager.com/clubs/club_3517.jpeg"
// },
// {
// "type": "space"
// },
// {
// "type": "string",
// "value": "-"
// },
// {
// "type": "space"
// },
// {
// "type": "string",
// "key": "club",
// "value": "ჯორჯია რუსთავი"
// },
// {
// "type": "space"
// },
// {
// "type": "string",
// "value": "("
// },
// {
// "type": "string",
// "key": "region_short",
// "value": "AKHG (ახლგ)"
// },
// {
// "type": "string",
// "value": ")"
// }
// ]
// }
// ]
