Skip to content

Commit

Permalink
feat: new funcs to see variables
Browse files Browse the repository at this point in the history
New function and new data file from running the converter.
  • Loading branch information
ryepup committed Jun 7, 2024
1 parent e17e6d1 commit 2fee1ee
Show file tree
Hide file tree
Showing 5 changed files with 1,108 additions and 67 deletions.
88 changes: 60 additions & 28 deletions reference-lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import reference from './src/reference.json'

export interface Directive {
name: string
module: string
description: string
syntax: string[]
contexts: string[]
isBlock: boolean
default: string
name: string
module: string
description: string
syntax: string[]
contexts: string[]
isBlock: boolean
default: string
}

export interface Variable {
name: string
module: string
description: string
}

export enum Format {
Expand Down Expand Up @@ -41,37 +47,63 @@ for (const modules of reference.modules) {
* Returns all the nginx directives
*
* @param: format: format of the return type HTML or markdown
*
* @return: an array of Directives
*/
export function getDirectives(format=Format.HTML): Directive[] {
const directives = reference.modules.flatMap((m) =>
m.directives.map((d) => ({...d, module: m.name})))
.map ((d) => ({
name: d.name,
module: d.module,
description: format === Format.HTML ? d.description_html : d.description_md,
syntax: format === Format.HTML ? d.syntax_html : d.syntax_md,
contexts: d.contexts,
isBlock: d.isBlock,
default: d.default
} as Directive))
return directives
export function getDirectives(format = Format.HTML): Directive[] {
const directives = reference.modules
.flatMap((m) => m.directives.map((d) => ({ ...d, module: m.name })))
.map(
(d) =>
({
name: d.name,
module: d.module,
description:
format === Format.HTML ? d.description_html : d.description_md,
syntax: format === Format.HTML ? d.syntax_html : d.syntax_md,
contexts: d.contexts,
isBlock: d.isBlock,
default: d.default,
} as Directive)
)
return directives
}

/**
* Returns all variables defined by any moduled
*
* @param: format: format of the return type HTML or markdown
* @return: an array of Variables
*/
export function getVariables(format = Format.HTML): Variable[] {
return reference.modules.flatMap(
(m) =>
m.variables?.map((v) => ({
name: v.name,
description:
format === Format.HTML ? v.description_html : v.description_md,
module: m.name,
})) ?? []
)
}

/**
* Returns the description corresponding to the directive name
* Returns the description corresponding to the directive or variable name
*
* @param: directive: directive name to find
* @param: module: optional name of module
* @param: format: format of the return type HTML or markdown
*
* @return: a string containing the description of the directive in xml or markdown format
*/
export function find(directive: string, module: string | undefined, format=Format.HTML): string | undefined {
const data =
module
? refDirectives.get(directive)?.find((d) => d.module.toUpperCase() === module.toUpperCase())
: refDirectives.get(directive)?.at(0)
return (format === Format.HTML ? data?.description_html : data?.description_md)
export function find(
directive: string,
module: string | undefined,
format = Format.HTML
): string | undefined {
const data = module
? refDirectives
.get(directive)
?.find((d) => d.module.toUpperCase() === module.toUpperCase())
: refDirectives.get(directive)?.at(0)
return format === Format.HTML ? data?.description_html : data?.description_md
}
2 changes: 1 addition & 1 deletion reference-lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nginx/reference-lib",
"version": "1.0.14",
"version": "1.1.0",
"description": "",
"main": "dist/index.js",
"type": "module",
Expand Down
29 changes: 16 additions & 13 deletions reference-lib/src/__mocks__/reference_mock.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
{"modules": [
{
"modules": [
{
"id": "/en/docs/http/ngx_http_access_module.html",
"name": "ngx_http_access_module",
"directives": [
{
"name": "allow",
"default": "",
"contexts": [
"http",
"server",
"location",
"limit_except"
],
"syntax_md": [
"*`address`* | *`CIDR`* | `unix:` | `all`"
],
"contexts": ["http", "server", "location", "limit_except"],
"syntax_md": ["*`address`* | *`CIDR`* | `unix:` | `all`"],
"syntax_html": [
"<p><em><code>address</code></em> | <em><code>CIDR</code></em> | <code>unix:</code> | <code>all</code></p>\n"
],
"isBlock": false,
"description_md": "Allows access for the specified network or address.",
"description_html": "\u003cp\u003eAllows access for the specified network or address\u003c/p\u003e"
}]
}]
}
}
],
"variables": [
{
"name": "$gzip_ratio",
"description_md": "achieved compression ratio, computed as the ratio between the\noriginal and compressed response sizes.",
"description_html": "<p>achieved compression ratio, computed as the ratio between the\noriginal and compressed response sizes.</p>\n"
}
]
}
]
}
Loading

0 comments on commit 2fee1ee

Please sign in to comment.