summaryrefslogtreecommitdiff
path: root/docgen/keyref.lua
blob: 56311d9742cfe7387631ccf977867d2f0e84db30 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
local M = {}

local key_refs = {}

M.add = function(key, link, lang)
    local rfs = key_refs[lang]
    if not rfs then
        key_refs[lang] = {}
        rfs = key_refs[lang]
    end
    rfs[key] = link
end

M.build = function()
    local writer = require("docgen.writer")
    local dutil = require("docgen.util")
    for lang, rfs in pairs(key_refs) do
        local f = writer.Writer({ "ref", lang, "keyword-list" })
        local arr = {}
        for refn, v in pairs(rfs) do
            arr[#arr + 1] = refn
            local rf = writer.Writer({ "ref", lang, "key", refn })
            v[#v + 1] = true
            rf:write_include(rf.INCLUDE_PAGE, v)
            rf:finish()
        end
        table.sort(arr)
        f:write_raw(table.concat(arr, "\n"))
        f:write_nl()
        f:finish()
        local lf = writer.Writer({ "ref", lang, "keyword-link" })
        lf:write_raw("/", dutil.path_join(
            dutil.nspace_to_path(dutil.get_root_ns()),
            "ref", lang, "key", "{FNAME}"
        ))
        lf:write_nl()
        lf:finish()
    end
end

return M