WIP: awesomerc.tl
should work #85
|
@ -937,4 +937,39 @@ describe("Scrap documentation", function()
|
||||||
global = false,
|
global = false,
|
||||||
token = "module",
|
token = "module",
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
it("should produce Variable for content in the Fields section", test(
|
||||||
|
[[
|
||||||
|
<h2 class="section-header "><a name="Fields"></a>Fields</h2>
|
||||||
|
<dl class="function">
|
||||||
|
<dt>
|
||||||
|
<a class="copy-link js-copy-link" name="primary" href="#primary">🔗</a>
|
||||||
|
<strong><span class="function_modname">screen.</span>primary</strong>
|
||||||
|
<span class="proptype"><span class="summary_type">screen</span></span>
|
||||||
|
<span class="baseclass"></span>
|
||||||
|
</dt>
|
||||||
|
<dd></dd>
|
||||||
|
</dl>
|
||||||
|
]],
|
||||||
|
"field_variable",
|
||||||
|
{
|
||||||
|
children = {
|
||||||
|
{
|
||||||
|
children = {},
|
||||||
|
name = "Signal",
|
||||||
|
token = "enum",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name = "primary",
|
||||||
|
types = { "screen" },
|
||||||
|
token = "variable",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
name = "Field_variable",
|
||||||
|
module_path = "field_variable",
|
||||||
|
dependencies = {},
|
||||||
|
descendants = {},
|
||||||
|
global = false,
|
||||||
|
token = "module",
|
||||||
|
}))
|
||||||
end)
|
end)
|
||||||
|
|
|
@ -34,7 +34,7 @@ local function extract_item_name(item_name_node: scan.HTMLNode): string, string
|
||||||
end
|
end
|
||||||
local module_name_node <const> = scraper_utils.find(item_name_node:outer_html(), "span.function_modname")[1]
|
local module_name_node <const> = scraper_utils.find(item_name_node:outer_html(), "span.function_modname")[1]
|
||||||
local module_name = module_name_node and module_name_node:inner_text():gsub("[%.:]$", "")
|
local module_name = module_name_node and module_name_node:inner_text():gsub("[%.:]$", "")
|
||||||
local name <const> = item_name_node:inner_text():gsub("^.*[%.:](.+)%s*[%(%{].*[%)%}]", "%1")
|
local name <const> = item_name_node:inner_text():gsub("(.+)[%(%{].*$", "%1"):gsub("^.*[%.:](.+)", "%1")
|
||||||
return utils.sanitize_string(name), module_name and utils.sanitize_string(module_name) or nil
|
return utils.sanitize_string(name), module_name and utils.sanitize_string(module_name) or nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -174,11 +174,11 @@ local function extract_section_functions(dl: string, module_name: string | nil):
|
||||||
return functions, other_functions
|
return functions, other_functions
|
||||||
end
|
end
|
||||||
|
|
||||||
local function extract_section_variables(dl: string): { Node }, { string }
|
local function extract_section_variables(dl: string, with_constraint: boolean): { Node }, { string }
|
||||||
local query_selectors <const>: { string : string } = {
|
local query_selectors <const>: { string : string } = {
|
||||||
variable_name = "dt strong",
|
variable_name = "dt strong",
|
||||||
variable_summary_type = "dt span.summary_type",
|
variable_summary_type = "dt span.summary_type",
|
||||||
variable_property_constraint = "dd span.property_type",
|
variable_property_constraint = with_constraint and "dd span.property_type",
|
||||||
}
|
}
|
||||||
|
|
||||||
local variables <const>: { Node } = {}
|
local variables <const>: { Node } = {}
|
||||||
|
@ -194,11 +194,13 @@ local function extract_section_variables(dl: string): { Node }, { string }
|
||||||
if #node.types == 1 and node.types[1] == "string" then
|
if #node.types == 1 and node.types[1] == "string" then
|
||||||
log:debug("extract variable string with constraints, this is an enum", { name = node.name })
|
log:debug("extract variable string with constraints, this is an enum", { name = node.name })
|
||||||
local type_enum <const> = ast.create_node("enum", utils.capitalize(node.name))
|
local type_enum <const> = ast.create_node("enum", utils.capitalize(node.name))
|
||||||
for _, constraint in ipairs(extract_property_constraints(nodes[query_selectors.variable_property_constraint])) do
|
if with_constraint then
|
||||||
table.insert(
|
for _, constraint in ipairs(extract_property_constraints(nodes[query_selectors.variable_property_constraint])) do
|
||||||
type_enum.children,
|
table.insert(
|
||||||
ast.create_node("identifier", (constraint:gsub(""", "")))
|
type_enum.children,
|
||||||
)
|
ast.create_node("identifier", (constraint:gsub(""", "")))
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
if #type_enum.children == 0 then
|
if #type_enum.children == 0 then
|
||||||
log:debug("Enum has no children, get back to variable", { name = node.name })
|
log:debug("Enum has no children, get back to variable", { name = node.name })
|
||||||
|
@ -235,6 +237,7 @@ end
|
||||||
local enum Section
|
local enum Section
|
||||||
"Constructors"
|
"Constructors"
|
||||||
"Static module functions"
|
"Static module functions"
|
||||||
|
"Fields"
|
||||||
"Object properties"
|
"Object properties"
|
||||||
"Object methods"
|
"Object methods"
|
||||||
"Signals"
|
"Signals"
|
||||||
|
@ -259,8 +262,12 @@ local section_scrapers <total>: { Section : function(html: string, record_name:
|
||||||
local static_functions, other_functions = extract_section_functions(html, module_name)
|
local static_functions, other_functions = extract_section_functions(html, module_name)
|
||||||
return static_functions, other_functions, {}
|
return static_functions, other_functions, {}
|
||||||
end,
|
end,
|
||||||
|
["Fields"] = function(html: string): { Node }, { Node }, { string }
|
||||||
|
local fields = extract_section_variables(html)
|
||||||
|
return fields, {}, {}
|
||||||
|
end,
|
||||||
["Object properties"] = function(html: string): { Node }, { Node }, { string }
|
["Object properties"] = function(html: string): { Node }, { Node }, { string }
|
||||||
local properties, signals = extract_section_variables(html)
|
local properties, signals = extract_section_variables(html, true)
|
||||||
return properties, {}, signals
|
return properties, {}, signals
|
||||||
end,
|
end,
|
||||||
["Object methods"] = function(html: string, record_name: string): { Node }, { Node }, { string }
|
["Object methods"] = function(html: string, record_name: string): { Node }, { Node }, { string }
|
||||||
|
|
Loading…
Reference in New Issue