diff --git a/rockspecs/awesomewm.d.tl-dev-1.rockspec b/rockspecs/awesomewm.d.tl-dev-1.rockspec index d91ae98..cc2af55 100644 --- a/rockspecs/awesomewm.d.tl-dev-1.rockspec +++ b/rockspecs/awesomewm.d.tl-dev-1.rockspec @@ -12,7 +12,6 @@ dependencies = { "lualogging 1.6.0", "inspect 3.1.3", "ansicolors 1.0.2", - "htmlparser 0.3.9", "web_sanitize 1.3.0", "penlight 1.13.1", "luasocket 3.1.0-1", diff --git a/src/awesomewm.d.tl/entities/Function_Info.lua b/src/awesomewm.d.tl/entities/Function_Info.lua new file mode 100644 index 0000000..956ac11 --- /dev/null +++ b/src/awesomewm.d.tl/entities/Function_Info.lua @@ -0,0 +1,23 @@ +local class = require "pl.class" +local List = require "pl.List" + +local Function_Info = class.Module_Doc() + +function Function_Info:_init() + self.name = "" + self.parameters = List() + self.return_types = List() +end + +function Function_Info:append_return_type(return_type) + self.return_types:append(return_type) +end + +function Function_Info:append_parameter(name, type) + self.parameters:append { + name = name, + type = type, + } +end + +return Function_Info diff --git a/src/awesomewm.d.tl/entities/Module_Doc.lua b/src/awesomewm.d.tl/entities/Module_Doc.lua new file mode 100644 index 0000000..48ddc31 --- /dev/null +++ b/src/awesomewm.d.tl/entities/Module_Doc.lua @@ -0,0 +1,12 @@ +local class = require "pl.class" +local List = require "pl.List" + +local Module_Doc = class.Module_Doc() + +function Module_Doc:_init() + self.constructors = List() + self.methods = List() + self.static_functions = List() +end + +return Module_Doc diff --git a/src/awesomewm.d.tl/entities/Module_Info.lua b/src/awesomewm.d.tl/entities/Module_Info.lua new file mode 100644 index 0000000..df163d9 --- /dev/null +++ b/src/awesomewm.d.tl/entities/Module_Info.lua @@ -0,0 +1,10 @@ +local class = require "pl.class" + +local Module_Info = class.Module_Info() + +function Module_Info:_init(name, uri) + self.name = name + self.uri = uri +end + +return Module_Info diff --git a/src/awesomewm.d.tl/init.lua b/src/awesomewm.d.tl/init.lua index decd5bb..686c1ee 100644 --- a/src/awesomewm.d.tl/init.lua +++ b/src/awesomewm.d.tl/init.lua @@ -3,19 +3,19 @@ local inspect = require "inspect" local log = require "logger" local properties = require "properties" local scraper = require "scraper" -local generator = require "generator" +-- local generator = require "generator" log:info( inspect { message = "Start extraction", base_url = properties.base_url } ) --- local index = crawler.fetch(properties.base_url .. properties.index_uri) --- local modules = scraper.get_modules_from_index( --- index, --- properties.ignored_modules --- ) +local index = crawler.fetch(properties.base_url .. properties.index_uri) --- log:info(inspect { modules_found = #modules }) +-- local modules = +-- scraper.get_modules_from_index(index, properties.ignored_modules) +local module_infos = scraper.module_info_list.get_modules_from_index(index) + +log:info(inspect { modules_found = #module_infos }) -- for i = 1, 1 do -- #modules do -- local m = modules[i] @@ -25,12 +25,15 @@ log:info( -- log:info(inspect { items }) -- end -local page = - crawler.fetch(properties.base_url .. "/widgets/wibox.widget.imagebox.html") -local items = scraper.get_doc_from_page(page) +local html = + crawler.fetch(properties.base_url .. "/widgets/wibox.widget.textbox.html") +local module_doc = scraper.module_doc.get_doc_from_page(html) +log:info(inspect { module_doc = module_doc }) + +-- local items = scraper.get_doc_from_page(page) -- log:info(inspect { items }) -generator.write( - generator.generate_teal(items), - properties.out_directory .. "/test.tl" -) +-- generator.write( +-- generator.generate_teal(items), +-- properties.out_directory .. "/test.tl" +-- ) diff --git a/src/awesomewm.d.tl/scraper/init.lua b/src/awesomewm.d.tl/scraper/init.lua index 6aa1cb2..77155e4 100644 --- a/src/awesomewm.d.tl/scraper/init.lua +++ b/src/awesomewm.d.tl/scraper/init.lua @@ -1,212 +1,5 @@ -local htmlparser = require "htmlparser" -local log = require "logger" -local utils = require "utils" - -local scraper = {} - -function scraper.get_modules_from_index(html, ignored) - local document = htmlparser.parse(html) - - local modules = utils.map(document "#navigation ul > li a", function(node) - return { - name = utils.sanitize_string(node:getcontent()), - uri = node.attributes.href, - } - end) - - local filtered_modules = utils.filter(modules, function(module) - return not utils.has_item(ignored, module.name) - end) - - return filtered_modules -end - -local function extract_first_node_or_fail(node, selector) - local extracted = node(selector)[1] - - if not extracted then - log:error { - message = "Can't find `" .. selector .. "` element!", - node = node:gettext(), - } - error "extract_first_node_or_fail" - end - - return extracted -end - -local function extract_first_node(node, selector) - local extracted = node(selector)[1] - - if not extracted then - return nil - end - - return extracted -end - -local function extract_inner_floating_text(node) - local html = node:getcontent() - - -- Remove inner tags from the html - for _, n in ipairs(node.nodes) do - html = utils.replace(html, n:gettext(), "") - end - - return utils.sanitize_string(html) -end - -local function extract_item_content_parameter_list(content) - for i, n in ipairs(content.nodes) do - -- The parameters