Implement module section types "Static module functions" (#33) #48
|
@ -26,7 +26,12 @@ $(snippets.indent(snippets.render_record_properties(module.properties)))
|
||||||
# if #module.constructors ~= 0 then
|
# if #module.constructors ~= 0 then
|
||||||
-- Constructors
|
-- Constructors
|
||||||
$(snippets.indent(snippets.render_record_functions(module.constructors)))
|
$(snippets.indent(snippets.render_record_functions(module.constructors)))
|
||||||
|
|
||||||
# end -- /constructors
|
# end -- /constructors
|
||||||
|
# if #module.static_functions ~= 0 then
|
||||||
|
-- Static functions
|
||||||
|
$(snippets.indent(snippets.render_record_functions(module.static_functions)))
|
||||||
|
# end -- /static_functions
|
||||||
end
|
end
|
||||||
|
|
||||||
return $(module.record_name)
|
return $(module.record_name)
|
||||||
|
|
|
@ -115,28 +115,45 @@ end
|
||||||
|
|
||||||
local function extract_section_functions(dl: string): { Function_Info.Function_Info }
|
local function extract_section_functions(dl: string): { Function_Info.Function_Info }
|
||||||
local query_selectors = {
|
local query_selectors = {
|
||||||
function_name = "dt a",
|
header = "dt",
|
||||||
function_parameters = "dd table",
|
name = "a",
|
||||||
function_return_type = "dd ol",
|
body = "dd",
|
||||||
|
parameters = "table",
|
||||||
|
return_types = "ol",
|
||||||
}
|
}
|
||||||
|
|
||||||
return scraper_utils.scrape_tuples(
|
return scraper_utils.scrape_tuples(
|
||||||
dl,
|
dl,
|
||||||
{ query_selectors.function_name, query_selectors.function_parameters, query_selectors.function_return_type },
|
{ query_selectors.header, query_selectors.body },
|
||||||
function(nodes: { string : scan.HTMLNode | nil }): Function_Info.Function_Info
|
function(nodes: { string : scan.HTMLNode | nil }): Function_Info.Function_Info
|
||||||
local function_info = Function_Info()
|
if not nodes[query_selectors.header] or not nodes[query_selectors.body] then
|
||||||
|
log:warn(
|
||||||
function_info.name =
|
logger.message_with_metadata(
|
||||||
extract_item_name(nodes[query_selectors.function_name])
|
"Missing header or body",
|
||||||
function_info.parameters =
|
{ nodes = nodes }
|
||||||
List(extract_function_parameters(nodes[query_selectors.function_parameters]))
|
|
||||||
function_info.return_types = List(
|
|
||||||
extract_function_return_types(
|
|
||||||
nodes[query_selectors.function_return_type]
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
error("Missing header or body")
|
||||||
return function_info
|
end
|
||||||
|
local header = nodes[query_selectors.header] as scan.HTMLNode
|
||||||
|
local body = nodes[query_selectors.body] as scan.HTMLNode
|
||||||
|
local body_elements = scraper_utils.extract_nodes(
|
||||||
|
body:outer_html(),
|
||||||
|
{ query_selectors.parameters, query_selectors.return_types }
|
||||||
|
)
|
||||||
|
return {
|
||||||
|
name = scraper_utils.scrape(
|
||||||
|
header:outer_html(),
|
||||||
|
query_selectors.name,
|
||||||
|
extract_item_name
|
||||||
|
)[1],
|
||||||
|
parameters = #body_elements:get(query_selectors.parameters) ~= 0 and
|
||||||
|
List(extract_function_parameters(body_elements:get(query_selectors.parameters)[1])) or
|
||||||
|
(List() as List<Function_Info.Parameter>),
|
||||||
|
return_types = #body_elements:get(query_selectors.return_types) ~= 0 and
|
||||||
|
List(extract_function_return_types(body_elements:get(query_selectors.return_types)[1])) or
|
||||||
|
(List() as List<string>),
|
||||||
|
}
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue