From c1d59fef2476e56f4dacf3ac158fb0c797fd1a9e Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sun, 18 Aug 2019 16:37:17 -0400 Subject: [PATCH] doc: Build property indexes for more classes instead of only client. These index will be used for the rules documentation. --- awesomeConfig.cmake | 21 +++++++---- docs/_parser.lua | 72 ++++++++++++++++++++------------------ docs/build_rules_index.lua | 12 +++++-- 3 files changed, 62 insertions(+), 43 deletions(-) diff --git a/awesomeConfig.cmake b/awesomeConfig.cmake index 3cf42b11..5e341abc 100644 --- a/awesomeConfig.cmake +++ b/awesomeConfig.cmake @@ -382,21 +382,25 @@ add_custom_command( ${SOURCE_DIR}/docs/_parser.lua ) -add_custom_command( - OUTPUT ${BUILD_DIR}/docs/common/rules_index.ldoc +foreach(RULE_TYPE client tag screen notification) + add_custom_command( + OUTPUT ${BUILD_DIR}/docs/common/${RULE_TYPE}_rules_index.ldoc COMMAND lua ${SOURCE_DIR}/docs/build_rules_index.lua - ${BUILD_DIR}/docs/common/rules_index.ldoc + ${BUILD_DIR}/docs/common/${RULE_TYPE}_rules_index.ldoc + ${RULE_TYPE} # Cheap trick until the ldoc `configure_file` is ported to be a build # step rather than part of cmake. - COMMAND ${CMAKE_COMMAND} -E copy ${BUILD_DIR}/docs/common/rules_index.ldoc - ${SOURCE_DIR}/docs/common/rules_index.ldoc + COMMAND ${CMAKE_COMMAND} -E + copy ${BUILD_DIR}/docs/common/${RULE_TYPE}_rules_index.ldoc + ${SOURCE_DIR}/docs/common/${RULE_TYPE}_rules_index.ldoc DEPENDS lgi-check-run ${SOURCE_DIR}/docs/build_rules_index.lua ${SOURCE_DIR}/docs/_parser.lua -) + ) +endforeach() add_custom_command( OUTPUT ${BUILD_DIR}/awesomerc.lua ${BUILD_DIR}/docs/05-awesomerc.md @@ -423,7 +427,10 @@ add_custom_target(generate_awesomerc DEPENDS ${BUILD_DIR}/docs/06-appearance.md ${SOURCE_DIR}/docs/05-awesomerc.md.lua ${SOURCE_DIR}/docs/build_rules_index.lua - ${BUILD_DIR}/docs/common/rules_index.ldoc + ${BUILD_DIR}/docs/common/client_rules_index.ldoc + ${BUILD_DIR}/docs/common/tag_rules_index.ldoc + ${BUILD_DIR}/docs/common/screen_rules_index.ldoc + ${BUILD_DIR}/docs/common/notification_rules_index.ldoc ${SOURCE_DIR}/docs/sample_theme.lua ${SOURCE_DIR}/docs/sample_files.lua ${SOURCE_DIR}/awesomerc.lua diff --git a/docs/_parser.lua b/docs/_parser.lua index 8d2ed5ef..3b248881 100644 --- a/docs/_parser.lua +++ b/docs/_parser.lua @@ -131,47 +131,51 @@ local function parse_files(paths, property_name, matcher, name_matcher) local buffer = "" - for line in f:lines() do + if f then + for line in f and f:lines() do - local var = line:gmatch(exp1)() + local var = line:gmatch(exp1)() - -- There is no backward/forward pattern in lua - if #line <= 1 then - buffer = "" - elseif #buffer and not var then - buffer = buffer.."\n"..line - elseif line:sub(1,3) == "---" or line:sub(1,3) == "/**" then - buffer = line - end + -- There is no backward/forward pattern in lua + if #line <= 1 then + buffer = "" + elseif #buffer and not var then + buffer = buffer.."\n"..line + elseif line:sub(1,3) == "---" or line:sub(1,3) == "/**" then + buffer = line + end - if var then - -- Get the @param, @see and @usage - local params = "" - for line in f:lines() do - if line:sub(1,2) ~= "--" and line:sub(1,2) ~= " *" then - break - else - params = params.."\n"..line + if var then + -- Get the @param, @see and @usage + local params = "" + for line in f:lines() do + if line:sub(1,2) ~= "--" and line:sub(1,2) ~= " *" then + break + else + params = params.."\n"..line + end end - end - local name = var:gmatch(exp2)() - if not name then - print("WARNING:", var, - "seems to be misformatted. Use `beautiful.namespace_name`" - ) - else - table.insert(ret, { - file = file, - name = name:gsub("_", "\\_"), - link = get_link(file, var, var:match(exp3):gsub("_", "\\_")), - desc = buffer:gmatch("[-*/ \n]+([^\n.]*)")() or "", - mod = path_to_module(file), - }) - end + local name = var:gmatch(exp2)() + if not name then + print("WARNING:", var, + "seems to be misformatted. Use `beautiful.namespace_name`" + ) + else + table.insert(ret, { + file = file, + name = name:gsub("_", "_"), + link = get_link(file, var, var:match(exp3):gsub("_", "\\_")), + desc = buffer:gmatch("[-*/ \n]+([^\n.]*)")() or "", + mod = path_to_module(file), + }) + end - buffer = "" + buffer = "" + end end + + f:close() end end diff --git a/docs/build_rules_index.lua b/docs/build_rules_index.lua index 9e4cb6c6..163d5020 100644 --- a/docs/build_rules_index.lua +++ b/docs/build_rules_index.lua @@ -1,15 +1,23 @@ #! /usr/bin/lua local args = {...} +local typename = args[2] local parser = require("docs._parser") -local files = {"./objects/client.c", "./lib/awful/client.lua"} +assert(typename) + +local files = { + "./objects/"..typename..".c", + "./lib/awful/"..typename..".lua", + "./lib/naughty/"..typename..".lua" +} + local matcher, matcher2 = "(.*)", ".*" -- The client function comes from 5 different files, but all of those are -- merged into one documentation page (aka, awful.client doesn't have content -- anymore). This override the path so the parser doesn't have to be aware of it function parser.path_to_html() - return "../core_components/client.html#" + return "../core_components/"..typename..".html#" end local clientruleproperty = parser.parse_files(files, "clientruleproperty", matcher, matcher2)