aboutsummaryrefslogtreecommitdiff
path: root/ldoc_json_filter.lua
diff options
context:
space:
mode:
Diffstat (limited to 'ldoc_json_filter.lua')
-rw-r--r--ldoc_json_filter.lua37
1 files changed, 37 insertions, 0 deletions
diff --git a/ldoc_json_filter.lua b/ldoc_json_filter.lua
new file mode 100644
index 0000000..33141cb
--- /dev/null
+++ b/ldoc_json_filter.lua
@@ -0,0 +1,37 @@
+local function get_labels(items)
+ local labels = {}
+ for _, item in ipairs(items) do
+ if item.items then
+ for _, label in ipairs(get_labels(item.items)) do
+ table.insert(labels, label)
+ end
+ else
+ local label = table.concat(item.names_hierarchy, '.')
+ table.insert(labels, label)
+ end
+ end
+ return labels
+end
+
+local function get_dir()
+ local dir = './doc'
+ for index, a in ipairs(arg) do
+ if a == '--dir' or a == '-d' then
+ dir = arg[index + 1]
+ end
+ end
+ return dir
+end
+
+return {
+ lua = function(doc)
+ local labels = get_labels(doc)
+ local file_path = get_dir() .. '/symbols.json'
+ local file, _ = io.open(file_path, 'w+')
+ if file then
+ local symbols = require 'dkjson'.encode(labels, { indent = true })
+ assert(file:write(symbols))
+ end
+ return false
+ end,
+}