Implement module section types "Signals" (#18) #23

Merged
Aire-One merged 5 commits from feat/#18 into master 2022-10-23 21:39:59 +02:00
2 changed files with 13 additions and 4 deletions
Showing only changes of commit 43cc531cc4 - Show all commits

View File

@ -9,6 +9,7 @@ local record Module_Doc
constructors: List<Function_Info.Function_Info> constructors: List<Function_Info.Function_Info>
methods: List<Function_Info.Function_Info> methods: List<Function_Info.Function_Info>
static_functions: List<Function_Info.Function_Info> static_functions: List<Function_Info.Function_Info>
signals: List<string>
end end
local __Module_Doc: metatable<Module_Doc> = { local __Module_Doc: metatable<Module_Doc> = {

View File

@ -8,6 +8,10 @@ local utils = require "utils"
local log = logger.log("scraper") local log = logger.log("scraper")
local function extract_node_text(node: scan.HTMLNode): string
return utils.sanitize_string(node:inner_text())
end
local function extract_function_name(function_name_node: scan.HTMLNode): string local function extract_function_name(function_name_node: scan.HTMLNode): string
return function_name_node and ((function_name_node.attr.name as string):gsub(".*:", "")) return function_name_node and ((function_name_node.attr.name as string):gsub(".*:", ""))
end end
@ -20,9 +24,7 @@ local function extract_function_return_types(function_return_types_node: scan.HT
local selector = "span.types .type" local selector = "span.types .type"
local html = function_return_types_node:outer_html() local html = function_return_types_node:outer_html()
return scraper_utils.scrape(html, selector, function(node: scan.HTMLNode): string return scraper_utils.scrape(html, selector, extract_node_text)
return utils.sanitize_string(node:inner_text())
end)
end end
local function extract_section_functions(dl: string): { Function_Info.Function_Info } local function extract_section_functions(dl: string): { Function_Info.Function_Info }
@ -50,6 +52,12 @@ local function extract_section_functions(dl: string): { Function_Info.Function_I
) )
end end
local function extract_section_signal(dl: string): { string }
local selector = "dt strong"
return scraper_utils.scrape(dl, selector, extract_node_text)
end
local module = {} local module = {}
function module.get_doc_from_page(html: string): Module_Doc.Module_Doc function module.get_doc_from_page(html: string): Module_Doc.Module_Doc
@ -80,7 +88,7 @@ function module.get_doc_from_page(html: string): Module_Doc.Module_Doc
elseif section_name == "Object methods" then elseif section_name == "Object methods" then
module_doc.methods = List(extract_section_functions(dl_html)) module_doc.methods = List(extract_section_functions(dl_html))
elseif section_name == "Signals" then elseif section_name == "Signals" then
log:warn("Not implemented: Signals") module_doc.signals = List(extract_section_signal(dl_html))
else else
error("Unknown section name: " .. section_name) error("Unknown section name: " .. section_name)
end end