Prepare extendability for the get_doc_from_page scraper method (#27) #73
|
@ -194,6 +194,38 @@ local function extract_section_signal(dl: string): { string }
|
||||||
return scraper_utils.scrape(dl, selector, extract_node_text)
|
return scraper_utils.scrape(dl, selector, extract_node_text)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local enum Section
|
||||||
|
"Constructors"
|
||||||
|
"Static module functions"
|
||||||
|
"Object properties"
|
||||||
|
"Object methods"
|
||||||
|
"Signals"
|
||||||
|
end
|
||||||
|
|
||||||
|
local section_scrapers: { Section : function(html: string, module_doc: Module_Doc.Module_Doc) } = {
|
||||||
|
["Constructors"] = function(html: string, module_doc: Module_Doc.Module_Doc)
|
||||||
|
module_doc.constructors = List(extract_section_functions(html))
|
||||||
|
end,
|
||||||
|
["Static module functions"] = function(html: string, module_doc: Module_Doc.Module_Doc)
|
||||||
|
module_doc.static_functions = List(extract_section_functions(html))
|
||||||
|
end,
|
||||||
|
["Object properties"] = function(html: string, module_doc: Module_Doc.Module_Doc)
|
||||||
|
module_doc.properties = List(extract_section_variables(html))
|
||||||
|
end,
|
||||||
|
["Object methods"] = function(html: string, module_doc: Module_Doc.Module_Doc)
|
||||||
|
local self_parameter = Variable_Info("self", List({ Type_Info(module_doc.record_name) }))
|
||||||
|
module_doc.methods = List(extract_section_functions(html)):map(
|
||||||
|
function(method: Function_Info.Function_Info): Function_Info.Function_Info
|
||||||
|
method.parameters:insert(1, self_parameter)
|
||||||
|
return method
|
||||||
|
end
|
||||||
|
)
|
||||||
|
end,
|
||||||
|
["Signals"] = function(html: string, module_doc: Module_Doc.Module_Doc)
|
||||||
|
module_doc.signals = List(extract_section_signal(html))
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
|
||||||
local module = {}
|
local module = {}
|
||||||
|
|
||||||
function module.get_doc_from_page(html: string, module_name: string): Module_Doc.Module_Doc
|
function module.get_doc_from_page(html: string, module_name: string): Module_Doc.Module_Doc
|
||||||
|
@ -209,31 +241,15 @@ function module.get_doc_from_page(html: string, module_name: string): Module_Doc
|
||||||
local module_doc = Module_Doc()
|
local module_doc = Module_Doc()
|
||||||
module_doc.record_name = utils.capitalize((module_name:gsub(".*%.", "")))
|
module_doc.record_name = utils.capitalize((module_name:gsub(".*%.", "")))
|
||||||
|
|
||||||
local self_type = Type_Info(module_doc.record_name)
|
|
||||||
local self_parameter = Variable_Info("self", List({ self_type }))
|
|
||||||
|
|
||||||
for i = 1, #nodes:get("h2.section-header") do
|
for i = 1, #nodes:get("h2.section-header") do
|
||||||
local h2 = nodes:get("h2.section-header")[i]
|
local h2 = nodes:get("h2.section-header")[i]
|
||||||
local section_name = utils.sanitize_string(h2:inner_text())
|
local section_name = utils.sanitize_string(h2:inner_text()) as Section -- promote to Section, we then test if the section_name is in the table
|
||||||
local dl_html = nodes:get("dl.function")[i]:outer_html()
|
local dl_html = nodes:get("dl.function")[i]:outer_html()
|
||||||
|
|
||||||
if section_name == "Constructors" then
|
if section_scrapers[section_name] then
|
||||||
module_doc.constructors = List(extract_section_functions(dl_html))
|
section_scrapers[section_name](dl_html, module_doc)
|
||||||
elseif section_name == "Static module functions" then
|
|
||||||
module_doc.static_functions = List(extract_section_functions(dl_html))
|
|
||||||
elseif section_name == "Object properties" then
|
|
||||||
module_doc.properties = List(extract_section_variables(dl_html))
|
|
||||||
elseif section_name == "Deprecated object properties" then
|
|
||||||
log:warn("Not implemented: Deprecated object properties")
|
|
||||||
elseif section_name == "Object methods" then
|
|
||||||
module_doc.methods = List(extract_section_functions(dl_html)):map(function(method: Function_Info.Function_Info): Function_Info.Function_Info
|
|
||||||
method.parameters:insert(1, self_parameter)
|
|
||||||
return method
|
|
||||||
end)
|
|
||||||
elseif section_name == "Signals" then
|
|
||||||
module_doc.signals = List(extract_section_signal(dl_html))
|
|
||||||
else
|
else
|
||||||
log:warn("Unknown section name: " .. section_name)
|
log:warn("Section scraper not implemented: " .. section_name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue